From 91fdc9a4761d45209fb45a840540a3519e6a9d19 Mon Sep 17 00:00:00 2001 From: wingdeans <66850754+wingdeans@users.noreply.github.com> Date: Mon, 27 Nov 2023 13:36:04 -0500 Subject: [PATCH] Always close WS, handle close message --- tool/net/redbean.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tool/net/redbean.c b/tool/net/redbean.c index bc70f1892..37bd3dea2 100644 --- a/tool/net/redbean.c +++ b/tool/net/redbean.c @@ -5256,6 +5256,9 @@ static int LuaReadWS(lua_State *L) { luaL_error(L, "Could not read WS data"); } + if ((wshdr[0] & 0xF) == 0x8) + luaL_error(L, "WS connection closed"); + for (i = 0, amt = amtread; i < got; ++i, ++amt) inbuf.p[amt] ^= mask[i & 0x3]; lua_pushlstring(L, inbuf.p + amtread, got); @@ -6624,14 +6627,12 @@ static bool StreamWS(char *p) { if (Send(iov, 4) == -1) break; } - if (rc != -1) { - wshdr[0] = 0x8; - wshdr[1] = 0; - iov[0].iov_len = 2; - Send(iov, 1); - } else { - connectionclose = true; - } + wshdr[0] = 0x8 | (1 << 7); + wshdr[1] = 0; + iov[0].iov_len = 2; + Send(iov, 1); + connectionclose = true; + return true; }