diff options
author | Carl Lerche <me@carllerche.com> | 2015-12-22 14:25:57 -0800 |
---|---|---|
committer | Carl Lerche <me@carllerche.com> | 2015-12-22 14:25:57 -0800 |
commit | 6479adfab4141b917f0df6cf6dc36e1688087afa (patch) | |
tree | 824550185fc76290d9aae067beaa0b568574f0f1 /src/sys/socket | |
parent | eb9718625708a951a615a18b6583561937875fd0 (diff) | |
download | nix-6479adfab4141b917f0df6cf6dc36e1688087afa.zip |
Fix broken tests on nightly
Diffstat (limited to 'src/sys/socket')
-rw-r--r-- | src/sys/socket/ffi.rs | 39 | ||||
-rw-r--r-- | src/sys/socket/mod.rs | 33 |
2 files changed, 39 insertions, 33 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 |