From 530e2ddba6e029cb0e4ba9e7aba57ab2e3339f97 Mon Sep 17 00:00:00 2001 From: Bart Massey Date: Fri, 25 Feb 2022 12:59:08 -0800 Subject: [PATCH 1/7] added TcpListener::bind_with_backlog to both sys_common and std::net Also added TcpListener::DEFAULT_BACKLOG to document the default backlog (currently 128). --- library/std/src/net/tcp.rs | 46 +++++++++++++++++++++++++++++-- library/std/src/sys_common/net.rs | 12 ++++++-- 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/library/std/src/net/tcp.rs b/library/std/src/net/tcp.rs index cc4e4fd4fdc77..7f51196a6d0e3 100644 --- a/library/std/src/net/tcp.rs +++ b/library/std/src/net/tcp.rs @@ -707,10 +707,52 @@ 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 = "none")] + 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. + /// + /// 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 + /// 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 = "none")] + pub fn bind_with_backlog(addr: A, backlog: usize) -> io::Result { + 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. /// /// 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 +790,7 @@ impl TcpListener { /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn bind(addr: A) -> io::Result { - 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. diff --git a/library/std/src/sys_common/net.rs b/library/std/src/sys_common/net.rs index 70b29d4a92ed5..8eaa15af5fb3e 100644 --- a/library/std/src/sys_common/net.rs +++ b/library/std/src/sys_common/net.rs @@ -363,9 +363,17 @@ pub struct TcpListener { } impl TcpListener { - pub fn bind(addr: io::Result<&SocketAddr>) -> io::Result { + pub fn bind_with_backlog( + addr: io::Result<&SocketAddr>, + backlog: usize, + ) -> io::Result { let addr = addr?; + // Type-convert the backlog + let backlog = backlog + .try_into() + .map_err(|e| crate::io::Error::new(crate::io::ErrorKind::InvalidData, e))?; + init(); let sock = Socket::new(addr, c::SOCK_STREAM)?; @@ -385,7 +393,7 @@ impl TcpListener { cvt(unsafe { c::bind(sock.as_raw(), addrp, len as _) })?; // Start listening - cvt(unsafe { c::listen(sock.as_raw(), 128) })?; + cvt(unsafe { c::listen(sock.as_raw(), backlog) })?; Ok(TcpListener { inner: sock }) } From 6f03b9508392868f00bc0d280e53117e1867cde0 Mon Sep 17 00:00:00 2001 From: Bart Massey Date: Sat, 26 Feb 2022 11:19:12 -0800 Subject: [PATCH 2/7] added UnixListener::bind_with_backlog and UnixListener::bind_addr_with_backlog Also added UnixListener::DEFAULT_BACKLOG --- library/std/src/os/unix/net/listener.rs | 99 ++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 2 deletions(-) diff --git a/library/std/src/os/unix/net/listener.rs b/library/std/src/os/unix/net/listener.rs index b23dd6062f682..5b0ada5701b05 100644 --- a/library/std/src/os/unix/net/listener.rs +++ b/library/std/src/os/unix/net/listener.rs @@ -5,6 +5,7 @@ use crate::sys::cvt; use crate::sys::net::Socket; use crate::sys_common::{AsInner, FromInner, IntoInner}; use crate::{fmt, io, mem}; +use core::convert::TryInto; /// A structure representing a Unix domain socket server. /// @@ -53,8 +54,18 @@ impl fmt::Debug for UnixListener { } impl UnixListener { + /// Default "backlog" for [`UnixListener::bind`] and + /// [`UnixListener::bind_addr`]. See [`UnixListener::bind_with_backlog`] + /// for an explanation of backlog values. + #[unstable(feature = "bind_with_backlog", issue = "none")] + pub const DEFAULT_BACKLOG: usize = 128; + /// Creates a new `UnixListener` bound to the specified socket. /// + /// The listener will have a backlog given by + /// [`UnixListener::DEFAULT_BACKLOG`]. See the documentation for + /// [`UnixListener::bind_with_backlog`] for further information. + /// /// # Examples /// /// ```no_run @@ -70,12 +81,50 @@ impl UnixListener { /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn bind>(path: P) -> io::Result { + UnixListener::bind_with_backlog(path, UnixListener::DEFAULT_BACKLOG) + } + + /// Creates a new `UnixListener` bound to the specified socket. + /// + /// The given backlog specifies the maximum number of outstanding + /// connections that will be buffered in the OS waiting to be accepted by + /// [`UnixListener::accept`]. The backlog argument overrides the default + /// specified by [`UnixListener::DEFAULT_BACKLOG`]; that default is + /// reasonable for most use cases. + /// + /// This function is otherwise [`UnixListener::bind`]: see that + /// documentation for full details of operation. + /// + /// # Examples + /// + /// ```no_run + /// use std::os::unix::net::UnixListener; + /// + /// let listener = match UnixListener::bind_with_backlog("/path/to/the/socket", 1000) { + /// Ok(sock) => sock, + /// Err(e) => { + /// println!("Couldn't connect: {:?}", e); + /// return + /// } + /// }; + /// ``` + /// + /// # 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 = "none")] + pub fn bind_with_backlog>(path: P, backlog: usize) -> io::Result { unsafe { + let backlog = backlog + .try_into() + .map_err(|e| crate::io::Error::new(crate::io::ErrorKind::InvalidData, e))?; let inner = Socket::new_raw(libc::AF_UNIX, libc::SOCK_STREAM)?; let (addr, len) = sockaddr_un(path.as_ref())?; cvt(libc::bind(inner.as_inner().as_raw_fd(), &addr as *const _ as *const _, len as _))?; - cvt(libc::listen(inner.as_inner().as_raw_fd(), 128))?; + cvt(libc::listen(inner.as_inner().as_raw_fd(), backlog))?; Ok(UnixListener(inner)) } @@ -107,14 +156,60 @@ impl UnixListener { /// ``` #[unstable(feature = "unix_socket_abstract", issue = "85410")] pub fn bind_addr(socket_addr: &SocketAddr) -> io::Result { + UnixListener::bind_addr_with_backlog(socket_addr, UnixListener::DEFAULT_BACKLOG) + } + + /// Creates a new `UnixListener` bound to the specified [`socket address`]. + /// + /// The given backlog specifies the maximum number of outstanding + /// connections that will be buffered in the OS waiting to be accepted by + /// [`UnixListener::accept`]. The backlog argument overrides the default + /// specified by [`UnixListener::DEFAULT_BACKLOG`]; that default is + /// reasonable for most use cases. + /// + /// This function is otherwise [`UnixListener::bind_addr`]: see that + /// documentation for full details of operation. + /// + /// [`socket address`]: crate::os::unix::net::SocketAddr + /// + /// # Examples + /// + /// ```no_run + /// #![feature(unix_socket_abstract)] + /// #![feature(bind_with_backlog)] + /// use std::os::unix::net::{UnixListener}; + /// + /// fn main() -> std::io::Result<()> { + /// let listener1 = UnixListener::bind("path/to/socket")?; + /// let addr = listener1.local_addr()?; + /// + /// let listener2 = match UnixListener::bind_addr_with_backlog(&addr, 1000) { + /// Ok(sock) => sock, + /// Err(err) => { + /// println!("Couldn't bind: {:?}", err); + /// return Err(err); + /// } + /// }; + /// Ok(()) + /// } + /// ``` + //#[unstable(feature = "unix_socket_abstract", issue = "85410")] + #[unstable(feature = "bind_with_backlog", issue = "none")] + pub fn bind_addr_with_backlog( + socket_addr: &SocketAddr, + backlog: usize, + ) -> io::Result { unsafe { + let backlog = backlog + .try_into() + .map_err(|e| crate::io::Error::new(crate::io::ErrorKind::InvalidData, e))?; let inner = Socket::new_raw(libc::AF_UNIX, libc::SOCK_STREAM)?; cvt(libc::bind( inner.as_raw_fd(), &socket_addr.addr as *const _ as *const _, socket_addr.len as _, ))?; - cvt(libc::listen(inner.as_raw_fd(), 128))?; + cvt(libc::listen(inner.as_raw_fd(), backlog))?; Ok(UnixListener(inner)) } } From a6ca55bbd278cea6872d659fd9afe33acf707e09 Mon Sep 17 00:00:00 2001 From: Bart Massey Date: Sat, 26 Feb 2022 12:42:31 -0800 Subject: [PATCH 3/7] modified TcpListener and UnixListener tests to use with_backlog variants where appropriate --- library/std/src/net/tcp.rs | 1 + library/std/src/net/tcp/tests.rs | 32 +++++++++++++++++++++---- library/std/src/os/unix/net/listener.rs | 1 + library/std/src/os/unix/net/tests.rs | 10 ++++---- 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/library/std/src/net/tcp.rs b/library/std/src/net/tcp.rs index 7f51196a6d0e3..ca9a4a568bf76 100644 --- a/library/std/src/net/tcp.rs +++ b/library/std/src/net/tcp.rs @@ -730,6 +730,7 @@ impl TcpListener { /// 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(); diff --git a/library/std/src/net/tcp/tests.rs b/library/std/src/net/tcp/tests.rs index c2061c1351262..8ead0e31270fe 100644 --- a/library/std/src/net/tcp/tests.rs +++ b/library/std/src/net/tcp/tests.rs @@ -48,7 +48,7 @@ fn connect_error() { #[test] fn listen_localhost() { let socket_addr = next_test_ip4(); - let listener = t!(TcpListener::bind(&socket_addr)); + let listener = t!(TcpListener::bind_with_backlog(&socket_addr, 1)); let _t = thread::spawn(move || { let mut stream = t!(TcpStream::connect(&("localhost", socket_addr.port()))); @@ -64,7 +64,7 @@ fn listen_localhost() { #[test] fn connect_loopback() { each_ip(&mut |addr| { - let acceptor = t!(TcpListener::bind(&addr)); + let acceptor = t!(TcpListener::bind_with_backlog(&addr, 1)); let _t = thread::spawn(move || { let host = match addr { @@ -85,7 +85,7 @@ fn connect_loopback() { #[test] fn smoke_test() { each_ip(&mut |addr| { - let acceptor = t!(TcpListener::bind(&addr)); + let acceptor = t!(TcpListener::bind_with_backlog(&addr, 1)); let (tx, rx) = channel(); let _t = thread::spawn(move || { @@ -172,11 +172,33 @@ fn multiple_connect_serial() { }) } +#[test] +fn multiple_connect_serial_with_backlog() { + each_ip(&mut |addr| { + let max = 10; + let acceptor = t!(TcpListener::bind_with_backlog(&addr, max)); + + let _t = thread::spawn(move || { + for _ in 0..max { + let mut stream = t!(TcpStream::connect(&addr)); + t!(stream.write(&[99])); + } + }); + + for stream in acceptor.incoming().take(max) { + let mut stream = t!(stream); + let mut buf = [0]; + t!(stream.read(&mut buf)); + assert_eq!(buf[0], 99); + } + }) +} + #[test] fn multiple_connect_interleaved_greedy_schedule() { const MAX: usize = 10; each_ip(&mut |addr| { - let acceptor = t!(TcpListener::bind(&addr)); + let acceptor = t!(TcpListener::bind_with_backlog(&addr, MAX)); let _t = thread::spawn(move || { let acceptor = acceptor; @@ -213,7 +235,7 @@ fn multiple_connect_interleaved_greedy_schedule() { fn multiple_connect_interleaved_lazy_schedule() { const MAX: usize = 10; each_ip(&mut |addr| { - let acceptor = t!(TcpListener::bind(&addr)); + let acceptor = t!(TcpListener::bind_with_backlog(&addr, MAX)); let _t = thread::spawn(move || { for stream in acceptor.incoming().take(MAX) { diff --git a/library/std/src/os/unix/net/listener.rs b/library/std/src/os/unix/net/listener.rs index 5b0ada5701b05..52799335cdd94 100644 --- a/library/std/src/os/unix/net/listener.rs +++ b/library/std/src/os/unix/net/listener.rs @@ -98,6 +98,7 @@ impl UnixListener { /// # Examples /// /// ```no_run + /// #![feature(bind_with_backlog)] /// use std::os::unix::net::UnixListener; /// /// let listener = match UnixListener::bind_with_backlog("/path/to/the/socket", 1000) { diff --git a/library/std/src/os/unix/net/tests.rs b/library/std/src/os/unix/net/tests.rs index 7ad4a02611e07..b06cc4abc116c 100644 --- a/library/std/src/os/unix/net/tests.rs +++ b/library/std/src/os/unix/net/tests.rs @@ -41,7 +41,7 @@ fn basic() { let msg1 = b"hello"; let msg2 = b"world!"; - let listener = or_panic!(UnixListener::bind(&socket_path)); + let listener = or_panic!(UnixListener::bind_with_backlog(&socket_path, 1)); let thread = thread::spawn(move || { let mut stream = or_panic!(listener.accept()).0; let mut buf = [0; 5]; @@ -111,7 +111,7 @@ fn try_clone() { let msg1 = b"hello"; let msg2 = b"world"; - let listener = or_panic!(UnixListener::bind(&socket_path)); + let listener = or_panic!(UnixListener::bind_with_backlog(&socket_path, 1)); let thread = thread::spawn(move || { let mut stream = or_panic!(listener.accept()).0; or_panic!(stream.write_all(msg1)); @@ -135,7 +135,7 @@ fn iter() { let dir = tmpdir(); let socket_path = dir.path().join("sock"); - let listener = or_panic!(UnixListener::bind(&socket_path)); + let listener = or_panic!(UnixListener::bind_with_backlog(&socket_path, 2)); let thread = thread::spawn(move || { for stream in listener.incoming().take(2) { let mut stream = or_panic!(stream); @@ -423,7 +423,7 @@ fn test_abstract_stream_connect() { let msg2 = b"world"; let socket_addr = or_panic!(SocketAddr::from_abstract_namespace(b"namespace")); - let listener = or_panic!(UnixListener::bind_addr(&socket_addr)); + let listener = or_panic!(UnixListener::bind_addr_with_backlog(&socket_addr, 1)); let thread = thread::spawn(move || { let mut stream = or_panic!(listener.accept()).0; @@ -451,7 +451,7 @@ fn test_abstract_stream_connect() { #[test] fn test_abstract_stream_iter() { let addr = or_panic!(SocketAddr::from_abstract_namespace(b"hidden")); - let listener = or_panic!(UnixListener::bind_addr(&addr)); + let listener = or_panic!(UnixListener::bind_addr_with_backlog(&addr, 2)); let thread = thread::spawn(move || { for stream in listener.incoming().take(2) { From 86439473e24cc79efa11fcd588c1c5d0dcb65d7d Mon Sep 17 00:00:00 2001 From: Bart Massey Date: Sat, 26 Feb 2022 14:36:42 -0800 Subject: [PATCH 4/7] added issue numbers for with_backlog --- library/std/src/net/tcp.rs | 4 ++-- library/std/src/os/unix/net/listener.rs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/library/std/src/net/tcp.rs b/library/std/src/net/tcp.rs index ca9a4a568bf76..74060c79e5b3d 100644 --- a/library/std/src/net/tcp.rs +++ b/library/std/src/net/tcp.rs @@ -710,7 +710,7 @@ impl TcpListener { /// Default "backlog" for [`TcpListener::bind`]. See /// [`TcpListener::bind_with_backlog`] for an explanation of backlog /// values. - #[unstable(feature = "bind_with_backlog", issue = "none")] + #[unstable(feature = "bind_with_backlog", issue = "94406")] pub const DEFAULT_BACKLOG: usize = 128; /// Creates a new `TcpListener` which will be bound to the specified @@ -741,7 +741,7 @@ impl TcpListener { /// 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 = "none")] + #[unstable(feature = "bind_with_backlog", issue = "94406")] pub fn bind_with_backlog(addr: A, backlog: usize) -> io::Result { super::each_addr(addr, move |a| net_imp::TcpListener::bind_with_backlog(a, backlog)) .map(TcpListener) diff --git a/library/std/src/os/unix/net/listener.rs b/library/std/src/os/unix/net/listener.rs index 52799335cdd94..d1b09976cb490 100644 --- a/library/std/src/os/unix/net/listener.rs +++ b/library/std/src/os/unix/net/listener.rs @@ -57,7 +57,7 @@ impl UnixListener { /// Default "backlog" for [`UnixListener::bind`] and /// [`UnixListener::bind_addr`]. See [`UnixListener::bind_with_backlog`] /// for an explanation of backlog values. - #[unstable(feature = "bind_with_backlog", issue = "none")] + #[unstable(feature = "bind_with_backlog", issue = "94406")] pub const DEFAULT_BACKLOG: usize = 128; /// Creates a new `UnixListener` bound to the specified socket. @@ -115,7 +115,7 @@ impl UnixListener { /// 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 = "none")] + #[unstable(feature = "bind_with_backlog", issue = "94406")] pub fn bind_with_backlog>(path: P, backlog: usize) -> io::Result { unsafe { let backlog = backlog @@ -195,7 +195,7 @@ impl UnixListener { /// } /// ``` //#[unstable(feature = "unix_socket_abstract", issue = "85410")] - #[unstable(feature = "bind_with_backlog", issue = "none")] + #[unstable(feature = "bind_with_backlog", issue = "94406")] pub fn bind_addr_with_backlog( socket_addr: &SocketAddr, backlog: usize, From b98c009ef5bd3b64bbb73d3249a32f39fd83a719 Mon Sep 17 00:00:00 2001 From: Bart Massey Date: Sat, 26 Feb 2022 15:17:16 -0800 Subject: [PATCH 5/7] unpublished listener DEFAULT_BACKLOGs --- library/std/src/net/tcp.rs | 13 ++++-------- library/std/src/os/unix/net/listener.rs | 28 ++++++++++++------------- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/library/std/src/net/tcp.rs b/library/std/src/net/tcp.rs index 74060c79e5b3d..74f03ecaa2ff8 100644 --- a/library/std/src/net/tcp.rs +++ b/library/std/src/net/tcp.rs @@ -707,11 +707,8 @@ 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; + /// Default listen backlog. + const DEFAULT_BACKLOG: usize = 128; /// Creates a new `TcpListener` which will be bound to the specified /// address. @@ -719,8 +716,7 @@ impl TcpListener { /// 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. + /// value of 128; that default is reasonable for most use cases. /// /// This function is otherwise [`TcpListener::bind`]: see that /// documentation for full details of operation. @@ -751,8 +747,7 @@ impl TcpListener { /// address. The returned listener is ready for accepting /// connections. /// - /// The listener will have a backlog given by - /// [`TcpListener::DEFAULT_BACKLOG`]. See the documentation for + /// The listener will have a backlog of 128. See the documentation for /// [`TcpListener::bind_with_backlog`] for further information. /// /// Binding with a port number of 0 will request that the OS assigns a port diff --git a/library/std/src/os/unix/net/listener.rs b/library/std/src/os/unix/net/listener.rs index d1b09976cb490..71bea61fbe825 100644 --- a/library/std/src/os/unix/net/listener.rs +++ b/library/std/src/os/unix/net/listener.rs @@ -54,16 +54,12 @@ impl fmt::Debug for UnixListener { } impl UnixListener { - /// Default "backlog" for [`UnixListener::bind`] and - /// [`UnixListener::bind_addr`]. See [`UnixListener::bind_with_backlog`] - /// for an explanation of backlog values. - #[unstable(feature = "bind_with_backlog", issue = "94406")] - pub const DEFAULT_BACKLOG: usize = 128; + /// Default backlog for `bind` and `bind_addr`. + const DEFAULT_BACKLOG: usize = 128; /// Creates a new `UnixListener` bound to the specified socket. /// - /// The listener will have a backlog given by - /// [`UnixListener::DEFAULT_BACKLOG`]. See the documentation for + /// The listener will have a backlog of 128. See the documentation for /// [`UnixListener::bind_with_backlog`] for further information. /// /// # Examples @@ -87,10 +83,10 @@ impl UnixListener { /// Creates a new `UnixListener` bound to the specified socket. /// /// The given backlog specifies the maximum number of outstanding - /// connections that will be buffered in the OS waiting to be accepted by - /// [`UnixListener::accept`]. The backlog argument overrides the default - /// specified by [`UnixListener::DEFAULT_BACKLOG`]; that default is - /// reasonable for most use cases. + /// connections that will be buffered in the OS waiting to be accepted + /// by [`UnixListener::accept`]. The backlog argument overrides the + /// default backlog of 128; that default is reasonable for most use + /// cases. /// /// This function is otherwise [`UnixListener::bind`]: see that /// documentation for full details of operation. @@ -133,6 +129,9 @@ impl UnixListener { /// Creates a new `UnixListener` bound to the specified [`socket address`]. /// + /// The listener will have a backlog of 128. See the documentation for + /// [`UnixListener::bind_addr_with_backlog`] for further information. + /// /// [`socket address`]: crate::os::unix::net::SocketAddr /// /// # Examples @@ -163,10 +162,9 @@ impl UnixListener { /// Creates a new `UnixListener` bound to the specified [`socket address`]. /// /// The given backlog specifies the maximum number of outstanding - /// connections that will be buffered in the OS waiting to be accepted by - /// [`UnixListener::accept`]. The backlog argument overrides the default - /// specified by [`UnixListener::DEFAULT_BACKLOG`]; that default is - /// reasonable for most use cases. + /// connections that will be buffered in the OS waiting to be accepted + /// by [`UnixListener::accept`]. The backlog argument overrides the + /// default of 128; that default is reasonable for most use cases. /// /// This function is otherwise [`UnixListener::bind_addr`]: see that /// documentation for full details of operation. From 56ec4936884d7209ed5fa7f877c2c9c0d47217ed Mon Sep 17 00:00:00 2001 From: Bart Massey Date: Sun, 27 Feb 2022 18:13:18 -0800 Subject: [PATCH 6/7] added forgotten wasm bind_with_backlog stub --- library/std/src/sys/unsupported/net.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/library/std/src/sys/unsupported/net.rs b/library/std/src/sys/unsupported/net.rs index dbb6ce22c22de..a50b36b5fb322 100644 --- a/library/std/src/sys/unsupported/net.rs +++ b/library/std/src/sys/unsupported/net.rs @@ -122,6 +122,10 @@ impl TcpListener { unsupported() } + pub fn bind_with_backlog(_: io::Result<&SocketAddr>, _: usize) -> io::Result { + unsupported() + } + pub fn socket_addr(&self) -> io::Result { self.0 } From 0b51968bd74590b1952ae4ca0631d8f761f7147d Mon Sep 17 00:00:00 2001 From: Bart Massey Date: Sun, 27 Feb 2022 18:50:46 -0800 Subject: [PATCH 7/7] added unsupported bind_with_backlog for wasi, l4re --- library/std/src/sys/unix/l4re.rs | 4 ++++ library/std/src/sys/wasi/net.rs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/library/std/src/sys/unix/l4re.rs b/library/std/src/sys/unix/l4re.rs index d13e1ecbbfed4..c5efcccb5e0e5 100644 --- a/library/std/src/sys/unix/l4re.rs +++ b/library/std/src/sys/unix/l4re.rs @@ -276,6 +276,10 @@ pub mod net { unimpl!(); } + pub fn bind_with_backlog(_: io::Result<&SocketAddr>, _: usize) -> io::Result { + unimpl!(); + } + pub fn socket(&self) -> &Socket { &self.inner } diff --git a/library/std/src/sys/wasi/net.rs b/library/std/src/sys/wasi/net.rs index c66e0e4d328ad..cd66f0ff9caa4 100644 --- a/library/std/src/sys/wasi/net.rs +++ b/library/std/src/sys/wasi/net.rs @@ -205,6 +205,10 @@ impl TcpListener { unsupported() } + pub fn bind_with_backlog(_: io::Result<&SocketAddr>, _: usize) -> io::Result { + unsupported() + } + pub fn socket_addr(&self) -> io::Result { unsupported() }