-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Update Mio to 0.7 #1767
Update Mio to 0.7 #1767
Conversation
0263c98
to
c89744e
Compare
This currently fails on Windows because of the use of mio-named-pipes which still depends on Mio 0.6. Will work on a fix for this, but those changes should be confined to |
tokio/src/net/driver/platform.rs
Outdated
@@ -1,28 +0,0 @@ | |||
pub(crate) use self::sys::*; |
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.
Deleting this file makes me happy.
tokio/src/net/driver/reactor/mod.rs
Outdated
@@ -266,7 +275,7 @@ impl Reactor { | |||
#[cfg(all(unix, not(target_os = "fuchsia")))] |
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.
We can delete any mention of fuchsia
as there is no fuchsia support ATM.
tokio/src/net/driver/registration.rs
Outdated
// This consumes the current readiness state **except** for | ||
// `READ_CLOSED` and `WRITE_CLOSED`. These are excluded because: | ||
// - They are a final state and never transitioned out of | ||
// - Both the read and the write directions should be able to observe |
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 line isn't really relevant anymore.
tokio/src/net/util/io_resource.rs
Outdated
/// [`poll_read_ready`]: #method.poll_read_ready | ||
/// [`poll_write_ready`]: #method.poll_write_ready | ||
pub struct IoResource<S: mio::event::Source> { | ||
io: Option<S>, |
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.
Since you are in here, can Option
be removed?
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.
It can! I was going to do it as part of this PR, but since IoResource::into_inner
moves the value out, the Drop
impl requires some additional handling to forget the value when this occurs. I can include it now, but had it as a note for a follow-up. It should be a fairly small 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.
I took a quick look and left some comments.
Overall I don't see many change that relate to using edge-triggers. Was Mio already using edge-trigger before? Last time I look was with futures 0.1, so its been a while and lots has changed.
@@ -93,14 +91,13 @@ iovec = "0.1" | |||
fnv = { version = "1.0.6", optional = true } | |||
lazy_static = { version = "1.0.2", optional = true } | |||
memchr = { version = "2.2", optional = true } | |||
mio = { version = "0.6.14", optional = true } | |||
mio = { git = "https://github.com/tokio-rs/mio", branch = "master", optional = 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.
Might want to fix to a specific commit to avoid breaking changes.
tokio/src/net/driver/reactor/mod.rs
Outdated
Ok(_) => {} | ||
Err(e) => return Err(e), | ||
Err(ref e) if e.kind() == io::ErrorKind::Interrupted => {} |
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.
You should probably add a loop here, now you're continueing with no events.
tokio/src/net/driver/reactor/mod.rs
Outdated
@@ -321,7 +330,7 @@ impl Handle { | |||
/// return immediately. | |||
fn wakeup(&self) { | |||
if let Some(inner) = self.inner() { | |||
inner.wakeup.set_readiness(mio::Ready::readable()).unwrap(); | |||
inner.waker.wake().expect("failed to wake reactor") |
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.
Don't you want to return the error here?
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.
wakeup
is only used in Handle::unpark
which does not return anything. I think handling an error here could be considered, but not necessarily as part of this change. Similar to before, if there an unexpected reason why wakeup
fails then a panic will happen.
tokio/src/net/driver/reactor/mod.rs
Outdated
}; | ||
|
||
waker.register(w); | ||
if readiness & ready.as_usize() != 0 { | ||
if readiness & interest.as_usize() != 0 { | ||
waker.wake(); |
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 call is now quite a bit more expansive then in Mio v0.6, since in v0.7 this is a system call. You might want to consider using a different mechanism for this.
tokio/src/net/driver/readiness.rs
Outdated
const READABLE: usize = 0b0_01; | ||
const WRITABLE: usize = 0b0_10; | ||
const READ_CLOSED: usize = 0b0_0100; | ||
const WRITE_CLOSED: usize = 0b0_1000; |
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 missing AIO (not supported), LIO (not supported), error and priority. This is the full list (from tokio-rs/mio#1145):
const READABLE: usize = 0b00_000_001;
const WRITABLE: usize = 0b00_000_010;
const AIO: usize = 0b00_000_100;
const LIO: usize = 0b00_001_000;
const ERROR: usize = 0b00_010_000;
const READ_CLOSED: usize = 0b00_100_000;
const WRITE_CLOSED: usize = 0b01_000_000;
const PRIORITY: usize = 0b10_000_000;
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.
It also just fits in 8 bits, if size is something to optimise for here.
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.
Yep I left those out for now. Readable and writeable readiness were supported before, and now Mio offers the cross-platform closed readiness that allows this change to remove platform-specific behavior. If support for these platform specific events provides values I think it should be done in a PR that is focused on adding functionality and not just updating.
tokio/src/net/util/io_resource.rs
Outdated
/// [`TcpListener`] implements poll_accept by using [`poll_read_ready`] and | ||
/// [`clear_read_ready`]. | ||
/// | ||
/// TODO |
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.
Couple TODOs left in these docs.
1fee31f
to
c89744e
Compare
Signed-off-by: Kevin Leimkuhler <[email protected]>
Signed-off-by: Kevin Leimkuhler <[email protected]>
Signed-off-by: Kevin Leimkuhler <[email protected]>
Signed-off-by: Kevin Leimkuhler <[email protected]>
Signed-off-by: Kevin Leimkuhler <[email protected]>
Signed-off-by: Kevin Leimkuhler <[email protected]>
Signed-off-by: Kevin Leimkuhler <[email protected]>
Signed-off-by: Kevin Leimkuhler <[email protected]>
Signed-off-by: Kevin Leimkuhler <[email protected]>
Signed-off-by: Kevin Leimkuhler <[email protected]>
Signed-off-by: Kevin Leimkuhler <[email protected]>
Signed-off-by: Kevin Leimkuhler <[email protected]>
Signed-off-by: Kevin Leimkuhler <[email protected]>
Signed-off-by: Kevin Leimkuhler <[email protected]>
Signed-off-by: Kevin Leimkuhler <[email protected]>
Signed-off-by: Kevin Leimkuhler <[email protected]>
Signed-off-by: Kevin Leimkuhler <[email protected]>
Signed-off-by: Kevin Leimkuhler <[email protected]>
Signed-off-by: Kevin Leimkuhler <[email protected]>
Signed-off-by: Kevin Leimkuhler <[email protected]>
Signed-off-by: Kevin Leimkuhler <[email protected]>
c89744e
to
78c17df
Compare
…pdate Signed-off-by: Kevin Leimkuhler <[email protected]>
…pdate Signed-off-by: Kevin Leimkuhler <[email protected]>
Closing as I'd like to keep this branch up to date as both libraries change towards their next big releases, and I will be making some temporary changes so that it stays compiling/testing on at least some platforms. |
This also makes Mio an implementation detail, removing it from the public API. This is based on #1767.
Hi QQ, cheers Rich |
See more at #3082. |
Summary
This PR updates Tokio to Mio
master
. A version 0.7 has not been releasedyet, but that is the intention of this change.
There should be no user-facing changes from this update. All changes are
confined to
tokio::net
with the majority taking place innet::driver::reactor
andnet::util::PollEvented
(nownet::util::IoResource
). Therefore, no tests have been added or changed.Details
PollEvented
->IoResource
With the change of
mio::Evented
->mio::event::Source
, it made sense tochange the Tokio wrapper as well. As this type is responsible for driving
all I/O resources, the name seemed to fit.
The internal API for
IoResource
have changed so that an interest/readinessdoes not need to be passed in to the poll functions (
poll_read_ready
andpoll_write_ready
). Both poll functions expand viapoll_readiness!
which isresponsible for driving the actual readiness of events on the I/O resource.
Readiness
represents any cross-platform event that has occurred on the I/Oresource since the last poll. The possible values are:
READABLE
,WRITEABLE
,READ_CLOSED
, andWRITE_CLOSED
.poll_readiness!
will poll the I/O resource until there is a readiness eventthat matches an event of interest. If there already is an event of interest
then it will return.
Finally,
poll_readiness!
does not actually implement the low-level pollingon the I/O resource. It dispatches to a
Registration
which changed mainly tohandle closed events.
Temporarily removed methods
The following
TcpStream
methods were removed due to changes in the Mio API.They will be reintroduced in further changes that either implement these
directly in Tokio, or Mio introducing a
TcpSocket
builder type that can beused by Tokio.
TcpStream::
connect_std
recv_buff_size
set_recv_buffer_size
send_buffer_size
set_send_buffer_size
keepalive
set_keepalive
linger
set_linger
{AsyncRead, AsyncWrite}::poll_read_buf
This method relies on the Bytes update so that
IoSlice
can be used. Thistemporarily performs un-vectored reads and writes.
Signed-off-by: Kevin Leimkuhler [email protected]