diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/sys/socket/mod.rs | 16 | ||||
-rw-r--r-- | src/unistd.rs | 2 |
2 files changed, 12 insertions, 6 deletions
diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index 9e8cefae..3ee02c3a 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -1075,10 +1075,13 @@ pub fn recv(sockfd: RawFd, buf: &mut [u8], flags: MsgFlags) -> Result<usize> { } /// Receive data from a connectionless or connection-oriented socket. Returns -/// the number of bytes read and the socket address of the sender. +/// the number of bytes read and, for connectionless sockets, the socket +/// address of the sender. /// /// [Further reading](http://pubs.opengroup.org/onlinepubs/9699919799/functions/recvfrom.html) -pub fn recvfrom(sockfd: RawFd, buf: &mut [u8]) -> Result<(usize, SockAddr)> { +pub fn recvfrom(sockfd: RawFd, buf: &mut [u8]) + -> Result<(usize, Option<SockAddr>)> +{ unsafe { let mut addr: sockaddr_storage = mem::zeroed(); let mut len = mem::size_of::<sockaddr_storage>() as socklen_t; @@ -1089,10 +1092,13 @@ pub fn recvfrom(sockfd: RawFd, buf: &mut [u8]) -> Result<(usize, SockAddr)> { buf.len() as size_t, 0, &mut addr as *mut libc::sockaddr_storage as *mut libc::sockaddr, - &mut len as *mut socklen_t))?; + &mut len as *mut socklen_t))? as usize; - sockaddr_storage_to_addr(&addr, len as usize) - .map(|addr| (ret as usize, addr)) + match sockaddr_storage_to_addr(&addr, len as usize) { + Err(Error::Sys(Errno::ENOTCONN)) => Ok((ret, None)), + Ok(addr) => Ok((ret, Some(addr))), + Err(e) => Err(e) + } } } diff --git a/src/unistd.rs b/src/unistd.rs index 886084e8..952799e6 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -88,7 +88,7 @@ impl Gid { getgid() } - /// Returns effective Gid of calling process. This is practically a more Rusty alias for `getgid`. + /// Returns effective Gid of calling process. This is practically a more Rusty alias for `getegid`. pub fn effective() -> Self { getegid() } |