forked from mirror/async-std
set nonblocking mode on conversion from std
This commit is contained in:
parent
9d0f2addd3
commit
121bc7d726
6 changed files with 30 additions and 0 deletions
|
@ -204,6 +204,11 @@ impl<'a> Stream for Incoming<'a> {
|
|||
impl From<std::net::TcpListener> 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),
|
||||
|
|
|
@ -370,6 +370,11 @@ impl Write for &TcpStream {
|
|||
impl From<std::net::TcpStream> 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)),
|
||||
|
|
|
@ -496,6 +496,11 @@ impl UdpSocket {
|
|||
impl From<std::net::UdpSocket> 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),
|
||||
|
|
|
@ -313,6 +313,11 @@ impl fmt::Debug for UnixDatagram {
|
|||
impl From<std::os::unix::net::UnixDatagram> 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),
|
||||
|
|
|
@ -195,6 +195,11 @@ impl Stream for Incoming<'_> {
|
|||
impl From<std::os::unix::net::UnixListener> 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),
|
||||
|
|
|
@ -235,6 +235,11 @@ impl fmt::Debug for UnixStream {
|
|||
impl From<std::os::unix::net::UnixStream> 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),
|
||||
|
|
Loading…
Reference in a new issue