From 54b7c1b10da9df8141af21041aa6f2526083050f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Oliveira?= Date: Wed, 11 Jul 2018 19:54:08 +0100 Subject: [PATCH] tokio-tcp: add tokio::net::TcpStream::try_clone (#448) --- tokio-tcp/src/stream.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tokio-tcp/src/stream.rs b/tokio-tcp/src/stream.rs index b68580cb2..8f4eeaeb0 100644 --- a/tokio-tcp/src/stream.rs +++ b/tokio-tcp/src/stream.rs @@ -374,6 +374,17 @@ impl TcpStream { pub fn set_linger(&self, dur: Option) -> 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 { + let io = self.io.get_ref().try_clone()?; + Ok(TcpStream::new(io)) + } } // ===== impl Read / Write =====