diff options
-rw-r--r-- | src/sys/socket/ffi.rs | 39 | ||||
-rw-r--r-- | src/sys/socket/mod.rs | 33 | ||||
-rw-r--r-- | src/unistd.rs | 2 |
3 files changed, 39 insertions, 35 deletions
diff --git a/src/sys/socket/ffi.rs b/src/sys/socket/ffi.rs index 1351071d..1cbf766c 100644 --- a/src/sys/socket/ffi.rs +++ b/src/sys/socket/ffi.rs @@ -1,9 +1,44 @@ // Silence invalid warnings due to rust-lang/rust#16719 #![allow(improper_ctypes)] -use libc::{c_int, c_void, socklen_t, ssize_t}; pub use libc::{socket, listen, bind, accept, connect, setsockopt, sendto, recvfrom, getsockname, getpeername, recv, send}; -use super::msghdr; + +use libc::{c_int, c_void, socklen_t, size_t, ssize_t}; +use sys::uio::IoVec; + + +#[cfg(target_os = "linux")] +pub type type_of_cmsg_len = size_t; + +#[cfg(not(target_os = "linux"))] +pub type type_of_cmsg_len = socklen_t; + +// Private because we don't expose any external functions that operate +// directly on this type; we just use it internally at FFI boundaries. +// Note that in some cases we store pointers in *const fields that the +// kernel will proceed to mutate, so users should be careful about the +// actual mutability of data pointed to by this structure. +#[repr(C)] +pub struct msghdr<'a> { + pub msg_name: *const c_void, + pub msg_namelen: socklen_t, + pub msg_iov: *const IoVec<&'a [u8]>, + pub msg_iovlen: size_t, + pub msg_control: *const c_void, + pub msg_controllen: size_t, + pub msg_flags: c_int, +} + +// As above, private because we don't expose any external functions that +// operate directly on this type, or any external types with a public +// cmsghdr member. +#[repr(C)] +pub struct cmsghdr { + pub cmsg_len: type_of_cmsg_len, + pub cmsg_level: c_int, + pub cmsg_type: c_int, + pub cmsg_data: [type_of_cmsg_len; 0] +} extern { pub fn getsockopt( diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index 7eb1901a..8a74029f 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -91,37 +91,8 @@ unsafe fn copy_bytes<'a, 'b, T: ?Sized>(src: &T, dst: &'a mut &'b mut [u8]) { mem::swap(dst, &mut remainder); } -// Private because we don't expose any external functions that operate -// directly on this type; we just use it internally at FFI boundaries. -// Note that in some cases we store pointers in *const fields that the -// kernel will proceed to mutate, so users should be careful about the -// actual mutability of data pointed to by this structure. -#[repr(C)] -struct msghdr<'a> { - msg_name: *const c_void, - msg_namelen: socklen_t, - msg_iov: *const IoVec<&'a [u8]>, - msg_iovlen: size_t, - msg_control: *const c_void, - msg_controllen: size_t, - msg_flags: c_int, -} - -#[cfg(target_os = "linux")] -type type_of_cmsg_len = size_t; -#[cfg(not(target_os = "linux"))] -type type_of_cmsg_len = socklen_t; - -// As above, private because we don't expose any external functions that -// operate directly on this type, or any external types with a public -// cmsghdr member. -#[repr(C)] -struct cmsghdr { - pub cmsg_len: type_of_cmsg_len, - pub cmsg_level: c_int, - pub cmsg_type: c_int, - cmsg_data: [type_of_cmsg_len; 0] -} + +use self::ffi::{cmsghdr, msghdr, type_of_cmsg_len}; /// A structure used to make room in a cmsghdr passed to recvmsg. The /// size and alignment match that of a cmsghdr followed by a T, but the diff --git a/src/unistd.rs b/src/unistd.rs index 627c63e5..aba2d79c 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -149,8 +149,6 @@ pub fn dup3(oldfd: RawFd, newfd: RawFd, flags: OFlag) -> Result<RawFd> { #[inline] fn dup3_polyfill(oldfd: RawFd, newfd: RawFd, flags: OFlag) -> Result<RawFd> { - use errno::EINVAL; - if oldfd == newfd { return Err(Error::Sys(Errno::EINVAL)); } |