MINOR: connections/mux: Add the wait reason(s) to wait_list.

Add a new element to the wait_list, that let us know which event(s) we are
waiting on.
diff --git a/src/connection.c b/src/connection.c
index df3df84..ee80e61 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -134,6 +134,7 @@
 			    struct wait_list *, list);
 			LIST_DEL(&sw->list);
 			LIST_INIT(&sw->list);
+			sw->wait_reason &= ~SUB_CAN_SEND;
 			tasklet_wakeup(sw->task);
 		}
 	}
@@ -338,8 +339,10 @@
 	switch (event_type) {
 	case SUB_CAN_SEND:
 		sw = param;
-		if (LIST_ISEMPTY(&sw->list))
+		if (!(sw->wait_reason & SUB_CAN_SEND)) {
+			sw->wait_reason |= SUB_CAN_SEND;
 			LIST_ADDQ(&conn->send_wait_list, &sw->list);
+		}
 		return 0;
 	default:
 		break;
diff --git a/src/mux_h2.c b/src/mux_h2.c
index 0ad4bac..538d21f 100644
--- a/src/mux_h2.c
+++ b/src/mux_h2.c
@@ -369,6 +369,7 @@
 		goto fail;
 	h2c->wait_list.task->process = h2_send;
 	h2c->wait_list.task->context = conn;
+	h2c->wait_list.wait_reason = 0;
 
 	h2c->ddht = hpack_dht_alloc(h2_settings_header_table_size);
 	if (!h2c->ddht)
@@ -2289,6 +2290,7 @@
 			    struct wait_list *, list);
 			LIST_DEL(&sw->list);
 			LIST_INIT(&sw->list);
+			sw->wait_reason &= ~SUB_CAN_SEND;
 			tasklet_wakeup(sw->task);
 		}
 
@@ -3409,8 +3411,11 @@
 	switch (event_type) {
 	case SUB_CAN_SEND:
 		sw = param;
-		if (LIST_ISEMPTY(&h2s->list) && LIST_ISEMPTY(&sw->list))
+		if (LIST_ISEMPTY(&h2s->list) &&
+		    !(sw->wait_reason & SUB_CAN_SEND)) {
 			LIST_ADDQ(&h2s->h2c->send_wait_list, &sw->list);
+			sw->wait_reason |= SUB_CAN_SEND;
+		}
 		return 0;
 	default:
 		break;
diff --git a/src/stream_interface.c b/src/stream_interface.c
index f2d6b6f..92b8e85 100644
--- a/src/stream_interface.c
+++ b/src/stream_interface.c
@@ -652,7 +652,7 @@
 	int did_send = 0;
 
 	/* We're already waiting to be able to send, give up */
-	if (!LIST_ISEMPTY(&cs->wait_list.list))
+	if (cs->wait_list.wait_reason & SUB_CAN_SEND)
 		return NULL;
 
 	if (conn->flags & CO_FL_ERROR || cs->flags & CS_FL_ERROR)
@@ -661,7 +661,7 @@
 	if (conn->flags & CO_FL_HANDSHAKE) {
 		/* a handshake was requested */
 		/* Schedule ourself to be woken up once the handshake is done */
-		LIST_ADDQ(&conn->send_wait_list, &cs->wait_list.list);
+		conn->xprt->subscribe(conn, SUB_CAN_SEND,  wl_set_waitcb(&cs->wait_list, si_cs_send, ctx));
 		return NULL;
 	}
 
@@ -751,6 +751,7 @@
 			    struct wait_list *, list);
 			LIST_DEL(&sw->list);
 			LIST_INIT(&sw->list);
+			sw->wait_reason &= ~SUB_CAN_SEND;
 			tasklet_wakeup(sw->task);
 		}
 	}