diff --git a/Cargo.toml b/Cargo.toml index 1edf690e0..fab1172f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ appveyor = { repository = "alexcrichton/tokio-core" } [dependencies] bytes = "0.4" log = "0.3" -mio = "0.6.5" +mio = "0.6.7" scoped-tls = "0.1.0" slab = "0.3" iovec = "0.1" diff --git a/src/net/tcp.rs b/src/net/tcp.rs index 06f8efd6c..fd49d5889 100644 --- a/src/net/tcp.rs +++ b/src/net/tcp.rs @@ -18,7 +18,7 @@ use reactor::{Handle, PollEvented}; /// This object can be converted into a stream of incoming connections for /// various forms of processing. pub struct TcpListener { - io: PollEvented, + io: PollEvented, pending_accept: Option>>, } @@ -34,7 +34,7 @@ impl TcpListener { /// The TCP listener will bind to the provided `addr` address, if available. /// If the result is `Ok`, the socket has successfully bound. pub fn bind(addr: &SocketAddr, handle: &Handle) -> io::Result { - let l = try!(mio::tcp::TcpListener::bind(addr)); + let l = try!(mio::net::TcpListener::bind(addr)); TcpListener::new(l, handle) } @@ -136,11 +136,11 @@ impl TcpListener { pub fn from_listener(listener: net::TcpListener, addr: &SocketAddr, handle: &Handle) -> io::Result { - let l = try!(mio::tcp::TcpListener::from_listener(listener, addr)); + let l = try!(mio::net::TcpListener::from_listener(listener, addr)); TcpListener::new(l, handle) } - fn new(listener: mio::tcp::TcpListener, handle: &Handle) + fn new(listener: mio::net::TcpListener, handle: &Handle) -> io::Result { let io = try!(PollEvented::new(listener, handle)); Ok(TcpListener { io: io, pending_accept: None }) @@ -229,7 +229,7 @@ impl Stream for Incoming { /// raw underlying I/O object as well as streams for the read/write /// notifications on the stream itself. pub struct TcpStream { - io: PollEvented, + io: PollEvented, } /// Future returned by `TcpStream::connect` which will resolve to a `TcpStream` @@ -253,14 +253,14 @@ impl TcpStream { /// connection or during the socket creation, that error will be returned to /// the future instead. pub fn connect(addr: &SocketAddr, handle: &Handle) -> TcpStreamNew { - let inner = match mio::tcp::TcpStream::connect(addr) { + let inner = match mio::net::TcpStream::connect(addr) { Ok(tcp) => TcpStream::new(tcp, handle), Err(e) => TcpStreamNewState::Error(e), }; TcpStreamNew { inner: inner } } - fn new(connected_stream: mio::tcp::TcpStream, handle: &Handle) + fn new(connected_stream: mio::net::TcpStream, handle: &Handle) -> TcpStreamNewState { match PollEvented::new(connected_stream, handle) { Ok(io) => TcpStreamNewState::Waiting(TcpStream { io: io }), @@ -275,7 +275,7 @@ impl TcpStream { /// returned is associated with the event loop and ready to perform I/O. pub fn from_stream(stream: net::TcpStream, handle: &Handle) -> io::Result { - let inner = try!(mio::tcp::TcpStream::from_stream(stream)); + let inner = try!(mio::net::TcpStream::from_stream(stream)); Ok(TcpStream { io: try!(PollEvented::new(inner, handle)), }) @@ -303,7 +303,7 @@ impl TcpStream { addr: &SocketAddr, handle: &Handle) -> Box + Send> { - let state = match mio::tcp::TcpStream::connect_stream(stream, addr) { + let state = match mio::net::TcpStream::connect_stream(stream, addr) { Ok(tcp) => TcpStream::new(tcp, handle), Err(e) => TcpStreamNewState::Error(e), }; diff --git a/src/net/udp/mod.rs b/src/net/udp/mod.rs index 7592ef21e..9befb33fc 100644 --- a/src/net/udp/mod.rs +++ b/src/net/udp/mod.rs @@ -10,7 +10,7 @@ use reactor::{Handle, PollEvented}; /// An I/O object representing a UDP socket. pub struct UdpSocket { - io: PollEvented, + io: PollEvented, } mod frame; @@ -22,11 +22,11 @@ impl UdpSocket { /// This function will create a new UDP socket and attempt to bind it to the /// `addr` provided. If the result is `Ok`, the socket has successfully bound. pub fn bind(addr: &SocketAddr, handle: &Handle) -> io::Result { - let udp = try!(mio::udp::UdpSocket::bind(addr)); + let udp = try!(mio::net::UdpSocket::bind(addr)); UdpSocket::new(udp, handle) } - fn new(socket: mio::udp::UdpSocket, handle: &Handle) -> io::Result { + fn new(socket: mio::net::UdpSocket, handle: &Handle) -> io::Result { let io = try!(PollEvented::new(socket, handle)); Ok(UdpSocket { io: io }) } @@ -42,7 +42,7 @@ impl UdpSocket { /// `reuse_address` or binding to multiple addresses. pub fn from_socket(socket: net::UdpSocket, handle: &Handle) -> io::Result { - let udp = try!(mio::udp::UdpSocket::from_socket(socket)); + let udp = try!(mio::net::UdpSocket::from_socket(socket)); UdpSocket::new(udp, handle) } @@ -104,12 +104,13 @@ impl UdpSocket { return Err(::would_block()) } match self.io.get_ref().send_to(buf, target) { - Ok(Some(n)) => Ok(n), - Ok(None) => { - self.io.need_write(); - Err(::would_block()) + Ok(n) => Ok(n), + Err(e) => { + if e.kind() == io::ErrorKind::WouldBlock { + self.io.need_write(); + } + Err(e) } - Err(e) => Err(e), } } @@ -147,12 +148,13 @@ impl UdpSocket { return Err(::would_block()) } match self.io.get_ref().recv_from(buf) { - Ok(Some(n)) => Ok(n), - Ok(None) => { - self.io.need_read(); - Err(::would_block()) + Ok(n) => Ok(n), + Err(e) => { + if e.kind() == io::ErrorKind::WouldBlock { + self.io.need_read(); + } + Err(e) } - Err(e) => Err(e), } }