Skip to content

Commit dafdcfa

Browse files
committed
changes from feedback
1 parent fa95f9f commit dafdcfa

File tree

1 file changed

+6
-7
lines changed
  • library/std/src/sys/net/connection/socket

1 file changed

+6
-7
lines changed

library/std/src/sys/net/connection/socket/unix.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -486,18 +486,17 @@ impl Socket {
486486
// bionic libc makes no use of this flag
487487
#[cfg(target_os = "linux")]
488488
pub fn set_deferaccept(&self, accept: Duration) -> io::Result<()> {
489-
setsockopt(
490-
self,
491-
libc::IPPROTO_TCP,
492-
libc::TCP_DEFER_ACCEPT,
493-
accept.as_secs_f64().round() as c_int,
494-
)
489+
let val = accept.as_secs();
490+
if val > i32::MAX as _ {
491+
return Err(io::Error::from_raw_os_error(libc::EINVAL));
492+
}
493+
setsockopt(self, libc::IPPROTO_TCP, libc::TCP_DEFER_ACCEPT, val as c_int)
495494
}
496495

497496
#[cfg(target_os = "linux")]
498497
pub fn deferaccept(&self) -> io::Result<Duration> {
499498
let raw: c_int = getsockopt(self, libc::IPPROTO_TCP, libc::TCP_DEFER_ACCEPT)?;
500-
Ok(Duration::from_secs(raw.try_into().unwrap()))
499+
Ok(Duration::from_secs(raw as _))
501500
}
502501

503502
#[cfg(any(target_os = "freebsd", target_os = "netbsd"))]

0 commit comments

Comments
 (0)