Skip to content
Merged
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
18 changes: 3 additions & 15 deletions src/sys/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,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 @@ -630,20 +630,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 @@ -754,6 +740,7 @@ pub(crate) fn recv_from_vectored(

/// Returns the (bytes received, sending address len, `RecvFlags`).
#[cfg(not(target_os = "redox"))]
#[allow(clippy::unnecessary_cast)] // For `IovLen::MAX as usize` (Already `usize` on Linux).
fn recvmsg(
fd: Socket,
msg_name: *mut sockaddr_storage,
Expand Down Expand Up @@ -814,6 +801,7 @@ pub(crate) fn send_to_vectored(

/// Returns the (bytes received, sending address len, `RecvFlags`).
#[cfg(not(target_os = "redox"))]
#[allow(clippy::unnecessary_cast)] // For `IovLen::MAX as usize` (Already `usize` on Linux).
fn sendmsg(
fd: Socket,
msg_name: *const sockaddr_storage,
Expand Down