Change need_read and need_write to return an error

This commit is targeted at solving tokio-rs/tokio-core#12 and incorporates the
solution from tokio-rs/tokio-core#17. Namely the `need_read` and `need_write`
functions on `PollEvented` now return an error when the connected reactor has
gone away and the task cannot be blocked. This will typically naturally
translate to errors being returned by various connected I/O objects and should
help tear down the world in a clean-ish fashion.
This commit is contained in:
Alex Crichton
2017-12-05 08:43:01 -08:00
parent 8fcce957cd
commit e86fc4917a
6 changed files with 97 additions and 23 deletions
+13
View File
@@ -231,6 +231,19 @@ impl fmt::Debug for Core {
}
}
impl Drop for Inner {
fn drop(&mut self) {
// When a reactor is dropped it needs to wake up all blocked tasks as
// they'll never receive a notification, and all connected I/O objects
// will start returning errors pretty quickly.
let io = self.io_dispatch.read().unwrap();
for (_, io) in io.iter() {
io.writer.notify();
io.reader.notify();
}
}
}
impl Inner {
/// Register an I/O resource with the reactor.
///