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

feat(tcp): add support for custom socket options #2458

Closed
wants to merge 1 commit into from
Closed

feat(tcp): add support for custom socket options #2458

wants to merge 1 commit into from

Conversation

roman-kashitsyn
Copy link

This change extends to AddrIncoming API to support setting custom
options before binding the server socket. This change introduces one
such option: reuse_port, which enables the SO_REUSEPORT option on
the socket on UNIX platforms.

Example:

use hyper::server::conn::{AddrIncoming, SocketOptions};
let incoming = AddrIncoming::bind_with_option(
    "0.0.0.0:80".parse().unwrap(),
    SocketOptions::new().reuse_port(true)
);

This change extends to AddrIncoming API to support setting custom
options before binding the server socket.  This change introduces one
such option: `reuse_port`, which enables the `SO_REUSEPORT` option on
the socket on UNIX platforms.

Example:

    use hyper::server::conn::{AddrIncoming, SocketOptions};
    let incoming = AddrIncoming::bind_with_option(
        "0.0.0.0:80".parse().unwrap(),
        SocketOptions::new().reuse_port(true)
    );
@seanmonstar
Copy link
Member

Thanks for the PR! Is the motivation that you want to make these options more convenient in hyper? Since it's possible to construct a TcpListener and then use AddrIncoming::from_std, it should already be possible to be done outside of hyper, right?

@roman-kashitsyn
Copy link
Author

roman-kashitsyn commented Mar 10, 2021

Since it's possible to construct a TcpListener and then use AddrIncoming::from_std, it should already be possible to be done outside of hyper, right?

I don't think so, from_std is private at the moment (pub(super)). But if you're OK with making it public, I'll be totally happy with this solution.

@seanmonstar
Copy link
Member

Oh sorry, there's from_listener which is publicly available. It just requires you to convert to a tokio::net::TcpListener first.

@roman-kashitsyn
Copy link
Author

Oh sorry, there's from_listener which is publicly available. It just requires you to convert to a tokio::net::TcpListener first.

Indeed! I was using https://docs.rs/hyper/0.14.4/hyper/server/conn/struct.AddrIncoming.html as a reference and didn't think there is a solution to the socket configuring problem already. I can now see that it was merged just 2 weeks ago (#2439).

I'll close this PR and wait for the next release then.

Thanks a lot!

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.

2 participants