From 2918eec1b35ad0ceba42bc7414ad0a00113ec36b Mon Sep 17 00:00:00 2001 From: Naja Melan Date: Thu, 12 Sep 2019 02:53:02 +0200 Subject: [PATCH] No longer accept to send after close --- src/protocol/mod.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/protocol/mod.rs b/src/protocol/mod.rs index 36a440d..31d5fd4 100644 --- a/src/protocol/mod.rs +++ b/src/protocol/mod.rs @@ -230,9 +230,14 @@ impl WebSocketContext { where Stream: Read + Write, { - // Do not write to already closed connections. + // When terminated, return AlreadyClosed. self.state.check_active()?; + // Do not write after sending a close frame. + if !self.state.is_active() { + return Err(Error::Protocol("Sending after closing is not allowed".into())); + } + if let Some(max_send_queue) = self.config.max_send_queue { if self.send_queue.len() >= max_send_queue { // Try to make some room for the new message.