mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-09-28 12:10:37 +00:00
Add TcpListener::accept_std (#284)
This commit is contained in:
parent
b7ff130a0d
commit
963eee3bc7
@ -108,6 +108,26 @@ impl TcpListener {
|
||||
}
|
||||
}
|
||||
|
||||
/// Like `accept`, except that it returns a raw `std::net::TcpStream`.
|
||||
///
|
||||
/// The stream is *in blocking mode*, and is not associated with the Tokio
|
||||
/// event loop.
|
||||
pub fn accept_std(&mut self) -> io::Result<(net::TcpStream, SocketAddr)> {
|
||||
if let Async::NotReady = self.io.poll_read() {
|
||||
return Err(io::Error::new(io::ErrorKind::WouldBlock, "not ready"))
|
||||
}
|
||||
|
||||
match self.io.get_ref().accept_std() {
|
||||
Err(e) => {
|
||||
if e.kind() == io::ErrorKind::WouldBlock {
|
||||
self.io.need_read();
|
||||
}
|
||||
Err(e)
|
||||
},
|
||||
Ok((sock, addr)) => Ok((sock, addr)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new TCP listener from the standard library's TCP listener.
|
||||
///
|
||||
/// This method can be used when the `Handle::tcp_listen` method isn't
|
||||
|
Loading…
x
Reference in New Issue
Block a user