summaryrefslogtreecommitdiffstats
path: root/tokio/src/signal
diff options
context:
space:
mode:
authorCarl Lerche <me@carllerche.com>2020-10-02 13:54:00 -0700
committerGitHub <noreply@github.com>2020-10-02 13:54:00 -0700
commit1e585ccb516c8dc7c13cbc3d50f8ca49260b9617 (patch)
tree00959b4ac82e4972314baa043cdbca2f2ebf5848 /tokio/src/signal
parent7ec6d88b21ea3e5531176f526a51dae0a4513025 (diff)
io: update to Mio 0.7 (#2893)
This also makes Mio an implementation detail, removing it from the public API. This is based on #1767.
Diffstat (limited to 'tokio/src/signal')
-rw-r--r--tokio/src/signal/unix.rs2
-rw-r--r--tokio/src/signal/unix/driver.rs36
2 files changed, 29 insertions, 9 deletions
diff --git a/tokio/src/signal/unix.rs b/tokio/src/signal/unix.rs
index 30a05872..77f300bb 100644
--- a/tokio/src/signal/unix.rs
+++ b/tokio/src/signal/unix.rs
@@ -9,7 +9,7 @@ use crate::signal::registry::{globals, EventId, EventInfo, Globals, Init, Storag
use crate::sync::mpsc::{channel, Receiver};
use libc::c_int;
-use mio_uds::UnixStream;
+use mio::net::UnixStream;
use std::io::{self, Error, ErrorKind, Write};
use std::pin::Pin;
use std::sync::atomic::{AtomicBool, Ordering};
diff --git a/tokio/src/signal/unix/driver.rs b/tokio/src/signal/unix/driver.rs
index 639a483e..ae60c22f 100644
--- a/tokio/src/signal/unix/driver.rs
+++ b/tokio/src/signal/unix/driver.rs
@@ -5,7 +5,8 @@ use crate::io::PollEvented;
use crate::park::Park;
use crate::runtime::context;
use crate::signal::registry::globals;
-use mio_uds::UnixStream;
+
+use mio::net::UnixStream;
use std::io::{self, Read};
use std::ptr;
use std::sync::{Arc, Weak};
@@ -42,22 +43,41 @@ pub(super) struct Inner(());
impl Driver {
/// Creates a new signal `Driver` instance that delegates wakeups to `park`.
pub(crate) fn new(park: IoDriver) -> io::Result<Self> {
+ use std::mem::ManuallyDrop;
+ use std::os::unix::io::{AsRawFd, FromRawFd};
+
// NB: We give each driver a "fresh" reciever file descriptor to avoid
// the issues described in alexcrichton/tokio-process#42.
//
// In the past we would reuse the actual receiver file descriptor and
// swallow any errors around double registration of the same descriptor.
- // I'm not sure if the second (failed) registration simply doesn't end up
- // receiving wake up notifications, or there could be some race condition
- // when consuming readiness events, but having distinct descriptors for
- // distinct PollEvented instances appears to mitigate this.
+ // I'm not sure if the second (failed) registration simply doesn't end
+ // up receiving wake up notifications, or there could be some race
+ // condition when consuming readiness events, but having distinct
+ // descriptors for distinct PollEvented instances appears to mitigate
+ // this.
//
// Unfortunately we cannot just use a single global PollEvented instance
// either, since we can't compare Handles or assume they will always
// point to the exact same reactor.
- let receiver = globals().receiver.try_clone()?;
- let receiver =
- PollEvented::new_with_ready_and_handle(receiver, mio::Ready::all(), park.handle())?;
+ //
+ // Mio 0.7 removed `try_clone()` as an API due to unexpected behavior
+ // with registering dups with the same reactor. In this case, duping is
+ // safe as each dup is registered with separate reactors **and** we
+ // only expect at least one dup to receive the notification.
+
+ // Manually drop as we don't actually own this instance of UnixStream.
+ let receiver_fd = globals().receiver.as_raw_fd();
+
+ // safety: there is nothing unsafe about this, but the `from_raw_fd` fn is marked as unsafe.
+ let original =
+ ManuallyDrop::new(unsafe { std::os::unix::net::UnixStream::from_raw_fd(receiver_fd) });
+ let receiver = UnixStream::from_std(original.try_clone()?);
+ let receiver = PollEvented::new_with_interest_and_handle(
+ receiver,
+ mio::Interest::READABLE | mio::Interest::WRITABLE,
+ park.handle(),
+ )?;
Ok(Self {
park,