Properly destroy closed WebSocketHandles
This commit is contained in:
+20
-2
@@ -100,6 +100,12 @@ NetworkManager::~NetworkManager()
|
|||||||
// Unregister with Lua.
|
// Unregister with Lua.
|
||||||
LUA->UnsetGlobal("NETWORK");
|
LUA->UnsetGlobal("NETWORK");
|
||||||
|
|
||||||
|
// Close all WebSocket connections
|
||||||
|
for (auto& handle : webSocketHandles) {
|
||||||
|
handle->webSocket.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the status to uninitialized.
|
||||||
ix::uninitNetSystem();
|
ix::uninitNetSystem();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,6 +268,8 @@ WebSocketHandlePtr NetworkManager::WebSocket(const WebSocketArgs& args)
|
|||||||
|
|
||||||
handle->webSocket.start();
|
handle->webSocket.start();
|
||||||
|
|
||||||
|
webSocketHandles.push_back(handle);
|
||||||
|
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -316,6 +324,10 @@ int HttpRequestFuture::Cancel(lua_State *L)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WebSocketHandle::~WebSocketHandle() {
|
||||||
|
webSocket.stop();
|
||||||
|
}
|
||||||
|
|
||||||
int WebSocketHandle::Collect(lua_State *L)
|
int WebSocketHandle::Collect(lua_State *L)
|
||||||
{
|
{
|
||||||
void *udata = luaL_checkudata(L, 1, "WebSocketHandle");
|
void *udata = luaL_checkudata(L, 1, "WebSocketHandle");
|
||||||
@@ -328,11 +340,17 @@ int WebSocketHandle::Close(lua_State *L)
|
|||||||
{
|
{
|
||||||
void *udata = luaL_checkudata(L, 1, "WebSocketHandle");
|
void *udata = luaL_checkudata(L, 1, "WebSocketHandle");
|
||||||
auto handle = *static_cast<WebSocketHandlePtr*>(udata);
|
auto handle = *static_cast<WebSocketHandlePtr*>(udata);
|
||||||
|
|
||||||
LUA->YieldLua();
|
LUA->YieldLua();
|
||||||
handle->webSocket.stop();
|
handle->webSocket.stop();
|
||||||
handle->onClose();
|
|
||||||
LUA->UnyieldLua();
|
LUA->UnyieldLua();
|
||||||
return 0;
|
|
||||||
|
if (handle->onClose)
|
||||||
|
{
|
||||||
|
handle->onClose();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int WebSocketHandle::Send(lua_State *L)
|
int WebSocketHandle::Send(lua_State *L)
|
||||||
|
|||||||
@@ -110,6 +110,7 @@ class WebSocketHandle
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WebSocketHandle() {};
|
WebSocketHandle() {};
|
||||||
|
~WebSocketHandle();
|
||||||
|
|
||||||
static int Collect(lua_State *L);
|
static int Collect(lua_State *L);
|
||||||
static int Close(lua_State *L);
|
static int Close(lua_State *L);
|
||||||
@@ -146,6 +147,8 @@ private:
|
|||||||
|
|
||||||
static Preference<bool> httpEnabled;
|
static Preference<bool> httpEnabled;
|
||||||
static Preference<RString> httpAllowHosts;
|
static Preference<RString> httpAllowHosts;
|
||||||
|
|
||||||
|
std::vector<std::shared_ptr<WebSocketHandle>> webSocketHandles;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern NetworkManager* NETWORK;
|
extern NetworkManager* NETWORK;
|
||||||
|
|||||||
Reference in New Issue
Block a user