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
20 changes: 3 additions & 17 deletions src/sys/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ pub(crate) fn poll_connect(socket: &crate::Socket, timeout: Duration) -> io::Res
}

let timeout = (timeout - elapsed).as_millis();
let timeout = clamp(timeout, 1, c_int::MAX as u128) as c_int;
let timeout = timeout.clamp(1, c_int::MAX as u128) as c_int;

match syscall!(poll(&mut pollfd, 1, timeout)) {
Ok(0) => return Err(io::ErrorKind::TimedOut.into()),
Expand All @@ -642,20 +642,6 @@ pub(crate) fn poll_connect(socket: &crate::Socket, timeout: Duration) -> io::Res
}
}

// TODO: use clamp from std lib, stable since 1.50.
fn clamp<T>(value: T, min: T, max: T) -> T
where
T: Ord,
{
if value <= min {
min
} else if value >= max {
max
} else {
value
}
}

pub(crate) fn listen(fd: Socket, backlog: c_int) -> io::Result<()> {
syscall!(listen(fd, backlog)).map(|_| ())
}
Expand Down Expand Up @@ -782,7 +768,7 @@ fn recvmsg(
msg.msg_name = msg_name.cast();
msg.msg_namelen = msg_namelen;
msg.msg_iov = bufs.as_mut_ptr().cast();
msg.msg_iovlen = min(bufs.len(), IovLen::MAX as usize) as IovLen;
msg.msg_iovlen = min(bufs.len(), IovLen::MAX) as IovLen;
syscall!(recvmsg(fd, &mut msg, flags))
.map(|n| (n as usize, msg.msg_namelen, RecvFlags(msg.msg_flags)))
}
Expand Down Expand Up @@ -842,7 +828,7 @@ fn sendmsg(
msg.msg_namelen = msg_namelen;
// Safety: Same as above about `*const` -> `*mut`.
msg.msg_iov = bufs.as_ptr() as *mut _;
msg.msg_iovlen = min(bufs.len(), IovLen::MAX as usize) as IovLen;
msg.msg_iovlen = min(bufs.len(), IovLen::MAX) as IovLen;
syscall!(sendmsg(fd, &msg, flags)).map(|n| n as usize)
}

Expand Down