From 87d72418338a9250f70cb4a43c8bea10371f8256 Mon Sep 17 00:00:00 2001 From: Thomas de Zeeuw Date: Fri, 17 May 2019 11:52:42 +0200 Subject: [PATCH] Fix kqueue on platforms where C's long is i32 --- src/sys/unix/kqueue.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/sys/unix/kqueue.rs b/src/sys/unix/kqueue.rs index 8269e3207..d64689fe9 100644 --- a/src/sys/unix/kqueue.rs +++ b/src/sys/unix/kqueue.rs @@ -74,7 +74,11 @@ impl Selector { ) -> io::Result { let timeout = timeout.map(|to| libc::timespec { tv_sec: cmp::min(to.as_secs(), time_t::max_value() as u64) as time_t, - tv_nsec: libc::c_long::from(to.subsec_nanos()), + // `Duration::subsec_nanos` is guaranteed to be less than one + // billion (the number of nanoseconds in a second), making the + // cast to i32 safe. The cast itself is needed for platforms + // where C's long is only 32 bits. + tv_nsec: libc::c_long::from(to.subsec_nanos() as i32), }); let timeout = timeout .as_ref()