]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: connection: simplify subscription by adding a registration function
authorWilly Tarreau <w@1wt.eu>
Wed, 18 Jul 2018 06:18:20 +0000 (08:18 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 19 Jul 2018 16:31:07 +0000 (18:31 +0200)
This new function wl_set_waitcb() prepopulates a wait_list with a tasklet
and a context and returns it so that it can be passed to ->subscribe() to
be added to a connection or conn_stream's wait_list. The caller doesn't
need to know all the insiders details anymore this way.

include/proto/connection.h
src/checks.c
src/stream_interface.c

index a2580f10b3cf96b90259906d944675881af36af7..8344c951dee5deec8ef8b7f27c8549cb0801e981 100644 (file)
@@ -773,6 +773,15 @@ static inline void cs_attach(struct conn_stream *cs, void *data, const struct da
        cs->data = data;
 }
 
+static inline struct wait_list *wl_set_waitcb(struct wait_list *wl, struct task *(*cb)(struct task *, void *, unsigned short), void *ctx)
+{
+       if (!wl->task->process) {
+               wl->task->process = cb;
+               wl->task->context = ctx;
+       }
+       return wl;
+}
+
 /* Installs the connection's mux layer for upper context <ctx>.
  * Returns < 0 on error.
  */
index 624a06594001cbcc82a797f481975d0cab535569..af6ddd453a1af265e8ba879c9af5fcc09bc2b9c2 100644 (file)
@@ -779,11 +779,7 @@ static void __event_srv_chk_w(struct conn_stream *cs)
                        goto out_wakeup;
                }
                if (b_data(&check->bo)) {
-                       if (!cs->wait_list.task->process) {
-                               cs->wait_list.task->process = event_srv_chk_w;
-                               cs->wait_list.task->context = cs;
-                       }
-                       conn->mux->subscribe(cs, SUB_CAN_SEND, &cs->wait_list);
+                       conn->mux->subscribe(cs, SUB_CAN_SEND, wl_set_waitcb(&cs->wait_list, event_srv_chk_w, cs));
                        goto out;
                }
        }
index 6fb7b535fc25e892c189508d2cfabbb0f909c1a1..f1b52c176b15e4d1178b84db276dbc31c1cf9cc3 100644 (file)
@@ -732,13 +732,9 @@ static struct task * si_cs_send(struct task *t, void *ctx, unsigned short state)
                }
        }
        /* We couldn't send all of our data, let the mux know we'd like to send more */
-       if (co_data(oc)) {
-               if (!cs->wait_list.task->process) {
-                       cs->wait_list.task->process = si_cs_send;
-                       cs->wait_list.task->context = ctx;
-               }
-               conn->mux->subscribe(cs, SUB_CAN_SEND, &cs->wait_list);
-       }
+       if (co_data(oc))
+               conn->mux->subscribe(cs, SUB_CAN_SEND, wl_set_waitcb(&cs->wait_list, si_cs_send, ctx));
+
 wake_others:
        /* Maybe somebody was waiting for this conn_stream, wake them */
        if (did_send) {