From: Willy Tarreau Date: Sun, 24 Jul 2011 17:23:38 +0000 (+0200) Subject: [MINOR] listeners: add listen_full() to mark a listener full X-Git-Tag: v1.5-dev8~178 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=627937158f7db8f1a5a951dac65b57777074947d;p=thirdparty%2Fhaproxy.git [MINOR] listeners: add listen_full() to mark a listener full This is just a cleanup which removes calls to EV_FD_CLR() and state setting everywhere in the code. --- diff --git a/include/proto/protocols.h b/include/proto/protocols.h index e0d6ee432d..354a4e971a 100644 --- a/include/proto/protocols.h +++ b/include/proto/protocols.h @@ -51,6 +51,11 @@ int pause_listener(struct listener *l); */ int resume_listener(struct listener *l); +/* Marks a ready listener as full so that the session code tries to re-enable + * it upon next close() using resume_listener(). + */ +void listener_full(struct listener *l); + /* This function adds all of the protocol's listener's file descriptors to the * polling lists when they are in the LI_LISTEN state. It is intended to be * used as a protocol's generic enable_all() primitive, for use after the diff --git a/src/protocols.c b/src/protocols.c index 49e7eaaa2e..7d8913d6cc 100644 --- a/src/protocols.c +++ b/src/protocols.c @@ -106,6 +106,17 @@ int resume_listener(struct listener *l) return 1; } +/* Marks a ready listener as full so that the session code tries to re-enable + * it upon next close() using resume_listener(). + */ +void listener_full(struct listener *l) +{ + if (l->state >= LI_READY) { + EV_FD_CLR(l->fd, DIR_RD); + l->state = LI_FULL; + } +} + /* This function adds all of the protocol's listener's file descriptors to the * polling lists when they are in the LI_LISTEN state. It is intended to be * used as a protocol's generic enable_all() primitive, for use after the diff --git a/src/session.c b/src/session.c index e5ac4eedd5..6e718c00cb 100644 --- a/src/session.c +++ b/src/session.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -2088,12 +2089,8 @@ struct task *process_session(struct task *t) actconn--; jobs--; s->listener->nbconn--; - if (s->listener->state == LI_FULL && - s->listener->nbconn < s->listener->maxconn) { - /* we should reactivate the listener */ - EV_FD_SET(s->listener->fd, DIR_RD); - s->listener->state = LI_READY; - } + if (s->listener->state == LI_FULL) + resume_listener(s->listener); if (unlikely((global.mode & MODE_DEBUG) && (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)))) { diff --git a/src/stream_sock.c b/src/stream_sock.c index c5cd1e5a88..10e13cb00a 100644 --- a/src/stream_sock.c +++ b/src/stream_sock.c @@ -1194,8 +1194,7 @@ int stream_sock_accept(int fd) int ret; if (unlikely(l->nbconn >= l->maxconn)) { - EV_FD_CLR(l->fd, DIR_RD); - l->state = LI_FULL; + listener_full(l); return 0; } @@ -1221,20 +1220,16 @@ int stream_sock_accept(int fd) send_log(p, LOG_EMERG, "Proxy %s reached system FD limit at %d. Please check system tunables.\n", p->id, maxfd); - if (l->nbconn) { - EV_FD_CLR(l->fd, DIR_RD); - l->state = LI_FULL; - } + if (l->nbconn) + listener_full(l); return 0; case EMFILE: if (p) send_log(p, LOG_EMERG, "Proxy %s reached process FD limit at %d. Please check 'ulimit-n' and restart.\n", p->id, maxfd); - if (l->nbconn) { - EV_FD_CLR(l->fd, DIR_RD); - l->state = LI_FULL; - } + if (l->nbconn) + listener_full(l); return 0; case ENOBUFS: case ENOMEM: @@ -1242,10 +1237,8 @@ int stream_sock_accept(int fd) send_log(p, LOG_EMERG, "Proxy %s reached system memory limit at %d sockets. Please check system tunables.\n", p->id, maxfd); - if (l->nbconn) { - EV_FD_CLR(l->fd, DIR_RD); - l->state = LI_FULL; - } + if (l->nbconn) + listener_full(l); return 0; default: return 0; @@ -1291,10 +1284,10 @@ int stream_sock_accept(int fd) } if (l->nbconn >= l->maxconn) { - EV_FD_CLR(l->fd, DIR_RD); - l->state = LI_FULL; + listener_full(l); return 0; } + } /* end of while (p->feconn < p->maxconn) */ return 0; }