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
19 changes: 9 additions & 10 deletions src/epoll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,16 @@ impl Poller {
it_interval: TS_ZERO,
it_value: match timeout {
None => TS_ZERO,
Some(t) => libc::timespec {
tv_sec: t.as_secs() as libc::time_t,
tv_nsec: (t.subsec_nanos() as libc::c_long).into(),
},
Some(t) => {
let mut ts = TS_ZERO;
ts.tv_sec = t.as_secs() as libc::time_t;
ts.tv_nsec = (t.subsec_nanos() as libc::c_long).into();
ts
}
},
};

syscall!(syscall(
libc::SYS_timerfd_settime,
syscall!(timerfd_settime(
timer_fd as libc::c_int,
0 as libc::c_int,
&new_val as *const libc::itimerspec,
Expand Down Expand Up @@ -262,10 +263,8 @@ impl Drop for Poller {
}

/// `timespec` value that equals zero.
const TS_ZERO: libc::timespec = libc::timespec {
tv_sec: 0,
tv_nsec: 0,
};
const TS_ZERO: libc::timespec =
unsafe { std::mem::transmute([0u8; std::mem::size_of::<libc::timespec>()]) };
Comment on lines +266 to +267
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I thought const transmute was stable at 1.56, but it seems to compile successfully at 1.47?

https://doc.rust-lang.org/stable/std/intrinsics/fn.transmute.html

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw that too, is that some kind of compiler magic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think it was special cased in the compiler for 1.46 and that special casing was removed in 1.56 when reading union fields in const contexts was stabilized.


/// Epoll flags for all possible readability events.
fn read_flags() -> libc::c_int {
Expand Down