]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: fd: merge the read and write error bits into RW error
authorWilly Tarreau <w@1wt.eu>
Wed, 26 Feb 2020 15:12:45 +0000 (16:12 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 28 Feb 2020 06:42:29 +0000 (07:42 +0100)
We always set them both, which makes sense since errors at the FD level
indicate a terminal condition for the socket that cannot be recovered.
Usually this is detected via a write error, but sometimes such an error
may asynchronously be reported on the read side. Let's simplify this
using only the write bit and calling it RW since it's used like this
everywhere, and leave the R bit spare for future use.

include/proto/fd.h
include/types/fd.h

index 9c7f66be2fc6efbaa712b2bb888d86766dca4614..3c778abc42852dddb7c04d9b53283d25ac25cd5f 100644 (file)
@@ -314,8 +314,7 @@ static inline void fd_update_events(int fd, unsigned char evts)
              ((evts & FD_EV_READY_R) ? FD_POLL_IN  : 0) |
              ((evts & FD_EV_READY_W) ? FD_POLL_OUT : 0) |
              ((evts & FD_EV_SHUT_R)  ? FD_POLL_HUP : 0) |
-             ((evts & FD_EV_ERR_R)   ? FD_POLL_ERR : 0) |
-             ((evts & FD_EV_ERR_W)   ? FD_POLL_ERR : 0);
+             ((evts & FD_EV_ERR_RW)  ? FD_POLL_ERR : 0);
 
        /* SHUTW reported while FD was active for writes is an error */
        if ((fdtab[fd].ev & FD_EV_ACTIVE_W) && (evts & FD_EV_SHUT_W))
@@ -327,11 +326,11 @@ static inline void fd_update_events(int fd, unsigned char evts)
                /* both sides stopped */
                must_stop = FD_POLL_IN | FD_POLL_OUT;
        }
-       else if (unlikely(!fd_recv_active(fd) && (evts & (FD_EV_READY_R | FD_EV_SHUT_R | FD_EV_ERR_R)))) {
+       else if (unlikely(!fd_recv_active(fd) && (evts & (FD_EV_READY_R | FD_EV_SHUT_R | FD_EV_ERR_RW)))) {
                /* only send remains */
                must_stop = FD_POLL_IN;
        }
-       else if (unlikely(!fd_send_active(fd) && (evts & (FD_EV_READY_W | FD_EV_SHUT_W | FD_EV_ERR_W)))) {
+       else if (unlikely(!fd_send_active(fd) && (evts & (FD_EV_READY_W | FD_EV_SHUT_W | FD_EV_ERR_RW)))) {
                /* only recv remains */
                must_stop = FD_POLL_OUT;
        }
index 2630b66de569ca58759eedb6ad78e43145349ac8..e62e2a4f3afaff651b5ae15efe02e6801d6e7513 100644 (file)
@@ -57,12 +57,12 @@ enum {
 #define FD_EV_ACTIVE_R_BIT 0
 #define FD_EV_READY_R_BIT  1
 #define FD_EV_SHUT_R_BIT   2
-#define FD_EV_ERR_R_BIT    3
+/* unused: 3 */
 
 #define FD_EV_ACTIVE_W_BIT 4
 #define FD_EV_READY_W_BIT  5
 #define FD_EV_SHUT_W_BIT   6
-#define FD_EV_ERR_W_BIT    7
+#define FD_EV_ERR_RW_BIT   7
 
 /* and flag values */
 #define FD_EV_ACTIVE_R  (1U << FD_EV_ACTIVE_R_BIT)
@@ -78,10 +78,10 @@ enum {
 #define FD_EV_SHUT_W    (1U << FD_EV_SHUT_W_BIT)
 #define FD_EV_SHUT_RW   (FD_EV_SHUT_R | FD_EV_SHUT_W)
 
-/* note that when FD_EV_ERR is set, SHUT is also set */
-#define FD_EV_ERR_R     (1U << FD_EV_ERR_R_BIT)
-#define FD_EV_ERR_W     (1U << FD_EV_ERR_W_BIT)
-#define FD_EV_ERR_RW    (FD_EV_ERR_R | FD_EV_ERR_W)
+/* note that when FD_EV_ERR is set, SHUT is also set. Also, ERR is for both
+ * directions at once (write error, socket dead, etc).
+ */
+#define FD_EV_ERR_RW    (1U << FD_EV_ERR_RW_BIT)
 
 
 /* This is the value used to mark a file descriptor as dead. This value is