diff options
Diffstat (limited to 'src/sys/unix/uds/listener.rs')
-rw-r--r-- | src/sys/unix/uds/listener.rs | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/src/sys/unix/uds/listener.rs b/src/sys/unix/uds/listener.rs index 79bd14e..3e33b30 100644 --- a/src/sys/unix/uds/listener.rs +++ b/src/sys/unix/uds/listener.rs @@ -7,19 +7,15 @@ use std::path::Path; use std::{io, mem}; pub(crate) fn bind(path: &Path) -> io::Result<net::UnixListener> { - let socket = new_socket(libc::AF_UNIX, libc::SOCK_STREAM)?; let (sockaddr, socklen) = socket_addr(path)?; let sockaddr = &sockaddr as *const libc::sockaddr_un as *const libc::sockaddr; - syscall!(bind(socket, sockaddr, socklen)) - .and_then(|_| syscall!(listen(socket, 1024))) - .map_err(|err| { - // Close the socket if we hit an error, ignoring the error from - // closing since we can't pass back two errors. - let _ = unsafe { libc::close(socket) }; - err - }) - .map(|_| unsafe { net::UnixListener::from_raw_fd(socket) }) + let fd = new_socket(libc::AF_UNIX, libc::SOCK_STREAM)?; + let socket = unsafe { net::UnixListener::from_raw_fd(fd) }; + syscall!(bind(fd, sockaddr, socklen))?; + syscall!(listen(fd, 1024))?; + + Ok(socket) } pub(crate) fn accept(listener: &net::UnixListener) -> io::Result<(UnixStream, SocketAddr)> { @@ -45,10 +41,7 @@ pub(crate) fn accept(listener: &net::UnixListener) -> io::Result<(UnixStream, So target_os = "redox", // Android x86's seccomp profile forbids calls to `accept4(2)` // See https://github.com/tokio-rs/mio/issues/1445 for details - all( - target_arch = "x86", - target_os = "android" - ) + all(target_arch = "x86", target_os = "android"), )))] let socket = { let flags = libc::SOCK_NONBLOCK | libc::SOCK_CLOEXEC; @@ -62,10 +55,10 @@ pub(crate) fn accept(listener: &net::UnixListener) -> io::Result<(UnixStream, So }; #[cfg(any( - target_os = "ios", - target_os = "macos", target_os = "netbsd", target_os = "redox", + target_os = "ios", + target_os = "macos", all(target_arch = "x86", target_os = "android") ))] let socket = syscall!(accept( |