From 8b2757c3398702b6fba868da33141def9fcba85f Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 19 Dec 2018 17:36:48 +0100 Subject: [PATCH] MINOR: mux-h2: add a new function h2s_alert() to call the data layer 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 | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/mux_h2.c b/src/mux_h2.c index 7a8f71b95..11f1a6c59 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -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 at address */ static inline __maybe_unused void h2_set_frame_size(void *frame, uint32_t len) {