]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: fd: add a new flag HAP_POLL_F_RDHUP to struct poller
authorWilly Tarreau <w@1wt.eu>
Mon, 13 Mar 2017 10:38:28 +0000 (11:38 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 21 Mar 2017 15:30:35 +0000 (16:30 +0100)
We'll need to differenciate between pollers which can report hangup at
the same time as read (POLL_RDHUP) from the other ones, because only
these ones may benefit from the fd_done_recv() optimization. Epoll has
had support for EPOLLRDHUP since Linux 2.6.17 and has always been used
this way in haproxy, so now we only set the flag once we've observed it
once in a response. It means that some initial requests may try to
perform a second recv() call, but after the first closed connection it
will be enough to know that the second call is not needed anymore.

Later we may extend these flags to designate event-triggered pollers.

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

index 7f63093548f21255135e03aaae5a22bc5d364a2d..2bd7c07f2a17887d22fff3c25a366cee04602345 100644 (file)
@@ -120,7 +120,11 @@ struct fdinfo {
  *    the term() function.
  *  - clo() should be used to do indicate the poller that fd will be closed.
  *  - poll() calls the poller, expiring at <exp>
+ *  - flags indicate what the poller supports (HAP_POLL_F_*)
  */
+
+#define HAP_POLL_F_RDHUP 0x00000001                          /* the poller notifies of HUP with reads */
+
 struct poller {
        void   *private;                                     /* any private data for the poller */
        void REGPRM1   (*clo)(const int fd);                 /* mark <fd> as closed */
@@ -130,6 +134,7 @@ struct poller {
        int  REGPRM1   (*test)(struct poller *p);            /* pre-init check of the poller */
        int  REGPRM1   (*fork)(struct poller *p);            /* post-fork re-opening */
        const char   *name;                                  /* poller name */
+       unsigned int flags;                                  /* HAP_POLL_F_* */
        int    pref;                                         /* try pollers with higher preference first */
 };
 
index ccb7c33772ab62f5aad297437e6795ea1f6d80a6..eb2bceb0383fa93851ec620be6eee82e58d39a65 100644 (file)
@@ -154,8 +154,10 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
                }
 
                /* always remap RDHUP to HUP as they're used similarly */
-               if (e & EPOLLRDHUP)
+               if (e & EPOLLRDHUP) {
+                       cur_poller.flags |= HAP_POLL_F_RDHUP;
                        n |= FD_POLL_HUP;
+               }
 
                fdtab[fd].ev |= n;
                if (n & (FD_POLL_IN | FD_POLL_HUP | FD_POLL_ERR))
@@ -263,6 +265,7 @@ static void _do_register(void)
 
        p->name = "epoll";
        p->pref = 300;
+       p->flags = 0;
        p->private = NULL;
 
        p->clo  = __fd_clo;
index 081e78aa775790079d0ece38ca177ce50fe44812..de7da655b26c7cbc1c051ff5f9ee08ba69d53ba8 100644 (file)
@@ -234,6 +234,7 @@ static void _do_register(void)
 
        p->name = "kqueue";
        p->pref = 300;
+       p->flags = 0;
        p->private = NULL;
 
        p->clo  = NULL;
index 80d88eb91e488baec75ae501303c404020c80a7b..9a6faa9bf718a3d61ea358429f73880ea8ad9d5b 100644 (file)
@@ -235,6 +235,7 @@ static void _do_register(void)
 
        p->name = "poll";
        p->pref = 200;
+       p->flags = 0;
        p->private = NULL;
 
        p->clo  = __fd_clo;
index 35d3c77db7a604a95d8e8246faf99e34833e5637..1b40ea1028a184edc9dff02f15aeae49db11774a 100644 (file)
@@ -235,6 +235,7 @@ static void _do_register(void)
 
        p->name = "select";
        p->pref = 150;
+       p->flags = 0;
        p->private = NULL;
 
        p->clo  = __fd_clo;