File tree Expand file tree Collapse file tree 4 files changed +29
-6
lines changed Expand file tree Collapse file tree 4 files changed +29
-6
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,13 @@ int CFunctions::sockOpen(lua_State* luaVM)
26
26
// Make sure host is a string, and port is a number
27
27
if ( lua_type ( luaVM, 1 ) == LUA_TSTRING && lua_type ( luaVM, 2 ) == LUA_TNUMBER )
28
28
{
29
+ // Socket limit exceeded ?
30
+ if ( CSocketManager::SocketLimitExceeded ( ) )
31
+ {
32
+ lua_pushboolean (luaVM, false );
33
+ return 1 ;
34
+ }
35
+
29
36
// Put the host in a string, and the port in an unsigned short
30
37
string strHost = lua_tostring ( luaVM, 1 );
31
38
unsigned short usPort = static_cast < unsigned short > ( lua_tonumber ( luaVM, 2 ) );
Original file line number Diff line number Diff line change @@ -22,10 +22,7 @@ class CFunctions;
22
22
#define __CFUNCTIONS_H
23
23
24
24
#include < stdio.h>
25
-
26
25
#include " ml_sockets.h"
27
- #include " include/ILuaModuleManager.h"
28
- extern ILuaModuleManager10 *pModuleManager;
29
26
30
27
class CFunctions
31
28
{
Original file line number Diff line number Diff line change @@ -28,11 +28,25 @@ void CSocketManager::DoPulse()
28
28
}
29
29
}
30
30
31
- void CSocketManager::SocketAdd (CSocket*& pSocket, bool bListen )
31
+ bool CSocketManager::SocketLimitExceeded ( void )
32
+ {
33
+ unsigned int uiSockets = vecSockets.size ();
34
+ if ( uiSockets > MAX_SOCKETS )
35
+ {
36
+ pModuleManager->ErrorPrintf ( " [Sockets] Sockets limit reached! (Max: %i)\n " , MAX_SOCKETS );
37
+ return true ;
38
+ }
39
+
40
+ return false ;
41
+ }
42
+
43
+ bool CSocketManager::SocketAdd (CSocket*& pSocket, bool bListen )
32
44
{
33
45
// Add the socket to the loop stuff
34
46
sSocketsStorage * pSocketStorage = new sSocketsStorage ( pSocket, bListen );
35
47
vecSockets.push_back ( pSocketStorage );
48
+
49
+ return true ;
36
50
}
37
51
38
52
bool CSocketManager::SocketRemove (CSocket*& pSocket)
Original file line number Diff line number Diff line change 12
12
class CSocket ;
13
13
14
14
#include < vector>
15
- #include " ml_sockets.h"
15
+ #include " ml_sockets.h"
16
+ #include " include/ILuaModuleManager.h"
17
+ extern ILuaModuleManager10 *pModuleManager;
18
+
19
+ #define MAX_SOCKETS 255
16
20
17
21
struct sSocketsStorage
18
22
{
@@ -31,7 +35,8 @@ class CSocketManager
31
35
public:
32
36
static void DoPulse ();
33
37
34
- static void SocketAdd ( CSocket*& pSocket, bool bListen = false );
38
+ static bool SocketLimitExceeded ( void );
39
+ static bool SocketAdd ( CSocket*& pSocket, bool bListen = false );
35
40
static bool SocketRemove ( CSocket*& pSocket );
36
41
static bool GetSocket ( CSocket*& pSocket, void * pUserdata );
37
42
You can’t perform that action at this time.
0 commit comments