-
Notifications
You must be signed in to change notification settings - Fork 735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Event a wrapper around a platform event #983
Conversation
Now Event is just a wrapper around a platform specific event to provide a nice API, with methods such as is_readable. This removes the Ready type and moves all its methods to the Event type.
Uses Event::new and that is gone now.
Ready is gone. Also fixes some type-o's while in the Waker docs.
Windows is left, the other platforms work. |
This basically moves the old Event and Ready into the windows module. Someone with more knowledge about IOCP and Windows should really look at this, the currently situation isn't great.
I've made an attempt at fixing Windows, basically moving |
waker_multiple_wakeups_same_thread fails on Windows because it explicitly check for a single event, but Windows creates three. @carllerche do we just want to make the test less strict? |
Now it accept mutltiple waker events, rather then just one.
With 31e271a Windows also works. |
src/sys/unix/epoll.rs
Outdated
// TODO: add readiness. | ||
f.debug_struct("Event") | ||
.field("token", &self.token()) | ||
//.field("readiness", &self.readiness()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we do with readiness? I could create a function epoll_event
/kevent
-> Ready
, but is worth the effort?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand the question / problem. Instead of readiness
, we could also include the details like "readable", "writable", "lio", ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've moved the Debug
impl to event_imp.rs
.
src/sys/mod.rs
Outdated
@@ -1,14 +1,16 @@ | |||
#[cfg(unix)] | |||
pub use self::unix::{ | |||
pipe, set_nonblock, EventedFd, Events, Io, Selector, TcpListener, TcpStream, UdpSocket, Waker, | |||
pipe, set_nonblock, Event, EventedFd, Events, Io, RawEvent, Selector, TcpListener, TcpStream, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if I like the name RawEvent
, would SysEvent
be better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SysEvent is probably best as we are going for "sys" terminology.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mentioned it in an in-progress review, but what about sys::Event
? It is a crate private type anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sys::Event
and SysEvent
are two different types. sys::Event
is a wrapper around SysEvent
to implement token
, is_readable
, etc. and SysEvent
is just an alias for epoll_event
/kevent
.
|
||
println!("SHUTTING DOWN"); | ||
// Now, shutdown the write half of the socket. | ||
socket.shutdown(Shutdown::Write).unwrap(); | ||
|
||
wait!(poll, is_readable); | ||
wait!(poll, is_readable, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a function change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before this wouldn't expect hup
here.
|
||
expect_no_events(&mut poll, &mut events); | ||
|
||
handle1.join().unwrap(); | ||
handle2.join().unwrap(); | ||
} | ||
|
||
fn expect_waker_event(poll: &mut Poll, events: &mut Events, token: Token) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This because less strict, allow multiple waker events rather then only one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good 👍 thanks for putting this together. I had a few minor questions inline.
src/event_imp.rs
Outdated
} | ||
/// Get access to the platform specific event, the returned value differs | ||
/// per platform. | ||
pub fn raw_event(&self) -> &sys::RawEvent { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this function intentionally part of the public API?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this allows users to access the underlying system event for platform specific extensions. You previously mentioned accessing kevent
for optimising Tokio.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, my intent was not to expose RawEvent
but have kqueue only fns directly on Event
(conditionally defined). WDYT? Either way, we can punt exposing the raw event until we get to exposing kqueue specific data.
src/event_imp.rs
Outdated
pub fn ready_from_usize(events: usize) -> Ready { | ||
Ready::from_usize(events) | ||
/// Create an `Event` from a platform specific event. | ||
pub fn from_raw_event(raw_event: sys::RawEvent) -> Event { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this function intentionally part of the public API?
Also, if we are bikeshedding names, what about:
sys::Event
fn as_sys(&self) -> &sys::Event
fn from_sys(sys::Event)
src/sys/mod.rs
Outdated
@@ -1,14 +1,16 @@ | |||
#[cfg(unix)] | |||
pub use self::unix::{ | |||
pipe, set_nonblock, EventedFd, Events, Io, Selector, TcpListener, TcpStream, UdpSocket, Waker, | |||
pipe, set_nonblock, Event, EventedFd, Events, Io, RawEvent, Selector, TcpListener, TcpStream, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mentioned it in an in-progress review, but what about sys::Event
? It is a crate private type anyway.
src/sys/unix/epoll.rs
Outdated
// TODO: add readiness. | ||
f.debug_struct("Event") | ||
.field("token", &self.token()) | ||
//.field("readiness", &self.readiness()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand the question / problem. Instead of readiness
, we could also include the details like "readable", "writable", "lio", ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving, but I recommend removing fn sys_event
and fn from_sys_event
for now and consider adding it back when we approach exposing kqueue specific data.
Very nice job 👍 |
I've removed the system event from the public API and opened #990. |
Now
Event
is just a wrapper around a platform specific event to providea nice API, with methods such as is_readable.
This removes the
Ready
type and moves all its methods to theEvent
type.TODO:
test_write_shutdown
test, the following failsassert!(!event.is_hup())
.test_waker
module (uses now removedEvent::new
).