Properly destroy closed WebSocketHandles

This commit is contained in:
sukibaby
2024-12-17 09:02:53 -08:00
committed by teejusb
parent 29d6531a50
commit 4af78281cf
2 changed files with 24 additions and 3 deletions
+20 -2
View File
@@ -100,6 +100,12 @@ NetworkManager::~NetworkManager()
// Unregister with Lua.
LUA->UnsetGlobal("NETWORK");
// Close all WebSocket connections
for (auto& handle : webSocketHandles) {
handle->webSocket.stop();
}
// Set the status to uninitialized.
ix::uninitNetSystem();
}
@@ -262,6 +268,8 @@ WebSocketHandlePtr NetworkManager::WebSocket(const WebSocketArgs& args)
handle->webSocket.start();
webSocketHandles.push_back(handle);
return handle;
}
@@ -316,6 +324,10 @@ int HttpRequestFuture::Cancel(lua_State *L)
return 0;
}
WebSocketHandle::~WebSocketHandle() {
webSocket.stop();
}
int WebSocketHandle::Collect(lua_State *L)
{
void *udata = luaL_checkudata(L, 1, "WebSocketHandle");
@@ -328,11 +340,17 @@ int WebSocketHandle::Close(lua_State *L)
{
void *udata = luaL_checkudata(L, 1, "WebSocketHandle");
auto handle = *static_cast<WebSocketHandlePtr*>(udata);
LUA->YieldLua();
handle->webSocket.stop();
handle->onClose();
LUA->UnyieldLua();
return 0;
if (handle->onClose)
{
handle->onClose();
}
return 1;
}
int WebSocketHandle::Send(lua_State *L)
+4 -1
View File
@@ -110,7 +110,8 @@ class WebSocketHandle
{
public:
WebSocketHandle() {};
~WebSocketHandle();
static int Collect(lua_State *L);
static int Close(lua_State *L);
static int Send(lua_State *L);
@@ -146,6 +147,8 @@ private:
static Preference<bool> httpEnabled;
static Preference<RString> httpAllowHosts;
std::vector<std::shared_ptr<WebSocketHandle>> webSocketHandles;
};
extern NetworkManager* NETWORK;