Skip to content

Commit be8b88f

Browse files
committed
Lower listen backlog to fix accept crashes
See Meziu#1
1 parent 4e808f8 commit be8b88f

File tree

1 file changed

+13
-6
lines changed
  • library/std/src/sys_common

1 file changed

+13
-6
lines changed

library/std/src/sys_common/net.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -398,13 +398,20 @@ impl TcpListener {
398398
let (addrp, len) = addr.into_inner();
399399
cvt(unsafe { c::bind(sock.as_raw(), addrp, len as _) })?;
400400

401-
// Start listening
402-
#[cfg(not(target_os = "horizon"))]
403-
cvt(unsafe { c::listen(sock.as_raw(), 128) })?;
404-
// 40 is the maximum for Horizon OS
405-
#[cfg(target_os = "horizon")]
406-
cvt(unsafe { c::listen(sock.as_raw(), 40) })?;
401+
cfg_if::cfg_if! {
402+
if #[cfg(target_os = "horizon")] {
403+
// The 3DS doesn't support a big connection backlog. Sometimes
404+
// it allows up to about 37, but other times it doesn't even
405+
// accept 32. There may be a global limitation causing this.
406+
let backlog = 20;
407+
} else {
408+
// The default for all other platforms
409+
let backlog = 128;
410+
}
411+
}
407412

413+
// Start listening
414+
cvt(unsafe { c::listen(sock.as_raw(), backlog) })?;
408415
Ok(TcpListener { inner: sock })
409416
}
410417

0 commit comments

Comments
 (0)