From 99da6eb8371669752e2fcec5a62ecbdc053553e4 Mon Sep 17 00:00:00 2001 From: Ansaf Ahmed Date: Tue, 10 Mar 2026 16:22:44 +1100 Subject: [PATCH 1/2] add support for sending close frames from the stream --- src/ws/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/ws/mod.rs b/src/ws/mod.rs index b6835fc..2a691e6 100644 --- a/src/ws/mod.rs +++ b/src/ws/mod.rs @@ -227,6 +227,11 @@ impl Websocket { self.send(true, protocol::op::PING, body) } + #[inline] + pub fn send_close(&mut self) -> Result<(), Error> { + self.send(true, protocol::op::CONNECTION_CLOSE, None) + } + #[inline] fn next(&mut self) -> Result, Error> { self.ensure_not_closed()?; From 096ade75e9e68c8006ca67b81fab5c1068135185 Mon Sep 17 00:00:00 2001 From: Ansaf Ahmed Date: Wed, 11 Mar 2026 10:43:01 +1100 Subject: [PATCH 2/2] fix: make sure to mark websocket as closed after sending close frame --- src/ws/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ws/mod.rs b/src/ws/mod.rs index 2a691e6..6664af2 100644 --- a/src/ws/mod.rs +++ b/src/ws/mod.rs @@ -229,7 +229,9 @@ impl Websocket { #[inline] pub fn send_close(&mut self) -> Result<(), Error> { - self.send(true, protocol::op::CONNECTION_CLOSE, None) + self.send(true, protocol::op::CONNECTION_CLOSE, None)?; + self.closed = true; + Ok(()) } #[inline]