commit - 2c2c93e311c09faa68cbdb4939902c2bca2d5383
commit + c997e043259af2663f40349490729668c7b61256
blob - 2e23ade8e8bf406a7c2c2f3771e8fe17abc1fce6
blob + a0f7f242abce3f424fae292d871ea89804cba661
--- src/ngircd/conn.c
+++ src/ngircd/conn.c
static array My_Listeners;
static array My_ConnArray;
+static size_t NumConnections;
#ifdef TCPWRAP
int allow_severity = LOG_INFO;
cb_listen(int sock, short irrelevant)
{
(void) irrelevant;
- New_Connection( sock );
+ if (New_Connection( sock ) >= 0)
+ NumConnections++;
}
/* Speicher fuer Verbindungs-Pool anfordern */
Pool_Size = CONNECTION_POOL;
- if( Conf_MaxConnections > 0 )
- {
- /* konfiguriertes Limit beachten */
- if( Pool_Size > Conf_MaxConnections ) Pool_Size = Conf_MaxConnections;
- }
-
+ if ((Conf_MaxConnections > 0) &&
+ (Pool_Size > Conf_MaxConnections))
+ Pool_Size = Conf_MaxConnections;
+
if (!array_alloc(&My_ConnArray, sizeof(CONNECTION), (size_t)Pool_Size)) {
Log( LOG_EMERG, "Can't allocate memory! [Conn_Init]" );
exit( 1 );
/* Clean up connection structure (=free it) */
Init_Conn_Struct( Idx );
- LogDebug("Shutdown of connection %d completed.", Idx );
+ assert(NumConnections > 0);
+ if (NumConnections)
+ NumConnections--;
+ LogDebug("Shutdown of connection %d completed", Idx );
} /* Conn_Close */
#endif
ng_ipaddr_t new_addr;
char ip_str[NG_INET_ADDRSTRLEN];
- int new_sock, new_sock_len, new_Pool_Size;
+ int new_sock, new_sock_len;
CLIENT *c;
long cnt;
Log(LOG_CRIT, "fd %d: Can't convert IP address!", new_sock);
Simple_Message(new_sock, "ERROR :Internal Server Error");
close(new_sock);
+ return -1;
}
#ifdef TCPWRAP
return -1;
}
- if( new_sock >= Pool_Size ) {
- new_Pool_Size = new_sock + 1;
- /* No free Connection Structures, check if we may accept further connections */
- if ((( Conf_MaxConnections > 0) && Pool_Size >= Conf_MaxConnections) ||
- (new_Pool_Size < Pool_Size))
- {
- Log( LOG_ALERT, "Can't accept connection: limit (%d) reached!", Pool_Size );
- Simple_Message( new_sock, "ERROR :Connection limit reached" );
- close( new_sock );
- return -1;
- }
+ if ((Conf_MaxConnections > 0) &&
+ (NumConnections >= (size_t) Conf_MaxConnections))
+ {
+ Log( LOG_ALERT, "Can't accept connection: limit (%d) reached!", Conf_MaxConnections);
+ Simple_Message( new_sock, "ERROR :Connection limit reached" );
+ close( new_sock );
+ return -1;
+ }
+ if( new_sock >= Pool_Size ) {
if (!array_alloc(&My_ConnArray, sizeof(CONNECTION),
(size_t)new_sock)) {
Log( LOG_EMERG, "Can't allocate memory! [New_Connection]" );
/* Adjust pointer to new block */
My_Connections = array_start(&My_ConnArray);
- while (Pool_Size < new_Pool_Size)
+ while (Pool_Size <= new_sock)
Init_Conn_Struct(Pool_Size++);
}