From 380bd2fc0286112abb434e9f6909f4bc53dc9b9a Mon Sep 17 00:00:00 2001 From: Astro Date: Sat, 26 Jan 2019 20:46:51 +0100 Subject: [PATCH] client: implement close() to close inner stream --- src/client/mod.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/client/mod.rs b/src/client/mod.rs index b4793f9..a33dade 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -208,4 +208,19 @@ impl Sink for Client { _ => Ok(Async::Ready(())), } } + + /// This closes the inner TCP stream. + /// + /// To synchronize your shutdown with the server side, you should + /// first send `Packet::StreamEnd` and wait it to be sent back + /// before closing the connection. + fn close(&mut self) -> Poll<(), Self::SinkError> { + match self.state { + ClientState::Connected(ref mut stream) => + stream.close() + .map_err(|e| e.into()), + _ => + Ok(Async::Ready(())), + } + } }