-
-
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
feat(server): Accepting futures::Streams of connections, and turning the server into a future #1326
Conversation
…rver into a future
Hey there, thanks for starting this up! I do indeed want to add the ability to use any stream of connections, without having to use the tokio-proto stack, so this is definitely the right idea. I recently outlined in #1322 that shows a proposed API for using Additionally, while we would eventually want to get rid of the |
Hi! As I figured out with my second commit, the tests currently in master do not pass with my proposed change, so I guess we'll have to wait for 0.12. By the way, I like how the server code is structured. It's really short and clean. |
Not likely, 0.12 will probably be a little while, there's still some upstream changes to figure out with futures and tokio. However! We don't need to wait for 0.12. As I said, we can morph this into the API in #1322, and be able to release it in a 0.11.x release. What do you think of trying to do that? |
Sure. So since the API are necessarily different (some have their own The Another question I had was, why did you require anything to be |
I believe it can be done without duplicating too much code. For instance:
This was because we hoped to soon move the internal |
An added benefit of this approach is making it possible to implement HTTP over unix domain sockets. Having TCP baked in as it is currently would make that rather annoying! |
Master has seen some updates, adding a Thank you so much for exploring this! This helped figure out that |
@kamalmarhubi: interesting, yet I personally have no idea how user clients could browse a website via Unix domain sockets. What would the purpose of such a feature be? |
Here's a really direct application of allowing arbitrary streams: tests! Maybe you don't can't open ports on you machine, and you want to run the protocol inside buffers (or on unix domain sockets if you want to benchmark what gets sent to the kernel). |
This PR is maybe not meant to be accepted as such, but solves a number of problems for me:
I can now run my own event loop, and configure my socket as I want before, without having to resort to low-level functions. This was already possible before, at the price of code duplication between Hyper and my crate. This solves issues Http::new(core: &'a Core) #1075 and Http::bind does not scale to uses where a Handle is needed #1263.
I can now use the latest developments of rustls (for example their recent addition of SNI): since the server now takes an arbitrary stream of connections, one example use is to negotiate a TLS connection and passing it as a stream, like so:
Of course, it work fine on plain
TcpListener
s, and that's actually whatHttp::bind
does.Also, this PR does not change the existing API, except for:
local_addr
, which is now impossible to implement with the more general setting of arbitrary streams of connections instead of just Incoming.handle
, but this is now useless: if you need a handle, you might as well run your own event loop.