MEDIUM: connection: make use of the control layer check_events/ignore_events

This changes the subscribe/unsubscribe functions to rely on the control
layer's check_events/ignore_events. At the moment only the socket version
of these functions is present so the code should basically be the same.
This commit is contained in:
Willy Tarreau 2020-12-11 17:06:11 +01:00
parent 472125bc04
commit 746b0515a4

View File

@ -127,10 +127,10 @@ int conn_ctrl_send(struct connection *conn, const void *buf, int len, int flags)
return ret; return ret;
} }
/* Called from the upper layer, to subscribe <es> to events <event_type>. The /* Called from the upper layer, to unsubscribe <es> from events <event_type>.
* event subscriber <es> is not allowed to change from a previous call as long * The event subscriber <es> is not allowed to change from a previous call as
* as at least one event is still subscribed. The <event_type> must only be a * long as at least one event is still subscribed. The <event_type> must only
* combination of SUB_RETRY_RECV and SUB_RETRY_SEND. It always returns 0. * be a combination of SUB_RETRY_RECV and SUB_RETRY_SEND. It always returns 0.
*/ */
int conn_unsubscribe(struct connection *conn, void *xprt_ctx, int event_type, struct wait_event *es) int conn_unsubscribe(struct connection *conn, void *xprt_ctx, int event_type, struct wait_event *es)
{ {
@ -141,56 +141,36 @@ int conn_unsubscribe(struct connection *conn, void *xprt_ctx, int event_type, st
if (!es->events) if (!es->events)
conn->subs = NULL; conn->subs = NULL;
if (conn_ctrl_ready(conn)) { if (conn_ctrl_ready(conn) && conn->ctrl->ignore_events)
if (event_type & SUB_RETRY_RECV) conn->ctrl->ignore_events(conn, event_type);
fd_stop_recv(conn->handle.fd);
if (event_type & SUB_RETRY_SEND)
fd_stop_send(conn->handle.fd);
}
return 0; return 0;
} }
/* Called from the upper layer, to subscribe <es> to events <event_type>. /* Called from the upper layer, to subscribe <es> to events <event_type>.
* The <es> struct is not allowed to differ from the one passed during a * The <es> struct is not allowed to differ from the one passed during a
* previous call to subscribe(). If the FD is ready, the wait_event is * previous call to subscribe(). If the connection's ctrl layer is ready,
* immediately woken up and the subcription is cancelled. It always * the wait_event is immediately woken up and the subcription is cancelled.
* returns zero. * It always returns zero.
*/ */
int conn_subscribe(struct connection *conn, void *xprt_ctx, int event_type, struct wait_event *es) int conn_subscribe(struct connection *conn, void *xprt_ctx, int event_type, struct wait_event *es)
{ {
int ret = 0;
BUG_ON(event_type & ~(SUB_RETRY_SEND|SUB_RETRY_RECV)); BUG_ON(event_type & ~(SUB_RETRY_SEND|SUB_RETRY_RECV));
BUG_ON(conn->subs && conn->subs != es); BUG_ON(conn->subs && conn->subs != es);
if (conn->subs && (conn->subs->events & event_type) == event_type) if (conn->subs && (conn->subs->events & event_type) == event_type)
return 0; return 0;
conn->subs = es; if (conn_ctrl_ready(conn) && conn->ctrl->check_events) {
es->events |= event_type; ret = conn->ctrl->check_events(conn, event_type);
if (ret)
if (conn_ctrl_ready(conn)) { tasklet_wakeup(es->tasklet);
if (event_type & SUB_RETRY_RECV) {
if (fd_recv_ready(conn->handle.fd)) {
tasklet_wakeup(es->tasklet);
es->events &= ~SUB_RETRY_RECV;
if (!es->events)
conn->subs = NULL;
}
else
fd_want_recv(conn->handle.fd);
}
if (event_type & SUB_RETRY_SEND) {
if (fd_send_ready(conn->handle.fd)) {
tasklet_wakeup(es->tasklet);
es->events &= ~SUB_RETRY_SEND;
if (!es->events)
conn->subs = NULL;
}
else
fd_want_send(conn->handle.fd);
}
} }
es->events = (es->events | event_type) & ~ret;
conn->subs = es->events ? es : NULL;
return 0; return 0;
} }