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
+3 -3
View File
@@ -64,7 +64,7 @@ impl TcpListener {
match self.io.get_ref().accept() {
Err(e) => {
if e.kind() == io::ErrorKind::WouldBlock {
self.io.need_read();
self.io.need_read()?;
}
Err(e)
},
@@ -576,7 +576,7 @@ impl<'a> AsyncRead for &'a TcpStream {
Ok(Async::Ready(n))
}
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
self.io.need_read();
self.io.need_read()?;
Ok(Async::NotReady)
}
Err(e) => Err(e),
@@ -614,7 +614,7 @@ impl<'a> AsyncWrite for &'a TcpStream {
Ok(Async::Ready(n))
}
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
self.io.need_write();
self.io.need_write()?;
Ok(Async::NotReady)
}
Err(e) => Err(e),
+4 -4
View File
@@ -93,7 +93,7 @@ impl UdpSocket {
Ok(n) => Ok(n),
Err(e) => {
if e.kind() == io::ErrorKind::WouldBlock {
self.io.need_write();
self.io.need_write()?;
}
Err(e)
}
@@ -115,7 +115,7 @@ impl UdpSocket {
Ok(n) => Ok(n),
Err(e) => {
if e.kind() == io::ErrorKind::WouldBlock {
self.io.need_read();
self.io.need_read()?;
}
Err(e)
}
@@ -163,7 +163,7 @@ impl UdpSocket {
Ok(n) => Ok(n),
Err(e) => {
if e.kind() == io::ErrorKind::WouldBlock {
self.io.need_write();
self.io.need_write()?;
}
Err(e)
}
@@ -205,7 +205,7 @@ impl UdpSocket {
Ok(n) => Ok(n),
Err(e) => {
if e.kind() == io::ErrorKind::WouldBlock {
self.io.need_read();
self.io.need_read()?;
}
Err(e)
}