Skip to content

Commit 6479adf

Browse files
committed
Fix broken tests on nightly
1 parent eb97186 commit 6479adf

File tree

3 files changed

+39
-35
lines changed

3 files changed

+39
-35
lines changed

src/sys/socket/ffi.rs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,44 @@
11
// Silence invalid warnings due to rust-lang/rust#16719
22
#![allow(improper_ctypes)]
33

4-
use libc::{c_int, c_void, socklen_t, ssize_t};
54
pub use libc::{socket, listen, bind, accept, connect, setsockopt, sendto, recvfrom, getsockname, getpeername, recv, send};
6-
use super::msghdr;
5+
6+
use libc::{c_int, c_void, socklen_t, size_t, ssize_t};
7+
use sys::uio::IoVec;
8+
9+
10+
#[cfg(target_os = "linux")]
11+
pub type type_of_cmsg_len = size_t;
12+
13+
#[cfg(not(target_os = "linux"))]
14+
pub type type_of_cmsg_len = socklen_t;
15+
16+
// Private because we don't expose any external functions that operate
17+
// directly on this type; we just use it internally at FFI boundaries.
18+
// Note that in some cases we store pointers in *const fields that the
19+
// kernel will proceed to mutate, so users should be careful about the
20+
// actual mutability of data pointed to by this structure.
21+
#[repr(C)]
22+
pub struct msghdr<'a> {
23+
pub msg_name: *const c_void,
24+
pub msg_namelen: socklen_t,
25+
pub msg_iov: *const IoVec<&'a [u8]>,
26+
pub msg_iovlen: size_t,
27+
pub msg_control: *const c_void,
28+
pub msg_controllen: size_t,
29+
pub msg_flags: c_int,
30+
}
31+
32+
// As above, private because we don't expose any external functions that
33+
// operate directly on this type, or any external types with a public
34+
// cmsghdr member.
35+
#[repr(C)]
36+
pub struct cmsghdr {
37+
pub cmsg_len: type_of_cmsg_len,
38+
pub cmsg_level: c_int,
39+
pub cmsg_type: c_int,
40+
pub cmsg_data: [type_of_cmsg_len; 0]
41+
}
742

843
extern {
944
pub fn getsockopt(

src/sys/socket/mod.rs

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -91,37 +91,8 @@ unsafe fn copy_bytes<'a, 'b, T: ?Sized>(src: &T, dst: &'a mut &'b mut [u8]) {
9191
mem::swap(dst, &mut remainder);
9292
}
9393

94-
// Private because we don't expose any external functions that operate
95-
// directly on this type; we just use it internally at FFI boundaries.
96-
// Note that in some cases we store pointers in *const fields that the
97-
// kernel will proceed to mutate, so users should be careful about the
98-
// actual mutability of data pointed to by this structure.
99-
#[repr(C)]
100-
struct msghdr<'a> {
101-
msg_name: *const c_void,
102-
msg_namelen: socklen_t,
103-
msg_iov: *const IoVec<&'a [u8]>,
104-
msg_iovlen: size_t,
105-
msg_control: *const c_void,
106-
msg_controllen: size_t,
107-
msg_flags: c_int,
108-
}
109-
110-
#[cfg(target_os = "linux")]
111-
type type_of_cmsg_len = size_t;
112-
#[cfg(not(target_os = "linux"))]
113-
type type_of_cmsg_len = socklen_t;
114-
115-
// As above, private because we don't expose any external functions that
116-
// operate directly on this type, or any external types with a public
117-
// cmsghdr member.
118-
#[repr(C)]
119-
struct cmsghdr {
120-
pub cmsg_len: type_of_cmsg_len,
121-
pub cmsg_level: c_int,
122-
pub cmsg_type: c_int,
123-
cmsg_data: [type_of_cmsg_len; 0]
124-
}
94+
95+
use self::ffi::{cmsghdr, msghdr, type_of_cmsg_len};
12596

12697
/// A structure used to make room in a cmsghdr passed to recvmsg. The
12798
/// size and alignment match that of a cmsghdr followed by a T, but the

src/unistd.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,6 @@ pub fn dup3(oldfd: RawFd, newfd: RawFd, flags: OFlag) -> Result<RawFd> {
149149

150150
#[inline]
151151
fn dup3_polyfill(oldfd: RawFd, newfd: RawFd, flags: OFlag) -> Result<RawFd> {
152-
use errno::EINVAL;
153-
154152
if oldfd == newfd {
155153
return Err(Error::Sys(Errno::EINVAL));
156154
}

0 commit comments

Comments
 (0)