Commit Diff


commit - 21140500f1d77bdb0912c67a5402ab7280f2ba42
commit + 1338ade65032e5aea4891694a61d8ee3d1c795e1
blob - b95f25ef61a47e6f720e66921a0a266298e77243
blob + 0861b08b9e10f38fbd754be58cc8bf44a4b249aa
--- src/ngircd/conn.c
+++ src/ngircd/conn.c
@@ -95,10 +95,12 @@ static bool Init_Socket PARAMS(( int Sock ));
 static void New_Server PARAMS(( int Server, ng_ipaddr_t *dest ));
 static void Simple_Message PARAMS(( int Sock, const char *Msg ));
 static int NewListener PARAMS(( const char *listen_addr, UINT16 Port ));
+static void Account_Connection PARAMS((void));
 
+
 static array My_Listeners;
 static array My_ConnArray;
-static size_t NumConnections;
+static size_t NumConnections, NumConnectionsMax, NumConnectionsAccepted;
 
 #ifdef TCPWRAP
 int allow_severity = LOG_INFO;
@@ -388,7 +390,8 @@ Conn_Init( void )
 	for (i = 0; i < Pool_Size; i++)
 		Init_Conn_Struct(i);
 
-	/* Global write counter */
+	/* Initialize global counters (required after RESTART command!) */
+	NumConnections = NumConnectionsMax = NumConnectionsAccepted = 0;
 	WCounter = 0;
 } /* Conn_Init */
 
@@ -1100,8 +1103,29 @@ Conn_Close( CONN_ID Idx, const char *LogMsg, const cha
 	LogDebug("Shutdown of connection %d completed, %ld connection%s left.",
 		 Idx, NumConnections, NumConnections != 1 ? "s" : "");
 } /* Conn_Close */
+
+
+GLOBAL long
+Conn_Count(void)
+{
+	return NumConnections;
+} /* Conn_Count */
 
 
+GLOBAL long
+Conn_CountMax(void)
+{
+	return NumConnectionsMax;
+} /* Conn_CountMax */
+
+
+GLOBAL long
+Conn_CountAccepted(void)
+{
+	return NumConnectionsAccepted;
+} /* Conn_CountAccepted */
+
+
 GLOBAL void
 Conn_SyncServerStruct( void )
 {
@@ -1242,6 +1266,7 @@ New_Connection(int Sock)
 		Log(LOG_CRIT, "Can't accept connection: %s!", strerror(errno));
 		return -1;
 	}
+	NumConnectionsAccepted++;
 
 	if (!ng_ipaddr_tostr_r(&new_addr, ip_str)) {
 		Log(LOG_CRIT, "fd %d: Can't convert IP address!", new_sock);
@@ -1361,10 +1386,20 @@ New_Connection(int Sock)
 	 * If there are results earlier, the delay is aborted. */
 	Conn_SetPenalty(new_sock, 4);
 
-	NumConnections++;
-	LogDebug("Total number of connections now %ld.", NumConnections);
+	Account_Connection();
 	return new_sock;
 } /* New_Connection */
+
+
+static void
+Account_Connection(void)
+{
+	NumConnections++;
+	if (NumConnections > NumConnectionsMax)
+		NumConnectionsMax = NumConnections;
+	LogDebug("Total number of connections now %lu (max %lu).",
+		 NumConnections, NumConnectionsMax);
+} /* Account_Connection */
 
 
 static CONN_ID
@@ -1806,7 +1841,7 @@ New_Server( int Server , ng_ipaddr_t *dest)
 	}
 
 	/* Conn_Close() decrements this counter again */
-	NumConnections++;
+	Account_Connection();
 	Client_SetIntroducer( c, c );
 	Client_SetToken( c, TOKEN_OUTBOUND );
 
blob - b94b10d5e513a8abccaa8c9d62c16366913be60c
blob + f2ec823ea6ee25bed5af38149263cbd228a6a2f7
--- src/ngircd/conn.h
+++ src/ngircd/conn.h
@@ -1,6 +1,6 @@
 /*
  * ngIRCd -- The Next Generation IRC Daemon
- * Copyright (c)2001-2009 by Alexander Barton (alex@barton.de)
+ * Copyright (c)2001-2010 Alexander Barton <alex@barton.de>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -122,5 +122,9 @@ static inline bool Conn_UsesSSL(UNUSED CONN_ID Idx) { 
 #endif
 #endif
 
+GLOBAL long Conn_Count PARAMS((void));
+GLOBAL long Conn_CountMax PARAMS((void));
+GLOBAL long Conn_CountAccepted PARAMS((void));
 
+
 /* -eof- */