From 35d116885d590a845b227e8ab808aa5fdf5890c1 Mon Sep 17 00:00:00 2001 From: Olivier Houchard Date: Tue, 14 May 2019 18:02:47 +0200 Subject: [PATCH] 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. --- src/connection.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/connection.c b/src/connection.c index adedb411d..908d098e4 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); } -- 2.47.3