[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 c1cf098..3ab879f 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 879205b..1d480af 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 d0c0891..2884ea5 100644
--- a/src/backend.c
+++ b/src/backend.c
@@ -432,11 +432,11 @@
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 5fc9e28..3085eab 100644
--- a/src/checks.c
+++ b/src/checks.c
@@ -115,7 +115,7 @@
/* 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 @@
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 @@
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 @@
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 <inter> for a connection to establish, but we should use another parameter */
@@ -370,7 +370,7 @@
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 @@
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 c723ca1..e1890f0 100644
--- a/src/client.c
+++ b/src/client.c
@@ -97,7 +97,7 @@
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 @@
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 @@
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 @@
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 66d963a..2f68651 100644
--- a/src/fd.c
+++ b/src/fd.c
@@ -28,6 +28,7 @@
#include <types/fd.h>
#include <types/global.h>
+#include <proto/fd.h>
#include <proto/polling.h>
#include <proto/task.h>
@@ -45,6 +46,29 @@
******************************/
+#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 @@
sr = (rn >> count) & 1;
sw = (wn >> count) & 1;
#else
- pr = FD_ISSET(fd&((1<<INTBITS)-1), (typeof(fd_set*))&ro);
- pw = FD_ISSET(fd&((1<<INTBITS)-1), (typeof(fd_set*))&wo);
- sr = FD_ISSET(fd&((1<<INTBITS)-1), (typeof(fd_set*))&rn);
- sw = FD_ISSET(fd&((1<<INTBITS)-1), (typeof(fd_set*))&wn);
+ pr = MY_FD_ISSET(fd&((1<<INTBITS)-1), (typeof(fd_set*))&ro);
+ pw = MY_FD_ISSET(fd&((1<<INTBITS)-1), (typeof(fd_set*))&wo);
+ sr = MY_FD_ISSET(fd&((1<<INTBITS)-1), (typeof(fd_set*))&rn);
+ sw = MY_FD_ISSET(fd&((1<<INTBITS)-1), (typeof(fd_set*))&wn);
#endif
#else
- pr = FD_ISSET(fd, PrevReadEvent);
- pw = FD_ISSET(fd, PrevWriteEvent);
- sr = FD_ISSET(fd, StaticReadEvent);
- sw = FD_ISSET(fd, StaticWriteEvent);
+ pr = MY_FD_ISSET(fd, PrevReadEvent);
+ pw = MY_FD_ISSET(fd, PrevWriteEvent);
+ sr = MY_FD_ISSET(fd, StaticReadEvent);
+ sw = MY_FD_ISSET(fd, StaticWriteEvent);
#endif
if (!((sr^pr) | (sw^pw)))
continue;
@@ -210,14 +234,14 @@
for (count = 0; count < status; count++) {
fd = epoll_events[count].data.fd;
- if (FD_ISSET(fd, StaticReadEvent)) {
+ if (MY_FD_ISSET(fd, StaticReadEvent)) {
if (fdtab[fd].state == FD_STCLOSE)
continue;
if (epoll_events[count].events & ( EPOLLIN | EPOLLERR | EPOLLHUP ))
fdtab[fd].cb[DIR_RD].f(fd);
}
- if (FD_ISSET(fd, StaticWriteEvent)) {
+ if (MY_FD_ISSET(fd, StaticWriteEvent)) {
if (fdtab[fd].state == FD_STCLOSE)
continue;
if (epoll_events[count].events & ( EPOLLOUT | EPOLLERR | EPOLLHUP ))
@@ -293,12 +317,12 @@
sr = (rn >> count) & 1;
sw = (wn >> count) & 1;
#else
- sr = FD_ISSET(fd&((1<<INTBITS)-1), (typeof(fd_set*))&rn);
- sw = FD_ISSET(fd&((1<<INTBITS)-1), (typeof(fd_set*))&wn);
+ sr = MY_FD_ISSET(fd&((1<<INTBITS)-1), (typeof(fd_set*))&rn);
+ sw = MY_FD_ISSET(fd&((1<<INTBITS)-1), (typeof(fd_set*))&wn);
#endif
#else
- sr = FD_ISSET(fd, StaticReadEvent);
- sw = FD_ISSET(fd, StaticWriteEvent);
+ sr = MY_FD_ISSET(fd, StaticReadEvent);
+ sw = MY_FD_ISSET(fd, StaticWriteEvent);
#endif
if ((sr|sw)) {
poll_events[nbfd].fd = fd;
@@ -322,14 +346,14 @@
/* ok, we found one active fd */
status--;
- if (FD_ISSET(fd, StaticReadEvent)) {
+ if (MY_FD_ISSET(fd, StaticReadEvent)) {
if (fdtab[fd].state == FD_STCLOSE)
continue;
if (poll_events[count].revents & ( POLLIN | POLLERR | POLLHUP ))
fdtab[fd].cb[DIR_RD].f(fd);
}
- if (FD_ISSET(fd, StaticWriteEvent)) {
+ if (MY_FD_ISSET(fd, StaticWriteEvent)) {
if (fdtab[fd].state == FD_STCLOSE)
continue;
if (poll_events[count].revents & ( POLLOUT | POLLERR | POLLHUP ))
@@ -409,9 +433,9 @@
// /* just a verification code, needs to be removed for performance */
// for (i=0; i<maxfd; i++) {
- // if (FD_ISSET(i, ReadEvent) != FD_ISSET(i, StaticReadEvent))
+ // if (MY_FD_ISSET(i, ReadEvent) != MY_FD_ISSET(i, StaticReadEvent))
// abort();
- // if (FD_ISSET(i, WriteEvent) != FD_ISSET(i, StaticWriteEvent))
+ // if (MY_FD_ISSET(i, WriteEvent) != MY_FD_ISSET(i, StaticWriteEvent))
// abort();
//
// }
@@ -440,13 +464,13 @@
/* if we specify read first, the accepts and zero reads will be
* seen first. Moreover, system buffers will be flushed faster.
*/
- if (FD_ISSET(fd, ReadEvent)) {
+ if (MY_FD_ISSET(fd, ReadEvent)) {
if (fdtab[fd].state == FD_STCLOSE)
continue;
fdtab[fd].cb[DIR_RD].f(fd);
}
- if (FD_ISSET(fd, WriteEvent)) {
+ if (MY_FD_ISSET(fd, WriteEvent)) {
if (fdtab[fd].state == FD_STCLOSE)
continue;
fdtab[fd].cb[DIR_WR].f(fd);
@@ -472,12 +496,12 @@
*/
void fd_delete(int fd)
{
- FD_CLR(fd, StaticReadEvent);
- FD_CLR(fd, StaticWriteEvent);
+ MY_FD_CLR(fd, StaticReadEvent);
+ MY_FD_CLR(fd, StaticWriteEvent);
#if defined(ENABLE_EPOLL)
if (PrevReadEvent) {
- FD_CLR(fd, PrevReadEvent);
- FD_CLR(fd, PrevWriteEvent);
+ MY_FD_CLR(fd, PrevReadEvent);
+ MY_FD_CLR(fd, PrevWriteEvent);
}
#endif
diff --git a/src/haproxy.c b/src/haproxy.c
index 917e202..ef246e6 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -267,10 +267,10 @@
s, tv_remain(&now, &t->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 9cd75f3..0ba52a4 100644
--- a/src/proto_http.c
+++ b/src/proto_http.c
@@ -85,8 +85,8 @@
*/
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 @@
#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 @@
* 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 @@
/* 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 @@
}
/* 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 @@
}
/* 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 @@
}
/* 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 @@
}
/* 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 @@
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 @@
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 @@
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 @@
* 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 @@
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 @@
//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 @@
}
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 @@
*/
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 @@
/* 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 @@
* 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 @@
}
/* 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 @@
* 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 @@
* 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 @@
}
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 @@
}
/* 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 @@
}
/* 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 @@
}
/* 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 @@
}
/* 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 @@
/* 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 @@
/* 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 @@
}
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 @@
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 @@
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 @@
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 @@
}
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 @@
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 @@
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 @@
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 6e6f8cc..0977061 100644
--- a/src/proxy.c
+++ b/src/proxy.c
@@ -128,7 +128,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 cece0a2..f0f80d1 100644
--- a/src/stream_sock.c
+++ b/src/stream_sock.c
@@ -77,7 +77,7 @@
}
if (max == 0) { /* not anymore room to store data */
- FD_CLR(fd, StaticReadEvent);
+ MY_FD_CLR(fd, StaticReadEvent);
break;
}
@@ -131,7 +131,7 @@
}
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 @@
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 @@
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;
}