]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: connections: Use BUG_ON() to enforce rules in subscribe/unsubscribe.
authorOlivier Houchard <ohouchard@haproxy.com>
Tue, 14 May 2019 16:02:47 +0000 (18:02 +0200)
committerOlivier Houchard <cognet@ci0.org>
Tue, 14 May 2019 16:18:25 +0000 (18:18 +0200)
It is not legal to subscribe if we're already subscribed, or to unsubscribe
if we did not subscribe, so instead of trying to handle those cases, just
assert that it's ok using the new BUG_ON() macro.

src/connection.c

index adedb411ddd598d483941712a4495b4547a3b33b..908d098e42a2ea82e68140cfbe893758edfdcd79 100644 (file)
@@ -319,18 +319,16 @@ int conn_unsubscribe(struct connection *conn, void *xprt_ctx, int event_type, vo
 
        if (event_type & SUB_RETRY_RECV) {
                sw = param;
-               if (sw->events & SUB_RETRY_RECV) {
-                       conn->recv_wait = NULL;
-                       sw->events &= ~SUB_RETRY_RECV;
-               }
+               BUG_ON(conn->recv_wait != sw);
+               conn->recv_wait = NULL;
+               sw->events &= ~SUB_RETRY_RECV;
                __conn_xprt_stop_recv(conn);
        }
        if (event_type & SUB_RETRY_SEND) {
                sw = param;
-               if (sw->events & SUB_RETRY_SEND) {
-                       conn->send_wait = NULL;
-                       sw->events &= ~SUB_RETRY_SEND;
-               }
+               BUG_ON(conn->send_wait != sw);
+               conn->send_wait = NULL;
+               sw->events &= ~SUB_RETRY_SEND;
                __conn_xprt_stop_send(conn);
        }
        conn_update_xprt_polling(conn);
@@ -343,19 +341,17 @@ int conn_subscribe(struct connection *conn, void *xprt_ctx, int event_type, void
 
        if (event_type & SUB_RETRY_RECV) {
                sw = param;
-               if (!(sw->events & SUB_RETRY_RECV)) {
-                       sw->events |= SUB_RETRY_RECV;
-                       conn->recv_wait = sw;
-               }
+               BUG_ON(conn->recv_wait != NULL || (sw->events & SUB_RETRY_RECV));
+               sw->events |= SUB_RETRY_RECV;
+               conn->recv_wait = sw;
                event_type &= ~SUB_RETRY_RECV;
                __conn_xprt_want_recv(conn);
        }
        if (event_type & SUB_RETRY_SEND) {
                sw = param;
-               if (!(sw->events & SUB_RETRY_SEND)) {
-                       sw->events |= SUB_RETRY_SEND;
-                       conn->send_wait = sw;
-               }
+               BUG_ON(conn->send_wait != NULL || (sw->events & SUB_RETRY_SEND));
+               sw->events |= SUB_RETRY_SEND;
+               conn->send_wait = sw;
                event_type &= ~SUB_RETRY_SEND;
                __conn_xprt_want_send(conn);
        }