Skip to content

Commit

Permalink
std::net::bind using -1 for openbsd which in turn sets it to somaxconn.
Browse files Browse the repository at this point in the history
trusting platform's SOMAXCONN instead of hardcoding to 128 otherwise.
  • Loading branch information
devnexen committed Dec 20, 2023
1 parent 51c0db6 commit 743eb65
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion library/std/src/os/unix/net/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,15 @@ impl UnixListener {
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 };
if cfg!(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd")) {
-1
} else if cfg!(target_os = "redox") {
// redox's relibc defines as 128
// FIXME: adding to libc's crate
128
} else {
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 743eb65

Please sign in to comment.