MINOR: fd: Use inlined functions to check fd state in fd_*_send/recv functions

It these functions, the test is inverted and we rely on fd_recv/send_* function
to check the fd state. This will ease threads support integration.
This commit is contained in:
Christopher Faulet 2017-08-30 10:07:47 +02:00 committed by Willy Tarreau
parent 8db2fdfaba
commit d82b180d6b

View File

@ -252,46 +252,46 @@ static inline int fd_active(const int fd)
/* Disable processing recv events on fd <fd> */ /* Disable processing recv events on fd <fd> */
static inline void fd_stop_recv(int fd) static inline void fd_stop_recv(int fd)
{ {
if (!((unsigned int)fdtab[fd].state & FD_EV_ACTIVE_R)) if (fd_recv_active(fd)) {
return; /* already disabled */
fdtab[fd].state &= ~FD_EV_ACTIVE_R; fdtab[fd].state &= ~FD_EV_ACTIVE_R;
fd_update_cache(fd); /* need an update entry to change the state */ fd_update_cache(fd); /* need an update entry to change the state */
} }
}
/* Disable processing send events on fd <fd> */ /* Disable processing send events on fd <fd> */
static inline void fd_stop_send(int fd) static inline void fd_stop_send(int fd)
{ {
if (!((unsigned int)fdtab[fd].state & FD_EV_ACTIVE_W)) if (fd_send_active(fd)) {
return; /* already disabled */
fdtab[fd].state &= ~FD_EV_ACTIVE_W; fdtab[fd].state &= ~FD_EV_ACTIVE_W;
fd_update_cache(fd); /* need an update entry to change the state */ fd_update_cache(fd); /* need an update entry to change the state */
} }
}
/* Disable processing of events on fd <fd> for both directions. */ /* Disable processing of events on fd <fd> for both directions. */
static inline void fd_stop_both(int fd) static inline void fd_stop_both(int fd)
{ {
if (!((unsigned int)fdtab[fd].state & FD_EV_ACTIVE_RW)) if (fd_active(fd)) {
return; /* already disabled */
fdtab[fd].state &= ~FD_EV_ACTIVE_RW; fdtab[fd].state &= ~FD_EV_ACTIVE_RW;
fd_update_cache(fd); /* need an update entry to change the state */ fd_update_cache(fd); /* need an update entry to change the state */
} }
}
/* Report that FD <fd> cannot receive anymore without polling (EAGAIN detected). */ /* Report that FD <fd> cannot receive anymore without polling (EAGAIN detected). */
static inline void fd_cant_recv(const int fd) static inline void fd_cant_recv(const int fd)
{ {
if (!(((unsigned int)fdtab[fd].state) & FD_EV_READY_R)) if (fd_recv_ready(fd)) {
return; /* already marked as blocked */
fdtab[fd].state &= ~FD_EV_READY_R; fdtab[fd].state &= ~FD_EV_READY_R;
fd_update_cache(fd); fd_update_cache(fd); /* need an update entry to change the state */
}
} }
/* Report that FD <fd> can receive anymore without polling. */ /* Report that FD <fd> can receive anymore without polling. */
static inline void fd_may_recv(const int fd) static inline void fd_may_recv(const int fd)
{ {
if (((unsigned int)fdtab[fd].state) & FD_EV_READY_R) if (!fd_recv_ready(fd)) {
return; /* already marked as blocked */
fdtab[fd].state |= FD_EV_READY_R; fdtab[fd].state |= FD_EV_READY_R;
fd_update_cache(fd); fd_update_cache(fd); /* need an update entry to change the state */
}
} }
/* Disable readiness when polled. This is useful to interrupt reading when it /* Disable readiness when polled. This is useful to interrupt reading when it
@ -301,45 +301,47 @@ static inline void fd_may_recv(const int fd)
*/ */
static inline void fd_done_recv(const int fd) static inline void fd_done_recv(const int fd)
{ {
if (fd_recv_polled(fd)) if (fd_recv_polled(fd) && fd_recv_ready(fd)) {
fd_cant_recv(fd); fdtab[fd].state &= ~FD_EV_READY_R;
fd_update_cache(fd); /* need an update entry to change the state */
}
} }
/* Report that FD <fd> cannot send anymore without polling (EAGAIN detected). */ /* Report that FD <fd> cannot send anymore without polling (EAGAIN detected). */
static inline void fd_cant_send(const int fd) static inline void fd_cant_send(const int fd)
{ {
if (!(((unsigned int)fdtab[fd].state) & FD_EV_READY_W)) if (fd_send_ready(fd)) {
return; /* already marked as blocked */
fdtab[fd].state &= ~FD_EV_READY_W; fdtab[fd].state &= ~FD_EV_READY_W;
fd_update_cache(fd); fd_update_cache(fd); /* need an update entry to change the state */
}
} }
/* Report that FD <fd> can send anymore without polling (EAGAIN detected). */ /* Report that FD <fd> can send anymore without polling (EAGAIN detected). */
static inline void fd_may_send(const int fd) static inline void fd_may_send(const int fd)
{ {
if (((unsigned int)fdtab[fd].state) & FD_EV_READY_W) if (!fd_send_ready(fd)) {
return; /* already marked as blocked */
fdtab[fd].state |= FD_EV_READY_W; fdtab[fd].state |= FD_EV_READY_W;
fd_update_cache(fd); fd_update_cache(fd); /* need an update entry to change the state */
}
} }
/* Prepare FD <fd> to try to receive */ /* Prepare FD <fd> to try to receive */
static inline void fd_want_recv(int fd) static inline void fd_want_recv(int fd)
{ {
if (((unsigned int)fdtab[fd].state & FD_EV_ACTIVE_R)) if (!fd_recv_active(fd)) {
return; /* already enabled */
fdtab[fd].state |= FD_EV_ACTIVE_R; fdtab[fd].state |= FD_EV_ACTIVE_R;
fd_update_cache(fd); /* need an update entry to change the state */ fd_update_cache(fd); /* need an update entry to change the state */
} }
}
/* Prepare FD <fd> to try to send */ /* Prepare FD <fd> to try to send */
static inline void fd_want_send(int fd) static inline void fd_want_send(int fd)
{ {
if (((unsigned int)fdtab[fd].state & FD_EV_ACTIVE_W)) if (!fd_send_active(fd)) {
return; /* already enabled */
fdtab[fd].state |= FD_EV_ACTIVE_W; fdtab[fd].state |= FD_EV_ACTIVE_W;
fd_update_cache(fd); /* need an update entry to change the state */ fd_update_cache(fd); /* need an update entry to change the state */
} }
}
/* Prepares <fd> for being polled */ /* Prepares <fd> for being polled */
static inline void fd_insert(int fd) static inline void fd_insert(int fd)