Skip to content

Commit

Permalink
Rollup merge of #97963 - devnexen:net_listener_neg, r=the8472
Browse files Browse the repository at this point in the history
net listen backlog set to negative on Linux.

it will be 4076 (from 5.4) or 128.
  • Loading branch information
matthiaskrgr authored Aug 20, 2022
2 parents dd01122 + 5454bca commit d9789b6
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions library/std/src/os/unix/net/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,13 @@ impl UnixListener {
unsafe {
let inner = Socket::new_raw(libc::AF_UNIX, libc::SOCK_STREAM)?;
let (addr, len) = sockaddr_un(path.as_ref())?;
#[cfg(target_os = "linux")]
const backlog: libc::c_int = -1;
#[cfg(not(target_os = "linux"))]
const backlog: libc::c_int = 128;

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))
}
Expand Down Expand Up @@ -109,12 +113,16 @@ impl UnixListener {
pub fn bind_addr(socket_addr: &SocketAddr) -> io::Result<UnixListener> {
unsafe {
let inner = Socket::new_raw(libc::AF_UNIX, libc::SOCK_STREAM)?;
#[cfg(target_os = "linux")]
const backlog: libc::c_int = -1;
#[cfg(not(target_os = "linux"))]
const backlog: libc::c_int = 128;
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))
}
}
Expand Down

0 comments on commit d9789b6

Please sign in to comment.