-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Closed
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
530e2dd
added TcpListener::bind_with_backlog to both sys_common and std::net
BartMassey 6f03b95
added UnixListener::bind_with_backlog and UnixListener::bind_addr_wit…
BartMassey a6ca55b
modified TcpListener and UnixListener tests to use with_backlog varia…
BartMassey 8643947
added issue numbers for with_backlog
BartMassey b98c009
unpublished listener DEFAULT_BACKLOGs
BartMassey 56ec493
added forgotten wasm bind_with_backlog stub
BartMassey 0b51968
added unsupported bind_with_backlog for wasi, l4re
BartMassey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -707,10 +707,53 @@ impl fmt::Debug for TcpStream { | |||||||||||||
} | ||||||||||||||
|
||||||||||||||
impl TcpListener { | ||||||||||||||
/// 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; | ||||||||||||||
|
||||||||||||||
/// Creates a new `TcpListener` which will be bound to the specified | ||||||||||||||
/// address. | ||||||||||||||
/// | ||||||||||||||
/// The returned listener is ready for accepting connections. | ||||||||||||||
/// The given backlog specifies the maximum number of outstanding | ||||||||||||||
/// connections that will be buffered in the OS waiting to be accepted by | ||||||||||||||
/// [`TcpListener::accept`]. The backlog argument overrides the default | ||||||||||||||
/// specified by [`TcpListener::DEFAULT_BACKLOG`]; that default is | ||||||||||||||
/// reasonable for most use cases. | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
/// | ||||||||||||||
/// This function is otherwise [`TcpListener::bind`]: see that | ||||||||||||||
/// documentation for full details of operation. | ||||||||||||||
/// | ||||||||||||||
/// # Examples | ||||||||||||||
/// | ||||||||||||||
/// Creates a TCP listener bound to `127.0.0.1:80` with a backlog of 1000: | ||||||||||||||
/// | ||||||||||||||
/// ```no_run | ||||||||||||||
/// #![feature(bind_with_backlog)] | ||||||||||||||
/// use std::net::TcpListener; | ||||||||||||||
/// | ||||||||||||||
/// let listener = TcpListener::bind_with_backlog("127.0.0.1:80", 1000).unwrap(); | ||||||||||||||
/// ``` | ||||||||||||||
/// | ||||||||||||||
/// # Errors | ||||||||||||||
/// | ||||||||||||||
/// The specified backlog may be larger than supported by the underlying | ||||||||||||||
/// system. In this case an [`io::Error`] with | ||||||||||||||
/// [`io::ErrorKind::InvalidData`] will be returned. | ||||||||||||||
#[unstable(feature = "bind_with_backlog", issue = "94406")] | ||||||||||||||
pub fn bind_with_backlog<A: ToSocketAddrs>(addr: A, backlog: usize) -> io::Result<TcpListener> { | ||||||||||||||
super::each_addr(addr, move |a| net_imp::TcpListener::bind_with_backlog(a, backlog)) | ||||||||||||||
.map(TcpListener) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/// Creates a new `TcpListener` which will be bound to the specified | ||||||||||||||
/// address. The returned listener is ready for accepting | ||||||||||||||
/// connections. | ||||||||||||||
/// | ||||||||||||||
/// The listener will have a backlog given by | ||||||||||||||
/// [`TcpListener::DEFAULT_BACKLOG`]. See the documentation for | ||||||||||||||
/// [`TcpListener::bind_with_backlog`] for further information. | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
/// | ||||||||||||||
/// Binding with a port number of 0 will request that the OS assigns a port | ||||||||||||||
/// to this listener. The port allocated can be queried via the | ||||||||||||||
|
@@ -748,7 +791,7 @@ impl TcpListener { | |||||||||||||
/// ``` | ||||||||||||||
#[stable(feature = "rust1", since = "1.0.0")] | ||||||||||||||
pub fn bind<A: ToSocketAddrs>(addr: A) -> io::Result<TcpListener> { | ||||||||||||||
super::each_addr(addr, net_imp::TcpListener::bind).map(TcpListener) | ||||||||||||||
Self::bind_with_backlog(addr, TcpListener::DEFAULT_BACKLOG) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/// Returns the local socket address of this listener. | ||||||||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 callbind
; 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 apub const
.