From 588b93a2bad8f9326a67e87c28778cf32d11122c Mon Sep 17 00:00:00 2001 From: brain Date: Tue, 17 May 2005 20:54:13 +0000 Subject: Added configurable SOMAXCONN size git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@1419 e03df62e-2008-0410-955e-edbf42e46eb7 --- docs/inspircd.conf.example | 14 ++++++++++++++ src/inspircd.cpp | 15 +++++++++++---- src/inspircd_io.cpp | 3 ++- src/servers.cpp | 3 ++- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/docs/inspircd.conf.example b/docs/inspircd.conf.example index 5a35a4be2..e99e9772e 100644 --- a/docs/inspircd.conf.example +++ b/docs/inspircd.conf.example @@ -347,12 +347,26 @@ # spam vector or means of flooding an ircd. The # # default is 128, it is not recommended to raise it # # above 1024. Values up to 65535 are permitted. # +# somaxconn - The maximum number of sockets that may be waiting # +# in the accept queue. This usually allows the ircd # +# to soak up more connections in a shorter space of # +# time when increased but please be aware there is a # +# system defined maximum value to this, the same way # +# there is a system defined maximum number of file # +# descriptors. Some systems may only allow this to # +# be up to 5 (ugh) while others such as FreeBSD will # +# default to a much nicer 128. # +# moduledir - This optional value indicates a runtime change of # +# the location where modules are to be found. This # +# does not add a supplementary directory. There can # +# only be one module path. # diff --git a/src/inspircd.cpp b/src/inspircd.cpp index d5156117a..baebc350c 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -88,7 +88,8 @@ int WHOWAS_STALE = 48; // default WHOWAS Entries last 2 days before they go 'sta int WHOWAS_MAX = 100; // default 100 people maximum in the WHOWAS list int DieDelay = 5; time_t startup_time = time(NULL); -int NetBufferSize = 10240; // NetBufferSize used as the buffer size for all read() ops +int NetBufferSize = 10240; // NetBufferSize used as the buffer size for all read() ops +int MaxConn = SOMAXCONN; // size of accept() backlog (128 by default on *BSD) extern int MaxWhoResults; time_t nb_start = 0; int dns_timeout = 5; @@ -232,7 +233,7 @@ std::string getadminnick() void ReadConfig(bool bail, userrec* user) { - char dbg[MAXBUF],pauseval[MAXBUF],Value[MAXBUF],timeout[MAXBUF],NB[MAXBUF],flood[MAXBUF],MW[MAXBUF]; + char dbg[MAXBUF],pauseval[MAXBUF],Value[MAXBUF],timeout[MAXBUF],NB[MAXBUF],flood[MAXBUF],MW[MAXBUF],MCON[MAXBUF]; char AH[MAXBUF],AP[MAXBUF],AF[MAXBUF],DNT[MAXBUF],pfreq[MAXBUF],thold[MAXBUF],sqmax[MAXBUF],rqmax[MAXBUF]; ConnectClass c; std::stringstream errstr; @@ -293,12 +294,18 @@ void ReadConfig(bool bail, userrec* user) ConfValue("dns","timeout",0,DNT,&config_f); ConfValue("options","moduledir",0,ModPath,&config_f); ConfValue("disabled","commands",0,DisabledCommands,&config_f); + ConfValue("options","somaxconn",0,MCON,&config_f); + MaxConn = atoi(MCON); + if (MaxConn > SOMAXCONN) + log(DEFAULT,"WARNING: value may be higher than the system-defined SOMAXCONN value!"); NetBufferSize = atoi(NB); MaxWhoResults = atoi(MW); dns_timeout = atoi(DNT); if (!dns_timeout) dns_timeout = 5; + if (!MaxConn) + MaxConn = SOMAXCONN; if (!DNSServer[0]) strlcpy(DNSServer,"127.0.0.1",MAXBUF); if (!ModPath[0]) @@ -2704,7 +2711,7 @@ int InspIRCd(char** argv, int argc) { struct kevent ke; log(DEBUG,"kqueue: Add listening socket to events, kq=%d socket=%d",lkq,openSockfd[count]); - EV_SET(&ke, openSockfd[count], EVFILT_READ, EV_ADD, 0, 32, NULL); + EV_SET(&ke, openSockfd[count], EVFILT_READ, EV_ADD, 0, MaxConn, NULL); int i = kevent(lkq, &ke, 1, 0, 0, NULL); if (i == -1) { @@ -2719,7 +2726,7 @@ int InspIRCd(char** argv, int argc) if (me[t]) { log(DEBUG,"kqueue: Add listening SERVER socket to events, kq=%d socket=%d",skq,me[t]->fd); - EV_SET(&ke, me[t]->fd, EVFILT_READ, EV_ADD, 0, 32, NULL); + EV_SET(&ke, me[t]->fd, EVFILT_READ, EV_ADD, 0, MaxConn, NULL); int i = kevent(skq, &ke, 1, 0, 0, NULL); if (i == -1) { diff --git a/src/inspircd_io.cpp b/src/inspircd_io.cpp index e5a0bdcac..1a5046068 100644 --- a/src/inspircd_io.cpp +++ b/src/inspircd_io.cpp @@ -35,6 +35,7 @@ extern int boundPortCount; extern int openSockfd[MAXSOCKS]; extern time_t TIME; extern bool unlimitcore; +extern int MaxConn; void WriteOpers(char* text, ...); @@ -637,7 +638,7 @@ int BindSocket (int sockfd, struct sockaddr_in client, struct sockaddr_in server } else { - listen(sockfd,32); + listen(sockfd, MaxConn); return(TRUE); } } diff --git a/src/servers.cpp b/src/servers.cpp index 56e0d0c41..440a01e38 100644 --- a/src/servers.cpp +++ b/src/servers.cpp @@ -35,6 +35,7 @@ using namespace std; #include "connection.h" extern time_t TIME; +extern int MaxConn; std::deque xsums; @@ -128,7 +129,7 @@ bool serverrec::CreateListener(char* newhost, int p) this->port = p; - listen(this->fd,32); + listen(this->fd, MaxConn); return true; } -- cgit v1.2.3