[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.
This commit is contained in:
Willy Tarreau 2006-10-15 14:52:29 +02:00
parent 0bbc3cf157
commit 2a429503e0
10 changed files with 192 additions and 136 deletions

View File

@ -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 */

View File

@ -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)
{

View File

@ -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

View File

@ -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 <inter> 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);

View File

@ -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);
}

View File

@ -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 @@ 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<<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 @@ int epoll_loop(int action)
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 @@ int poll_loop(int action)
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 @@ int poll_loop(int action)
/* 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 @@ int select_loop(int action)
// /* 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 @@ int select_loop(int action)
/* 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 @@ int select_loop(int action)
*/
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

View File

@ -267,10 +267,10 @@ void dump(int sig)
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
);
}

View File

@ -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

View File

@ -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

View File

@ -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;
}