This commit is contained in:
Milan Landaverde 2021-05-16 17:49:54 -04:00 committed by Milan
parent 63ebfc2c55
commit 1c2143193f
4 changed files with 25 additions and 6 deletions

View File

@ -285,7 +285,11 @@ impl SocketAddr {
));
}
ptr::copy_nonoverlapping(namespace.as_ptr(), addr.sun_path.as_mut_ptr().offset(1) as *mut u8, namespace.len());
ptr::copy_nonoverlapping(
namespace.as_ptr(),
addr.sun_path.as_mut_ptr().offset(1) as *mut u8,
namespace.len(),
);
let len = (sun_path_offset(&addr) + 1 + namespace.len()) as libc::socklen_t;
SocketAddr::from_parts(addr, len)
}

View File

@ -136,7 +136,11 @@ impl UnixDatagram {
pub fn bind_addr(socket_addr: &SocketAddr) -> io::Result<UnixDatagram> {
unsafe {
let socket = UnixDatagram::unbound()?;
cvt(libc::bind(*socket.0.as_inner(), &socket_addr.addr as *const _ as *const _, socket_addr.len as _))?;
cvt(libc::bind(
*socket.0.as_inner(),
&socket_addr.addr as *const _ as *const _,
socket_addr.len as _,
))?;
Ok(socket)
}
}
@ -245,7 +249,11 @@ impl UnixDatagram {
#[unstable(feature = "unix_socket_abstract", issue = "42048")]
pub fn connect_addr(&self, socket_addr: &SocketAddr) -> io::Result<()> {
unsafe {
cvt(libc::connect(*self.0.as_inner(), &socket_addr.addr as *const _ as *const _, socket_addr.len))?;
cvt(libc::connect(
*self.0.as_inner(),
&socket_addr.addr as *const _ as *const _,
socket_addr.len,
))?;
}
Ok(())
}

View File

@ -107,14 +107,17 @@ impl UnixListener {
pub fn bind_addr(socket_addr: &SocketAddr) -> io::Result<UnixListener> {
unsafe {
let inner = Socket::new_raw(libc::AF_UNIX, libc::SOCK_STREAM)?;
cvt(libc::bind(*inner.as_inner(), &socket_addr.addr as *const _ as *const _, socket_addr.len as _))?;
cvt(libc::bind(
*inner.as_inner(),
&socket_addr.addr as *const _ as *const _,
socket_addr.len as _,
))?;
cvt(libc::listen(*inner.as_inner(), 128))?;
Ok(UnixListener(inner))
}
}
/// Accepts a new incoming connection to this listener.
///
/// This function will block the calling thread until a new Unix connection

View File

@ -132,7 +132,11 @@ impl UnixStream {
pub fn connect_addr(socket_addr: &SocketAddr) -> io::Result<UnixStream> {
unsafe {
let inner = Socket::new_raw(libc::AF_UNIX, libc::SOCK_STREAM)?;
cvt(libc::connect(*inner.as_inner(), &socket_addr.addr as *const _ as *const _, socket_addr.len))?;
cvt(libc::connect(
*inner.as_inner(),
&socket_addr.addr as *const _ as *const _,
socket_addr.len,
))?;
Ok(UnixStream(inner))
}
}