Skip to content
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

add Server::from_tcp() #1624

Merged
merged 1 commit into from
Aug 8, 2018
Merged

add Server::from_tcp() #1624

merged 1 commit into from
Aug 8, 2018

Conversation

yoshuawuyts
Copy link
Contributor

@yoshuawuyts yoshuawuyts commented Aug 6, 2018

Heya 👋, this implements #1602. I'm pretty sure there's a few rough edges to this PR, but I wanted to kick things off anyway.

Questions

Error handling

The result type for from_tcp() is now:

Result<Builder<tokio_tcp::Incoming>, Box<dyn error::Error>> {

I wasn't sure what the best way to approach the errors was; any pointers here would be fantastic!

Runtime Features

I wasn't sure what the runtime features are for (no_std related perhaps?), but figured I'd follow the prior art and add them where it seemed appropriate.

Rustfmt

Rustfmt tends to run on every save; sorry if it changed things it shouldn't have. Happy to go back in and revert changes - but also happy to leave it if it doesn't matter 😁

Method name

I ended up going with .from_tcp() because I felt it was the most descriptive, but happy to change it to any other method if people feel that's more appropriate!

Tests

I only tested this on an example application to make sure it works. What would be the best way to test this?


Hope this is helpful! 🎉

@seanmonstar
Copy link
Member

Thanks for starting this!

Box<dyn error::Error>

This is likely the reason CI is failing, it's not compatible with the minimum supported Rust version. I'd change to returning hyper::Error, using hyper::Error::new_listen().

Runtime features

These enable tokio support, it can be disabled if people wish to use hyper with a different runtime.

Rustfmt

Last time I tried out rustfmt (admittedly a while ago), it broke some things. I've just pushed a .rustfmt.toml file to master that should disable rustfmt for everyone in hyper for now. When it's released stable, I'll re-enable it. That should also make it easier for you to work in the repo without making unrelated style changes.

Builder<tokio_tcp::Incoming>

This is probably fine! Or... I mean, maybe it could be converted to the internal AddrIncoming automatically, which could make it easier to eventually configure the extra features AddrIncoming provides? I'm uncertain.

@yoshuawuyts yoshuawuyts force-pushed the from_tcp branch 6 times, most recently from 6422474 to 10628d4 Compare August 7, 2018 14:15
@yoshuawuyts
Copy link
Contributor Author

Okay, updated the errors & rustfmt!

This is probably fine! Or... I mean, maybe it could be converted to the internal AddrIncoming automatically, which could make it easier to eventually configure the extra features AddrIncoming provides? I'm uncertain.

Hmm, I don't have enought background knowledge to comment on this. The only thing I know is that it'd be slightly harder to implement - but happy to do that if you think that's the right thing to do! - would probably need a bit of guidance on it though, haha.

Bar tests passing, I think this PR should be mostly done now! Are there any other things that need adding?

@@ -96,6 +106,19 @@ impl<I> Server<I, ()> {
}
}

impl Server<tokio_tcp::Incoming, ()> {
/// Create a new instance from a `std::net::TcpListener` instance.
#[cfg(feature = "runtime")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems CI noticed that this cfg should go on the impl instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, since this should change to convert into an AddrIncoming, this whole impl can just be merge with the one below it...

#[cfg(feature = "runtime")]
pub fn from_tcp(
listener: net::TcpListener,
) -> Result<Builder<tokio_tcp::Incoming>, ::Error> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about it some more, and I do think it makes sense to convert into the internal AddrIncoming type instead. The changes will be easy, and then anyone using it will be able to take advantage of the default improvements like sleeping when max FDs is reached.

The changes are to add a pub(super) fn from_tcp() to AddrIncomong. The new function can be split, such that after getting the std_listener, it just calls AddrIncoming::from_tcp internally. And then this function also can just call AddrIncoming::from_tcp(listener).

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey, I was about to send in a similar patch. I wrote hyper-tls-hack , an implementation of AddrIncoming that supports TLS using tokio-tls. It has a from_std_listener(std_listener: StdTcpListener,.... method, which I was about to split off and add to hyper's AddrIncoming. See the code here .

@yoshuawuyts yoshuawuyts force-pushed the from_tcp branch 4 times, most recently from b155ae7 to f6fae7f Compare August 8, 2018 13:18
Adds the `from_tcp()` method as per
hyperium#1602.

fix clippy changes
@yoshuawuyts
Copy link
Contributor Author

@seanmonstar updated the patch again with your feedback; hope this is good! ✨

@seanmonstar seanmonstar merged commit bb4c5e2 into hyperium:master Aug 8, 2018
@seanmonstar
Copy link
Member

Thank you! \o/

@yoshuawuyts yoshuawuyts deleted the from_tcp branch August 8, 2018 18:32
@yoshuawuyts
Copy link
Contributor Author

Yayay, so happy this landed! Thanks for all the help! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants