Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions library/std/src/sys/net/connection/socket/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,11 +362,16 @@ impl Socket {
}

#[cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin"))]
pub fn recv_msg(&self, msg: &mut libc::msghdr) -> io::Result<usize> {
let n = cvt(unsafe { libc::recvmsg(self.as_raw_fd(), msg, libc::MSG_CMSG_CLOEXEC) })?;
pub fn recv_msg_with_flags(&self, msg: &mut libc::msghdr, flags: c_int) -> io::Result<usize> {
let n = cvt(unsafe { libc::recvmsg(self.as_raw_fd(), msg, flags) })?;
Ok(n as usize)
}

#[cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin"))]
pub fn recv_msg(&self, msg: &mut libc::msghdr) -> io::Result<usize> {
self.recv_msg_with_flags(msg, libc::MSG_CMSG_CLOEXEC)
}

pub fn peek_from(&self, buf: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
self.recv_from_with_flags(buf, MSG_PEEK)
}
Expand All @@ -385,11 +390,16 @@ impl Socket {
}

#[cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin"))]
pub fn send_msg(&self, msg: &mut libc::msghdr) -> io::Result<usize> {
let n = cvt(unsafe { libc::sendmsg(self.as_raw_fd(), msg, 0) })?;
pub fn send_msg_with_flags(&self, msg: &libc::msghdr, flags: c_int) -> io::Result<usize> {
let n = cvt(unsafe { libc::sendmsg(self.as_raw_fd(), msg, flags) })?;
Ok(n as usize)
}

#[cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin"))]
pub fn send_msg(&self, msg: &libc::msghdr) -> io::Result<usize> {
self.send_msg_with_flags(msg, 0)
}

pub fn set_timeout(&self, dur: Option<Duration>, kind: libc::c_int) -> io::Result<()> {
let timeout = match dur {
Some(dur) => {
Expand Down
Loading