mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-22 14:21:25 +02:00
REORG/MEDIUM: fd: remove FD_STCLOSE from struct fdtab
In an attempt to get rid of fdtab[].state, and to move the relevant parts to the connection struct, we remove the FD_STCLOSE state which can easily be deduced from the <owner> pointer as there is a 1:1 match.
This commit is contained in:
parent
801a0a353a
commit
db3b32610f
@ -32,7 +32,6 @@
|
||||
#include <types/protocols.h>
|
||||
|
||||
/* different possible states for the fd */
|
||||
#define FD_STCLOSE 0
|
||||
#define FD_STLISTEN 1
|
||||
#define FD_STCONN 2
|
||||
#define FD_STREADY 3
|
||||
@ -70,7 +69,7 @@ struct fdtab {
|
||||
struct {
|
||||
int (*f)(int fd); /* read/write function */
|
||||
} cb[DIR_SIZE];
|
||||
void *owner; /* the session (or proxy) associated with this fd */
|
||||
void *owner; /* the session (or proxy) associated with this fd, NULL if closed */
|
||||
struct { /* used by pollers which support speculative polling */
|
||||
unsigned char e; /* read and write events status. 4 bits, may be merged into flags' lower bits */
|
||||
unsigned int s1; /* Position in spec list+1. 0=not in list. */
|
||||
|
@ -257,14 +257,14 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
|
||||
((e & EPOLLHUP) ? FD_POLL_HUP : 0);
|
||||
|
||||
if ((fd_evts[FD2OFS(fd)] >> FD2BIT(fd)) & DIR2MSK(DIR_RD)) {
|
||||
if (fdtab[fd].state == FD_STCLOSE)
|
||||
if (!fdtab[fd].owner)
|
||||
continue;
|
||||
if (fdtab[fd].ev & (FD_POLL_IN|FD_POLL_HUP|FD_POLL_ERR))
|
||||
fdtab[fd].cb[DIR_RD].f(fd);
|
||||
}
|
||||
|
||||
if ((fd_evts[FD2OFS(fd)] >> FD2BIT(fd)) & DIR2MSK(DIR_WR)) {
|
||||
if (fdtab[fd].state == FD_STCLOSE)
|
||||
if (!fdtab[fd].owner)
|
||||
continue;
|
||||
if (fdtab[fd].ev & (FD_POLL_OUT|FD_POLL_ERR|FD_POLL_HUP))
|
||||
fdtab[fd].cb[DIR_WR].f(fd);
|
||||
|
@ -140,14 +140,14 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
|
||||
fd = kev[count].ident;
|
||||
if (kev[count].filter == EVFILT_READ) {
|
||||
if (FD_ISSET(fd, fd_evts[DIR_RD])) {
|
||||
if (fdtab[fd].state == FD_STCLOSE)
|
||||
if (!fdtab[fd].owner)
|
||||
continue;
|
||||
fdtab[fd].ev |= FD_POLL_IN;
|
||||
fdtab[fd].cb[DIR_RD].f(fd);
|
||||
}
|
||||
} else if (kev[count].filter == EVFILT_WRITE) {
|
||||
if (FD_ISSET(fd, fd_evts[DIR_WR])) {
|
||||
if (fdtab[fd].state == FD_STCLOSE)
|
||||
if (!fdtab[fd].owner)
|
||||
continue;
|
||||
fdtab[fd].ev |= FD_POLL_OUT;
|
||||
fdtab[fd].cb[DIR_WR].f(fd);
|
||||
|
@ -160,14 +160,14 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
|
||||
status--;
|
||||
|
||||
if (FD_ISSET(fd, fd_evts[DIR_RD])) {
|
||||
if (fdtab[fd].state == FD_STCLOSE)
|
||||
if (!fdtab[fd].owner)
|
||||
continue;
|
||||
if (fdtab[fd].ev & (FD_POLL_IN|FD_POLL_HUP|FD_POLL_ERR))
|
||||
fdtab[fd].cb[DIR_RD].f(fd);
|
||||
}
|
||||
|
||||
if (FD_ISSET(fd, fd_evts[DIR_WR])) {
|
||||
if (fdtab[fd].state == FD_STCLOSE)
|
||||
if (!fdtab[fd].owner)
|
||||
continue;
|
||||
if (fdtab[fd].ev & (FD_POLL_OUT|FD_POLL_ERR|FD_POLL_HUP))
|
||||
fdtab[fd].cb[DIR_WR].f(fd);
|
||||
|
@ -147,14 +147,14 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
|
||||
* seen first. Moreover, system buffers will be flushed faster.
|
||||
*/
|
||||
if (FD_ISSET(fd, tmp_evts[DIR_RD])) {
|
||||
if (fdtab[fd].state == FD_STCLOSE)
|
||||
if (!fdtab[fd].owner)
|
||||
continue;
|
||||
fdtab[fd].ev |= FD_POLL_IN;
|
||||
fdtab[fd].cb[DIR_RD].f(fd);
|
||||
}
|
||||
|
||||
if (FD_ISSET(fd, tmp_evts[DIR_WR])) {
|
||||
if (fdtab[fd].state == FD_STCLOSE)
|
||||
if (!fdtab[fd].owner)
|
||||
continue;
|
||||
fdtab[fd].ev |= FD_POLL_OUT;
|
||||
fdtab[fd].cb[DIR_WR].f(fd);
|
||||
|
@ -202,7 +202,7 @@ REGPRM2 static int __fd_is_set(const int fd, int dir)
|
||||
int ret;
|
||||
|
||||
#if DEBUG_DEV
|
||||
if (fdtab[fd].state == FD_STCLOSE) {
|
||||
if (!fdtab[fd].owner) {
|
||||
fprintf(stderr, "sepoll.fd_isset called on closed fd #%d.\n", fd);
|
||||
ABORT_NOW();
|
||||
}
|
||||
@ -220,7 +220,7 @@ REGPRM2 static int __fd_set(const int fd, int dir)
|
||||
unsigned int i;
|
||||
|
||||
#if DEBUG_DEV
|
||||
if (fdtab[fd].state == FD_STCLOSE) {
|
||||
if (!fdtab[fd].owner) {
|
||||
fprintf(stderr, "sepoll.fd_set called on closed fd #%d.\n", fd);
|
||||
ABORT_NOW();
|
||||
}
|
||||
@ -242,7 +242,7 @@ REGPRM2 static int __fd_clr(const int fd, int dir)
|
||||
unsigned int i;
|
||||
|
||||
#if DEBUG_DEV
|
||||
if (fdtab[fd].state == FD_STCLOSE) {
|
||||
if (!fdtab[fd].owner) {
|
||||
fprintf(stderr, "sepoll.fd_clr called on closed fd #%d.\n", fd);
|
||||
ABORT_NOW();
|
||||
}
|
||||
@ -410,14 +410,14 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
|
||||
((e & EPOLLHUP) ? FD_POLL_HUP : 0);
|
||||
|
||||
if ((fdtab[fd].spec.e & FD_EV_MASK_R) == FD_EV_WAIT_R) {
|
||||
if (fdtab[fd].state == FD_STCLOSE || fdtab[fd].state == FD_STERROR)
|
||||
if (!fdtab[fd].owner || fdtab[fd].state == FD_STERROR)
|
||||
continue;
|
||||
if (fdtab[fd].ev & (FD_POLL_IN|FD_POLL_HUP|FD_POLL_ERR))
|
||||
fdtab[fd].cb[DIR_RD].f(fd);
|
||||
}
|
||||
|
||||
if ((fdtab[fd].spec.e & FD_EV_MASK_W) == FD_EV_WAIT_W) {
|
||||
if (fdtab[fd].state == FD_STCLOSE || fdtab[fd].state == FD_STERROR)
|
||||
if (!fdtab[fd].owner || fdtab[fd].state == FD_STERROR)
|
||||
continue;
|
||||
if (fdtab[fd].ev & (FD_POLL_OUT|FD_POLL_ERR))
|
||||
fdtab[fd].cb[DIR_WR].f(fd);
|
||||
@ -471,7 +471,7 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
|
||||
}
|
||||
|
||||
/* one callback might already have closed the fd by itself */
|
||||
if (fdtab[fd].state == FD_STCLOSE)
|
||||
if (!fdtab[fd].owner)
|
||||
continue;
|
||||
|
||||
if (!(fdtab[fd].spec.e & (FD_EV_RW_SL|FD_EV_RW_PL))) {
|
||||
|
4
src/fd.c
4
src/fd.c
@ -41,9 +41,9 @@ void fd_delete(int fd)
|
||||
port_range_release_port(fdinfo[fd].port_range, fdinfo[fd].local_port);
|
||||
fdinfo[fd].port_range = NULL;
|
||||
close(fd);
|
||||
fdtab[fd].state = FD_STCLOSE;
|
||||
fdtab[fd].owner = NULL;
|
||||
|
||||
while ((maxfd-1 >= 0) && (fdtab[maxfd-1].state == FD_STCLOSE))
|
||||
while ((maxfd-1 >= 0) && !fdtab[maxfd-1].owner)
|
||||
maxfd--;
|
||||
}
|
||||
|
||||
|
@ -351,7 +351,6 @@ void dump(struct sig_handler *sh)
|
||||
*/
|
||||
void init(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
int arg_mode = 0; /* MODE_DEBUG, ... */
|
||||
char *tmp;
|
||||
char *cfg_pidfile = NULL;
|
||||
@ -691,10 +690,6 @@ void init(int argc, char **argv)
|
||||
sizeof(struct fdinfo) * (global.maxsock));
|
||||
fdtab = (struct fdtab *)calloc(1,
|
||||
sizeof(struct fdtab) * (global.maxsock));
|
||||
for (i = 0; i < global.maxsock; i++) {
|
||||
fdtab[i].state = FD_STCLOSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Note: we could register external pollers here.
|
||||
* Built-in pollers have been registered before main().
|
||||
|
@ -320,7 +320,7 @@ int session_accept(struct listener *l, int cfd, struct sockaddr_storage *addr)
|
||||
send(cfd, err_msg->str, err_msg->len, MSG_DONTWAIT|MSG_NOSIGNAL);
|
||||
}
|
||||
|
||||
if (fdtab[cfd].state != FD_STCLOSE)
|
||||
if (fdtab[cfd].owner)
|
||||
fd_delete(cfd);
|
||||
else
|
||||
close(cfd);
|
||||
|
Loading…
x
Reference in New Issue
Block a user