@@ -39,17 +39,29 @@ void CSocketManager::DoPulse()
3939 }
4040}
4141
42+
43+ void CSocketManager::ResourceStopped ( lua_State * luaVM )
44+ {
45+ // Enusure all sockets using luaVM are closed
46+ CSocket* pSocket;
47+ while ( GetSocketByLuaVM ( pSocket, luaVM ) )
48+ {
49+ SocketRemove ( pSocket, false );
50+ }
51+ }
52+
53+
4254void CSocketManager::SocketAdd (CSocket*& pSocket)
4355{
4456 // Add the socket to the loop stuff
4557 vecSockets.push_back (pSocket);
4658}
4759
48- void CSocketManager::SocketRemove (CSocket*& pSocket)
60+ void CSocketManager::SocketRemove (CSocket*& pSocket, bool bTriggerCloseEvent )
4961{
5062 ListRemove (vecSockets, pSocket);
5163 ListRemove (processQueue, pSocket);
52- pSocket->CloseSocketWithEvent ();
64+ pSocket->CloseSocketWithEvent (bTriggerCloseEvent );
5365 ListRemove (deleteList, pSocket);
5466 deleteList.push_back (pSocket);
5567}
@@ -75,6 +87,24 @@ bool CSocketManager::GetSocket(CSocket*& pSocket, void* pUserdata)
7587 return false ;
7688}
7789
90+
91+ bool CSocketManager::GetSocketByLuaVM (CSocket*& pSocket, lua_State * luaVM)
92+ {
93+ // Loop through all sockets
94+ for (unsigned int i = 0 ; i < vecSockets.size (); ++i)
95+ {
96+ // Compare the current socket's luaVM with the one we're looking for
97+ if (vecSockets[i]->GetLuaVM () == luaVM)
98+ {
99+ // If it's the one we want, assign pSocket to it and return true
100+ pSocket = vecSockets[i];
101+ return true ;
102+ }
103+ }
104+
105+ return false ;
106+ }
107+
78108void CSocketManager::HandleStop ()
79109{
80110 // Triggered at module stop. Simply destroys all sockets
0 commit comments