]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: mux-h2: add a new function h2s_alert() to call the data layer
authorWilly Tarreau <w@1wt.eu>
Wed, 19 Dec 2018 16:36:48 +0000 (17:36 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 19 Dec 2018 17:13:48 +0000 (18:13 +0100)
In order to report an error to the data layer, we have different ways
depending on the situation. At a lot of places it's open-coded and not
always correct. Let's create a new function h2s_alert() to handle this
task. It tries to wake on recv() first, then on send(), then using
wake().

src/mux_h2.c

index 7a8f71b95bd576ae7b15905f09248ab0a1e95536..11f1a6c59432a7688614b43d3be2d9fc51f21c5b 100644 (file)
@@ -247,6 +247,7 @@ static int h2s_decode_headers(struct h2s *h2s);
 static int h2_frt_transfer_data(struct h2s *h2s);
 static struct task *h2_deferred_shut(struct task *t, void *ctx, unsigned short state);
 static struct h2s *h2c_bck_stream_new(struct h2c *h2c, struct conn_stream *cs, struct session *sess);
+static void h2s_alert(struct h2s *h2s);
 
 /*****************************************************/
 /* functions below are for dynamic buffer management */
@@ -624,6 +625,24 @@ static void __maybe_unused h2s_notify_send(struct h2s *h2s)
        }
 }
 
+/* alerts the data layer, trying to wake it up by all means, following
+ * this sequence :
+ *   - if the h2s' data layer is subscribed to recv, then it's woken up for recv
+ *   - if its subscribed to send, then it's woken up for send
+ *   - if it was subscribed to neither, its ->wake() callback is called
+ * It is safe to call this function with a closed stream which doesn't have a
+ * conn_stream anymore.
+ */
+static void __maybe_unused h2s_alert(struct h2s *h2s)
+{
+       if (h2s->recv_wait || h2s->send_wait) {
+               h2s_notify_recv(h2s);
+               h2s_notify_send(h2s);
+       }
+       else if (h2s->cs && h2s->cs->data_cb->wake != NULL)
+               h2s->cs->data_cb->wake(h2s->cs);
+}
+
 /* writes the 24-bit frame size <len> at address <frame> */
 static inline __maybe_unused void h2_set_frame_size(void *frame, uint32_t len)
 {