diff --git a/src/net/tcp/listener.rs b/src/net/tcp/listener.rs index dc0b917..fc99d9f 100644 --- a/src/net/tcp/listener.rs +++ b/src/net/tcp/listener.rs @@ -204,6 +204,11 @@ impl<'a> Stream for Incoming<'a> { impl From for TcpListener { /// Converts a `std::net::TcpListener` into its asynchronous equivalent. fn from(listener: std::net::TcpListener) -> TcpListener { + // Make sure we are in nonblocking mode. + listener + .set_nonblocking(true) + .expect("failed to set nonblocking mode"); + let mio_listener = mio::net::TcpListener::from_std(listener); TcpListener { watcher: Watcher::new(mio_listener), diff --git a/src/net/tcp/stream.rs b/src/net/tcp/stream.rs index e1bb067..7952964 100644 --- a/src/net/tcp/stream.rs +++ b/src/net/tcp/stream.rs @@ -370,6 +370,11 @@ impl Write for &TcpStream { impl From for TcpStream { /// Converts a `std::net::TcpStream` into its asynchronous equivalent. fn from(stream: std::net::TcpStream) -> TcpStream { + // Make sure we are in nonblocking mode. + stream + .set_nonblocking(true) + .expect("failed to set nonblocking mode"); + let mio_stream = mio::net::TcpStream::from_std(stream); TcpStream { watcher: Arc::new(Watcher::new(mio_stream)), diff --git a/src/net/udp/mod.rs b/src/net/udp/mod.rs index b1a7025..4698b45 100644 --- a/src/net/udp/mod.rs +++ b/src/net/udp/mod.rs @@ -496,6 +496,11 @@ impl UdpSocket { impl From for UdpSocket { /// Converts a `std::net::UdpSocket` into its asynchronous equivalent. fn from(socket: std::net::UdpSocket) -> UdpSocket { + // Make sure we are in nonblocking mode. + socket + .set_nonblocking(true) + .expect("failed to set nonblocking mode"); + let mio_socket = mio::net::UdpSocket::from_std(socket); UdpSocket { watcher: Watcher::new(mio_socket), diff --git a/src/os/unix/net/datagram.rs b/src/os/unix/net/datagram.rs index 20b1046..c7c9403 100644 --- a/src/os/unix/net/datagram.rs +++ b/src/os/unix/net/datagram.rs @@ -313,6 +313,11 @@ impl fmt::Debug for UnixDatagram { impl From for UnixDatagram { /// Converts a `std::os::unix::net::UnixDatagram` into its asynchronous equivalent. fn from(datagram: std::os::unix::net::UnixDatagram) -> UnixDatagram { + // Make sure we are in nonblocking mode. + datagram + .set_nonblocking(true) + .expect("failed to set nonblocking mode"); + let mio_datagram = mio::net::UnixDatagram::from_std(datagram); UnixDatagram { watcher: Watcher::new(mio_datagram), diff --git a/src/os/unix/net/listener.rs b/src/os/unix/net/listener.rs index ecced86..e77d423 100644 --- a/src/os/unix/net/listener.rs +++ b/src/os/unix/net/listener.rs @@ -195,6 +195,11 @@ impl Stream for Incoming<'_> { impl From for UnixListener { /// Converts a `std::os::unix::net::UnixListener` into its asynchronous equivalent. fn from(listener: std::os::unix::net::UnixListener) -> UnixListener { + // Make sure we are in nonblocking mode. + listener + .set_nonblocking(true) + .expect("failed to set nonblocking mode"); + let mio_listener = mio::net::UnixListener::from_std(listener); UnixListener { watcher: Watcher::new(mio_listener), diff --git a/src/os/unix/net/stream.rs b/src/os/unix/net/stream.rs index 169ad22..3cd8fc9 100644 --- a/src/os/unix/net/stream.rs +++ b/src/os/unix/net/stream.rs @@ -235,6 +235,11 @@ impl fmt::Debug for UnixStream { impl From for UnixStream { /// Converts a `std::os::unix::net::UnixStream` into its asynchronous equivalent. fn from(stream: std::os::unix::net::UnixStream) -> UnixStream { + // Make sure we are in nonblocking mode. + stream + .set_nonblocking(true) + .expect("failed to set nonblocking mode"); + let mio_stream = mio::net::UnixStream::from_std(stream); UnixStream { watcher: Watcher::new(mio_stream),