about summary refs log tree commit diff
path: root/library/std/src/sys_common/net.rs
diff options
context:
space:
mode:
authorAzureMarker <mark.drobnak@gmail.com>2021-12-29 17:53:55 -0500
committerMark Drobnak <mark.drobnak@gmail.com>2022-06-13 20:44:56 -0700
commitbe8b88f2b6929a09e0f147cd1fa027298f19cc5b (patch)
tree976024421189bdc4ac7650ababc70cc0c08c369c /library/std/src/sys_common/net.rs
parent4e808f87ccb706d339c9ea10c3c9a9c9fd7fc6cb (diff)
downloadrust-be8b88f2b6929a09e0f147cd1fa027298f19cc5b.tar.gz
rust-be8b88f2b6929a09e0f147cd1fa027298f19cc5b.zip
Lower listen backlog to fix accept crashes
See https://github.com/Meziu/rust-horizon/pull/1
Diffstat (limited to 'library/std/src/sys_common/net.rs')
-rw-r--r--library/std/src/sys_common/net.rs19
1 files changed, 13 insertions, 6 deletions
diff --git a/library/std/src/sys_common/net.rs b/library/std/src/sys_common/net.rs
index 7498e61d3d0..f5730a2cea5 100644
--- a/library/std/src/sys_common/net.rs
+++ b/library/std/src/sys_common/net.rs
@@ -398,13 +398,20 @@ impl TcpListener {
         let (addrp, len) = addr.into_inner();
         cvt(unsafe { c::bind(sock.as_raw(), addrp, len as _) })?;
 
-        // Start listening
-        #[cfg(not(target_os = "horizon"))]
-        cvt(unsafe { c::listen(sock.as_raw(), 128) })?;
-        // 40 is the maximum for Horizon OS
-        #[cfg(target_os = "horizon")]
-        cvt(unsafe { c::listen(sock.as_raw(), 40) })?;
+        cfg_if::cfg_if! {
+            if #[cfg(target_os = "horizon")] {
+                // The 3DS doesn't support a big connection backlog. Sometimes
+                // it allows up to about 37, but other times it doesn't even
+                // accept 32. There may be a global limitation causing this.
+                let backlog = 20;
+            } else {
+                // The default for all other platforms
+                let backlog = 128;
+            }
+        }
 
+        // Start listening
+        cvt(unsafe { c::listen(sock.as_raw(), backlog) })?;
         Ok(TcpListener { inner: sock })
     }