From: Olivier Houchard Date: Tue, 14 May 2019 16:02:47 +0000 (+0200) Subject: MINOR: connections: Use BUG_ON() to enforce rules in subscribe/unsubscribe. X-Git-Tag: v2.0-dev3~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=35d116885d590a845b227e8ab808aa5fdf5890c1;p=thirdparty%2Fhaproxy.git MINOR: connections: Use BUG_ON() to enforce rules in subscribe/unsubscribe. 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. --- diff --git a/src/connection.c b/src/connection.c index adedb411dd..908d098e42 100644 --- a/src/connection.c +++ b/src/connection.c @@ -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); }