Skip to content

Commit

Permalink
Rollup merge of rust-lang#119026 - devnexen:listener_upd, r=Mark-Simu…
Browse files Browse the repository at this point in the history
…lacrum

std::net::bind using -1 for openbsd which in turn sets it to somaxconn.

trusting platform's SOMAXCONN instead of hardcoding to 128 otherwise.
  • Loading branch information
compiler-errors authored Jan 4, 2024
2 parents 3250798 + ce5af1c commit dab5f72
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions library/std/src/os/unix/net/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,18 @@ impl UnixListener {
unsafe {
let inner = Socket::new_raw(libc::AF_UNIX, libc::SOCK_STREAM)?;
let (addr, len) = sockaddr_un(path.as_ref())?;
const backlog: libc::c_int =
if cfg!(any(target_os = "linux", target_os = "freebsd")) { -1 } else { 128 };
#[cfg(any(target_os = "windows", target_os = "redox"))]
const backlog: libc::c_int = 128;
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"))]
const backlog: libc::c_int = -1;
#[cfg(not(any(
target_os = "windows",
target_os = "redox",
target_os = "linux",
target_os = "freebsd",
target_os = "openbsd"
)))]
const backlog: libc::c_int = libc::SOMAXCONN;

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(), backlog))?;
Expand Down

0 comments on commit dab5f72

Please sign in to comment.