Gracefull close ws socket

This commit is contained in:
Nikolay Govorov
2026-03-16 20:20:47 +00:00
parent 0675c23217
commit 6d0dc6cb1e
3 changed files with 13 additions and 2 deletions

View File

@@ -308,6 +308,7 @@ pub fn Reader(comptime EXPECT_MASK: bool) type {
pub const WsConnection = struct {
// CLOSE, 2 length, code
const CLOSE_NORMAL = [_]u8{ 136, 2, 3, 232 }; // code: 1000
const CLOSE_GOING_AWAY = [_]u8{ 136, 2, 3, 233 }; // code: 1001
const CLOSE_TOO_BIG = [_]u8{ 136, 2, 3, 241 }; // 1009
const CLOSE_PROTOCOL_ERROR = [_]u8{ 136, 2, 3, 234 }; //code: 1002
// "private-use" close codes must be from 4000-49999
@@ -583,6 +584,10 @@ pub const WsConnection = struct {
return address;
}
pub fn sendClose(self: *WsConnection) void {
self.send(&CLOSE_GOING_AWAY) catch {};
}
pub fn shutdown(self: *WsConnection) void {
posix.shutdown(self.socket, .recv) catch {};
}