diff options
-rw-r--r-- | include/config.h | 4 | ||||
-rw-r--r-- | mbbsd/mbbsd.c | 33 | ||||
-rw-r--r-- | sample/pttbbs.conf | 5 |
3 files changed, 35 insertions, 7 deletions
diff --git a/include/config.h b/include/config.h index 4958b24f..55ed2d21 100644 --- a/include/config.h +++ b/include/config.h @@ -97,6 +97,10 @@ #define DIRCACHESIZE (40) /* cache ゅ彻い程40絞 */ #endif +#ifndef OVERLOADBLOCKFDS +#define OVERLOADBLOCKFDS (0) /* 禬更穦玂痙硂或 fd */ +#endif + /* 临ゼ俱瞶 */ #define MAX_FRIEND (256) /* 更 cache ぇ程狟ね计ヘ */ #define MAX_REJECT (32) /* 更 cache ぇ程胊计ヘ */ diff --git a/mbbsd/mbbsd.c b/mbbsd/mbbsd.c index 5bd1185b..c6575a39 100644 --- a/mbbsd/mbbsd.c +++ b/mbbsd/mbbsd.c @@ -1309,8 +1309,12 @@ daemon_login(int argc, char *argv[], char *envp[]) int msock, csock; /* socket for Master and Child */ FILE *fp; int listen_port = 23; - int len_of_sock_addr; + int len_of_sock_addr, overloading = 0; char buf[256]; +#if OVERLOADBLOCKFDS + int blockfd[OVERLOADBLOCKFDS]; + int i, nblocked = 0; +#endif /* setup standalone */ @@ -1367,19 +1371,35 @@ daemon_login(int argc, char *argv[], char *envp[]) } /* main loop */ - for (;;) { + while( 1 ){ len_of_sock_addr = sizeof(xsin); - csock = accept(msock, (struct sockaddr *) & xsin, (socklen_t *) & len_of_sock_addr); - - if (csock < 0) { + if( (csock = accept(msock, (struct sockaddr *)&xsin, + (socklen_t *)&len_of_sock_addr)) < 0 ){ if (errno != EINTR) sleep(1); continue; } - if (check_ban_and_load(csock)) { + + overloading = check_ban_and_load(csock); +#if OVERLOADBLOCKFDS + if( (!overloading && nblocked) || + (overloading && nblocked == OVERLOADBLOCKFDS) ){ + for( i = 0 ; i < OVERLOADBLOCKFDS ; ++i ) + if( blockfd[i] != csock ) + close(blockfd[i]); + nblocked = 0; + } +#endif + + if( overloading ){ +#if OVERLOADBLOCKFDS + blockfd[nblocked++] = csock; +#else close(csock); +#endif continue; } + #ifdef NO_FORK break; #else @@ -1388,7 +1408,6 @@ daemon_login(int argc, char *argv[], char *envp[]) else close(csock); #endif - } /* here is only child running */ diff --git a/sample/pttbbs.conf b/sample/pttbbs.conf index 4aea85f3..86de5cd8 100644 --- a/sample/pttbbs.conf +++ b/sample/pttbbs.conf @@ -128,6 +128,11 @@ 秖╰参璽㎝ (代刚い, ゼЧΘ) */ //#define NOKILLWATERBALL + +/* 璝﹚竡, 玥╰参禬筁璽颤, 穝钡硈絬穦痙 OVERLOADBLOCKFDS + 硂或 fd , 磷ㄏノ╣硈硑Θ璽颤 (default: 0) */ +//#define OVERLOADBLOCKFDS 128 + /* 玡秈礶 */ #define INSCREEN \ "玡秈礶 (叫 pttbbs.conf э眤玡秈礶)" |