From: Willy Tarreau Date: Sun, 15 Oct 2006 12:52:29 +0000 (+0200) Subject: [MINOR] turn every FD_* into functions X-Git-Tag: v1.3.3~14 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2a429503e03b53b4f68a300637137f67faa2b7b8;p=thirdparty%2Fhaproxy.git [MINOR] turn every FD_* into functions On recent CPUs, functions are about twice as fast as inline FD_*, so there is now a #define CONFIG_HAP_INLINE_FD_SET to choose between the two modes. --- diff --git a/include/common/config.h b/include/common/config.h index c1cf098b8a..3ab879fc59 100644 --- a/include/common/config.h +++ b/include/common/config.h @@ -40,4 +40,12 @@ #endif /* CONFIG_HAP_NO_MEM_OPTIM */ +/* CONFIG_HAP_INLINE_FD_SET + * This makes use of inline FD_* macros instead of calling equivalent + * functions. Benchmarks on a Pentium-M show that using functions is + * generally twice as fast. So it's better to keep this option unset. + */ +//#undef CONFIG_HAP_INLINE_FD_SET + + #endif /* _COMMON_CONFIG_H */ diff --git a/include/proto/fd.h b/include/proto/fd.h index 879205b788..1d480af9c2 100644 --- a/include/proto/fd.h +++ b/include/proto/fd.h @@ -35,6 +35,30 @@ void fd_delete(int fd); +/* + * Benchmarks performed on a Pentium-M notebook show that using functions + * instead of the usual macros improve the FD_* performance by about 80%, + * and that marking them regparm(2) adds another 20%. + */ +#if defined(CONFIG_HAP_INLINE_FD_SET) + +# define MY_FD_SET FD_SET +# define MY_FD_CLR FD_CLR +# define MY_FD_ISSET FD_ISSET + +#else + +# define MY_FD_SET my_fd_set +# define MY_FD_CLR my_fd_clr +# define MY_FD_ISSET my_fd_isset + +void __attribute__((regparm(2))) my_fd_set(const int fd, fd_set *ev); +void __attribute__((regparm(2))) my_fd_clr(const int fd, fd_set *ev); +int __attribute__((regparm(2))) my_fd_isset(const int fd, const fd_set *ev); + +#endif + + /* recomputes the maxfd limit from the fd */ static inline void fd_insert(int fd) { diff --git a/src/backend.c b/src/backend.c index d0c089178a..2884ea539f 100644 --- a/src/backend.c +++ b/src/backend.c @@ -432,11 +432,11 @@ int connect_server(struct session *s) fdtab[fd].cb[DIR_WR].f = &stream_sock_write; fdtab[fd].cb[DIR_WR].b = s->req; - FD_SET(fd, StaticWriteEvent); /* for connect status */ + MY_FD_SET(fd, StaticWriteEvent); /* for connect status */ #if defined(DEBUG_FULL) && defined(ENABLE_EPOLL) if (PrevReadEvent) { - assert(!(FD_ISSET(fd, PrevReadEvent))); - assert(!(FD_ISSET(fd, PrevWriteEvent))); + assert(!(MY_FD_ISSET(fd, PrevReadEvent))); + assert(!(MY_FD_ISSET(fd, PrevWriteEvent))); } #endif diff --git a/src/checks.c b/src/checks.c index 5fc9e285bf..3085eab930 100644 --- a/src/checks.c +++ b/src/checks.c @@ -115,7 +115,7 @@ int event_srv_chk_w(int fd) /* in case of TCP only, this tells us if the connection failed */ s->result = -1; fdtab[fd].state = FD_STERROR; - FD_CLR(fd, StaticWriteEvent); + MY_FD_CLR(fd, StaticWriteEvent); } else if (s->result != -1) { /* we don't want to mark 'UP' a server on which we detected an error earlier */ @@ -138,13 +138,13 @@ int event_srv_chk_w(int fd) ret = send(fd, s->proxy->check_req, s->proxy->check_len, MSG_DONTWAIT | MSG_NOSIGNAL); #endif if (ret == s->proxy->check_len) { - FD_SET(fd, StaticReadEvent); /* prepare for reading reply */ - FD_CLR(fd, StaticWriteEvent); /* nothing more to write */ + MY_FD_SET(fd, StaticReadEvent); /* prepare for reading reply */ + MY_FD_CLR(fd, StaticWriteEvent); /* nothing more to write */ return 0; } else { s->result = -1; - FD_CLR(fd, StaticWriteEvent); + MY_FD_CLR(fd, StaticWriteEvent); } } else { @@ -203,7 +203,7 @@ int event_srv_chk_r(int fd) if (s->result != -1) s->result = result; - FD_CLR(fd, StaticReadEvent); + MY_FD_CLR(fd, StaticReadEvent); task_wakeup(&rq, t); return 0; } @@ -285,9 +285,9 @@ int process_chk(struct task *t) fdtab[fd].cb[DIR_WR].f = &event_srv_chk_w; fdtab[fd].cb[DIR_WR].b = NULL; fdtab[fd].state = FD_STCONN; /* connection in progress */ - FD_SET(fd, StaticWriteEvent); /* for connect status */ + MY_FD_SET(fd, StaticWriteEvent); /* for connect status */ #ifdef DEBUG_FULL - assert (!FD_ISSET(fd, StaticReadEvent)); + assert (!MY_FD_ISSET(fd, StaticReadEvent)); #endif fd_insert(fd); /* FIXME: we allow up to for a connection to establish, but we should use another parameter */ @@ -370,7 +370,7 @@ int process_chk(struct task *t) s->health = s->rise + s->fall - 1; /* OK now */ } s->curfd = -1; /* no check running anymore */ - //FD_CLR(fd, StaticWriteEvent); + //MY_FD_CLR(fd, StaticWriteEvent); fd_delete(fd); while (tv_cmp2_ms(&t->expire, &now) <= 0) tv_delayfrom(&t->expire, &t->expire, s->inter); @@ -386,7 +386,7 @@ int process_chk(struct task *t) else set_server_down(s); s->curfd = -1; - //FD_CLR(fd, StaticWriteEvent); + //MY_FD_CLR(fd, StaticWriteEvent); fd_delete(fd); while (tv_cmp2_ms(&t->expire, &now) <= 0) tv_delayfrom(&t->expire, &t->expire, s->inter); diff --git a/src/client.c b/src/client.c index c723ca1beb..e1890f0e8b 100644 --- a/src/client.c +++ b/src/client.c @@ -97,7 +97,7 @@ int event_accept(int fd) { if ((s = pool_alloc(session)) == NULL) { /* disable this proxy for a while */ Alert("out of memory in event_accept().\n"); - FD_CLR(fd, StaticReadEvent); + MY_FD_CLR(fd, StaticReadEvent); p->state = PR_STIDLE; close(cfd); return 0; @@ -120,7 +120,7 @@ int event_accept(int fd) { if ((t = pool_alloc(task)) == NULL) { /* disable this proxy for a while */ Alert("out of memory in event_accept().\n"); - FD_CLR(fd, StaticReadEvent); + MY_FD_CLR(fd, StaticReadEvent); p->state = PR_STIDLE; close(cfd); pool_free(session, s); @@ -354,13 +354,13 @@ int event_accept(int fd) { client_retnclose(s, 3, "OK\n"); /* forge an "OK" response */ } else { - FD_SET(cfd, StaticReadEvent); + MY_FD_SET(cfd, StaticReadEvent); } #if defined(DEBUG_FULL) && defined(ENABLE_EPOLL) if (PrevReadEvent) { - assert(!(FD_ISSET(cfd, PrevReadEvent))); - assert(!(FD_ISSET(cfd, PrevWriteEvent))); + assert(!(MY_FD_ISSET(cfd, PrevReadEvent))); + assert(!(MY_FD_ISSET(cfd, PrevWriteEvent))); } #endif fd_insert(cfd); @@ -372,9 +372,9 @@ int event_accept(int fd) { tv_eternity(&s->rep->wex); if (s->proxy->clitimeout) { - if (FD_ISSET(cfd, StaticReadEvent)) + if (MY_FD_ISSET(cfd, StaticReadEvent)) tv_delayfrom(&s->req->rex, &now, s->proxy->clitimeout); - if (FD_ISSET(cfd, StaticWriteEvent)) + if (MY_FD_ISSET(cfd, StaticWriteEvent)) tv_delayfrom(&s->rep->wex, &now, s->proxy->clitimeout); } diff --git a/src/fd.c b/src/fd.c index 66d963a4cb..2f68651964 100644 --- a/src/fd.c +++ b/src/fd.c @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -45,6 +46,29 @@ int cfg_polling_mechanism = 0; /* POLL_USE_{SELECT|POLL|EPOLL} */ ******************************/ +#if !defined(CONFIG_HAP_INLINE_FD_SET) +/* + * Benchmarks performed on a Pentium-M notebook show that using functions + * instead of the usual macros improve the FD_* performance by about 80%, + * and that marking them regparm(2) adds another 20%. + */ +void __attribute__((regparm(2))) my_fd_set(const int fd, fd_set *ev) +{ + FD_SET(fd, ev); +} + +void __attribute__((regparm(2))) my_fd_clr(const int fd, fd_set *ev) +{ + FD_CLR(fd, ev); +} + +int __attribute__((regparm(2))) my_fd_isset(const int fd, const fd_set *ev) +{ + return FD_ISSET(fd, ev); +} +#endif + + /* * FIXME: this is dirty, but at the moment, there's no other solution to remove * the old FDs from outside the loop. Perhaps we should export a global 'poll' @@ -139,16 +163,16 @@ int epoll_loop(int action) sr = (rn >> count) & 1; sw = (wn >> count) & 1; #else - pr = FD_ISSET(fd&((1<> count) & 1; sw = (wn >> count) & 1; #else - sr = FD_ISSET(fd&((1<expire), s->cli_state, s->srv_state, - FD_ISSET(s->cli_fd, StaticReadEvent), - FD_ISSET(s->cli_fd, StaticWriteEvent), - FD_ISSET(s->srv_fd, StaticReadEvent), - FD_ISSET(s->srv_fd, StaticWriteEvent), + MY_FD_ISSET(s->cli_fd, StaticReadEvent), + MY_FD_ISSET(s->cli_fd, StaticWriteEvent), + MY_FD_ISSET(s->srv_fd, StaticReadEvent), + MY_FD_ISSET(s->srv_fd, StaticWriteEvent), s->req->l, s->rep?s->rep->l:0, s->cli_fd ); } diff --git a/src/proto_http.c b/src/proto_http.c index 9cd75f323b..0ba52a4dd4 100644 --- a/src/proto_http.c +++ b/src/proto_http.c @@ -85,8 +85,8 @@ static char *srv_stnames[7] = {"IDL", "CON", "HDR", "DAT", "SHR", "SHW", "CLS" } */ void client_retnclose(struct session *s, int len, const char *msg) { - FD_CLR(s->cli_fd, StaticReadEvent); - FD_SET(s->cli_fd, StaticWriteEvent); + MY_FD_CLR(s->cli_fd, StaticReadEvent); + MY_FD_SET(s->cli_fd, StaticWriteEvent); tv_eternity(&s->req->rex); if (s->proxy->clitimeout) tv_delayfrom(&s->rep->wex, &now, s->proxy->clitimeout); @@ -225,13 +225,13 @@ int process_cli(struct session *t) #ifdef DEBUG_FULL fprintf(stderr,"process_cli: c=%s s=%s set(r,w)=%d,%d exp(r,w)=%d.%d,%d.%d\n", cli_stnames[c], srv_stnames[s], - FD_ISSET(t->cli_fd, StaticReadEvent), FD_ISSET(t->cli_fd, StaticWriteEvent), + MY_FD_ISSET(t->cli_fd, StaticReadEvent), MY_FD_ISSET(t->cli_fd, StaticWriteEvent), req->rex.tv_sec, req->rex.tv_usec, rep->wex.tv_sec, rep->wex.tv_usec); #endif //fprintf(stderr,"process_cli: c=%d, s=%d, cr=%d, cw=%d, sr=%d, sw=%d\n", c, s, - //FD_ISSET(t->cli_fd, StaticReadEvent), FD_ISSET(t->cli_fd, StaticWriteEvent), - //FD_ISSET(t->srv_fd, StaticReadEvent), FD_ISSET(t->srv_fd, StaticWriteEvent) + //MY_FD_ISSET(t->cli_fd, StaticReadEvent), MY_FD_ISSET(t->cli_fd, StaticWriteEvent), + //MY_FD_ISSET(t->srv_fd, StaticReadEvent), MY_FD_ISSET(t->srv_fd, StaticWriteEvent) //); if (c == CL_STHEADERS) { /* now parse the partial (or complete) headers */ @@ -428,7 +428,7 @@ int process_cli(struct session *t) * eternity as long as the server-side does not enable data xfer. * CL_STDATA also has to take care of this, which is done below. */ - //FD_CLR(t->cli_fd, StaticReadEvent); + //MY_FD_CLR(t->cli_fd, StaticReadEvent); //tv_eternity(&req->rex); /* FIXME: if we break here (as up to 1.1.23), having the client @@ -983,12 +983,12 @@ int process_cli(struct session *t) /* end of header processing (even if incomplete) */ - if ((req->l < req->rlim - req->data) && ! FD_ISSET(t->cli_fd, StaticReadEvent)) { + if ((req->l < req->rlim - req->data) && ! MY_FD_ISSET(t->cli_fd, StaticReadEvent)) { /* fd in StaticReadEvent was disabled, perhaps because of a previous buffer * full. We cannot loop here since stream_sock_read will disable it only if * req->l == rlim-data */ - FD_SET(t->cli_fd, StaticReadEvent); + MY_FD_SET(t->cli_fd, StaticReadEvent); if (t->proxy->clitimeout) tv_delayfrom(&req->rex, &now, t->proxy->clitimeout); else @@ -1060,7 +1060,7 @@ int process_cli(struct session *t) } /* last read, or end of server write */ else if (req->flags & BF_READ_NULL || s == SV_STSHUTW || s == SV_STCLOSE) { - FD_CLR(t->cli_fd, StaticReadEvent); + MY_FD_CLR(t->cli_fd, StaticReadEvent); tv_eternity(&req->rex); shutdown(t->cli_fd, SHUT_RD); t->cli_state = CL_STSHUTR; @@ -1068,12 +1068,12 @@ int process_cli(struct session *t) } /* last server read and buffer empty */ else if ((s == SV_STSHUTR || s == SV_STCLOSE) && (rep->l == 0)) { - FD_CLR(t->cli_fd, StaticWriteEvent); + MY_FD_CLR(t->cli_fd, StaticWriteEvent); tv_eternity(&rep->wex); shutdown(t->cli_fd, SHUT_WR); /* We must ensure that the read part is still alive when switching * to shutw */ - FD_SET(t->cli_fd, StaticReadEvent); + MY_FD_SET(t->cli_fd, StaticReadEvent); if (t->proxy->clitimeout) tv_delayfrom(&req->rex, &now, t->proxy->clitimeout); t->cli_state = CL_STSHUTW; @@ -1082,7 +1082,7 @@ int process_cli(struct session *t) } /* read timeout */ else if (tv_cmp2_ms(&req->rex, &now) <= 0) { - FD_CLR(t->cli_fd, StaticReadEvent); + MY_FD_CLR(t->cli_fd, StaticReadEvent); tv_eternity(&req->rex); shutdown(t->cli_fd, SHUT_RD); t->cli_state = CL_STSHUTR; @@ -1100,12 +1100,12 @@ int process_cli(struct session *t) } /* write timeout */ else if (tv_cmp2_ms(&rep->wex, &now) <= 0) { - FD_CLR(t->cli_fd, StaticWriteEvent); + MY_FD_CLR(t->cli_fd, StaticWriteEvent); tv_eternity(&rep->wex); shutdown(t->cli_fd, SHUT_WR); /* We must ensure that the read part is still alive when switching * to shutw */ - FD_SET(t->cli_fd, StaticReadEvent); + MY_FD_SET(t->cli_fd, StaticReadEvent); if (t->proxy->clitimeout) tv_delayfrom(&req->rex, &now, t->proxy->clitimeout); @@ -1125,15 +1125,15 @@ int process_cli(struct session *t) if (req->l >= req->rlim - req->data) { /* no room to read more data */ - if (FD_ISSET(t->cli_fd, StaticReadEvent)) { + if (MY_FD_ISSET(t->cli_fd, StaticReadEvent)) { /* stop reading until we get some space */ - FD_CLR(t->cli_fd, StaticReadEvent); + MY_FD_CLR(t->cli_fd, StaticReadEvent); tv_eternity(&req->rex); } } else { /* there's still some space in the buffer */ - if (! FD_ISSET(t->cli_fd, StaticReadEvent)) { - FD_SET(t->cli_fd, StaticReadEvent); + if (! MY_FD_ISSET(t->cli_fd, StaticReadEvent)) { + MY_FD_SET(t->cli_fd, StaticReadEvent); if (!t->proxy->clitimeout || (t->srv_state < SV_STDATA && t->proxy->srvtimeout)) /* If the client has no timeout, or if the server not ready yet, and we @@ -1149,14 +1149,14 @@ int process_cli(struct session *t) if ((rep->l == 0) || ((s < SV_STDATA) /* FIXME: this may be optimized && (rep->w == rep->h)*/)) { - if (FD_ISSET(t->cli_fd, StaticWriteEvent)) { - FD_CLR(t->cli_fd, StaticWriteEvent); /* stop writing */ + if (MY_FD_ISSET(t->cli_fd, StaticWriteEvent)) { + MY_FD_CLR(t->cli_fd, StaticWriteEvent); /* stop writing */ tv_eternity(&rep->wex); } } else { /* buffer not empty */ - if (! FD_ISSET(t->cli_fd, StaticWriteEvent)) { - FD_SET(t->cli_fd, StaticWriteEvent); /* restart writing */ + if (! MY_FD_ISSET(t->cli_fd, StaticWriteEvent)) { + MY_FD_SET(t->cli_fd, StaticWriteEvent); /* restart writing */ if (t->proxy->clitimeout) { tv_delayfrom(&rep->wex, &now, t->proxy->clitimeout); /* FIXME: to prevent the client from expiring read timeouts during writes, @@ -1222,14 +1222,14 @@ int process_cli(struct session *t) if ((rep->l == 0) || ((s == SV_STHEADERS) /* FIXME: this may be optimized && (rep->w == rep->h)*/)) { - if (FD_ISSET(t->cli_fd, StaticWriteEvent)) { - FD_CLR(t->cli_fd, StaticWriteEvent); /* stop writing */ + if (MY_FD_ISSET(t->cli_fd, StaticWriteEvent)) { + MY_FD_CLR(t->cli_fd, StaticWriteEvent); /* stop writing */ tv_eternity(&rep->wex); } } else { /* buffer not empty */ - if (! FD_ISSET(t->cli_fd, StaticWriteEvent)) { - FD_SET(t->cli_fd, StaticWriteEvent); /* restart writing */ + if (! MY_FD_ISSET(t->cli_fd, StaticWriteEvent)) { + MY_FD_SET(t->cli_fd, StaticWriteEvent); /* restart writing */ if (t->proxy->clitimeout) { tv_delayfrom(&rep->wex, &now, t->proxy->clitimeout); /* FIXME: to prevent the client from expiring read timeouts during writes, @@ -1288,16 +1288,16 @@ int process_cli(struct session *t) * after the timeout by sending more data after it receives a close ? */ - if (FD_ISSET(t->cli_fd, StaticReadEvent)) { + if (MY_FD_ISSET(t->cli_fd, StaticReadEvent)) { /* stop reading until we get some space */ - FD_CLR(t->cli_fd, StaticReadEvent); + MY_FD_CLR(t->cli_fd, StaticReadEvent); tv_eternity(&req->rex); //fprintf(stderr,"%p:%s(%d), c=%d, s=%d\n", t, __FUNCTION__, __LINE__, t->cli_state, t->cli_state); } } else { /* there's still some space in the buffer */ - if (! FD_ISSET(t->cli_fd, StaticReadEvent)) { - FD_SET(t->cli_fd, StaticReadEvent); + if (! MY_FD_ISSET(t->cli_fd, StaticReadEvent)) { + MY_FD_SET(t->cli_fd, StaticReadEvent); if (t->proxy->clitimeout) tv_delayfrom(&req->rex, &now, t->proxy->clitimeout); else @@ -1337,8 +1337,8 @@ int process_srv(struct session *t) fprintf(stderr,"process_srv: c=%s, s=%s\n", cli_stnames[c], srv_stnames[s]); #endif //fprintf(stderr,"process_srv: c=%d, s=%d, cr=%d, cw=%d, sr=%d, sw=%d\n", c, s, - //FD_ISSET(t->cli_fd, StaticReadEvent), FD_ISSET(t->cli_fd, StaticWriteEvent), - //FD_ISSET(t->srv_fd, StaticReadEvent), FD_ISSET(t->srv_fd, StaticWriteEvent) + //MY_FD_ISSET(t->cli_fd, StaticReadEvent), MY_FD_ISSET(t->cli_fd, StaticWriteEvent), + //MY_FD_ISSET(t->srv_fd, StaticReadEvent), MY_FD_ISSET(t->srv_fd, StaticWriteEvent) //); if (s == SV_STIDLE) { if (c == CL_STHEADERS) @@ -1499,10 +1499,10 @@ int process_srv(struct session *t) //fprintf(stderr,"3: c=%d, s=%d\n", c, s); if (req->l == 0) /* nothing to write */ { - FD_CLR(t->srv_fd, StaticWriteEvent); + MY_FD_CLR(t->srv_fd, StaticWriteEvent); tv_eternity(&req->wex); } else /* need the right to write */ { - FD_SET(t->srv_fd, StaticWriteEvent); + MY_FD_SET(t->srv_fd, StaticWriteEvent); if (t->proxy->srvtimeout) { tv_delayfrom(&req->wex, &now, t->proxy->srvtimeout); /* FIXME: to prevent the server from expiring read timeouts during writes, @@ -1514,7 +1514,7 @@ int process_srv(struct session *t) } if (t->proxy->mode == PR_MODE_TCP) { /* let's allow immediate data connection in this case */ - FD_SET(t->srv_fd, StaticReadEvent); + MY_FD_SET(t->srv_fd, StaticReadEvent); if (t->proxy->srvtimeout) tv_delayfrom(&rep->rex, &now, t->proxy->srvtimeout); else @@ -1673,12 +1673,12 @@ int process_srv(struct session *t) */ if ((req->l == 0) && (c == CL_STSHUTR || c == CL_STCLOSE || t->proxy->options & PR_O_FORCE_CLO)) { - FD_CLR(t->srv_fd, StaticWriteEvent); + MY_FD_CLR(t->srv_fd, StaticWriteEvent); tv_eternity(&req->wex); /* We must ensure that the read part is still alive when switching * to shutw */ - FD_SET(t->srv_fd, StaticReadEvent); + MY_FD_SET(t->srv_fd, StaticReadEvent); if (t->proxy->srvtimeout) tv_delayfrom(&rep->rex, &now, t->proxy->srvtimeout); @@ -2029,12 +2029,12 @@ int process_srv(struct session *t) /* end of header processing (even if incomplete) */ - if ((rep->l < rep->rlim - rep->data) && ! FD_ISSET(t->srv_fd, StaticReadEvent)) { + if ((rep->l < rep->rlim - rep->data) && ! MY_FD_ISSET(t->srv_fd, StaticReadEvent)) { /* fd in StaticReadEvent was disabled, perhaps because of a previous buffer * full. We cannot loop here since stream_sock_read will disable it only if * rep->l == rlim-data */ - FD_SET(t->srv_fd, StaticReadEvent); + MY_FD_SET(t->srv_fd, StaticReadEvent); if (t->proxy->srvtimeout) tv_delayfrom(&rep->rex, &now, t->proxy->srvtimeout); else @@ -2072,7 +2072,7 @@ int process_srv(struct session *t) * won't be able to free more later, so the session will never terminate. */ else if (rep->flags & BF_READ_NULL || c == CL_STSHUTW || c == CL_STCLOSE || rep->l >= rep->rlim - rep->data) { - FD_CLR(t->srv_fd, StaticReadEvent); + MY_FD_CLR(t->srv_fd, StaticReadEvent); tv_eternity(&rep->rex); shutdown(t->srv_fd, SHUT_RD); t->srv_state = SV_STSHUTR; @@ -2081,7 +2081,7 @@ int process_srv(struct session *t) } /* read timeout : return a 504 to the client. */ - else if (FD_ISSET(t->srv_fd, StaticReadEvent) && tv_cmp2_ms(&rep->rex, &now) <= 0) { + else if (MY_FD_ISSET(t->srv_fd, StaticReadEvent) && tv_cmp2_ms(&rep->rex, &now) <= 0) { tv_eternity(&rep->rex); tv_eternity(&req->wex); fd_delete(t->srv_fd); @@ -2114,12 +2114,12 @@ int process_srv(struct session *t) * is kept until a response comes back or the timeout is reached. */ else if ((/*c == CL_STSHUTR ||*/ c == CL_STCLOSE) && (req->l == 0)) { - FD_CLR(t->srv_fd, StaticWriteEvent); + MY_FD_CLR(t->srv_fd, StaticWriteEvent); tv_eternity(&req->wex); /* We must ensure that the read part is still alive when switching * to shutw */ - FD_SET(t->srv_fd, StaticReadEvent); + MY_FD_SET(t->srv_fd, StaticReadEvent); if (t->proxy->srvtimeout) tv_delayfrom(&rep->rex, &now, t->proxy->srvtimeout); @@ -2132,19 +2132,19 @@ int process_srv(struct session *t) * client shuts read too early, because we may still have * some work to do on the headers. */ - else if (FD_ISSET(t->srv_fd, StaticWriteEvent) && tv_cmp2_ms(&req->wex, &now) <= 0) { - FD_CLR(t->srv_fd, StaticWriteEvent); + else if (MY_FD_ISSET(t->srv_fd, StaticWriteEvent) && tv_cmp2_ms(&req->wex, &now) <= 0) { + MY_FD_CLR(t->srv_fd, StaticWriteEvent); tv_eternity(&req->wex); shutdown(t->srv_fd, SHUT_WR); /* We must ensure that the read part is still alive when switching * to shutw */ - FD_SET(t->srv_fd, StaticReadEvent); + MY_FD_SET(t->srv_fd, StaticReadEvent); if (t->proxy->srvtimeout) tv_delayfrom(&rep->rex, &now, t->proxy->srvtimeout); /* We must ensure that the read part is still alive when switching * to shutw */ - FD_SET(t->srv_fd, StaticReadEvent); + MY_FD_SET(t->srv_fd, StaticReadEvent); if (t->proxy->srvtimeout) tv_delayfrom(&rep->rex, &now, t->proxy->srvtimeout); @@ -2157,14 +2157,14 @@ int process_srv(struct session *t) } if (req->l == 0) { - if (FD_ISSET(t->srv_fd, StaticWriteEvent)) { - FD_CLR(t->srv_fd, StaticWriteEvent); /* stop writing */ + if (MY_FD_ISSET(t->srv_fd, StaticWriteEvent)) { + MY_FD_CLR(t->srv_fd, StaticWriteEvent); /* stop writing */ tv_eternity(&req->wex); } } else { /* client buffer not empty */ - if (! FD_ISSET(t->srv_fd, StaticWriteEvent)) { - FD_SET(t->srv_fd, StaticWriteEvent); /* restart writing */ + if (! MY_FD_ISSET(t->srv_fd, StaticWriteEvent)) { + MY_FD_SET(t->srv_fd, StaticWriteEvent); /* restart writing */ if (t->proxy->srvtimeout) { tv_delayfrom(&req->wex, &now, t->proxy->srvtimeout); /* FIXME: to prevent the server from expiring read timeouts during writes, @@ -2210,7 +2210,7 @@ int process_srv(struct session *t) } /* last read, or end of client write */ else if (rep->flags & BF_READ_NULL || c == CL_STSHUTW || c == CL_STCLOSE) { - FD_CLR(t->srv_fd, StaticReadEvent); + MY_FD_CLR(t->srv_fd, StaticReadEvent); tv_eternity(&rep->rex); shutdown(t->srv_fd, SHUT_RD); t->srv_state = SV_STSHUTR; @@ -2219,12 +2219,12 @@ int process_srv(struct session *t) } /* end of client read and no more data to send */ else if ((c == CL_STSHUTR || c == CL_STCLOSE) && (req->l == 0)) { - FD_CLR(t->srv_fd, StaticWriteEvent); + MY_FD_CLR(t->srv_fd, StaticWriteEvent); tv_eternity(&req->wex); shutdown(t->srv_fd, SHUT_WR); /* We must ensure that the read part is still alive when switching * to shutw */ - FD_SET(t->srv_fd, StaticReadEvent); + MY_FD_SET(t->srv_fd, StaticReadEvent); if (t->proxy->srvtimeout) tv_delayfrom(&rep->rex, &now, t->proxy->srvtimeout); @@ -2233,7 +2233,7 @@ int process_srv(struct session *t) } /* read timeout */ else if (tv_cmp2_ms(&rep->rex, &now) <= 0) { - FD_CLR(t->srv_fd, StaticReadEvent); + MY_FD_CLR(t->srv_fd, StaticReadEvent); tv_eternity(&rep->rex); shutdown(t->srv_fd, SHUT_RD); t->srv_state = SV_STSHUTR; @@ -2245,12 +2245,12 @@ int process_srv(struct session *t) } /* write timeout */ else if (tv_cmp2_ms(&req->wex, &now) <= 0) { - FD_CLR(t->srv_fd, StaticWriteEvent); + MY_FD_CLR(t->srv_fd, StaticWriteEvent); tv_eternity(&req->wex); shutdown(t->srv_fd, SHUT_WR); /* We must ensure that the read part is still alive when switching * to shutw */ - FD_SET(t->srv_fd, StaticReadEvent); + MY_FD_SET(t->srv_fd, StaticReadEvent); if (t->proxy->srvtimeout) tv_delayfrom(&rep->rex, &now, t->proxy->srvtimeout); t->srv_state = SV_STSHUTW; @@ -2263,14 +2263,14 @@ int process_srv(struct session *t) /* recompute request time-outs */ if (req->l == 0) { - if (FD_ISSET(t->srv_fd, StaticWriteEvent)) { - FD_CLR(t->srv_fd, StaticWriteEvent); /* stop writing */ + if (MY_FD_ISSET(t->srv_fd, StaticWriteEvent)) { + MY_FD_CLR(t->srv_fd, StaticWriteEvent); /* stop writing */ tv_eternity(&req->wex); } } else { /* buffer not empty, there are still data to be transferred */ - if (! FD_ISSET(t->srv_fd, StaticWriteEvent)) { - FD_SET(t->srv_fd, StaticWriteEvent); /* restart writing */ + if (! MY_FD_ISSET(t->srv_fd, StaticWriteEvent)) { + MY_FD_SET(t->srv_fd, StaticWriteEvent); /* restart writing */ if (t->proxy->srvtimeout) { tv_delayfrom(&req->wex, &now, t->proxy->srvtimeout); /* FIXME: to prevent the server from expiring read timeouts during writes, @@ -2284,14 +2284,14 @@ int process_srv(struct session *t) /* recompute response time-outs */ if (rep->l == BUFSIZE) { /* no room to read more data */ - if (FD_ISSET(t->srv_fd, StaticReadEvent)) { - FD_CLR(t->srv_fd, StaticReadEvent); + if (MY_FD_ISSET(t->srv_fd, StaticReadEvent)) { + MY_FD_CLR(t->srv_fd, StaticReadEvent); tv_eternity(&rep->rex); } } else { - if (! FD_ISSET(t->srv_fd, StaticReadEvent)) { - FD_SET(t->srv_fd, StaticReadEvent); + if (! MY_FD_ISSET(t->srv_fd, StaticReadEvent)) { + MY_FD_SET(t->srv_fd, StaticReadEvent); if (t->proxy->srvtimeout) tv_delayfrom(&rep->rex, &now, t->proxy->srvtimeout); else @@ -2303,7 +2303,7 @@ int process_srv(struct session *t) } else if (s == SV_STSHUTR) { if (req->flags & BF_WRITE_ERROR) { - //FD_CLR(t->srv_fd, StaticWriteEvent); + //MY_FD_CLR(t->srv_fd, StaticWriteEvent); tv_eternity(&req->wex); fd_delete(t->srv_fd); if (t->srv) { @@ -2326,7 +2326,7 @@ int process_srv(struct session *t) return 1; } else if ((c == CL_STSHUTR || c == CL_STCLOSE) && (req->l == 0)) { - //FD_CLR(t->srv_fd, StaticWriteEvent); + //MY_FD_CLR(t->srv_fd, StaticWriteEvent); tv_eternity(&req->wex); fd_delete(t->srv_fd); if (t->srv) @@ -2342,7 +2342,7 @@ int process_srv(struct session *t) return 1; } else if (tv_cmp2_ms(&req->wex, &now) <= 0) { - //FD_CLR(t->srv_fd, StaticWriteEvent); + //MY_FD_CLR(t->srv_fd, StaticWriteEvent); tv_eternity(&req->wex); fd_delete(t->srv_fd); if (t->srv) @@ -2362,14 +2362,14 @@ int process_srv(struct session *t) return 1; } else if (req->l == 0) { - if (FD_ISSET(t->srv_fd, StaticWriteEvent)) { - FD_CLR(t->srv_fd, StaticWriteEvent); /* stop writing */ + if (MY_FD_ISSET(t->srv_fd, StaticWriteEvent)) { + MY_FD_CLR(t->srv_fd, StaticWriteEvent); /* stop writing */ tv_eternity(&req->wex); } } else { /* buffer not empty */ - if (! FD_ISSET(t->srv_fd, StaticWriteEvent)) { - FD_SET(t->srv_fd, StaticWriteEvent); /* restart writing */ + if (! MY_FD_ISSET(t->srv_fd, StaticWriteEvent)) { + MY_FD_SET(t->srv_fd, StaticWriteEvent); /* restart writing */ if (t->proxy->srvtimeout) { tv_delayfrom(&req->wex, &now, t->proxy->srvtimeout); /* FIXME: to prevent the server from expiring read timeouts during writes, @@ -2384,7 +2384,7 @@ int process_srv(struct session *t) } else if (s == SV_STSHUTW) { if (rep->flags & BF_READ_ERROR) { - //FD_CLR(t->srv_fd, StaticReadEvent); + //MY_FD_CLR(t->srv_fd, StaticReadEvent); tv_eternity(&rep->rex); fd_delete(t->srv_fd); if (t->srv) { @@ -2407,7 +2407,7 @@ int process_srv(struct session *t) return 1; } else if (rep->flags & BF_READ_NULL || c == CL_STSHUTW || c == CL_STCLOSE) { - //FD_CLR(t->srv_fd, StaticReadEvent); + //MY_FD_CLR(t->srv_fd, StaticReadEvent); tv_eternity(&rep->rex); fd_delete(t->srv_fd); if (t->srv) @@ -2423,7 +2423,7 @@ int process_srv(struct session *t) return 1; } else if (tv_cmp2_ms(&rep->rex, &now) <= 0) { - //FD_CLR(t->srv_fd, StaticReadEvent); + //MY_FD_CLR(t->srv_fd, StaticReadEvent); tv_eternity(&rep->rex); fd_delete(t->srv_fd); if (t->srv) @@ -2443,14 +2443,14 @@ int process_srv(struct session *t) return 1; } else if (rep->l == BUFSIZE) { /* no room to read more data */ - if (FD_ISSET(t->srv_fd, StaticReadEvent)) { - FD_CLR(t->srv_fd, StaticReadEvent); + if (MY_FD_ISSET(t->srv_fd, StaticReadEvent)) { + MY_FD_CLR(t->srv_fd, StaticReadEvent); tv_eternity(&rep->rex); } } else { - if (! FD_ISSET(t->srv_fd, StaticReadEvent)) { - FD_SET(t->srv_fd, StaticReadEvent); + if (! MY_FD_ISSET(t->srv_fd, StaticReadEvent)) { + MY_FD_SET(t->srv_fd, StaticReadEvent); if (t->proxy->srvtimeout) tv_delayfrom(&rep->rex, &now, t->proxy->srvtimeout); else diff --git a/src/proxy.c b/src/proxy.c index 6e6f8cc4ed..09770612ed 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -128,7 +128,7 @@ int start_proxies(int verbose) fdtab[fd].cb[DIR_RD].b = fdtab[fd].cb[DIR_WR].b = NULL; fdtab[fd].owner = (struct task *)curproxy; /* reference the proxy instead of a task */ fdtab[fd].state = FD_STLISTEN; - FD_SET(fd, StaticReadEvent); + MY_FD_SET(fd, StaticReadEvent); fd_insert(fd); listeners++; } @@ -164,7 +164,7 @@ int maintain_proxies(void) if (p->nbconn < p->maxconn) { if (p->state == PR_STIDLE) { for (l = p->listen; l != NULL; l = l->next) { - FD_SET(l->fd, StaticReadEvent); + MY_FD_SET(l->fd, StaticReadEvent); } p->state = PR_STRUN; } @@ -172,7 +172,7 @@ int maintain_proxies(void) else { if (p->state == PR_STRUN) { for (l = p->listen; l != NULL; l = l->next) { - FD_CLR(l->fd, StaticReadEvent); + MY_FD_CLR(l->fd, StaticReadEvent); } p->state = PR_STIDLE; } @@ -184,7 +184,7 @@ int maintain_proxies(void) while (p) { if (p->state == PR_STRUN) { for (l = p->listen; l != NULL; l = l->next) { - FD_CLR(l->fd, StaticReadEvent); + MY_FD_CLR(l->fd, StaticReadEvent); } p->state = PR_STIDLE; } @@ -257,7 +257,7 @@ void pause_proxy(struct proxy *p) if (shutdown(l->fd, SHUT_WR) == 0 && listen(l->fd, p->maxconn) == 0 && shutdown(l->fd, SHUT_RD) == 0) { - FD_CLR(l->fd, StaticReadEvent); + MY_FD_CLR(l->fd, StaticReadEvent); if (p->state != PR_STERROR) p->state = PR_STPAUSED; } @@ -323,7 +323,7 @@ void listen_proxies(void) for (l = p->listen; l != NULL; l = l->next) { if (listen(l->fd, p->maxconn) == 0) { if (actconn < global.maxconn && p->nbconn < p->maxconn) { - FD_SET(l->fd, StaticReadEvent); + MY_FD_SET(l->fd, StaticReadEvent); p->state = PR_STRUN; } else diff --git a/src/stream_sock.c b/src/stream_sock.c index cece0a2092..f0f80d1e27 100644 --- a/src/stream_sock.c +++ b/src/stream_sock.c @@ -77,7 +77,7 @@ int stream_sock_read(int fd) { } if (max == 0) { /* not anymore room to store data */ - FD_CLR(fd, StaticReadEvent); + MY_FD_CLR(fd, StaticReadEvent); break; } @@ -131,7 +131,7 @@ int stream_sock_read(int fd) { } if (b->flags & BF_READ_STATUS) { - if (b->rto && FD_ISSET(fd, StaticReadEvent)) + if (b->rto && MY_FD_ISSET(fd, StaticReadEvent)) tv_delayfrom(&b->rex, &now, b->rto); else tv_eternity(&b->rex); @@ -177,7 +177,7 @@ int stream_sock_write(int fd) { fdtab[fd].state = FD_STERROR; task_wakeup(&rq, fdtab[fd].owner); tv_eternity(&b->wex); - FD_CLR(fd, StaticWriteEvent); + MY_FD_CLR(fd, StaticWriteEvent); return 0; } } @@ -186,7 +186,7 @@ int stream_sock_write(int fd) { task_wakeup(&rq, fdtab[fd].owner); fdtab[fd].state = FD_STREADY; tv_eternity(&b->wex); - FD_CLR(fd, StaticWriteEvent); + MY_FD_CLR(fd, StaticWriteEvent); return 0; }