]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REORG/MEDIUM: fd: remove FD_STCLOSE from struct fdtab
authorWilly Tarreau <w@1wt.eu>
Thu, 5 Jul 2012 21:19:22 +0000 (23:19 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 2 Sep 2012 19:51:25 +0000 (21:51 +0200)
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.

include/types/fd.h
src/ev_epoll.c
src/ev_kqueue.c
src/ev_poll.c
src/ev_select.c
src/ev_sepoll.c
src/fd.c
src/haproxy.c
src/session.c

index 0abd3ef10fc1b422218b8d3a969413ed3c080b14..c75734512bdd604a54bdede24cae8f816dab82d2 100644 (file)
@@ -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. */
index 7026d56d300a7c42a771127dd9fe05606ae1f904..482992ee6271b6bc455f63164e279d7ee346d7c7 100644 (file)
@@ -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);
index df4f920b754d93fb36233d3e5a04e3d6fbeda033..b27f37231bdb11b50369bcd3859457c504e56d5c 100644 (file)
@@ -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);
index 8f2e1d986edd6bd4708c306f4a1f0a7459a53ee6..6351a72f0d41ae38e08831fee64591bf76156cf3 100644 (file)
@@ -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);
index 72eca0b3f42e85a61e2df35bd87aa112bc55b581..64031cc3eeec43da132d6103c9bf2d62a8e0dd59 100644 (file)
@@ -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);
index b5048157bd8dc62ca31937dee44d95fc7b20f838..4b1580995e08b174aca7428651a41069ed4cb3a6 100644 (file)
@@ -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))) {
index 80bddd6a0f78863801d7f02f49e2bb6d4ded9a84..7958087e479f64c679d5138dbabbb49b68cfb827 100644 (file)
--- a/src/fd.c
+++ b/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--;
 }
 
index cede41ca65293fe67946685b09e1a1addd9cd8de..499d3985de4d59eccebe64f954e20ece421a771b 100644 (file)
@@ -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().
index 43252b86375bf95c10cad9dc7d04d5ca0bcc17ee..e839922e396841307afb7dfb6fe0db3c246bbabc 100644 (file)
@@ -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);