summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-01-09 15:35:35 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-01-09 15:35:35 +0800
commit394f5dd03c48e260d0aea6af8faa5b3571953500 (patch)
tree3109fa5910bdd8c696d8473ad76ab1685f1ce7f3
parent23c0ec2222be9680dce65e51b9c19ba217ae83a8 (diff)
downloadpttbbs-394f5dd03c48e260d0aea6af8faa5b3571953500.tar
pttbbs-394f5dd03c48e260d0aea6af8faa5b3571953500.tar.gz
pttbbs-394f5dd03c48e260d0aea6af8faa5b3571953500.tar.bz2
pttbbs-394f5dd03c48e260d0aea6af8faa5b3571953500.tar.lz
pttbbs-394f5dd03c48e260d0aea6af8faa5b3571953500.tar.xz
pttbbs-394f5dd03c48e260d0aea6af8faa5b3571953500.tar.zst
pttbbs-394f5dd03c48e260d0aea6af8faa5b3571953500.zip
OVERLOADBLOCKFDS
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1477 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--include/config.h4
-rw-r--r--mbbsd/mbbsd.c33
-rw-r--r--sample/pttbbs.conf5
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 э眤玡秈礶)"