summaryrefslogtreecommitdiffstats
path: root/mbbsd
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 /mbbsd
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
Diffstat (limited to 'mbbsd')
-rw-r--r--mbbsd/mbbsd.c33
1 files changed, 26 insertions, 7 deletions
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 */