Willy Tarreau | cff6411 | 2008-11-03 06:26:53 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Functions managing stream_interface structures |
| 3 | * |
Willy Tarreau | f873d75 | 2012-05-11 17:47:17 +0200 | [diff] [blame] | 4 | * Copyright 2000-2012 Willy Tarreau <w@1wt.eu> |
Willy Tarreau | cff6411 | 2008-11-03 06:26:53 +0100 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | */ |
| 12 | |
| 13 | #include <errno.h> |
| 14 | #include <fcntl.h> |
| 15 | #include <stdio.h> |
| 16 | #include <stdlib.h> |
| 17 | |
| 18 | #include <sys/socket.h> |
| 19 | #include <sys/stat.h> |
| 20 | #include <sys/types.h> |
| 21 | |
Willy Tarreau | 4c7e4b7 | 2020-05-27 12:58:42 +0200 | [diff] [blame] | 22 | #include <haproxy/api.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 23 | #include <haproxy/applet.h> |
Willy Tarreau | f1d32c4 | 2020-06-04 21:07:02 +0200 | [diff] [blame] | 24 | #include <haproxy/channel.h> |
Willy Tarreau | 7ea393d | 2020-06-04 18:02:10 +0200 | [diff] [blame] | 25 | #include <haproxy/connection.h> |
Christopher Faulet | 0c6a64c | 2022-04-01 08:58:29 +0200 | [diff] [blame] | 26 | #include <haproxy/conn_stream.h> |
| 27 | #include <haproxy/cs_utils.h> |
Willy Tarreau | 2741c8c | 2020-06-02 11:28:02 +0200 | [diff] [blame] | 28 | #include <haproxy/dynbuf.h> |
Willy Tarreau | b7fc4c4 | 2021-10-06 18:56:42 +0200 | [diff] [blame] | 29 | #include <haproxy/http_ana.h> |
Willy Tarreau | 8773533 | 2020-06-04 09:08:41 +0200 | [diff] [blame] | 30 | #include <haproxy/http_htx.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 31 | #include <haproxy/pipe-t.h> |
| 32 | #include <haproxy/pipe.h> |
Christopher Faulet | cda94ac | 2021-12-23 17:28:17 +0100 | [diff] [blame] | 33 | #include <haproxy/pool.h> |
Willy Tarreau | a264d96 | 2020-06-04 22:29:18 +0200 | [diff] [blame] | 34 | #include <haproxy/proxy.h> |
Willy Tarreau | dfd3de8 | 2020-06-04 23:46:14 +0200 | [diff] [blame] | 35 | #include <haproxy/stream-t.h> |
Willy Tarreau | 5e539c9 | 2020-06-04 20:45:39 +0200 | [diff] [blame] | 36 | #include <haproxy/stream_interface.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 37 | #include <haproxy/task.h> |
Willy Tarreau | c2f7c58 | 2020-06-02 18:15:32 +0200 | [diff] [blame] | 38 | #include <haproxy/ticks.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 39 | #include <haproxy/tools.h> |
Willy Tarreau | cff6411 | 2008-11-03 06:26:53 +0100 | [diff] [blame] | 40 | |
Willy Tarreau | fd31e53 | 2012-07-23 18:24:25 +0200 | [diff] [blame] | 41 | |
Christopher Faulet | cda94ac | 2021-12-23 17:28:17 +0100 | [diff] [blame] | 42 | DECLARE_POOL(pool_head_streaminterface, "stream_interface", sizeof(struct stream_interface)); |
| 43 | |
Willy Tarreau | 14bfe9a | 2018-12-19 15:19:27 +0100 | [diff] [blame] | 44 | /* last read notification */ |
Christopher Faulet | d715d36 | 2022-04-01 16:38:32 +0200 | [diff] [blame] | 45 | static void cs_conn_read0(struct conn_stream *cs); |
Willy Tarreau | 14bfe9a | 2018-12-19 15:19:27 +0100 | [diff] [blame] | 46 | |
| 47 | /* post-IO notification callback */ |
Christopher Faulet | 9029a72 | 2022-04-01 16:48:36 +0200 | [diff] [blame] | 48 | static void cs_notify(struct conn_stream *cs); |
Willy Tarreau | f873d75 | 2012-05-11 17:47:17 +0200 | [diff] [blame] | 49 | |
Willy Tarreau | 74beec3 | 2012-10-03 00:41:04 +0200 | [diff] [blame] | 50 | struct data_cb si_conn_cb = { |
Olivier Houchard | 21df6cc | 2018-09-14 23:21:44 +0200 | [diff] [blame] | 51 | .wake = si_cs_process, |
Willy Tarreau | 8e0bb0a | 2016-11-24 16:58:12 +0100 | [diff] [blame] | 52 | .name = "STRM", |
Willy Tarreau | c578891 | 2012-08-24 18:12:41 +0200 | [diff] [blame] | 53 | }; |
| 54 | |
Christopher Faulet | cda94ac | 2021-12-23 17:28:17 +0100 | [diff] [blame] | 55 | |
Christopher Faulet | 6059ba4 | 2022-04-01 16:34:53 +0200 | [diff] [blame] | 56 | struct data_cb cs_data_applet_cb = { |
| 57 | .wake = cs_applet_process, |
| 58 | .name = "STRM", |
| 59 | }; |
| 60 | |
Christopher Faulet | cda94ac | 2021-12-23 17:28:17 +0100 | [diff] [blame] | 61 | struct stream_interface *si_new(struct conn_stream *cs) |
| 62 | { |
| 63 | struct stream_interface *si; |
| 64 | |
| 65 | si = pool_alloc(pool_head_streaminterface); |
| 66 | if (unlikely(!si)) |
| 67 | return NULL; |
| 68 | si->flags = SI_FL_NONE; |
Christopher Faulet | 014ac35 | 2022-01-06 08:13:46 +0100 | [diff] [blame] | 69 | if (si_init(si) < 0) { |
Christopher Faulet | cda94ac | 2021-12-23 17:28:17 +0100 | [diff] [blame] | 70 | pool_free(pool_head_streaminterface, si); |
| 71 | return NULL; |
| 72 | } |
| 73 | si->cs = cs; |
| 74 | return si; |
| 75 | } |
| 76 | |
| 77 | void si_free(struct stream_interface *si) |
| 78 | { |
| 79 | if (!si) |
| 80 | return; |
| 81 | |
Christopher Faulet | cda94ac | 2021-12-23 17:28:17 +0100 | [diff] [blame] | 82 | pool_free(pool_head_streaminterface, si); |
| 83 | } |
| 84 | |
Christopher Faulet | 13045f0 | 2022-04-01 14:23:38 +0200 | [diff] [blame] | 85 | /* This function is the equivalent to cs_update() except that it's |
Willy Tarreau | 615f28b | 2015-09-23 18:40:09 +0200 | [diff] [blame] | 86 | * designed to be called from outside the stream handlers, typically the lower |
| 87 | * layers (applets, connections) after I/O completion. After updating the stream |
| 88 | * interface and timeouts, it will try to forward what can be forwarded, then to |
| 89 | * wake the associated task up if an important event requires special handling. |
Willy Tarreau | d0f5bbc | 2018-11-14 11:10:26 +0100 | [diff] [blame] | 90 | * It may update SI_FL_WAIT_DATA and/or SI_FL_RXBLK_ROOM, that the callers are |
Willy Tarreau | 0dfccb2 | 2018-10-25 13:55:20 +0200 | [diff] [blame] | 91 | * encouraged to watch to take appropriate action. |
Christopher Faulet | 13045f0 | 2022-04-01 14:23:38 +0200 | [diff] [blame] | 92 | * It should not be called from within the stream itself, cs_update() |
Willy Tarreau | 615f28b | 2015-09-23 18:40:09 +0200 | [diff] [blame] | 93 | * is designed for this. |
| 94 | */ |
Christopher Faulet | 9029a72 | 2022-04-01 16:48:36 +0200 | [diff] [blame] | 95 | static void cs_notify(struct conn_stream *cs) |
Willy Tarreau | 615f28b | 2015-09-23 18:40:09 +0200 | [diff] [blame] | 96 | { |
Christopher Faulet | 9029a72 | 2022-04-01 16:48:36 +0200 | [diff] [blame] | 97 | struct channel *ic = cs_ic(cs); |
| 98 | struct channel *oc = cs_oc(cs); |
| 99 | struct conn_stream *cso = cs_opposite(cs); |
| 100 | struct task *task = cs_strm_task(cs); |
Willy Tarreau | 615f28b | 2015-09-23 18:40:09 +0200 | [diff] [blame] | 101 | |
| 102 | /* process consumer side */ |
| 103 | if (channel_is_empty(oc)) { |
Christopher Faulet | 9029a72 | 2022-04-01 16:48:36 +0200 | [diff] [blame] | 104 | struct connection *conn = cs_conn(cs); |
Olivier Houchard | e9bed53 | 2017-11-16 17:49:25 +0100 | [diff] [blame] | 105 | |
Willy Tarreau | 615f28b | 2015-09-23 18:40:09 +0200 | [diff] [blame] | 106 | if (((oc->flags & (CF_SHUTW|CF_SHUTW_NOW)) == CF_SHUTW_NOW) && |
Christopher Faulet | 9029a72 | 2022-04-01 16:48:36 +0200 | [diff] [blame] | 107 | (cs->state == CS_ST_EST) && (!conn || !(conn->flags & (CO_FL_WAIT_XPRT | CO_FL_EARLY_SSL_HS)))) |
| 108 | cs_shutw(cs); |
Willy Tarreau | 615f28b | 2015-09-23 18:40:09 +0200 | [diff] [blame] | 109 | oc->wex = TICK_ETERNITY; |
| 110 | } |
| 111 | |
Willy Tarreau | 8cf9c8e | 2016-12-13 15:21:25 +0100 | [diff] [blame] | 112 | /* indicate that we may be waiting for data from the output channel or |
| 113 | * we're about to close and can't expect more data if SHUTW_NOW is there. |
| 114 | */ |
Christopher Faulet | b3e0de4 | 2018-10-11 13:54:13 +0200 | [diff] [blame] | 115 | if (!(oc->flags & (CF_SHUTW|CF_SHUTW_NOW))) |
Christopher Faulet | 9029a72 | 2022-04-01 16:48:36 +0200 | [diff] [blame] | 116 | cs->si->flags |= SI_FL_WAIT_DATA; |
Willy Tarreau | 8cf9c8e | 2016-12-13 15:21:25 +0100 | [diff] [blame] | 117 | else if ((oc->flags & (CF_SHUTW|CF_SHUTW_NOW)) == CF_SHUTW_NOW) |
Christopher Faulet | 9029a72 | 2022-04-01 16:48:36 +0200 | [diff] [blame] | 118 | cs->si->flags &= ~SI_FL_WAIT_DATA; |
Willy Tarreau | 615f28b | 2015-09-23 18:40:09 +0200 | [diff] [blame] | 119 | |
| 120 | /* update OC timeouts and wake the other side up if it's waiting for room */ |
| 121 | if (oc->flags & CF_WRITE_ACTIVITY) { |
| 122 | if ((oc->flags & (CF_SHUTW|CF_WRITE_PARTIAL)) == CF_WRITE_PARTIAL && |
| 123 | !channel_is_empty(oc)) |
| 124 | if (tick_isset(oc->wex)) |
| 125 | oc->wex = tick_add_ifset(now_ms, oc->wto); |
| 126 | |
Christopher Faulet | 9029a72 | 2022-04-01 16:48:36 +0200 | [diff] [blame] | 127 | if (!(cs->flags & CS_FL_INDEP_STR)) |
Willy Tarreau | 615f28b | 2015-09-23 18:40:09 +0200 | [diff] [blame] | 128 | if (tick_isset(ic->rex)) |
| 129 | ic->rex = tick_add_ifset(now_ms, ic->rto); |
Willy Tarreau | f26c26c | 2018-11-12 16:11:08 +0100 | [diff] [blame] | 130 | } |
Willy Tarreau | 615f28b | 2015-09-23 18:40:09 +0200 | [diff] [blame] | 131 | |
Willy Tarreau | b26a6f9 | 2018-11-14 17:10:36 +0100 | [diff] [blame] | 132 | if (oc->flags & CF_DONT_READ) |
Christopher Faulet | 9029a72 | 2022-04-01 16:48:36 +0200 | [diff] [blame] | 133 | si_rx_chan_blk(cso->si); |
Willy Tarreau | b26a6f9 | 2018-11-14 17:10:36 +0100 | [diff] [blame] | 134 | else |
Christopher Faulet | 9029a72 | 2022-04-01 16:48:36 +0200 | [diff] [blame] | 135 | si_rx_chan_rdy(cso->si); |
Willy Tarreau | 615f28b | 2015-09-23 18:40:09 +0200 | [diff] [blame] | 136 | |
| 137 | /* Notify the other side when we've injected data into the IC that |
| 138 | * needs to be forwarded. We can do fast-forwarding as soon as there |
| 139 | * are output data, but we avoid doing this if some of the data are |
| 140 | * not yet scheduled for being forwarded, because it is very likely |
| 141 | * that it will be done again immediately afterwards once the following |
Willy Tarreau | d0f5bbc | 2018-11-14 11:10:26 +0100 | [diff] [blame] | 142 | * data are parsed (eg: HTTP chunking). We only SI_FL_RXBLK_ROOM once |
Willy Tarreau | 615f28b | 2015-09-23 18:40:09 +0200 | [diff] [blame] | 143 | * we've emptied *some* of the output buffer, and not just when there |
| 144 | * is available room, because applets are often forced to stop before |
| 145 | * the buffer is full. We must not stop based on input data alone because |
| 146 | * an HTTP parser might need more data to complete the parsing. |
| 147 | */ |
| 148 | if (!channel_is_empty(ic) && |
Christopher Faulet | 9029a72 | 2022-04-01 16:48:36 +0200 | [diff] [blame] | 149 | (cso->si->flags & SI_FL_WAIT_DATA) && |
Willy Tarreau | 89b6a2b | 2018-11-18 15:46:10 +0100 | [diff] [blame] | 150 | (!(ic->flags & CF_EXPECT_MORE) || c_full(ic) || ci_data(ic) == 0 || ic->pipe)) { |
Willy Tarreau | 615f28b | 2015-09-23 18:40:09 +0200 | [diff] [blame] | 151 | int new_len, last_len; |
| 152 | |
Willy Tarreau | 77e478c | 2018-06-19 07:03:14 +0200 | [diff] [blame] | 153 | last_len = co_data(ic); |
Willy Tarreau | 615f28b | 2015-09-23 18:40:09 +0200 | [diff] [blame] | 154 | if (ic->pipe) |
| 155 | last_len += ic->pipe->data; |
| 156 | |
Christopher Faulet | 9029a72 | 2022-04-01 16:48:36 +0200 | [diff] [blame] | 157 | cs_chk_snd(cso); |
Willy Tarreau | 615f28b | 2015-09-23 18:40:09 +0200 | [diff] [blame] | 158 | |
Willy Tarreau | 77e478c | 2018-06-19 07:03:14 +0200 | [diff] [blame] | 159 | new_len = co_data(ic); |
Willy Tarreau | 615f28b | 2015-09-23 18:40:09 +0200 | [diff] [blame] | 160 | if (ic->pipe) |
| 161 | new_len += ic->pipe->data; |
| 162 | |
| 163 | /* check if the consumer has freed some space either in the |
| 164 | * buffer or in the pipe. |
| 165 | */ |
Willy Tarreau | 47baeb8 | 2018-11-15 07:46:57 +0100 | [diff] [blame] | 166 | if (new_len < last_len) |
Christopher Faulet | 9029a72 | 2022-04-01 16:48:36 +0200 | [diff] [blame] | 167 | si_rx_room_rdy(cs->si); |
Willy Tarreau | 615f28b | 2015-09-23 18:40:09 +0200 | [diff] [blame] | 168 | } |
| 169 | |
Willy Tarreau | b26a6f9 | 2018-11-14 17:10:36 +0100 | [diff] [blame] | 170 | if (!(ic->flags & CF_DONT_READ)) |
Christopher Faulet | 9029a72 | 2022-04-01 16:48:36 +0200 | [diff] [blame] | 171 | si_rx_chan_rdy(cs->si); |
Willy Tarreau | b26a6f9 | 2018-11-14 17:10:36 +0100 | [diff] [blame] | 172 | |
Christopher Faulet | 9029a72 | 2022-04-01 16:48:36 +0200 | [diff] [blame] | 173 | cs_chk_rcv(cs); |
| 174 | cs_chk_rcv(cso); |
Willy Tarreau | 47baeb8 | 2018-11-15 07:46:57 +0100 | [diff] [blame] | 175 | |
Christopher Faulet | 9029a72 | 2022-04-01 16:48:36 +0200 | [diff] [blame] | 176 | if (si_rx_blocked(cs->si)) { |
Willy Tarreau | 615f28b | 2015-09-23 18:40:09 +0200 | [diff] [blame] | 177 | ic->rex = TICK_ETERNITY; |
| 178 | } |
Willy Tarreau | b26a6f9 | 2018-11-14 17:10:36 +0100 | [diff] [blame] | 179 | else if ((ic->flags & (CF_SHUTR|CF_READ_PARTIAL)) == CF_READ_PARTIAL) { |
Christopher Faulet | da098e6 | 2022-03-31 17:44:45 +0200 | [diff] [blame] | 180 | /* we must re-enable reading if cs_chk_snd() has freed some space */ |
Willy Tarreau | 615f28b | 2015-09-23 18:40:09 +0200 | [diff] [blame] | 181 | if (!(ic->flags & CF_READ_NOEXP) && tick_isset(ic->rex)) |
| 182 | ic->rex = tick_add_ifset(now_ms, ic->rto); |
| 183 | } |
| 184 | |
| 185 | /* wake the task up only when needed */ |
| 186 | if (/* changes on the production side */ |
| 187 | (ic->flags & (CF_READ_NULL|CF_READ_ERROR)) || |
Christopher Faulet | 9029a72 | 2022-04-01 16:48:36 +0200 | [diff] [blame] | 188 | !cs_state_in(cs->state, CS_SB_CON|CS_SB_RDY|CS_SB_EST) || |
| 189 | (cs->endp->flags & CS_EP_ERROR) || |
Willy Tarreau | 615f28b | 2015-09-23 18:40:09 +0200 | [diff] [blame] | 190 | ((ic->flags & CF_READ_PARTIAL) && |
Christopher Faulet | 9029a72 | 2022-04-01 16:48:36 +0200 | [diff] [blame] | 191 | ((ic->flags & CF_EOI) || !ic->to_forward || cso->state != CS_ST_EST)) || |
Willy Tarreau | 615f28b | 2015-09-23 18:40:09 +0200 | [diff] [blame] | 192 | |
| 193 | /* changes on the consumption side */ |
| 194 | (oc->flags & (CF_WRITE_NULL|CF_WRITE_ERROR)) || |
Willy Tarreau | ede3d88 | 2018-10-24 17:17:56 +0200 | [diff] [blame] | 195 | ((oc->flags & CF_WRITE_ACTIVITY) && |
Willy Tarreau | 615f28b | 2015-09-23 18:40:09 +0200 | [diff] [blame] | 196 | ((oc->flags & CF_SHUTW) || |
Willy Tarreau | 78f5ff8 | 2018-12-19 11:00:00 +0100 | [diff] [blame] | 197 | (((oc->flags & CF_WAKE_WRITE) || |
| 198 | !(oc->flags & (CF_AUTO_CLOSE|CF_SHUTW_NOW|CF_SHUTW))) && |
Christopher Faulet | 9029a72 | 2022-04-01 16:48:36 +0200 | [diff] [blame] | 199 | (cso->state != CS_ST_EST || |
Willy Tarreau | 615f28b | 2015-09-23 18:40:09 +0200 | [diff] [blame] | 200 | (channel_is_empty(oc) && !oc->to_forward)))))) { |
Christopher Faulet | d7607de | 2019-01-03 16:24:54 +0100 | [diff] [blame] | 201 | task_wakeup(task, TASK_WOKEN_IO); |
| 202 | } |
| 203 | else { |
| 204 | /* Update expiration date for the task and requeue it */ |
| 205 | task->expire = tick_first((tick_is_expired(task->expire, now_ms) ? 0 : task->expire), |
| 206 | tick_first(tick_first(ic->rex, ic->wex), |
| 207 | tick_first(oc->rex, oc->wex))); |
Willy Tarreau | 45bcb37 | 2019-08-01 18:51:38 +0200 | [diff] [blame] | 208 | |
| 209 | task->expire = tick_first(task->expire, ic->analyse_exp); |
| 210 | task->expire = tick_first(task->expire, oc->analyse_exp); |
Christopher Faulet | 9029a72 | 2022-04-01 16:48:36 +0200 | [diff] [blame] | 211 | task->expire = tick_first(task->expire, __cs_strm(cs)->conn_exp); |
Willy Tarreau | 45bcb37 | 2019-08-01 18:51:38 +0200 | [diff] [blame] | 212 | |
Christopher Faulet | d7607de | 2019-01-03 16:24:54 +0100 | [diff] [blame] | 213 | task_queue(task); |
Willy Tarreau | 615f28b | 2015-09-23 18:40:09 +0200 | [diff] [blame] | 214 | } |
| 215 | if (ic->flags & CF_READ_ACTIVITY) |
| 216 | ic->flags &= ~CF_READ_DONTWAIT; |
Willy Tarreau | 615f28b | 2015-09-23 18:40:09 +0200 | [diff] [blame] | 217 | } |
| 218 | |
Olivier Houchard | c2aa711 | 2018-09-11 18:27:21 +0200 | [diff] [blame] | 219 | /* Called by I/O handlers after completion.. It propagates |
Willy Tarreau | 651e182 | 2015-09-23 20:06:13 +0200 | [diff] [blame] | 220 | * connection flags to the stream interface, updates the stream (which may or |
| 221 | * may not take this opportunity to try to forward data), then update the |
| 222 | * connection's polling based on the channels and stream interface's final |
| 223 | * states. The function always returns 0. |
Willy Tarreau | 100c467 | 2012-08-20 12:06:26 +0200 | [diff] [blame] | 224 | */ |
Christopher Faulet | 9b7a9b4 | 2022-04-01 13:48:39 +0200 | [diff] [blame] | 225 | int si_cs_process(struct conn_stream *cs) |
Willy Tarreau | fd31e53 | 2012-07-23 18:24:25 +0200 | [diff] [blame] | 226 | { |
Christopher Faulet | 693b23b | 2022-02-28 09:09:05 +0100 | [diff] [blame] | 227 | struct connection *conn = __cs_conn(cs); |
Christopher Faulet | f835dea | 2021-12-21 14:35:17 +0100 | [diff] [blame] | 228 | struct stream_interface *si = cs_si(cs); |
Willy Tarreau | afc8a22 | 2014-11-28 15:46:27 +0100 | [diff] [blame] | 229 | struct channel *ic = si_ic(si); |
| 230 | struct channel *oc = si_oc(si); |
Willy Tarreau | fd31e53 | 2012-07-23 18:24:25 +0200 | [diff] [blame] | 231 | |
Christopher Faulet | 897d612 | 2021-12-17 17:28:35 +0100 | [diff] [blame] | 232 | BUG_ON(!conn); |
| 233 | |
Olivier Houchard | c7ffa91 | 2018-08-28 19:37:41 +0200 | [diff] [blame] | 234 | /* If we have data to send, try it now */ |
Christopher Faulet | 2f35e7b | 2022-03-31 11:09:28 +0200 | [diff] [blame] | 235 | if (!channel_is_empty(oc) && !(si->cs->wait_event.events & SUB_RETRY_SEND)) |
Willy Tarreau | 908d26f | 2018-10-25 14:02:47 +0200 | [diff] [blame] | 236 | si_cs_send(cs); |
| 237 | |
Christopher Faulet | af642df | 2022-03-30 10:06:11 +0200 | [diff] [blame] | 238 | /* First step, report to the conn-stream what was detected at the |
Willy Tarreau | 651e182 | 2015-09-23 20:06:13 +0200 | [diff] [blame] | 239 | * connection layer : errors and connection establishment. |
Christopher Faulet | 6cd56d5 | 2022-03-30 10:47:32 +0200 | [diff] [blame] | 240 | * Only add CS_EP_ERROR if we're connected, or we're attempting to |
Olivier Houchard | c31e2cb | 2019-06-24 16:08:08 +0200 | [diff] [blame] | 241 | * connect, we may get there because we got woken up, but only run |
| 242 | * after process_stream() noticed there were an error, and decided |
| 243 | * to retry to connect, the connection may still have CO_FL_ERROR, |
Christopher Faulet | 6cd56d5 | 2022-03-30 10:47:32 +0200 | [diff] [blame] | 244 | * and we don't want to add CS_EP_ERROR back |
Christopher Faulet | 36b536d | 2019-11-20 11:56:33 +0100 | [diff] [blame] | 245 | * |
| 246 | * Note: This test is only required because si_cs_process is also the SI |
| 247 | * wake callback. Otherwise si_cs_recv()/si_cs_send() already take |
| 248 | * care of it. |
Willy Tarreau | 651e182 | 2015-09-23 20:06:13 +0200 | [diff] [blame] | 249 | */ |
Willy Tarreau | d1480cc | 2022-03-17 16:19:09 +0100 | [diff] [blame] | 250 | |
Christopher Faulet | 62e7574 | 2022-03-31 09:16:34 +0200 | [diff] [blame] | 251 | if (si->cs->state >= CS_ST_CON) { |
Christopher Faulet | 6cd56d5 | 2022-03-30 10:47:32 +0200 | [diff] [blame] | 252 | if (si_is_conn_error(si)) |
| 253 | cs->endp->flags |= CS_EP_ERROR; |
Willy Tarreau | d1480cc | 2022-03-17 16:19:09 +0100 | [diff] [blame] | 254 | } |
Willy Tarreau | 3c55ec2 | 2012-07-23 19:19:51 +0200 | [diff] [blame] | 255 | |
Olivier Houchard | ccaa7de | 2017-10-02 11:51:03 +0200 | [diff] [blame] | 256 | /* If we had early data, and the handshake ended, then |
| 257 | * we can remove the flag, and attempt to wake the task up, |
| 258 | * in the event there's an analyser waiting for the end of |
| 259 | * the handshake. |
| 260 | */ |
Willy Tarreau | 911db9b | 2020-01-23 16:27:54 +0100 | [diff] [blame] | 261 | if (!(conn->flags & (CO_FL_WAIT_XPRT | CO_FL_EARLY_SSL_HS)) && |
Christopher Faulet | e9e4820 | 2022-03-22 18:13:29 +0100 | [diff] [blame] | 262 | (cs->endp->flags & CS_EP_WAIT_FOR_HS)) { |
| 263 | cs->endp->flags &= ~CS_EP_WAIT_FOR_HS; |
Olivier Houchard | ccaa7de | 2017-10-02 11:51:03 +0200 | [diff] [blame] | 264 | task_wakeup(si_task(si), TASK_WOKEN_MSG); |
| 265 | } |
| 266 | |
Christopher Faulet | 62e7574 | 2022-03-31 09:16:34 +0200 | [diff] [blame] | 267 | if (!cs_state_in(si->cs->state, CS_SB_EST|CS_SB_DIS|CS_SB_CLO) && |
Willy Tarreau | 911db9b | 2020-01-23 16:27:54 +0100 | [diff] [blame] | 268 | (conn->flags & CO_FL_WAIT_XPRT) == 0) { |
Christopher Faulet | ae024ce | 2022-03-29 19:02:31 +0200 | [diff] [blame] | 269 | __cs_strm(cs)->conn_exp = TICK_ETERNITY; |
Willy Tarreau | afc8a22 | 2014-11-28 15:46:27 +0100 | [diff] [blame] | 270 | oc->flags |= CF_WRITE_NULL; |
Christopher Faulet | 62e7574 | 2022-03-31 09:16:34 +0200 | [diff] [blame] | 271 | if (si->cs->state == CS_ST_CON) |
| 272 | si->cs->state = CS_ST_RDY; |
Willy Tarreau | 8f8c92f | 2012-07-23 19:45:44 +0200 | [diff] [blame] | 273 | } |
| 274 | |
Christopher Faulet | 89e34c2 | 2021-01-21 16:22:01 +0100 | [diff] [blame] | 275 | /* Report EOS on the channel if it was reached from the mux point of |
| 276 | * view. |
| 277 | * |
| 278 | * Note: This test is only required because si_cs_process is also the SI |
| 279 | * wake callback. Otherwise si_cs_recv()/si_cs_send() already take |
| 280 | * care of it. |
| 281 | */ |
Christopher Faulet | b041b23 | 2022-03-24 10:27:02 +0100 | [diff] [blame] | 282 | if (cs->endp->flags & CS_EP_EOS && !(ic->flags & CF_SHUTR)) { |
Christopher Faulet | 89e34c2 | 2021-01-21 16:22:01 +0100 | [diff] [blame] | 283 | /* we received a shutdown */ |
| 284 | ic->flags |= CF_READ_NULL; |
| 285 | if (ic->flags & CF_AUTO_CLOSE) |
| 286 | channel_shutw_now(ic); |
Christopher Faulet | d715d36 | 2022-04-01 16:38:32 +0200 | [diff] [blame] | 287 | cs_conn_read0(cs); |
Christopher Faulet | 89e34c2 | 2021-01-21 16:22:01 +0100 | [diff] [blame] | 288 | } |
| 289 | |
Christopher Faulet | 297d3e2 | 2019-03-22 14:16:14 +0100 | [diff] [blame] | 290 | /* Report EOI on the channel if it was reached from the mux point of |
Christopher Faulet | 36b536d | 2019-11-20 11:56:33 +0100 | [diff] [blame] | 291 | * view. |
| 292 | * |
| 293 | * Note: This test is only required because si_cs_process is also the SI |
| 294 | * wake callback. Otherwise si_cs_recv()/si_cs_send() already take |
| 295 | * care of it. |
| 296 | */ |
Christopher Faulet | b041b23 | 2022-03-24 10:27:02 +0100 | [diff] [blame] | 297 | if ((cs->endp->flags & CS_EP_EOI) && !(ic->flags & CF_EOI)) |
Christopher Faulet | 8e9e3ef | 2019-05-17 09:14:10 +0200 | [diff] [blame] | 298 | ic->flags |= (CF_EOI|CF_READ_PARTIAL); |
Christopher Faulet | 203b2b0 | 2019-03-08 09:23:46 +0100 | [diff] [blame] | 299 | |
Willy Tarreau | 651e182 | 2015-09-23 20:06:13 +0200 | [diff] [blame] | 300 | /* Second step : update the stream-int and channels, try to forward any |
| 301 | * pending data, then possibly wake the stream up based on the new |
| 302 | * stream-int status. |
Willy Tarreau | 44b5dc6 | 2012-08-24 12:12:53 +0200 | [diff] [blame] | 303 | */ |
Christopher Faulet | 9029a72 | 2022-04-01 16:48:36 +0200 | [diff] [blame] | 304 | cs_notify(cs); |
Willy Tarreau | a64c703 | 2019-08-01 14:17:02 +0200 | [diff] [blame] | 305 | stream_release_buffers(si_strm(si)); |
Willy Tarreau | 2396c1c | 2012-10-03 21:12:16 +0200 | [diff] [blame] | 306 | return 0; |
Willy Tarreau | fd31e53 | 2012-07-23 18:24:25 +0200 | [diff] [blame] | 307 | } |
Willy Tarreau | 2c6be84 | 2012-07-06 17:12:34 +0200 | [diff] [blame] | 308 | |
Willy Tarreau | 5368d80 | 2012-08-21 18:22:06 +0200 | [diff] [blame] | 309 | /* |
| 310 | * This function is called to send buffer data to a stream socket. |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 311 | * It calls the mux layer's snd_buf function. It relies on the |
Godbach | 4f48990 | 2013-12-04 17:24:06 +0800 | [diff] [blame] | 312 | * caller to commit polling changes. The caller should check conn->flags |
| 313 | * for errors. |
Willy Tarreau | 5368d80 | 2012-08-21 18:22:06 +0200 | [diff] [blame] | 314 | */ |
Christopher Faulet | 9b7a9b4 | 2022-04-01 13:48:39 +0200 | [diff] [blame] | 315 | int si_cs_send(struct conn_stream *cs) |
Willy Tarreau | 5368d80 | 2012-08-21 18:22:06 +0200 | [diff] [blame] | 316 | { |
Christopher Faulet | 693b23b | 2022-02-28 09:09:05 +0100 | [diff] [blame] | 317 | struct connection *conn = __cs_conn(cs); |
Christopher Faulet | f835dea | 2021-12-21 14:35:17 +0100 | [diff] [blame] | 318 | struct stream_interface *si = cs_si(cs); |
Christopher Faulet | e05bf9e | 2022-03-29 15:23:40 +0200 | [diff] [blame] | 319 | struct stream *s = si_strm(si); |
Willy Tarreau | afc8a22 | 2014-11-28 15:46:27 +0100 | [diff] [blame] | 320 | struct channel *oc = si_oc(si); |
Willy Tarreau | 5368d80 | 2012-08-21 18:22:06 +0200 | [diff] [blame] | 321 | int ret; |
Olivier Houchard | 910b2bc | 2018-07-17 18:49:38 +0200 | [diff] [blame] | 322 | int did_send = 0; |
| 323 | |
Christopher Faulet | b041b23 | 2022-03-24 10:27:02 +0100 | [diff] [blame] | 324 | if (cs->endp->flags & (CS_EP_ERROR|CS_EP_ERR_PENDING) || si_is_conn_error(si)) { |
Olivier Houchard | c31e2cb | 2019-06-24 16:08:08 +0200 | [diff] [blame] | 325 | /* We're probably there because the tasklet was woken up, |
| 326 | * but process_stream() ran before, detected there were an |
Christopher Faulet | 62e7574 | 2022-03-31 09:16:34 +0200 | [diff] [blame] | 327 | * error and put the si back to CS_ST_TAR. There's still |
Olivier Houchard | c31e2cb | 2019-06-24 16:08:08 +0200 | [diff] [blame] | 328 | * CO_FL_ERROR on the connection but we don't want to add |
Christopher Faulet | 6cd56d5 | 2022-03-30 10:47:32 +0200 | [diff] [blame] | 329 | * CS_EP_ERROR back, so give up |
Olivier Houchard | c31e2cb | 2019-06-24 16:08:08 +0200 | [diff] [blame] | 330 | */ |
Christopher Faulet | 62e7574 | 2022-03-31 09:16:34 +0200 | [diff] [blame] | 331 | if (si->cs->state < CS_ST_CON) |
Olivier Houchard | c31e2cb | 2019-06-24 16:08:08 +0200 | [diff] [blame] | 332 | return 0; |
Christopher Faulet | 6cd56d5 | 2022-03-30 10:47:32 +0200 | [diff] [blame] | 333 | cs->endp->flags |= CS_EP_ERROR; |
Olivier Houchard | c2aa711 | 2018-09-11 18:27:21 +0200 | [diff] [blame] | 334 | return 1; |
Willy Tarreau | bddf7fc | 2018-12-19 17:17:10 +0100 | [diff] [blame] | 335 | } |
Olivier Houchard | 910b2bc | 2018-07-17 18:49:38 +0200 | [diff] [blame] | 336 | |
Christopher Faulet | 328ed22 | 2019-09-23 15:57:29 +0200 | [diff] [blame] | 337 | /* We're already waiting to be able to send, give up */ |
Christopher Faulet | 2f35e7b | 2022-03-31 11:09:28 +0200 | [diff] [blame] | 338 | if (si->cs->wait_event.events & SUB_RETRY_SEND) |
Christopher Faulet | 328ed22 | 2019-09-23 15:57:29 +0200 | [diff] [blame] | 339 | return 0; |
| 340 | |
Olivier Houchard | 910b2bc | 2018-07-17 18:49:38 +0200 | [diff] [blame] | 341 | /* we might have been called just after an asynchronous shutw */ |
Willy Tarreau | f22758d | 2020-01-23 18:25:23 +0100 | [diff] [blame] | 342 | if (oc->flags & CF_SHUTW) |
Olivier Houchard | c2aa711 | 2018-09-11 18:27:21 +0200 | [diff] [blame] | 343 | return 1; |
Willy Tarreau | 5368d80 | 2012-08-21 18:22:06 +0200 | [diff] [blame] | 344 | |
Christopher Faulet | e96993b | 2020-07-30 09:26:46 +0200 | [diff] [blame] | 345 | /* we must wait because the mux is not installed yet */ |
| 346 | if (!conn->mux) |
| 347 | return 0; |
| 348 | |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 349 | if (oc->pipe && conn->xprt->snd_pipe && conn->mux->snd_pipe) { |
| 350 | ret = conn->mux->snd_pipe(cs, oc->pipe); |
Christopher Faulet | 86162db | 2019-07-05 11:49:11 +0200 | [diff] [blame] | 351 | if (ret > 0) |
Olivier Houchard | 910b2bc | 2018-07-17 18:49:38 +0200 | [diff] [blame] | 352 | did_send = 1; |
Willy Tarreau | 5368d80 | 2012-08-21 18:22:06 +0200 | [diff] [blame] | 353 | |
Willy Tarreau | afc8a22 | 2014-11-28 15:46:27 +0100 | [diff] [blame] | 354 | if (!oc->pipe->data) { |
| 355 | put_pipe(oc->pipe); |
| 356 | oc->pipe = NULL; |
Willy Tarreau | 5368d80 | 2012-08-21 18:22:06 +0200 | [diff] [blame] | 357 | } |
| 358 | |
Christopher Faulet | 3f76f4c | 2018-11-20 10:21:08 +0100 | [diff] [blame] | 359 | if (oc->pipe) |
| 360 | goto end; |
Willy Tarreau | 5368d80 | 2012-08-21 18:22:06 +0200 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | /* At this point, the pipe is empty, but we may still have data pending |
| 364 | * in the normal buffer. |
| 365 | */ |
Christopher Faulet | 55dec0d | 2018-11-20 10:30:02 +0100 | [diff] [blame] | 366 | if (co_data(oc)) { |
| 367 | /* when we're here, we already know that there is no spliced |
| 368 | * data left, and that there are sendable buffered data. |
| 369 | */ |
Willy Tarreau | 5368d80 | 2012-08-21 18:22:06 +0200 | [diff] [blame] | 370 | |
Willy Tarreau | 5368d80 | 2012-08-21 18:22:06 +0200 | [diff] [blame] | 371 | /* check if we want to inform the kernel that we're interested in |
| 372 | * sending more data after this call. We want this if : |
| 373 | * - we're about to close after this last send and want to merge |
| 374 | * the ongoing FIN with the last segment. |
| 375 | * - we know we can't send everything at once and must get back |
| 376 | * here because of unaligned data |
| 377 | * - there is still a finite amount of data to forward |
| 378 | * The test is arranged so that the most common case does only 2 |
| 379 | * tests. |
| 380 | */ |
Willy Tarreau | 1049b1f | 2014-02-02 01:51:17 +0100 | [diff] [blame] | 381 | unsigned int send_flag = 0; |
Willy Tarreau | 5368d80 | 2012-08-21 18:22:06 +0200 | [diff] [blame] | 382 | |
Willy Tarreau | afc8a22 | 2014-11-28 15:46:27 +0100 | [diff] [blame] | 383 | if ((!(oc->flags & (CF_NEVER_WAIT|CF_SEND_DONTWAIT)) && |
| 384 | ((oc->to_forward && oc->to_forward != CHN_INFINITE_FORWARD) || |
Willy Tarreau | 8945bb6 | 2020-06-19 17:07:06 +0200 | [diff] [blame] | 385 | (oc->flags & CF_EXPECT_MORE) || |
Christopher Faulet | 9e3dc83 | 2020-07-22 16:28:44 +0200 | [diff] [blame] | 386 | (IS_HTX_STRM(si_strm(si)) && |
| 387 | (!(oc->flags & (CF_EOI|CF_SHUTR)) && htx_expect_more(htxbuf(&oc->buf)))))) || |
Willy Tarreau | ecd2e15 | 2017-11-07 15:07:25 +0100 | [diff] [blame] | 388 | ((oc->flags & CF_ISRESP) && |
| 389 | ((oc->flags & (CF_AUTO_CLOSE|CF_SHUTW_NOW)) == (CF_AUTO_CLOSE|CF_SHUTW_NOW)))) |
Willy Tarreau | 1049b1f | 2014-02-02 01:51:17 +0100 | [diff] [blame] | 390 | send_flag |= CO_SFL_MSG_MORE; |
Willy Tarreau | 5368d80 | 2012-08-21 18:22:06 +0200 | [diff] [blame] | 391 | |
Willy Tarreau | afc8a22 | 2014-11-28 15:46:27 +0100 | [diff] [blame] | 392 | if (oc->flags & CF_STREAMER) |
Willy Tarreau | 7bed945 | 2014-02-02 02:00:24 +0100 | [diff] [blame] | 393 | send_flag |= CO_SFL_STREAMER; |
| 394 | |
Christopher Faulet | e05bf9e | 2022-03-29 15:23:40 +0200 | [diff] [blame] | 395 | if (s->txn && s->txn->flags & TX_L7_RETRY && !b_data(&s->txn->l7_buffer)) { |
Christopher Faulet | 9f5382e | 2021-05-21 13:46:14 +0200 | [diff] [blame] | 396 | /* If we want to be able to do L7 retries, copy |
| 397 | * the data we're about to send, so that we are able |
| 398 | * to resend them if needed |
| 399 | */ |
| 400 | /* Try to allocate a buffer if we had none. |
| 401 | * If it fails, the next test will just |
| 402 | * disable the l7 retries by setting |
| 403 | * l7_conn_retries to 0. |
| 404 | */ |
Christopher Faulet | e05bf9e | 2022-03-29 15:23:40 +0200 | [diff] [blame] | 405 | if (s->txn->req.msg_state != HTTP_MSG_DONE) |
| 406 | s->txn->flags &= ~TX_L7_RETRY; |
Christopher Faulet | 9f5382e | 2021-05-21 13:46:14 +0200 | [diff] [blame] | 407 | else { |
Christopher Faulet | e05bf9e | 2022-03-29 15:23:40 +0200 | [diff] [blame] | 408 | if (b_alloc(&s->txn->l7_buffer) == NULL) |
| 409 | s->txn->flags &= ~TX_L7_RETRY; |
Christopher Faulet | 9f5382e | 2021-05-21 13:46:14 +0200 | [diff] [blame] | 410 | else { |
Christopher Faulet | e05bf9e | 2022-03-29 15:23:40 +0200 | [diff] [blame] | 411 | memcpy(b_orig(&s->txn->l7_buffer), |
Christopher Faulet | 9f5382e | 2021-05-21 13:46:14 +0200 | [diff] [blame] | 412 | b_orig(&oc->buf), |
| 413 | b_size(&oc->buf)); |
Christopher Faulet | e05bf9e | 2022-03-29 15:23:40 +0200 | [diff] [blame] | 414 | s->txn->l7_buffer.head = co_data(oc); |
| 415 | b_add(&s->txn->l7_buffer, co_data(oc)); |
Christopher Faulet | 9f5382e | 2021-05-21 13:46:14 +0200 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | } |
| 419 | } |
| 420 | |
Christopher Faulet | 897d612 | 2021-12-17 17:28:35 +0100 | [diff] [blame] | 421 | ret = conn->mux->snd_buf(cs, &oc->buf, co_data(oc), send_flag); |
Godbach | e68e02d | 2013-10-11 15:48:29 +0800 | [diff] [blame] | 422 | if (ret > 0) { |
Olivier Houchard | 910b2bc | 2018-07-17 18:49:38 +0200 | [diff] [blame] | 423 | did_send = 1; |
Willy Tarreau | 8424004 | 2022-02-28 16:51:23 +0100 | [diff] [blame] | 424 | c_rew(oc, ret); |
Willy Tarreau | deccd11 | 2018-06-14 18:38:55 +0200 | [diff] [blame] | 425 | c_realign_if_empty(oc); |
| 426 | |
| 427 | if (!co_data(oc)) { |
Godbach | e68e02d | 2013-10-11 15:48:29 +0800 | [diff] [blame] | 428 | /* Always clear both flags once everything has been sent, they're one-shot */ |
Willy Tarreau | afc8a22 | 2014-11-28 15:46:27 +0100 | [diff] [blame] | 429 | oc->flags &= ~(CF_EXPECT_MORE | CF_SEND_DONTWAIT); |
Godbach | e68e02d | 2013-10-11 15:48:29 +0800 | [diff] [blame] | 430 | } |
Godbach | e68e02d | 2013-10-11 15:48:29 +0800 | [diff] [blame] | 431 | /* if some data remain in the buffer, it's only because the |
| 432 | * system buffers are full, we will try next time. |
| 433 | */ |
Willy Tarreau | 5368d80 | 2012-08-21 18:22:06 +0200 | [diff] [blame] | 434 | } |
Godbach | e68e02d | 2013-10-11 15:48:29 +0800 | [diff] [blame] | 435 | } |
Christopher Faulet | 55dec0d | 2018-11-20 10:30:02 +0100 | [diff] [blame] | 436 | |
Willy Tarreau | f6975aa | 2018-11-15 14:33:05 +0100 | [diff] [blame] | 437 | end: |
Christopher Faulet | 86162db | 2019-07-05 11:49:11 +0200 | [diff] [blame] | 438 | if (did_send) { |
| 439 | oc->flags |= CF_WRITE_PARTIAL | CF_WROTE_DATA; |
Christopher Faulet | 62e7574 | 2022-03-31 09:16:34 +0200 | [diff] [blame] | 440 | if (si->cs->state == CS_ST_CON) |
| 441 | si->cs->state = CS_ST_RDY; |
Christopher Faulet | 037b3eb | 2019-07-05 13:44:29 +0200 | [diff] [blame] | 442 | |
| 443 | si_rx_room_rdy(si_opposite(si)); |
Christopher Faulet | 86162db | 2019-07-05 11:49:11 +0200 | [diff] [blame] | 444 | } |
| 445 | |
Christopher Faulet | b041b23 | 2022-03-24 10:27:02 +0100 | [diff] [blame] | 446 | if (cs->endp->flags & (CS_EP_ERROR|CS_EP_ERR_PENDING)) { |
Christopher Faulet | 6cd56d5 | 2022-03-30 10:47:32 +0200 | [diff] [blame] | 447 | cs->endp->flags |= CS_EP_ERROR; |
Christopher Faulet | 86162db | 2019-07-05 11:49:11 +0200 | [diff] [blame] | 448 | return 1; |
| 449 | } |
| 450 | |
Olivier Houchard | 910b2bc | 2018-07-17 18:49:38 +0200 | [diff] [blame] | 451 | /* We couldn't send all of our data, let the mux know we'd like to send more */ |
Willy Tarreau | 691fe39 | 2018-11-12 18:48:52 +0100 | [diff] [blame] | 452 | if (!channel_is_empty(oc)) |
Christopher Faulet | 2f35e7b | 2022-03-31 11:09:28 +0200 | [diff] [blame] | 453 | conn->mux->subscribe(cs, SUB_RETRY_SEND, &si->cs->wait_event); |
Olivier Houchard | f653528 | 2018-08-31 17:29:12 +0200 | [diff] [blame] | 454 | return did_send; |
Willy Tarreau | 5368d80 | 2012-08-21 18:22:06 +0200 | [diff] [blame] | 455 | } |
| 456 | |
Christopher Faulet | 2f35e7b | 2022-03-31 11:09:28 +0200 | [diff] [blame] | 457 | /* This is the ->process() function for any conn-stream's wait_event task. |
Willy Tarreau | 8ccd208 | 2018-11-07 07:47:52 +0100 | [diff] [blame] | 458 | * It's assigned during the stream-interface's initialization, for any type of |
| 459 | * stream interface. Thus it is always safe to perform a tasklet_wakeup() on a |
| 460 | * stream interface, as the presence of the CS is checked there. |
| 461 | */ |
Christopher Faulet | 4a7764a | 2022-04-01 16:58:52 +0200 | [diff] [blame^] | 462 | struct task *cs_conn_io_cb(struct task *t, void *ctx, unsigned int state) |
Olivier Houchard | 91894cb | 2018-08-02 18:06:28 +0200 | [diff] [blame] | 463 | { |
Christopher Faulet | 4a7764a | 2022-04-01 16:58:52 +0200 | [diff] [blame^] | 464 | struct conn_stream *cs = ctx; |
Olivier Houchard | f653528 | 2018-08-31 17:29:12 +0200 | [diff] [blame] | 465 | int ret = 0; |
Olivier Houchard | a6ff035 | 2018-08-21 15:59:43 +0200 | [diff] [blame] | 466 | |
Christopher Faulet | 0256da1 | 2021-12-15 09:50:17 +0100 | [diff] [blame] | 467 | if (!cs_conn(cs)) |
Willy Tarreau | 7416314 | 2021-03-13 11:30:19 +0100 | [diff] [blame] | 468 | return t; |
Willy Tarreau | 8ccd208 | 2018-11-07 07:47:52 +0100 | [diff] [blame] | 469 | |
Christopher Faulet | 4a7764a | 2022-04-01 16:58:52 +0200 | [diff] [blame^] | 470 | if (!(cs->wait_event.events & SUB_RETRY_SEND) && !channel_is_empty(cs_oc(cs))) |
Olivier Houchard | f653528 | 2018-08-31 17:29:12 +0200 | [diff] [blame] | 471 | ret = si_cs_send(cs); |
Christopher Faulet | 2f35e7b | 2022-03-31 11:09:28 +0200 | [diff] [blame] | 472 | if (!(cs->wait_event.events & SUB_RETRY_RECV)) |
Olivier Houchard | f653528 | 2018-08-31 17:29:12 +0200 | [diff] [blame] | 473 | ret |= si_cs_recv(cs); |
| 474 | if (ret != 0) |
Olivier Houchard | c2aa711 | 2018-09-11 18:27:21 +0200 | [diff] [blame] | 475 | si_cs_process(cs); |
Olivier Houchard | f653528 | 2018-08-31 17:29:12 +0200 | [diff] [blame] | 476 | |
Christopher Faulet | 4a7764a | 2022-04-01 16:58:52 +0200 | [diff] [blame^] | 477 | stream_release_buffers(__cs_strm(cs)); |
Willy Tarreau | 7416314 | 2021-03-13 11:30:19 +0100 | [diff] [blame] | 478 | return t; |
Olivier Houchard | 91894cb | 2018-08-02 18:06:28 +0200 | [diff] [blame] | 479 | } |
| 480 | |
Christopher Faulet | 9936dc6 | 2022-02-28 09:21:58 +0100 | [diff] [blame] | 481 | /* This tries to perform a synchronous receive on the stream interface to |
| 482 | * try to collect last arrived data. In practice it's only implemented on |
| 483 | * conn_streams. Returns 0 if nothing was done, non-zero if new data or a |
| 484 | * shutdown were collected. This may result on some delayed receive calls |
| 485 | * to be programmed and performed later, though it doesn't provide any |
| 486 | * such guarantee. |
| 487 | */ |
| 488 | int si_sync_recv(struct stream_interface *si) |
| 489 | { |
Christopher Faulet | 62e7574 | 2022-03-31 09:16:34 +0200 | [diff] [blame] | 490 | if (!cs_state_in(si->cs->state, CS_SB_RDY|CS_SB_EST)) |
Christopher Faulet | 9936dc6 | 2022-02-28 09:21:58 +0100 | [diff] [blame] | 491 | return 0; |
| 492 | |
| 493 | if (!cs_conn_mux(si->cs)) |
| 494 | return 0; // only conn_streams are supported |
| 495 | |
Christopher Faulet | 2f35e7b | 2022-03-31 11:09:28 +0200 | [diff] [blame] | 496 | if (si->cs->wait_event.events & SUB_RETRY_RECV) |
Christopher Faulet | 9936dc6 | 2022-02-28 09:21:58 +0100 | [diff] [blame] | 497 | return 0; // already subscribed |
| 498 | |
| 499 | if (!si_rx_endp_ready(si) || si_rx_blocked(si)) |
| 500 | return 0; // already failed |
| 501 | |
| 502 | return si_cs_recv(si->cs); |
| 503 | } |
| 504 | |
Willy Tarreau | 3b285d7 | 2019-06-06 08:20:17 +0200 | [diff] [blame] | 505 | /* perform a synchronous send() for the stream interface. The CF_WRITE_NULL and |
| 506 | * CF_WRITE_PARTIAL flags are cleared prior to the attempt, and will possibly |
| 507 | * be updated in case of success. |
| 508 | */ |
| 509 | void si_sync_send(struct stream_interface *si) |
| 510 | { |
| 511 | struct channel *oc = si_oc(si); |
Willy Tarreau | 3b285d7 | 2019-06-06 08:20:17 +0200 | [diff] [blame] | 512 | |
| 513 | oc->flags &= ~(CF_WRITE_NULL|CF_WRITE_PARTIAL); |
| 514 | |
| 515 | if (oc->flags & CF_SHUTW) |
| 516 | return; |
| 517 | |
| 518 | if (channel_is_empty(oc)) |
| 519 | return; |
| 520 | |
Christopher Faulet | 62e7574 | 2022-03-31 09:16:34 +0200 | [diff] [blame] | 521 | if (!cs_state_in(si->cs->state, CS_SB_CON|CS_SB_RDY|CS_SB_EST)) |
Willy Tarreau | 3b285d7 | 2019-06-06 08:20:17 +0200 | [diff] [blame] | 522 | return; |
| 523 | |
Christopher Faulet | 13a35e5 | 2021-12-20 15:34:16 +0100 | [diff] [blame] | 524 | if (!cs_conn_mux(si->cs)) |
Willy Tarreau | 3b285d7 | 2019-06-06 08:20:17 +0200 | [diff] [blame] | 525 | return; |
| 526 | |
Christopher Faulet | 13a35e5 | 2021-12-20 15:34:16 +0100 | [diff] [blame] | 527 | si_cs_send(si->cs); |
Willy Tarreau | 3b285d7 | 2019-06-06 08:20:17 +0200 | [diff] [blame] | 528 | } |
| 529 | |
Willy Tarreau | 8b3d7df | 2013-09-29 14:51:58 +0200 | [diff] [blame] | 530 | /* |
Willy Tarreau | ce323de | 2012-08-20 21:41:06 +0200 | [diff] [blame] | 531 | * This is the callback which is called by the connection layer to receive data |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 532 | * into the buffer from the connection. It iterates over the mux layer's |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 533 | * rcv_buf function. |
Willy Tarreau | ce323de | 2012-08-20 21:41:06 +0200 | [diff] [blame] | 534 | */ |
Christopher Faulet | 9b7a9b4 | 2022-04-01 13:48:39 +0200 | [diff] [blame] | 535 | int si_cs_recv(struct conn_stream *cs) |
Willy Tarreau | ce323de | 2012-08-20 21:41:06 +0200 | [diff] [blame] | 536 | { |
Christopher Faulet | 693b23b | 2022-02-28 09:09:05 +0100 | [diff] [blame] | 537 | struct connection *conn = __cs_conn(cs); |
Christopher Faulet | f835dea | 2021-12-21 14:35:17 +0100 | [diff] [blame] | 538 | struct stream_interface *si = cs_si(cs); |
Willy Tarreau | afc8a22 | 2014-11-28 15:46:27 +0100 | [diff] [blame] | 539 | struct channel *ic = si_ic(si); |
Olivier Houchard | f653528 | 2018-08-31 17:29:12 +0200 | [diff] [blame] | 540 | int ret, max, cur_read = 0; |
Willy Tarreau | ce323de | 2012-08-20 21:41:06 +0200 | [diff] [blame] | 541 | int read_poll = MAX_READ_POLL_LOOPS; |
Christopher Faulet | c6618d6 | 2018-10-11 15:56:04 +0200 | [diff] [blame] | 542 | int flags = 0; |
Willy Tarreau | ce323de | 2012-08-20 21:41:06 +0200 | [diff] [blame] | 543 | |
Christopher Faulet | 04400bc | 2019-10-25 10:21:01 +0200 | [diff] [blame] | 544 | /* If not established yet, do nothing. */ |
Christopher Faulet | 62e7574 | 2022-03-31 09:16:34 +0200 | [diff] [blame] | 545 | if (cs->state != CS_ST_EST) |
Christopher Faulet | 04400bc | 2019-10-25 10:21:01 +0200 | [diff] [blame] | 546 | return 0; |
| 547 | |
Olivier Houchard | f653528 | 2018-08-31 17:29:12 +0200 | [diff] [blame] | 548 | /* If another call to si_cs_recv() failed, and we subscribed to |
| 549 | * recv events already, give up now. |
| 550 | */ |
Christopher Faulet | 2f35e7b | 2022-03-31 11:09:28 +0200 | [diff] [blame] | 551 | if (si->cs->wait_event.events & SUB_RETRY_RECV) |
Olivier Houchard | f653528 | 2018-08-31 17:29:12 +0200 | [diff] [blame] | 552 | return 0; |
Willy Tarreau | ce323de | 2012-08-20 21:41:06 +0200 | [diff] [blame] | 553 | |
Willy Tarreau | ce323de | 2012-08-20 21:41:06 +0200 | [diff] [blame] | 554 | /* maybe we were called immediately after an asynchronous shutr */ |
Willy Tarreau | afc8a22 | 2014-11-28 15:46:27 +0100 | [diff] [blame] | 555 | if (ic->flags & CF_SHUTR) |
Olivier Houchard | c2aa711 | 2018-09-11 18:27:21 +0200 | [diff] [blame] | 556 | return 1; |
Willy Tarreau | ce323de | 2012-08-20 21:41:06 +0200 | [diff] [blame] | 557 | |
Christopher Faulet | e96993b | 2020-07-30 09:26:46 +0200 | [diff] [blame] | 558 | /* we must wait because the mux is not installed yet */ |
| 559 | if (!conn->mux) |
| 560 | return 0; |
| 561 | |
Willy Tarreau | 54e917c | 2017-08-30 07:35:35 +0200 | [diff] [blame] | 562 | /* stop here if we reached the end of data */ |
Christopher Faulet | b041b23 | 2022-03-24 10:27:02 +0100 | [diff] [blame] | 563 | if (cs->endp->flags & CS_EP_EOS) |
Christopher Faulet | 36b536d | 2019-11-20 11:56:33 +0100 | [diff] [blame] | 564 | goto end_recv; |
Willy Tarreau | 54e917c | 2017-08-30 07:35:35 +0200 | [diff] [blame] | 565 | |
Christopher Faulet | f061e42 | 2018-12-07 14:51:20 +0100 | [diff] [blame] | 566 | /* stop immediately on errors. Note that we DON'T want to stop on |
| 567 | * POLL_ERR, as the poller might report a write error while there |
| 568 | * are still data available in the recv buffer. This typically |
| 569 | * happens when we send too large a request to a backend server |
| 570 | * which rejects it before reading it all. |
| 571 | */ |
Christopher Faulet | b041b23 | 2022-03-24 10:27:02 +0100 | [diff] [blame] | 572 | if (!(cs->endp->flags & CS_EP_RCV_MORE)) { |
Christopher Faulet | f061e42 | 2018-12-07 14:51:20 +0100 | [diff] [blame] | 573 | if (!conn_xprt_ready(conn)) |
| 574 | return 0; |
Christopher Faulet | b041b23 | 2022-03-24 10:27:02 +0100 | [diff] [blame] | 575 | if (cs->endp->flags & CS_EP_ERROR) |
Christopher Faulet | 36b536d | 2019-11-20 11:56:33 +0100 | [diff] [blame] | 576 | goto end_recv; |
Christopher Faulet | f061e42 | 2018-12-07 14:51:20 +0100 | [diff] [blame] | 577 | } |
Willy Tarreau | f26c26c | 2018-11-12 16:11:08 +0100 | [diff] [blame] | 578 | |
Willy Tarreau | 7ab99a3 | 2018-12-18 09:15:43 +0100 | [diff] [blame] | 579 | /* prepare to detect if the mux needs more room */ |
Christopher Faulet | b041b23 | 2022-03-24 10:27:02 +0100 | [diff] [blame] | 580 | cs->endp->flags &= ~CS_EP_WANT_ROOM; |
Willy Tarreau | 7ab99a3 | 2018-12-18 09:15:43 +0100 | [diff] [blame] | 581 | |
Willy Tarreau | 77e478c | 2018-06-19 07:03:14 +0200 | [diff] [blame] | 582 | if ((ic->flags & (CF_STREAMER | CF_STREAMER_FAST)) && !co_data(ic) && |
Willy Tarreau | 7e31273 | 2014-02-12 16:35:14 +0100 | [diff] [blame] | 583 | global.tune.idle_timer && |
Willy Tarreau | afc8a22 | 2014-11-28 15:46:27 +0100 | [diff] [blame] | 584 | (unsigned short)(now_ms - ic->last_read) >= global.tune.idle_timer) { |
Willy Tarreau | c5890e6 | 2014-02-09 17:47:01 +0100 | [diff] [blame] | 585 | /* The buffer was empty and nothing was transferred for more |
| 586 | * than one second. This was caused by a pause and not by |
| 587 | * congestion. Reset any streaming mode to reduce latency. |
| 588 | */ |
Willy Tarreau | afc8a22 | 2014-11-28 15:46:27 +0100 | [diff] [blame] | 589 | ic->xfer_small = 0; |
| 590 | ic->xfer_large = 0; |
| 591 | ic->flags &= ~(CF_STREAMER | CF_STREAMER_FAST); |
Willy Tarreau | c5890e6 | 2014-02-09 17:47:01 +0100 | [diff] [blame] | 592 | } |
| 593 | |
Willy Tarreau | 96199b1 | 2012-08-24 00:46:52 +0200 | [diff] [blame] | 594 | /* First, let's see if we may splice data across the channel without |
| 595 | * using a buffer. |
| 596 | */ |
Christopher Faulet | e9e4820 | 2022-03-22 18:13:29 +0100 | [diff] [blame] | 597 | if (cs->endp->flags & CS_EP_MAY_SPLICE && |
Willy Tarreau | afc8a22 | 2014-11-28 15:46:27 +0100 | [diff] [blame] | 598 | (ic->pipe || ic->to_forward >= MIN_SPLICE_FORWARD) && |
| 599 | ic->flags & CF_KERN_SPLICING) { |
Willy Tarreau | d760eec | 2018-07-10 09:50:25 +0200 | [diff] [blame] | 600 | if (c_data(ic)) { |
Willy Tarreau | 96199b1 | 2012-08-24 00:46:52 +0200 | [diff] [blame] | 601 | /* We're embarrassed, there are already data pending in |
| 602 | * the buffer and we don't want to have them at two |
| 603 | * locations at a time. Let's indicate we need some |
| 604 | * place and ask the consumer to hurry. |
| 605 | */ |
Christopher Faulet | c6618d6 | 2018-10-11 15:56:04 +0200 | [diff] [blame] | 606 | flags |= CO_RFL_BUF_FLUSH; |
Willy Tarreau | 96199b1 | 2012-08-24 00:46:52 +0200 | [diff] [blame] | 607 | goto abort_splice; |
| 608 | } |
Willy Tarreau | ce323de | 2012-08-20 21:41:06 +0200 | [diff] [blame] | 609 | |
Willy Tarreau | afc8a22 | 2014-11-28 15:46:27 +0100 | [diff] [blame] | 610 | if (unlikely(ic->pipe == NULL)) { |
| 611 | if (pipes_used >= global.maxpipes || !(ic->pipe = get_pipe())) { |
| 612 | ic->flags &= ~CF_KERN_SPLICING; |
Willy Tarreau | 96199b1 | 2012-08-24 00:46:52 +0200 | [diff] [blame] | 613 | goto abort_splice; |
| 614 | } |
| 615 | } |
| 616 | |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 617 | ret = conn->mux->rcv_pipe(cs, ic->pipe, ic->to_forward); |
Willy Tarreau | 96199b1 | 2012-08-24 00:46:52 +0200 | [diff] [blame] | 618 | if (ret < 0) { |
| 619 | /* splice not supported on this end, let's disable it */ |
Willy Tarreau | afc8a22 | 2014-11-28 15:46:27 +0100 | [diff] [blame] | 620 | ic->flags &= ~CF_KERN_SPLICING; |
Willy Tarreau | 96199b1 | 2012-08-24 00:46:52 +0200 | [diff] [blame] | 621 | goto abort_splice; |
| 622 | } |
Willy Tarreau | ce323de | 2012-08-20 21:41:06 +0200 | [diff] [blame] | 623 | |
Willy Tarreau | 96199b1 | 2012-08-24 00:46:52 +0200 | [diff] [blame] | 624 | if (ret > 0) { |
Willy Tarreau | afc8a22 | 2014-11-28 15:46:27 +0100 | [diff] [blame] | 625 | if (ic->to_forward != CHN_INFINITE_FORWARD) |
| 626 | ic->to_forward -= ret; |
| 627 | ic->total += ret; |
Willy Tarreau | 96199b1 | 2012-08-24 00:46:52 +0200 | [diff] [blame] | 628 | cur_read += ret; |
Willy Tarreau | afc8a22 | 2014-11-28 15:46:27 +0100 | [diff] [blame] | 629 | ic->flags |= CF_READ_PARTIAL; |
Willy Tarreau | ce323de | 2012-08-20 21:41:06 +0200 | [diff] [blame] | 630 | } |
Willy Tarreau | 96199b1 | 2012-08-24 00:46:52 +0200 | [diff] [blame] | 631 | |
Christopher Faulet | b041b23 | 2022-03-24 10:27:02 +0100 | [diff] [blame] | 632 | if (cs->endp->flags & (CS_EP_EOS|CS_EP_ERROR)) |
Christopher Faulet | 36b536d | 2019-11-20 11:56:33 +0100 | [diff] [blame] | 633 | goto end_recv; |
Willy Tarreau | 96199b1 | 2012-08-24 00:46:52 +0200 | [diff] [blame] | 634 | |
Willy Tarreau | 61d39a0 | 2013-07-18 21:49:32 +0200 | [diff] [blame] | 635 | if (conn->flags & CO_FL_WAIT_ROOM) { |
| 636 | /* the pipe is full or we have read enough data that it |
| 637 | * could soon be full. Let's stop before needing to poll. |
| 638 | */ |
Willy Tarreau | db39843 | 2018-11-15 11:08:52 +0100 | [diff] [blame] | 639 | si_rx_room_blk(si); |
Willy Tarreau | ffb1205 | 2018-11-15 16:06:02 +0100 | [diff] [blame] | 640 | goto done_recv; |
Willy Tarreau | 61d39a0 | 2013-07-18 21:49:32 +0200 | [diff] [blame] | 641 | } |
Willy Tarreau | 56a77e5 | 2012-09-02 18:34:44 +0200 | [diff] [blame] | 642 | |
Willy Tarreau | ce323de | 2012-08-20 21:41:06 +0200 | [diff] [blame] | 643 | /* splice not possible (anymore), let's go on on standard copy */ |
| 644 | } |
Willy Tarreau | 96199b1 | 2012-08-24 00:46:52 +0200 | [diff] [blame] | 645 | |
| 646 | abort_splice: |
Willy Tarreau | afc8a22 | 2014-11-28 15:46:27 +0100 | [diff] [blame] | 647 | if (ic->pipe && unlikely(!ic->pipe->data)) { |
| 648 | put_pipe(ic->pipe); |
| 649 | ic->pipe = NULL; |
Willy Tarreau | 96199b1 | 2012-08-24 00:46:52 +0200 | [diff] [blame] | 650 | } |
| 651 | |
Christopher Faulet | e9e4820 | 2022-03-22 18:13:29 +0100 | [diff] [blame] | 652 | if (ic->pipe && ic->to_forward && !(flags & CO_RFL_BUF_FLUSH) && cs->endp->flags & CS_EP_MAY_SPLICE) { |
Willy Tarreau | c640ef1 | 2019-12-03 18:13:04 +0100 | [diff] [blame] | 653 | /* don't break splicing by reading, but still call rcv_buf() |
| 654 | * to pass the flag. |
| 655 | */ |
| 656 | goto done_recv; |
| 657 | } |
| 658 | |
Christopher Faulet | a73e59b | 2016-12-09 17:30:18 +0100 | [diff] [blame] | 659 | /* now we'll need a input buffer for the stream */ |
Willy Tarreau | 581abd3 | 2018-10-25 10:21:41 +0200 | [diff] [blame] | 660 | if (!si_alloc_ibuf(si, &(si_strm(si)->buffer_wait))) |
Willy Tarreau | 10fc09e | 2014-11-25 19:46:36 +0100 | [diff] [blame] | 661 | goto end_recv; |
Willy Tarreau | 10fc09e | 2014-11-25 19:46:36 +0100 | [diff] [blame] | 662 | |
Christopher Faulet | 2bc364c | 2021-09-21 15:22:12 +0200 | [diff] [blame] | 663 | /* For an HTX stream, if the buffer is stuck (no output data with some |
| 664 | * input data) and if the HTX message is fragmented or if its free space |
| 665 | * wraps, we force an HTX deframentation. It is a way to have a |
| 666 | * contiguous free space nad to let the mux to copy as much data as |
| 667 | * possible. |
| 668 | * |
| 669 | * NOTE: A possible optim may be to let the mux decides if defrag is |
| 670 | * required or not, depending on amount of data to be xferred. |
| 671 | */ |
| 672 | if (IS_HTX_STRM(si_strm(si)) && !co_data(ic)) { |
| 673 | struct htx *htx = htxbuf(&ic->buf); |
| 674 | |
| 675 | if (htx_is_not_empty(htx) && ((htx->flags & HTX_FL_FRAGMENTED) || htx_space_wraps(htx))) |
| 676 | htx_defrag(htxbuf(&ic->buf), NULL, 0); |
| 677 | } |
Christopher Faulet | 68a14db | 2021-09-21 15:14:57 +0200 | [diff] [blame] | 678 | |
| 679 | /* Instruct the mux it must subscribed for read events */ |
| 680 | flags |= ((!conn_is_back(conn) && (si_strm(si)->be->options & PR_O_ABRT_CLOSE)) ? CO_RFL_KEEP_RECV : 0); |
| 681 | |
Willy Tarreau | 61d39a0 | 2013-07-18 21:49:32 +0200 | [diff] [blame] | 682 | /* Important note : if we're called with POLL_IN|POLL_HUP, it means the read polling |
| 683 | * was enabled, which implies that the recv buffer was not full. So we have a guarantee |
| 684 | * that if such an event is not handled above in splice, it will be handled here by |
| 685 | * recv(). |
| 686 | */ |
Christopher Faulet | b041b23 | 2022-03-24 10:27:02 +0100 | [diff] [blame] | 687 | while ((cs->endp->flags & CS_EP_RCV_MORE) || |
Willy Tarreau | d1480cc | 2022-03-17 16:19:09 +0100 | [diff] [blame] | 688 | (!(conn->flags & CO_FL_HANDSHAKE) && |
Christopher Faulet | b041b23 | 2022-03-24 10:27:02 +0100 | [diff] [blame] | 689 | (!(cs->endp->flags & (CS_EP_ERROR|CS_EP_EOS))) && !(ic->flags & CF_SHUTR))) { |
Christopher Faulet | 68a14db | 2021-09-21 15:14:57 +0200 | [diff] [blame] | 690 | int cur_flags = flags; |
| 691 | |
| 692 | /* Compute transient CO_RFL_* flags */ |
Christopher Faulet | 564e39c | 2021-09-21 15:50:55 +0200 | [diff] [blame] | 693 | if (co_data(ic)) { |
| 694 | cur_flags |= (CO_RFL_BUF_WET | CO_RFL_BUF_NOT_STUCK); |
| 695 | } |
Christopher Faulet | 68a14db | 2021-09-21 15:14:57 +0200 | [diff] [blame] | 696 | |
Christopher Faulet | 4eb7d74 | 2018-10-11 15:29:21 +0200 | [diff] [blame] | 697 | /* <max> may be null. This is the mux responsibility to set |
Christopher Faulet | b041b23 | 2022-03-24 10:27:02 +0100 | [diff] [blame] | 698 | * CS_EP_RCV_MORE on the CS if more space is needed. |
Christopher Faulet | 4eb7d74 | 2018-10-11 15:29:21 +0200 | [diff] [blame] | 699 | */ |
Willy Tarreau | afc8a22 | 2014-11-28 15:46:27 +0100 | [diff] [blame] | 700 | max = channel_recv_max(ic); |
Christopher Faulet | 897d612 | 2021-12-17 17:28:35 +0100 | [diff] [blame] | 701 | ret = conn->mux->rcv_buf(cs, &ic->buf, max, cur_flags); |
Willy Tarreau | 674e0ad | 2018-12-05 13:45:41 +0100 | [diff] [blame] | 702 | |
Christopher Faulet | b041b23 | 2022-03-24 10:27:02 +0100 | [diff] [blame] | 703 | if (cs->endp->flags & CS_EP_WANT_ROOM) { |
| 704 | /* CS_EP_WANT_ROOM must not be reported if the channel's |
Christopher Faulet | ae17925 | 2022-02-21 16:12:00 +0100 | [diff] [blame] | 705 | * buffer is empty. |
| 706 | */ |
| 707 | BUG_ON(c_empty(ic)); |
| 708 | |
Willy Tarreau | db39843 | 2018-11-15 11:08:52 +0100 | [diff] [blame] | 709 | si_rx_room_blk(si); |
Christopher Faulet | df99408 | 2021-09-23 14:17:20 +0200 | [diff] [blame] | 710 | /* Add READ_PARTIAL because some data are pending but |
| 711 | * cannot be xferred to the channel |
| 712 | */ |
| 713 | ic->flags |= CF_READ_PARTIAL; |
| 714 | } |
Willy Tarreau | 6577b48 | 2017-12-10 21:19:33 +0100 | [diff] [blame] | 715 | |
Willy Tarreau | f26c26c | 2018-11-12 16:11:08 +0100 | [diff] [blame] | 716 | if (ret <= 0) { |
Willy Tarreau | 1ac5f20 | 2019-12-03 18:08:45 +0100 | [diff] [blame] | 717 | /* if we refrained from reading because we asked for a |
| 718 | * flush to satisfy rcv_pipe(), we must not subscribe |
| 719 | * and instead report that there's not enough room |
| 720 | * here to proceed. |
| 721 | */ |
| 722 | if (flags & CO_RFL_BUF_FLUSH) |
| 723 | si_rx_room_blk(si); |
Willy Tarreau | ce323de | 2012-08-20 21:41:06 +0200 | [diff] [blame] | 724 | break; |
Willy Tarreau | f26c26c | 2018-11-12 16:11:08 +0100 | [diff] [blame] | 725 | } |
Willy Tarreau | ce323de | 2012-08-20 21:41:06 +0200 | [diff] [blame] | 726 | |
| 727 | cur_read += ret; |
| 728 | |
| 729 | /* if we're allowed to directly forward data, we must update ->o */ |
Willy Tarreau | afc8a22 | 2014-11-28 15:46:27 +0100 | [diff] [blame] | 730 | if (ic->to_forward && !(ic->flags & (CF_SHUTW|CF_SHUTW_NOW))) { |
Willy Tarreau | ce323de | 2012-08-20 21:41:06 +0200 | [diff] [blame] | 731 | unsigned long fwd = ret; |
Willy Tarreau | afc8a22 | 2014-11-28 15:46:27 +0100 | [diff] [blame] | 732 | if (ic->to_forward != CHN_INFINITE_FORWARD) { |
| 733 | if (fwd > ic->to_forward) |
| 734 | fwd = ic->to_forward; |
| 735 | ic->to_forward -= fwd; |
Willy Tarreau | ce323de | 2012-08-20 21:41:06 +0200 | [diff] [blame] | 736 | } |
Willy Tarreau | bcbd393 | 2018-06-06 07:13:22 +0200 | [diff] [blame] | 737 | c_adv(ic, fwd); |
Willy Tarreau | ce323de | 2012-08-20 21:41:06 +0200 | [diff] [blame] | 738 | } |
| 739 | |
Willy Tarreau | afc8a22 | 2014-11-28 15:46:27 +0100 | [diff] [blame] | 740 | ic->flags |= CF_READ_PARTIAL; |
| 741 | ic->total += ret; |
Willy Tarreau | ce323de | 2012-08-20 21:41:06 +0200 | [diff] [blame] | 742 | |
Christopher Faulet | 883d83e | 2021-09-09 10:17:59 +0200 | [diff] [blame] | 743 | /* End-of-input reached, we can leave. In this case, it is |
| 744 | * important to break the loop to not block the SI because of |
| 745 | * the channel's policies.This way, we are still able to receive |
| 746 | * shutdowns. |
| 747 | */ |
Christopher Faulet | b041b23 | 2022-03-24 10:27:02 +0100 | [diff] [blame] | 748 | if (cs->endp->flags & CS_EP_EOI) |
Christopher Faulet | 883d83e | 2021-09-09 10:17:59 +0200 | [diff] [blame] | 749 | break; |
| 750 | |
Willy Tarreau | f26c26c | 2018-11-12 16:11:08 +0100 | [diff] [blame] | 751 | if ((ic->flags & CF_READ_DONTWAIT) || --read_poll <= 0) { |
| 752 | /* we're stopped by the channel's policy */ |
Willy Tarreau | b26a6f9 | 2018-11-14 17:10:36 +0100 | [diff] [blame] | 753 | si_rx_chan_blk(si); |
Willy Tarreau | 62dd698 | 2017-11-18 11:26:20 +0100 | [diff] [blame] | 754 | break; |
Willy Tarreau | f26c26c | 2018-11-12 16:11:08 +0100 | [diff] [blame] | 755 | } |
Willy Tarreau | ce323de | 2012-08-20 21:41:06 +0200 | [diff] [blame] | 756 | |
| 757 | /* if too many bytes were missing from last read, it means that |
| 758 | * it's pointless trying to read again because the system does |
| 759 | * not have them in buffers. |
| 760 | */ |
| 761 | if (ret < max) { |
Willy Tarreau | ce323de | 2012-08-20 21:41:06 +0200 | [diff] [blame] | 762 | /* if a streamer has read few data, it may be because we |
| 763 | * have exhausted system buffers. It's not worth trying |
| 764 | * again. |
| 765 | */ |
Willy Tarreau | f26c26c | 2018-11-12 16:11:08 +0100 | [diff] [blame] | 766 | if (ic->flags & CF_STREAMER) { |
| 767 | /* we're stopped by the channel's policy */ |
Willy Tarreau | b26a6f9 | 2018-11-14 17:10:36 +0100 | [diff] [blame] | 768 | si_rx_chan_blk(si); |
Willy Tarreau | ce323de | 2012-08-20 21:41:06 +0200 | [diff] [blame] | 769 | break; |
Willy Tarreau | f26c26c | 2018-11-12 16:11:08 +0100 | [diff] [blame] | 770 | } |
Willy Tarreau | ce323de | 2012-08-20 21:41:06 +0200 | [diff] [blame] | 771 | |
| 772 | /* if we read a large block smaller than what we requested, |
| 773 | * it's almost certain we'll never get anything more. |
| 774 | */ |
Willy Tarreau | f26c26c | 2018-11-12 16:11:08 +0100 | [diff] [blame] | 775 | if (ret >= global.tune.recv_enough) { |
| 776 | /* we're stopped by the channel's policy */ |
Willy Tarreau | b26a6f9 | 2018-11-14 17:10:36 +0100 | [diff] [blame] | 777 | si_rx_chan_blk(si); |
Willy Tarreau | ce323de | 2012-08-20 21:41:06 +0200 | [diff] [blame] | 778 | break; |
Willy Tarreau | f26c26c | 2018-11-12 16:11:08 +0100 | [diff] [blame] | 779 | } |
Willy Tarreau | ce323de | 2012-08-20 21:41:06 +0200 | [diff] [blame] | 780 | } |
Christopher Faulet | b3e0de4 | 2018-10-11 13:54:13 +0200 | [diff] [blame] | 781 | |
| 782 | /* if we are waiting for more space, don't try to read more data |
| 783 | * right now. |
| 784 | */ |
Willy Tarreau | b26a6f9 | 2018-11-14 17:10:36 +0100 | [diff] [blame] | 785 | if (si_rx_blocked(si)) |
Christopher Faulet | b3e0de4 | 2018-10-11 13:54:13 +0200 | [diff] [blame] | 786 | break; |
Willy Tarreau | ce323de | 2012-08-20 21:41:06 +0200 | [diff] [blame] | 787 | } /* while !flags */ |
| 788 | |
Willy Tarreau | ffb1205 | 2018-11-15 16:06:02 +0100 | [diff] [blame] | 789 | done_recv: |
Willy Tarreau | c5890e6 | 2014-02-09 17:47:01 +0100 | [diff] [blame] | 790 | if (cur_read) { |
Willy Tarreau | afc8a22 | 2014-11-28 15:46:27 +0100 | [diff] [blame] | 791 | if ((ic->flags & (CF_STREAMER | CF_STREAMER_FAST)) && |
Willy Tarreau | c9fa048 | 2018-07-10 17:43:27 +0200 | [diff] [blame] | 792 | (cur_read <= ic->buf.size / 2)) { |
Willy Tarreau | afc8a22 | 2014-11-28 15:46:27 +0100 | [diff] [blame] | 793 | ic->xfer_large = 0; |
| 794 | ic->xfer_small++; |
| 795 | if (ic->xfer_small >= 3) { |
Willy Tarreau | c5890e6 | 2014-02-09 17:47:01 +0100 | [diff] [blame] | 796 | /* we have read less than half of the buffer in |
| 797 | * one pass, and this happened at least 3 times. |
| 798 | * This is definitely not a streamer. |
| 799 | */ |
Willy Tarreau | afc8a22 | 2014-11-28 15:46:27 +0100 | [diff] [blame] | 800 | ic->flags &= ~(CF_STREAMER | CF_STREAMER_FAST); |
Willy Tarreau | c5890e6 | 2014-02-09 17:47:01 +0100 | [diff] [blame] | 801 | } |
Willy Tarreau | afc8a22 | 2014-11-28 15:46:27 +0100 | [diff] [blame] | 802 | else if (ic->xfer_small >= 2) { |
Willy Tarreau | c5890e6 | 2014-02-09 17:47:01 +0100 | [diff] [blame] | 803 | /* if the buffer has been at least half full twice, |
| 804 | * we receive faster than we send, so at least it |
| 805 | * is not a "fast streamer". |
| 806 | */ |
Willy Tarreau | afc8a22 | 2014-11-28 15:46:27 +0100 | [diff] [blame] | 807 | ic->flags &= ~CF_STREAMER_FAST; |
Willy Tarreau | c5890e6 | 2014-02-09 17:47:01 +0100 | [diff] [blame] | 808 | } |
| 809 | } |
Willy Tarreau | afc8a22 | 2014-11-28 15:46:27 +0100 | [diff] [blame] | 810 | else if (!(ic->flags & CF_STREAMER_FAST) && |
Willy Tarreau | c9fa048 | 2018-07-10 17:43:27 +0200 | [diff] [blame] | 811 | (cur_read >= ic->buf.size - global.tune.maxrewrite)) { |
Willy Tarreau | c5890e6 | 2014-02-09 17:47:01 +0100 | [diff] [blame] | 812 | /* we read a full buffer at once */ |
Willy Tarreau | afc8a22 | 2014-11-28 15:46:27 +0100 | [diff] [blame] | 813 | ic->xfer_small = 0; |
| 814 | ic->xfer_large++; |
| 815 | if (ic->xfer_large >= 3) { |
Willy Tarreau | c5890e6 | 2014-02-09 17:47:01 +0100 | [diff] [blame] | 816 | /* we call this buffer a fast streamer if it manages |
| 817 | * to be filled in one call 3 consecutive times. |
| 818 | */ |
Willy Tarreau | afc8a22 | 2014-11-28 15:46:27 +0100 | [diff] [blame] | 819 | ic->flags |= (CF_STREAMER | CF_STREAMER_FAST); |
Willy Tarreau | c5890e6 | 2014-02-09 17:47:01 +0100 | [diff] [blame] | 820 | } |
| 821 | } |
| 822 | else { |
Willy Tarreau | afc8a22 | 2014-11-28 15:46:27 +0100 | [diff] [blame] | 823 | ic->xfer_small = 0; |
| 824 | ic->xfer_large = 0; |
Willy Tarreau | c5890e6 | 2014-02-09 17:47:01 +0100 | [diff] [blame] | 825 | } |
Willy Tarreau | afc8a22 | 2014-11-28 15:46:27 +0100 | [diff] [blame] | 826 | ic->last_read = now_ms; |
Willy Tarreau | c5890e6 | 2014-02-09 17:47:01 +0100 | [diff] [blame] | 827 | } |
| 828 | |
Willy Tarreau | 10fc09e | 2014-11-25 19:46:36 +0100 | [diff] [blame] | 829 | end_recv: |
Christopher Faulet | e6d8cb1 | 2019-11-20 16:42:00 +0100 | [diff] [blame] | 830 | ret = (cur_read != 0); |
| 831 | |
Christopher Faulet | 36b536d | 2019-11-20 11:56:33 +0100 | [diff] [blame] | 832 | /* Report EOI on the channel if it was reached from the mux point of |
| 833 | * view. */ |
Christopher Faulet | b041b23 | 2022-03-24 10:27:02 +0100 | [diff] [blame] | 834 | if ((cs->endp->flags & CS_EP_EOI) && !(ic->flags & CF_EOI)) { |
Christopher Faulet | 36b536d | 2019-11-20 11:56:33 +0100 | [diff] [blame] | 835 | ic->flags |= (CF_EOI|CF_READ_PARTIAL); |
Christopher Faulet | e6d8cb1 | 2019-11-20 16:42:00 +0100 | [diff] [blame] | 836 | ret = 1; |
| 837 | } |
Willy Tarreau | 10fc09e | 2014-11-25 19:46:36 +0100 | [diff] [blame] | 838 | |
Christopher Faulet | 6cd56d5 | 2022-03-30 10:47:32 +0200 | [diff] [blame] | 839 | if (cs->endp->flags & CS_EP_ERROR) |
Christopher Faulet | e6d8cb1 | 2019-11-20 16:42:00 +0100 | [diff] [blame] | 840 | ret = 1; |
Christopher Faulet | b041b23 | 2022-03-24 10:27:02 +0100 | [diff] [blame] | 841 | else if (cs->endp->flags & CS_EP_EOS) { |
Willy Tarreau | 18955db | 2020-01-23 16:32:24 +0100 | [diff] [blame] | 842 | /* we received a shutdown */ |
| 843 | ic->flags |= CF_READ_NULL; |
| 844 | if (ic->flags & CF_AUTO_CLOSE) |
| 845 | channel_shutw_now(ic); |
Christopher Faulet | d715d36 | 2022-04-01 16:38:32 +0200 | [diff] [blame] | 846 | cs_conn_read0(cs); |
Christopher Faulet | e6d8cb1 | 2019-11-20 16:42:00 +0100 | [diff] [blame] | 847 | ret = 1; |
Christopher Faulet | 36b536d | 2019-11-20 11:56:33 +0100 | [diff] [blame] | 848 | } |
| 849 | else if (!si_rx_blocked(si)) { |
| 850 | /* Subscribe to receive events if we're blocking on I/O */ |
Christopher Faulet | 2f35e7b | 2022-03-31 11:09:28 +0200 | [diff] [blame] | 851 | conn->mux->subscribe(cs, SUB_RETRY_RECV, &si->cs->wait_event); |
Willy Tarreau | dd5621a | 2018-11-15 16:55:14 +0100 | [diff] [blame] | 852 | si_rx_endp_done(si); |
| 853 | } else { |
| 854 | si_rx_endp_more(si); |
Christopher Faulet | e6d8cb1 | 2019-11-20 16:42:00 +0100 | [diff] [blame] | 855 | ret = 1; |
Willy Tarreau | dd5621a | 2018-11-15 16:55:14 +0100 | [diff] [blame] | 856 | } |
Christopher Faulet | e6d8cb1 | 2019-11-20 16:42:00 +0100 | [diff] [blame] | 857 | return ret; |
Willy Tarreau | ce323de | 2012-08-20 21:41:06 +0200 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | /* |
Willy Tarreau | 9bf9c14 | 2012-08-20 15:38:41 +0200 | [diff] [blame] | 861 | * This function propagates a null read received on a socket-based connection. |
Christopher Faulet | 8abe712 | 2022-03-30 15:10:18 +0200 | [diff] [blame] | 862 | * It updates the stream interface. If the stream interface has CS_FL_NOHALF, |
Willy Tarreau | 1140512 | 2015-03-12 22:32:27 +0100 | [diff] [blame] | 863 | * the close is also forwarded to the write side as an abort. |
Willy Tarreau | 9bf9c14 | 2012-08-20 15:38:41 +0200 | [diff] [blame] | 864 | */ |
Christopher Faulet | d715d36 | 2022-04-01 16:38:32 +0200 | [diff] [blame] | 865 | static void cs_conn_read0(struct conn_stream *cs) |
Willy Tarreau | 9bf9c14 | 2012-08-20 15:38:41 +0200 | [diff] [blame] | 866 | { |
Christopher Faulet | d715d36 | 2022-04-01 16:38:32 +0200 | [diff] [blame] | 867 | struct channel *ic = cs_ic(cs); |
| 868 | struct channel *oc = cs_oc(cs); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 869 | |
Christopher Faulet | 13a35e5 | 2021-12-20 15:34:16 +0100 | [diff] [blame] | 870 | BUG_ON(!cs_conn(cs)); |
| 871 | |
Christopher Faulet | d715d36 | 2022-04-01 16:38:32 +0200 | [diff] [blame] | 872 | si_rx_shut_blk(cs->si); |
Willy Tarreau | afc8a22 | 2014-11-28 15:46:27 +0100 | [diff] [blame] | 873 | if (ic->flags & CF_SHUTR) |
Willy Tarreau | 9bf9c14 | 2012-08-20 15:38:41 +0200 | [diff] [blame] | 874 | return; |
Willy Tarreau | afc8a22 | 2014-11-28 15:46:27 +0100 | [diff] [blame] | 875 | ic->flags |= CF_SHUTR; |
| 876 | ic->rex = TICK_ETERNITY; |
Willy Tarreau | 9bf9c14 | 2012-08-20 15:38:41 +0200 | [diff] [blame] | 877 | |
Christopher Faulet | 62e7574 | 2022-03-31 09:16:34 +0200 | [diff] [blame] | 878 | if (!cs_state_in(cs->state, CS_SB_CON|CS_SB_RDY|CS_SB_EST)) |
Willy Tarreau | 9bf9c14 | 2012-08-20 15:38:41 +0200 | [diff] [blame] | 879 | return; |
| 880 | |
Willy Tarreau | afc8a22 | 2014-11-28 15:46:27 +0100 | [diff] [blame] | 881 | if (oc->flags & CF_SHUTW) |
Willy Tarreau | 9bf9c14 | 2012-08-20 15:38:41 +0200 | [diff] [blame] | 882 | goto do_close; |
| 883 | |
Christopher Faulet | 8abe712 | 2022-03-30 15:10:18 +0200 | [diff] [blame] | 884 | if (cs->flags & CS_FL_NOHALF) { |
Willy Tarreau | 9bf9c14 | 2012-08-20 15:38:41 +0200 | [diff] [blame] | 885 | /* we want to immediately forward this close to the write side */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 886 | /* force flag on ssl to keep stream in cache */ |
Christopher Faulet | 69ef6c9 | 2022-03-31 14:20:00 +0200 | [diff] [blame] | 887 | cs_conn_shutw(cs, CO_SHW_SILENT); |
Willy Tarreau | 9bf9c14 | 2012-08-20 15:38:41 +0200 | [diff] [blame] | 888 | goto do_close; |
| 889 | } |
| 890 | |
| 891 | /* otherwise that's just a normal read shutdown */ |
Willy Tarreau | 9bf9c14 | 2012-08-20 15:38:41 +0200 | [diff] [blame] | 892 | return; |
| 893 | |
| 894 | do_close: |
Christopher Faulet | da098e6 | 2022-03-31 17:44:45 +0200 | [diff] [blame] | 895 | /* OK we completely close the socket here just as if we went through cs_shut[rw]() */ |
Christopher Faulet | 69ef6c9 | 2022-03-31 14:20:00 +0200 | [diff] [blame] | 896 | cs_conn_close(cs); |
Willy Tarreau | f9fbfe8 | 2012-11-21 21:51:53 +0100 | [diff] [blame] | 897 | |
Willy Tarreau | afc8a22 | 2014-11-28 15:46:27 +0100 | [diff] [blame] | 898 | oc->flags &= ~CF_SHUTW_NOW; |
| 899 | oc->flags |= CF_SHUTW; |
| 900 | oc->wex = TICK_ETERNITY; |
Willy Tarreau | f9fbfe8 | 2012-11-21 21:51:53 +0100 | [diff] [blame] | 901 | |
Christopher Faulet | d715d36 | 2022-04-01 16:38:32 +0200 | [diff] [blame] | 902 | si_done_get(cs->si); |
Willy Tarreau | f9fbfe8 | 2012-11-21 21:51:53 +0100 | [diff] [blame] | 903 | |
Christopher Faulet | 62e7574 | 2022-03-31 09:16:34 +0200 | [diff] [blame] | 904 | cs->state = CS_ST_DIS; |
Christopher Faulet | ae024ce | 2022-03-29 19:02:31 +0200 | [diff] [blame] | 905 | __cs_strm(cs)->conn_exp = TICK_ETERNITY; |
Willy Tarreau | 9bf9c14 | 2012-08-20 15:38:41 +0200 | [diff] [blame] | 906 | return; |
| 907 | } |
| 908 | |
Willy Tarreau | 651e182 | 2015-09-23 20:06:13 +0200 | [diff] [blame] | 909 | /* Callback to be used by applet handlers upon completion. It updates the stream |
| 910 | * (which may or may not take this opportunity to try to forward data), then |
Emeric Brun | 2802b07 | 2017-06-30 14:11:56 +0200 | [diff] [blame] | 911 | * may re-enable the applet's based on the channels and stream interface's final |
Willy Tarreau | 651e182 | 2015-09-23 20:06:13 +0200 | [diff] [blame] | 912 | * states. |
| 913 | */ |
Christopher Faulet | 6059ba4 | 2022-04-01 16:34:53 +0200 | [diff] [blame] | 914 | int cs_applet_process(struct conn_stream *cs) |
Willy Tarreau | e5f8649 | 2015-04-19 15:16:35 +0200 | [diff] [blame] | 915 | { |
Christopher Faulet | 6059ba4 | 2022-04-01 16:34:53 +0200 | [diff] [blame] | 916 | struct channel *ic = cs_ic(cs); |
Willy Tarreau | eca572f | 2015-09-25 19:11:55 +0200 | [diff] [blame] | 917 | |
Christopher Faulet | 6059ba4 | 2022-04-01 16:34:53 +0200 | [diff] [blame] | 918 | BUG_ON(!cs_appctx(cs)); |
Christopher Faulet | 693b23b | 2022-02-28 09:09:05 +0100 | [diff] [blame] | 919 | |
Willy Tarreau | eca572f | 2015-09-25 19:11:55 +0200 | [diff] [blame] | 920 | /* If the applet wants to write and the channel is closed, it's a |
| 921 | * broken pipe and it must be reported. |
| 922 | */ |
Christopher Faulet | 6059ba4 | 2022-04-01 16:34:53 +0200 | [diff] [blame] | 923 | if (!(cs->si->flags & SI_FL_RX_WAIT_EP) && (ic->flags & CF_SHUTR)) |
| 924 | cs->endp->flags |= CS_EP_ERROR; |
Willy Tarreau | eca572f | 2015-09-25 19:11:55 +0200 | [diff] [blame] | 925 | |
Willy Tarreau | 186dcdd | 2018-11-16 16:18:34 +0100 | [diff] [blame] | 926 | /* automatically mark the applet having data available if it reported |
| 927 | * begin blocked by the channel. |
| 928 | */ |
Christopher Faulet | 6059ba4 | 2022-04-01 16:34:53 +0200 | [diff] [blame] | 929 | if (si_rx_blocked(cs->si)) |
| 930 | si_rx_endp_more(cs->si); |
Willy Tarreau | 186dcdd | 2018-11-16 16:18:34 +0100 | [diff] [blame] | 931 | |
Willy Tarreau | 651e182 | 2015-09-23 20:06:13 +0200 | [diff] [blame] | 932 | /* update the stream-int, channels, and possibly wake the stream up */ |
Christopher Faulet | 9029a72 | 2022-04-01 16:48:36 +0200 | [diff] [blame] | 933 | cs_notify(cs); |
Christopher Faulet | 6059ba4 | 2022-04-01 16:34:53 +0200 | [diff] [blame] | 934 | stream_release_buffers(__cs_strm(cs)); |
Willy Tarreau | e5f8649 | 2015-04-19 15:16:35 +0200 | [diff] [blame] | 935 | |
Christopher Faulet | 9029a72 | 2022-04-01 16:48:36 +0200 | [diff] [blame] | 936 | /* cs_notify may have passed through chk_snd and released some |
Willy Tarreau | 32742fd | 2018-11-14 14:07:59 +0100 | [diff] [blame] | 937 | * RXBLK flags. Process_stream will consider those flags to wake up the |
| 938 | * appctx but in the case the task is not in runqueue we may have to |
| 939 | * wakeup the appctx immediately. |
Emeric Brun | 2802b07 | 2017-06-30 14:11:56 +0200 | [diff] [blame] | 940 | */ |
Christopher Faulet | 6059ba4 | 2022-04-01 16:34:53 +0200 | [diff] [blame] | 941 | if ((si_rx_endp_ready(cs->si) && !si_rx_blocked(cs->si)) || |
| 942 | (si_tx_endp_ready(cs->si) && !si_tx_blocked(cs->si))) |
| 943 | appctx_wakeup(__cs_appctx(cs)); |
| 944 | return 0; |
Willy Tarreau | d45b9f8 | 2015-04-13 16:30:14 +0200 | [diff] [blame] | 945 | } |
| 946 | |
Willy Tarreau | dded32d | 2008-11-30 19:48:07 +0100 | [diff] [blame] | 947 | /* |
Willy Tarreau | cff6411 | 2008-11-03 06:26:53 +0100 | [diff] [blame] | 948 | * Local variables: |
| 949 | * c-indent-level: 8 |
| 950 | * c-basic-offset: 8 |
| 951 | * End: |
| 952 | */ |