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 with_backlog functionality to TcpListener and UnixListener #94407

Closed
wants to merge 7 commits into from

Conversation

BartMassey
Copy link
Contributor

Adds

  • std::net::TcpListener::DEFAULT_BACKLOG
  • std::net::TcpListener::bind_with_backlog
  • std::os::unix::net::UnixListener::DEFAULT_BACKLOG
  • std::os::unix::net::UnixListener::bind_with_backlog
  • std::os::unix::net::UnixListener::bind_addr_with_backlog

Closes #94406

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @kennytm (or someone else) soon.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 26, 2022
Comment on lines 754 to 756
/// The listener will have a backlog given by
/// [`TcpListener::DEFAULT_BACKLOG`]. See the documentation for
/// [`TcpListener::bind_with_backlog`] for further information.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// The listener will have a backlog given by
/// [`TcpListener::DEFAULT_BACKLOG`]. See the documentation for
/// [`TcpListener::bind_with_backlog`] for further information.
/// The listener will have a backlog of 128. See the documentation
/// of [`TcpListener::bind_with_backlog`] for further information.

Comment on lines 721 to 723
/// [`TcpListener::accept`]. The backlog argument overrides the default
/// specified by [`TcpListener::DEFAULT_BACKLOG`]; that default is
/// reasonable for most use cases.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// [`TcpListener::accept`]. The backlog argument overrides the default
/// specified by [`TcpListener::DEFAULT_BACKLOG`]; that default is
/// reasonable for most use cases.
/// [`TcpListener::accept`]. The backlog argument overrides the default
/// backlog used by [`TcpListener::bind`]; that default works reasonably
/// for most use cases.

Comment on lines 710 to 715
/// Default "backlog" for [`TcpListener::bind`]. See
/// [`TcpListener::bind_with_backlog`] for an explanation of backlog
/// values.
#[unstable(feature = "bind_with_backlog", issue = "94406")]
pub const DEFAULT_BACKLOG: usize = 128;

Copy link
Member

@joshtriplett joshtriplett Feb 26, 2022

Choose a reason for hiding this comment

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

Suggested change
/// Default "backlog" for [`TcpListener::bind`]. See
/// [`TcpListener::bind_with_backlog`] for an explanation of backlog
/// values.
#[unstable(feature = "bind_with_backlog", issue = "94406")]
pub const DEFAULT_BACKLOG: usize = 128;

I think, rather than exposing this backlog as a constant, we can just document it. If people want to override it they can call bind_with_backlog; if they want to use the default they can call bind; if they want to have a default value for some configurable backlog parameter, they can determine an appropriate default themselves with our documentation for inspiration.

That said, this should absolutely be a const in this module, I just don't think it should be a pub const.

@BartMassey
Copy link
Contributor Author

Have unpublished DEFAULT_BACKLOG for listeners and adjusted the docs accordingly.

@joshtriplett
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Feb 27, 2022

📌 Commit b98c009 has been approved by joshtriplett

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 27, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Feb 27, 2022
…=joshtriplett

Add `with_backlog` functionality to `TcpListener` and `UnixListener`

Adds

* `std::net::TcpListener::DEFAULT_BACKLOG`
* `std::net::TcpListener::bind_with_backlog`
* `std::os::unix::net::UnixListener::DEFAULT_BACKLOG`
* `std::os::unix::net::UnixListener::bind_with_backlog`
* `std::os::unix::net::UnixListener::bind_addr_with_backlog`

Closes rust-lang#94406
@Dylan-DPC
Copy link
Member

failed in rollup on wasm

@Dylan-DPC
Copy link
Member

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 27, 2022
@BartMassey
Copy link
Contributor Author

@joshtriplett @Dylan-DPC Looks like I forgot a wasm stub somehow. Fixed.

@BartMassey
Copy link
Contributor Author

Actually, looks like I forgot a bunch more stuff. Pls hold until I fix the rest of them.

@BartMassey
Copy link
Contributor Author

What to do with platforms like sgx, sgx_fortanix and hermit that apparently support bind() but have no notion of backlog? I'm stuck for now.

@JohnCSimon
Copy link
Member

@BartMassey

Ping from triage: Can you please post the status of this PR? You can close it as inactive.
Thank you.

@BartMassey
Copy link
Contributor Author

Sure, let's call it inactive for now. I'll try again once I've sorted some stuff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ability to specify backlog size for TcpListener and UnixListener
7 participants