mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-10-01 12:20:39 +00:00
signal: Ensure that the driver dies once the signal does
`tokio::run` expects that all futures finish processing so we can't leave `Driver` around forever or `tokio::run` would never return.
This commit is contained in:
parent
f759e4d70f
commit
209232befd
@ -328,6 +328,7 @@ impl Driver {
|
|||||||
/// repo, though, as I'd love to chat about this! In other words, I'd love to
|
/// repo, though, as I'd love to chat about this! In other words, I'd love to
|
||||||
/// alleviate some of these limitations if possible!
|
/// alleviate some of these limitations if possible!
|
||||||
pub struct Signal {
|
pub struct Signal {
|
||||||
|
driver: Driver,
|
||||||
signal: c_int,
|
signal: c_int,
|
||||||
// Used only as an identifier. We place the real sender into a Box, so it
|
// Used only as an identifier. We place the real sender into a Box, so it
|
||||||
// stays on the same address forever. That gives us a unique pointer, so we
|
// stays on the same address forever. That gives us a unique pointer, so we
|
||||||
@ -370,7 +371,7 @@ impl Signal {
|
|||||||
|
|
||||||
// Ensure there's a driver for our associated event loop processing
|
// Ensure there's a driver for our associated event loop processing
|
||||||
// signals.
|
// signals.
|
||||||
::tokio_executor::spawn(try!(Driver::new(&handle)));
|
let driver = try!(Driver::new(&handle));
|
||||||
|
|
||||||
// One wakeup in a queue is enough, no need for us to buffer up any
|
// One wakeup in a queue is enough, no need for us to buffer up any
|
||||||
// more.
|
// more.
|
||||||
@ -380,6 +381,7 @@ impl Signal {
|
|||||||
let idx = signal as usize;
|
let idx = signal as usize;
|
||||||
globals().signals[idx].recipients.lock().unwrap().push(tx);
|
globals().signals[idx].recipients.lock().unwrap().push(tx);
|
||||||
Ok(Signal {
|
Ok(Signal {
|
||||||
|
driver: driver,
|
||||||
rx: rx,
|
rx: rx,
|
||||||
id: id,
|
id: id,
|
||||||
signal: signal,
|
signal: signal,
|
||||||
@ -395,6 +397,7 @@ impl Stream for Signal {
|
|||||||
type Error = io::Error;
|
type Error = io::Error;
|
||||||
|
|
||||||
fn poll(&mut self) -> Poll<Option<c_int>, io::Error> {
|
fn poll(&mut self) -> Poll<Option<c_int>, io::Error> {
|
||||||
|
self.driver.poll().unwrap();
|
||||||
// receivers don't generate errors
|
// receivers don't generate errors
|
||||||
self.rx.poll().map_err(|_| panic!())
|
self.rx.poll().map_err(|_| panic!())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user