diff options
| author | Austin Hellyer <[email protected]> | 2016-11-10 07:31:56 -0800 |
|---|---|---|
| committer | Austin Hellyer <[email protected]> | 2016-11-10 07:31:56 -0800 |
| commit | 29b93af4b0c4ef85a709af8e47f132c4bab5b165 (patch) | |
| tree | da2a20381c096675269fa4f9f7778eae632e3ce3 /src/client | |
| parent | Add a Feature enum (diff) | |
| download | serenity-29b93af4b0c4ef85a709af8e47f132c4bab5b165.tar.xz serenity-29b93af4b0c4ef85a709af8e47f132c4bab5b165.zip | |
Correctly shutdown the connection
Rather than completely dropping the connection, send a close code prior.
Diffstat (limited to 'src/client')
| -rw-r--r-- | src/client/connection.rs | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/client/connection.rs b/src/client/connection.rs index cb3501b..fd06160 100644 --- a/src/client/connection.rs +++ b/src/client/connection.rs @@ -2,6 +2,7 @@ use flate2::read::ZlibDecoder; use serde_json::builder::ObjectBuilder; use serde_json; use std::fmt::{self, Display}; +use std::io::Write; use std::net::Shutdown; use std::sync::mpsc::{ self, @@ -416,11 +417,18 @@ impl Connection { Ok(first_event) } - pub fn shutdown(mut self) -> Result<()> { - try!(self.receiver - .get_mut() - .get_mut() - .shutdown(Shutdown::Both)); + pub fn shutdown(&mut self) -> Result<()> { + let stream = self.receiver.get_mut().get_mut(); + + { + let mut sender = Sender::new(stream.by_ref(), true); + let message = WsMessage::close_because(1000, ""); + + try!(sender.send_message(&message)); + } + + try!(stream.flush()); + try!(stream.shutdown(Shutdown::Both)); Ok(()) } |