MINOR: connections/mux: Add a new "subscribe" method.
Add a new "subscribe" method for connection, conn_stream and mux, so that
upper layer can subscribe to them, to be called when the event happens.
Right now, the only event implemented is "SUB_CAN_SEND", where the upper
layer can register to be called back when it is possible to send data.
The connection and conn_stream got a new "send_wait_list" entry, which
required to move a few struct members around to maintain an efficient
cache alignment (and actually this slightly improved performance).
diff --git a/src/connection.c b/src/connection.c
index db869fb..94e7209 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -128,6 +128,13 @@
*/
flags = 0;
conn->mux->send(conn);
+ while (!LIST_ISEMPTY(&conn->send_wait_list)) {
+ struct wait_list *sw = LIST_ELEM(conn->send_wait_list.n,
+ struct wait_list *, list);
+ LIST_DEL(&sw->list);
+ LIST_INIT(&sw->list);
+ tasklet_wakeup(sw->task);
+ }
}
/* The data transfer starts here and stops on error and handshakes. Note
@@ -323,6 +330,22 @@
return ret;
}
+int conn_subscribe(struct connection *conn, int event_type, void *param)
+{
+ struct wait_list *sw;
+
+ switch (event_type) {
+ case SUB_CAN_SEND:
+ sw = param;
+ if (LIST_ISEMPTY(&sw->list))
+ LIST_ADDQ(&conn->send_wait_list, &sw->list);
+ return 0;
+ default:
+ break;
+ }
+ return (-1);
+}
+
/* Drains possibly pending incoming data on the file descriptor attached to the
* connection and update the connection's flags accordingly. This is used to
* know whether we need to disable lingering on close. Returns non-zero if it