From: Fredrik Tolf Date: Sun, 13 Apr 2014 22:49:26 +0000 (+0200) Subject: htparser: Accept more connections in bulk. X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=f24b7bb50470e554202f00ca7f66b6925f473ff1;p=ashd.git htparser: Accept more connections in bulk. If not for this, htparser will concentrate unduly on processing existing connection, leaving the socket backlog filling up in the meantime, dropping requests unnecessarily. --- diff --git a/src/plaintcp.c b/src/plaintcp.c index 7d36a1d..6524955 100644 --- a/src/plaintcp.c +++ b/src/plaintcp.c @@ -168,20 +168,28 @@ void servetcp(struct muth *muth, va_list args) static void listenloop(struct muth *muth, va_list args) { vavar(struct tcpport *, tcp); - int i, 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); if(block(tcp->fd, EV_READ, 0) == 0) goto out; - ns = accept(tcp->fd, (struct sockaddr *)&name, &namelen); - if(ns < 0) { - flog(LOG_ERR, "accept: %s", strerror(errno)); - goto out; + n = 0; + while(1) { + ns = accept(tcp->fd, (struct sockaddr *)&name, &namelen); + if(ns < 0) { + if(errno == EAGAIN) + break; + flog(LOG_ERR, "accept: %s", strerror(errno)); + goto out; + } + mustart(servetcp, ns, name, tcp); + if(++n >= 100) + break; } - mustart(servetcp, ns, name, tcp); } out: diff --git a/src/ssl-gnutls.c b/src/ssl-gnutls.c index 436141b..1ab040d 100644 --- a/src/ssl-gnutls.c +++ b/src/ssl-gnutls.c @@ -360,20 +360,28 @@ out: static void listenloop(struct muth *muth, va_list args) { vavar(struct sslport *, pd); - int i, ns; + int i, ns, n; struct sockaddr_storage name; socklen_t namelen; + fcntl(pd->fd, F_SETFL, fcntl(tcp->fd, F_GETFL) | O_NONBLOCK); while(1) { namelen = sizeof(name); if(block(pd->fd, EV_READ, 0) == 0) goto out; - ns = accept(pd->fd, (struct sockaddr *)&name, &namelen); - if(ns < 0) { - flog(LOG_ERR, "accept: %s", strerror(errno)); - goto out; + n = 0; + while(1) { + ns = accept(pd->fd, (struct sockaddr *)&name, &namelen); + if(ns < 0) { + if(errno == EAGAIN) + break; + flog(LOG_ERR, "accept: %s", strerror(errno)); + goto out; + } + mustart(servessl, ns, name, pd); + if(++n >= 100) + break; } - mustart(servessl, ns, name, pd); } out: