tokio-tcp: add tokio::net::TcpStream::try_clone (#448)

This commit is contained in:
João Oliveira
2018-07-11 11:54:08 -07:00
committed by Carl Lerche
parent e6fc3d209d
commit 54b7c1b10d
+11
View File
@@ -374,6 +374,17 @@ impl TcpStream {
pub fn set_linger(&self, dur: Option<Duration>) -> io::Result<()> {
self.io.get_ref().set_linger(dur)
}
/// Creates a new independently owned handle to the underlying socket.
///
/// The returned `TcpStream` is a reference to the same stream that this
/// object references. Both handles will read and write the same stream of
/// data, and options set on one stream will be propagated to the other
/// stream.
pub fn try_clone(&self) -> io::Result<TcpStream> {
let io = self.io.get_ref().try_clone()?;
Ok(TcpStream::new(io))
}
}
// ===== impl Read / Write =====