-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exposing current event loop handle to a service #1207
Comments
You can do something like this w/o modifying hyper: let mut core = Core::new().unwrap();
let handle2 = core.handle();
let listener = TcpListener::bind(&http_listen_addr, &handle2).unwrap();
let server = listener.incoming().for_each(|(sock, addr)| {
let s = MySuperService;
Http::new().bind_connection(&handle2, sock, addr, s);
Ok(())
});
core.run(server).unwrap(); Btw, I don't think tokio-file-unix does what you think it does. |
Ah, fair enough. I was worried that I would lose the goodness of What's your concern about tokio-file-unix? The docs say "Asynchronous support for file-like objects via Tokio", and a superficial look through its |
It doesn't work for regular files. |
I'm not sure what you mean by that. We have used it succesfully to read files from disk in our tests (using the code I pasted above), and it appeared to be behaving in a correctly asynchronous manner (judging by the response behaviour etc). This is on CentOS. By "doesn't work" do you mean it panics, or it appears to work but isn't fully asynchronous? |
OK, the answer to my original question seems to be that Hyper is fine, but the docs don't make it clear that if you want access to the handle, you must use Please could the docs be improved? As a newbie, I clicked through to I think those statements are a bit too strong.
|
@kw217 would you mind providing a small gist of what your final solution (with #1207 (comment)) looks like? I'm having troubles finding how to get back a reference to the |
Your service is a struct which implements the The key point is that you should construct the server the way #1207 (comment) does with |
There is #1322 opened which proposes a solution to the base problem encountered here. As such, I'm going to close this particular issue. |
OK, I'm happy to follow #1322 instead, as long as the docs are improved to make the new usage clear. |
Hi – I’m trying to get async file I/O working within a Hyper service, and I’m having trouble getting hold of the event loop handle. I’m not sure if I’m missing something obvious, or if there is something missing from hyper 0.11a0.
(This may be related to #1075, and maybe I’ve just confused myself by using the “easy mode” APIs. If so, perhaps some improved docs / examples of how and when to do things the non-easy way would be helpful.)
I recently wrote a little static file webserver in Rust, which serves the files using async I/O. The crate tokio-file-unix (0.4.0) supports async I/O; all I needed to do was:
However,
tokio_file_unix::File::into_reader
needs to be provided with atokio::reactor::handle
(a handle to the current event loop), which it ultimately passes totokio::reactor::PollEvented::new
.My problem is that I can’t see how to get hold of that handle!
As far as I can see,
hyper::server::Http::bind()
just passes anhttp::request::Request
to the enclosedtokio_service::Service
. There is no mention of handles.To work around this, I forked hyper and made the following change. As you can see, it does the following:
hyper::server::Http::bind_connection
now stores a clone of the currentHandle
in theHttpService
struct.Service
’sRequest
is now a pair(http::request::Request, tokio::reactor::Handle)
rather than just anhttp::request::Request
.HttpService::call
now passes a clone of theHandle
(from theHttpService
struct) to the service.That’s obviously not the right solution. Am I missing something obvious, or is there something missing from Hyper at the moment?
Thanks.
The text was updated successfully, but these errors were encountered: