Skip to content

Commit f1349f3

Browse files
nikarhThomasdezeeuw
authored andcommitted
Fixes after review
1 parent beeb126 commit f1349f3

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,8 @@ impl<'addr, 'bufs, 'control> MsgHdrMut<'addr, 'bufs, 'control> {
684684
///
685685
/// Corresponds to setting `msg_name` and `msg_namelen` on Unix and `name`
686686
/// and `namelen` on Windows.
687-
pub fn with_addr(mut self, addr: &SockAddr) -> Self {
687+
#[allow(clippy::needless_pass_by_ref_mut)]
688+
pub fn with_addr(mut self, addr: &'addr mut SockAddr) -> Self {
688689
sys::set_msghdr_name(&mut self.inner, addr);
689690
self
690691
}

src/socket.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ impl Socket {
368368
/// `O_NONBLOCK`.
369369
///
370370
/// On Windows it is not possible retrieve the nonblocking mode status.
371-
#[cfg(any(target_os = "vita", all(feature = "all", unix)))]
371+
#[cfg(all(feature = "all", unix))]
372372
#[cfg_attr(docsrs, doc(cfg(all(feature = "all", unix))))]
373373
pub fn nonblocking(&self) -> io::Result<bool> {
374374
sys::nonblocking(self.as_raw())

src/sys/unix.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ pub(crate) fn nonblocking(fd: Socket) -> io::Result<bool> {
939939
Ok((file_status_flags & libc::O_NONBLOCK) != 0)
940940
}
941941

942-
#[cfg(target_os = "vita")]
942+
#[cfg(all(feature = "all", target_os = "vita"))]
943943
pub(crate) fn nonblocking(fd: Socket) -> io::Result<bool> {
944944
unsafe {
945945
getsockopt::<Bool>(fd, libc::SOL_SOCKET, libc::SO_NONBLOCK).map(|non_block| non_block != 0)

tests/socket.rs

+21-2
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ fn assert_common_flags(socket: &Socket, expected: bool) {
233233
#[cfg(windows)]
234234
assert_flag_no_inherit(socket, expected);
235235

236+
// Vita does not have process API, so neither SO_NOSIGPIPE nor FD_CLOEXEC are supported on this platform
236237
#[cfg(target_os = "vita")]
237238
{
238239
let _ = socket;
@@ -293,14 +294,32 @@ fn type_nonblocking() {
293294
#[cfg(unix)]
294295
#[track_caller]
295296
pub fn assert_nonblocking(socket: &Socket, want: bool) {
296-
#[cfg(any(target_os = "vita", all(feature = "all", unix)))]
297+
#[cfg(all(feature = "all", unix))]
297298
assert_eq!(socket.nonblocking().unwrap(), want, "non-blocking option");
298299

299300
#[cfg(all(not(target_os = "vita"), not(all(feature = "all", unix))))]
300301
{
301302
let flags = unsafe { libc::fcntl(socket.as_raw_fd(), libc::F_GETFL) };
302303
assert_eq!(flags & libc::O_NONBLOCK != 0, want, "non-blocking option");
303304
}
305+
306+
#[cfg(all(target_os = "vita", not(feature = "all")))]
307+
{
308+
let mut optval: libc::c_int = 0;
309+
let mut optlen = std::mem::size_of::<libc::c_int>() as libc::socklen_t;
310+
311+
let res = unsafe {
312+
libc::getsockopt(
313+
socket.as_raw_fd(),
314+
libc::SOL_SOCKET,
315+
libc::SO_NONBLOCK,
316+
&mut optval as *mut libc::c_int as _,
317+
&mut optlen,
318+
)
319+
};
320+
assert_eq!(res, 0, "unable to get non-blocing option");
321+
assert_eq!(optval > 0, want, "non-blocking option");
322+
}
304323
}
305324

306325
#[cfg(windows)]
@@ -871,7 +890,7 @@ fn tcp_keepalive() {
871890

872891
#[cfg(all(
873892
feature = "all",
874-
not(any(windows, target_os = "haiku", target_os = "openbsd",))
893+
not(any(windows, target_os = "haiku", target_os = "openbsd"))
875894
))]
876895
assert_eq!(socket.keepalive_time().unwrap(), Duration::from_secs(200));
877896

0 commit comments

Comments
 (0)