From be78f6578befe107deabdf040d4297f994a52054 Mon Sep 17 00:00:00 2001 From: Astro Date: Tue, 29 Jan 2019 01:34:44 +0100 Subject: [PATCH] Revert "client: add more state to make close() send ``" This reverts commit 6379f91e02fc0813e8478a1115bb9050d2a23cb6. --- src/client/mod.rs | 48 +++++++++-------------------------------------- 1 file changed, 9 insertions(+), 39 deletions(-) diff --git a/src/client/mod.rs b/src/client/mod.rs index 025b439..9033b83 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -35,8 +35,6 @@ enum ClientState { Disconnected, Connecting(Box>), Connected(XMPPStream), - ClosingSendEnd(futures::sink::Send), - ClosingClose(XMPPStream), } impl Client { @@ -190,14 +188,6 @@ impl Stream for Client { Err(e) => Err(e)?, } } - ClientState::ClosingSendEnd(_) => { - self.state = state; - Ok(Async::NotReady) - } - ClientState::ClosingClose(_) => { - self.state = state; - Ok(Async::NotReady) - } } } } @@ -229,40 +219,20 @@ impl Sink for Client { fn poll_complete(&mut self) -> Poll<(), Self::SinkError> { match self.state { ClientState::Connected(ref mut stream) => stream.poll_complete().map_err(|e| e.into()), - ClientState::ClosingSendEnd(ref mut send) => { - match send.poll()? { - Async::NotReady => - Ok(Async::NotReady), - Async::Ready(stream) => { - self.state = ClientState::ClosingClose(stream); - self.poll_complete() - } - } - } - ClientState::ClosingClose(ref mut stream) => { - match stream.close()? { - Async::NotReady => - Ok(Async::NotReady), - Async::Ready(()) => { - self.state = ClientState::Disconnected; - Ok(Async::Ready(())) - } - } - } _ => Ok(Async::Ready(())), } } - /// Send ` and later close the inner TCP stream. + /// This closes the inner TCP stream. + /// + /// To synchronize your shutdown with the server side, you should + /// first send `Packet::StreamEnd` and wait for the end of the + /// incoming stream before closing the connection. fn close(&mut self) -> Poll<(), Self::SinkError> { - let state = replace(&mut self.state, ClientState::Disconnected); - - match state { - ClientState::Connected(stream) => { - let send = stream.send(Packet::StreamEnd); - self.state = ClientState::ClosingSendEnd(send); - self.poll_complete() - } + match self.state { + ClientState::Connected(ref mut stream) => + stream.close() + .map_err(|e| e.into()), _ => Ok(Async::Ready(())), }