X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fplaintcp.c;h=05921660a16c8c6bf94a0deb34405fbb077050ca;hb=51893006c3f6a5dbae8b5bee6672165124b4e44c;hp=321be41d35380015a9ccd024435a42bff6726876;hpb=4d2dc22a9a68395a5788ae66c84ae0ced2d0e733;p=ashd.git diff --git a/src/plaintcp.c b/src/plaintcp.c index 321be41..0592166 100644 --- a/src/plaintcp.c +++ b/src/plaintcp.c @@ -65,7 +65,7 @@ int listensock4(int port) close(fd); return(-1); } - if(listen(fd, 16) < 0) { + if(listen(fd, 128) < 0) { close(fd); return(-1); } @@ -90,7 +90,7 @@ int listensock6(int port) close(fd); return(-1); } - if(listen(fd, 16) < 0) { + if(listen(fd, 128) < 0) { close(fd); return(-1); } @@ -168,24 +168,39 @@ void servetcp(struct muth *muth, va_list args) static void listenloop(struct muth *muth, va_list args) { vavar(struct tcpport *, tcp); - int ns; + int i, ns, n; struct sockaddr_storage name; socklen_t namelen; + fcntl(tcp->fd, F_SETFL, fcntl(tcp->fd, F_GETFL) | O_NONBLOCK); while(1) { namelen = sizeof(name); - block(tcp->fd, EV_READ, 0); - ns = accept(tcp->fd, (struct sockaddr *)&name, &namelen); - if(ns < 0) { - flog(LOG_ERR, "accept: %s", strerror(errno)); + if(block(tcp->fd, EV_READ, 0) == 0) goto out; + n = 0; + while(1) { + ns = accept(tcp->fd, (struct sockaddr *)&name, &namelen); + if(ns < 0) { + if(errno == EAGAIN) + break; + if(errno == ECONNABORTED) + continue; + flog(LOG_ERR, "accept: %s", strerror(errno)); + goto out; + } + mustart(servetcp, ns, name, tcp); + if(++n >= 100) + break; } - mustart(servetcp, ns, name, tcp); } out: close(tcp->fd); free(tcp); + for(i = 0; i < listeners.d; i++) { + if(listeners.b[i] == muth) + bufdel(listeners, i); + } } void handleplain(int argc, char **argp, char **argv) @@ -215,7 +230,7 @@ void handleplain(int argc, char **argp, char **argv) omalloc(tcp); tcp->fd = fd; tcp->sport = port; - mustart(listenloop, tcp); + bufadd(listeners, mustart(listenloop, tcp)); if((fd = listensock4(port)) < 0) { if(errno != EADDRINUSE) { flog(LOG_ERR, "could not listen on IPv4 (port %i): %s", port, strerror(errno)); @@ -225,6 +240,6 @@ void handleplain(int argc, char **argp, char **argv) omalloc(tcp); tcp->fd = fd; tcp->sport = port; - mustart(listenloop, tcp); + bufadd(listeners, mustart(listenloop, tcp)); } }