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.
This commit is contained in:
Olivier Houchard 2019-05-14 18:02:47 +02:00 committed by Olivier Houchard
parent 00b8f7c60b
commit 35d116885d
1 changed files with 12 additions and 16 deletions

View File

@ -319,18 +319,16 @@ int conn_unsubscribe(struct connection *conn, void *xprt_ctx, int event_type, vo
if (event_type & SUB_RETRY_RECV) { if (event_type & SUB_RETRY_RECV) {
sw = param; sw = param;
if (sw->events & SUB_RETRY_RECV) { BUG_ON(conn->recv_wait != sw);
conn->recv_wait = NULL; conn->recv_wait = NULL;
sw->events &= ~SUB_RETRY_RECV; sw->events &= ~SUB_RETRY_RECV;
}
__conn_xprt_stop_recv(conn); __conn_xprt_stop_recv(conn);
} }
if (event_type & SUB_RETRY_SEND) { if (event_type & SUB_RETRY_SEND) {
sw = param; sw = param;
if (sw->events & SUB_RETRY_SEND) { BUG_ON(conn->send_wait != sw);
conn->send_wait = NULL; conn->send_wait = NULL;
sw->events &= ~SUB_RETRY_SEND; sw->events &= ~SUB_RETRY_SEND;
}
__conn_xprt_stop_send(conn); __conn_xprt_stop_send(conn);
} }
conn_update_xprt_polling(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) { if (event_type & SUB_RETRY_RECV) {
sw = param; sw = param;
if (!(sw->events & SUB_RETRY_RECV)) { BUG_ON(conn->recv_wait != NULL || (sw->events & SUB_RETRY_RECV));
sw->events |= SUB_RETRY_RECV; sw->events |= SUB_RETRY_RECV;
conn->recv_wait = sw; conn->recv_wait = sw;
}
event_type &= ~SUB_RETRY_RECV; event_type &= ~SUB_RETRY_RECV;
__conn_xprt_want_recv(conn); __conn_xprt_want_recv(conn);
} }
if (event_type & SUB_RETRY_SEND) { if (event_type & SUB_RETRY_SEND) {
sw = param; sw = param;
if (!(sw->events & SUB_RETRY_SEND)) { BUG_ON(conn->send_wait != NULL || (sw->events & SUB_RETRY_SEND));
sw->events |= SUB_RETRY_SEND; sw->events |= SUB_RETRY_SEND;
conn->send_wait = sw; conn->send_wait = sw;
}
event_type &= ~SUB_RETRY_SEND; event_type &= ~SUB_RETRY_SEND;
__conn_xprt_want_send(conn); __conn_xprt_want_send(conn);
} }