| | varnish-cache/bin/varnishd/http2/cache_http2_send.c |
| 0 |
|
/*- |
| 1 |
|
* Copyright (c) 2016 Varnish Software AS |
| 2 |
|
* All rights reserved. |
| 3 |
|
* |
| 4 |
|
* Author: Poul-Henning Kamp <phk@phk.freebsd.dk> |
| 5 |
|
* |
| 6 |
|
* SPDX-License-Identifier: BSD-2-Clause |
| 7 |
|
* |
| 8 |
|
* Redistribution and use in source and binary forms, with or without |
| 9 |
|
* modification, are permitted provided that the following conditions |
| 10 |
|
* are met: |
| 11 |
|
* 1. Redistributions of source code must retain the above copyright |
| 12 |
|
* notice, this list of conditions and the following disclaimer. |
| 13 |
|
* 2. Redistributions in binary form must reproduce the above copyright |
| 14 |
|
* notice, this list of conditions and the following disclaimer in the |
| 15 |
|
* documentation and/or other materials provided with the distribution. |
| 16 |
|
* |
| 17 |
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
| 18 |
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 |
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 20 |
|
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE |
| 21 |
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 22 |
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 23 |
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 24 |
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 25 |
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 26 |
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 27 |
|
* SUCH DAMAGE. |
| 28 |
|
* |
| 29 |
|
*/ |
| 30 |
|
|
| 31 |
|
#include "config.h" |
| 32 |
|
|
| 33 |
|
#include <sys/uio.h> |
| 34 |
|
|
| 35 |
|
#include "cache/cache_varnishd.h" |
| 36 |
|
|
| 37 |
|
#include "cache/cache_transport.h" |
| 38 |
|
#include "http2/cache_http2.h" |
| 39 |
|
|
| 40 |
|
#include "vend.h" |
| 41 |
|
#include "vtim.h" |
| 42 |
|
|
| 43 |
|
static h2_error |
| 44 |
22614 |
h2_errcheck(const struct h2_req *r2, const struct h2_sess *h2) |
| 45 |
|
{ |
| 46 |
22614 |
CHECK_OBJ_NOTNULL(r2, H2_REQ_MAGIC); |
| 47 |
22614 |
CHECK_OBJ_NOTNULL(h2, H2_SESS_MAGIC); |
| 48 |
|
|
| 49 |
22614 |
if (r2->error != NULL) |
| 50 |
3572 |
return (r2->error); |
| 51 |
19042 |
if (h2->error != NULL && r2->stream > h2->goaway_last_stream) |
| 52 |
30 |
return (h2->error); |
| 53 |
19012 |
return (NULL); |
| 54 |
22614 |
} |
| 55 |
|
|
| 56 |
|
static int |
| 57 |
498 |
h2_cond_wait(pthread_cond_t *cond, struct h2_sess *h2, struct h2_req *r2) |
| 58 |
|
{ |
| 59 |
498 |
vtim_dur tmo = 0.; |
| 60 |
|
vtim_real now; |
| 61 |
|
h2_error h2e; |
| 62 |
|
int r; |
| 63 |
|
|
| 64 |
498 |
AN(cond); |
| 65 |
498 |
CHECK_OBJ_NOTNULL(h2, H2_SESS_MAGIC); |
| 66 |
498 |
CHECK_OBJ_NOTNULL(r2, H2_REQ_MAGIC); |
| 67 |
|
|
| 68 |
498 |
Lck_AssertHeld(&h2->sess->mtx); |
| 69 |
|
|
| 70 |
498 |
if (cache_param->h2_window_timeout > 0.) |
| 71 |
498 |
tmo = cache_param->h2_window_timeout; |
| 72 |
|
|
| 73 |
498 |
r = Lck_CondWaitTimeout(cond, &h2->sess->mtx, tmo); |
| 74 |
498 |
assert(r == 0 || r == ETIMEDOUT); |
| 75 |
|
|
| 76 |
498 |
now = VTIM_real(); |
| 77 |
|
|
| 78 |
|
/* NB: when we grab h2_window_timeout before acquiring the session |
| 79 |
|
* lock we may time out, but once we wake up both send_timeout and |
| 80 |
|
* h2_window_timeout may have changed meanwhile. For this reason |
| 81 |
|
* h2_stream_tmo() may not log what timed out and we need to call |
| 82 |
|
* again with a magic NAN "now" that indicates to h2_stream_tmo() |
| 83 |
|
* that the stream reached the h2_window_timeout via the lock and |
| 84 |
|
* force it to log it. |
| 85 |
|
*/ |
| 86 |
498 |
h2e = h2_stream_tmo(h2, r2, now); |
| 87 |
498 |
if (h2e == NULL && r == ETIMEDOUT) { |
| 88 |
40 |
h2e = h2_stream_tmo(h2, r2, NAN); |
| 89 |
40 |
AN(h2e); |
| 90 |
40 |
} |
| 91 |
|
|
| 92 |
498 |
if (r2->error == NULL) |
| 93 |
458 |
r2->error = h2e; |
| 94 |
|
|
| 95 |
498 |
return (h2e != NULL ? -1 : 0); |
| 96 |
|
} |
| 97 |
|
|
| 98 |
|
static void |
| 99 |
31699 |
h2_send_get_locked(struct worker *wrk, struct h2_sess *h2, struct h2_req *r2) |
| 100 |
|
{ |
| 101 |
|
|
| 102 |
31699 |
CHECK_OBJ_NOTNULL(h2, H2_SESS_MAGIC); |
| 103 |
31699 |
CHECK_OBJ_NOTNULL(r2, H2_REQ_MAGIC); |
| 104 |
31699 |
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); |
| 105 |
|
|
| 106 |
31699 |
Lck_AssertHeld(&h2->sess->mtx); |
| 107 |
31699 |
if (&wrk->cond == h2->cond) |
| 108 |
16279 |
ASSERT_RXTHR(h2); |
| 109 |
31699 |
AZ(H2_SEND_HELD(h2, r2)); |
| 110 |
31699 |
AZ(r2->wrk); |
| 111 |
31699 |
r2->wrk = wrk; |
| 112 |
31699 |
VTAILQ_INSERT_TAIL(&h2->txqueue, r2, tx_list); |
| 113 |
32093 |
while (!H2_SEND_HELD(h2, r2)) |
| 114 |
394 |
AZ(Lck_CondWait(&wrk->cond, &h2->sess->mtx)); |
| 115 |
31699 |
r2->wrk = NULL; |
| 116 |
31699 |
} |
| 117 |
|
|
| 118 |
|
void |
| 119 |
31260 |
H2_Send_Get(struct worker *wrk, struct h2_sess *h2, struct h2_req *r2) |
| 120 |
|
{ |
| 121 |
|
|
| 122 |
31260 |
CHECK_OBJ_NOTNULL(h2, H2_SESS_MAGIC); |
| 123 |
31260 |
CHECK_OBJ_NOTNULL(r2, H2_REQ_MAGIC); |
| 124 |
31260 |
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); |
| 125 |
|
|
| 126 |
31260 |
Lck_Lock(&h2->sess->mtx); |
| 127 |
31260 |
h2_send_get_locked(wrk, h2, r2); |
| 128 |
31260 |
Lck_Unlock(&h2->sess->mtx); |
| 129 |
31260 |
} |
| 130 |
|
|
| 131 |
|
static void |
| 132 |
31700 |
h2_send_rel_locked(struct h2_sess *h2, const struct h2_req *r2) |
| 133 |
|
{ |
| 134 |
31700 |
CHECK_OBJ_NOTNULL(r2, H2_REQ_MAGIC); |
| 135 |
31700 |
CHECK_OBJ_NOTNULL(h2, H2_SESS_MAGIC); |
| 136 |
|
|
| 137 |
31700 |
Lck_AssertHeld(&h2->sess->mtx); |
| 138 |
31700 |
AN(H2_SEND_HELD(h2, r2)); |
| 139 |
31700 |
VTAILQ_REMOVE(&h2->txqueue, r2, tx_list); |
| 140 |
31700 |
r2 = VTAILQ_FIRST(&h2->txqueue); |
| 141 |
31700 |
if (r2 != NULL) { |
| 142 |
394 |
CHECK_OBJ_NOTNULL(r2->wrk, WORKER_MAGIC); |
| 143 |
394 |
PTOK(pthread_cond_signal(&r2->wrk->cond)); |
| 144 |
394 |
} |
| 145 |
31700 |
} |
| 146 |
|
|
| 147 |
|
void |
| 148 |
31260 |
H2_Send_Rel(struct h2_sess *h2, const struct h2_req *r2) |
| 149 |
|
{ |
| 150 |
31260 |
CHECK_OBJ_NOTNULL(h2, H2_SESS_MAGIC); |
| 151 |
31260 |
CHECK_OBJ_NOTNULL(r2, H2_REQ_MAGIC); |
| 152 |
|
|
| 153 |
31260 |
Lck_Lock(&h2->sess->mtx); |
| 154 |
31260 |
h2_send_rel_locked(h2, r2); |
| 155 |
31260 |
Lck_Unlock(&h2->sess->mtx); |
| 156 |
31260 |
} |
| 157 |
|
|
| 158 |
|
static void |
| 159 |
30375 |
h2_mk_hdr(uint8_t *hdr, h2_frame ftyp, uint8_t flags, |
| 160 |
|
uint32_t len, uint32_t stream) |
| 161 |
|
{ |
| 162 |
|
|
| 163 |
30375 |
AN(hdr); |
| 164 |
30375 |
assert(len < (1U << 24)); |
| 165 |
30375 |
vbe32enc(hdr, len << 8); |
| 166 |
30375 |
hdr[3] = ftyp->type; |
| 167 |
30375 |
hdr[4] = flags; |
| 168 |
30375 |
vbe32enc(hdr + 5, stream); |
| 169 |
30375 |
} |
| 170 |
|
|
| 171 |
|
/* |
| 172 |
|
* This is the "raw" frame sender, all per-stream accounting and |
| 173 |
|
* prioritization must have happened before this is called, and |
| 174 |
|
* the session mtx must be held. |
| 175 |
|
*/ |
| 176 |
|
|
| 177 |
|
void |
| 178 |
30375 |
H2_Send_Frame(struct worker *wrk, struct h2_sess *h2, |
| 179 |
|
h2_frame ftyp, uint8_t flags, |
| 180 |
|
uint32_t len, uint32_t stream, const void *ptr) |
| 181 |
|
{ |
| 182 |
|
uint8_t hdr[9]; |
| 183 |
|
ssize_t s; |
| 184 |
|
struct iovec iov[2]; |
| 185 |
|
|
| 186 |
30375 |
(void)wrk; |
| 187 |
|
|
| 188 |
30375 |
AN(ftyp); |
| 189 |
30375 |
AZ(flags & ~(ftyp->flags)); |
| 190 |
30375 |
if (stream == 0) |
| 191 |
19600 |
AZ(ftyp->act_szero); |
| 192 |
|
else |
| 193 |
10775 |
AZ(ftyp->act_snonzero); |
| 194 |
|
|
| 195 |
30375 |
h2_mk_hdr(hdr, ftyp, flags, len, stream); |
| 196 |
30375 |
Lck_Lock(&h2->sess->mtx); |
| 197 |
30375 |
VSLb_bin(h2->vsl, SLT_H2TxHdr, 9, hdr); |
| 198 |
30375 |
h2->srq->acct.resp_hdrbytes += 9; |
| 199 |
30375 |
if (ftyp->overhead) |
| 200 |
22813 |
h2->srq->acct.resp_bodybytes += len; |
| 201 |
30375 |
Lck_Unlock(&h2->sess->mtx); |
| 202 |
|
|
| 203 |
30375 |
memset(iov, 0, sizeof iov); |
| 204 |
30375 |
iov[0].iov_base = (void*)hdr; |
| 205 |
30375 |
iov[0].iov_len = sizeof hdr; |
| 206 |
30375 |
iov[1].iov_base = TRUST_ME(ptr); |
| 207 |
30375 |
iov[1].iov_len = len; |
| 208 |
30375 |
s = writev(h2->sess->fd, iov, len == 0 ? 1 : 2); |
| 209 |
30375 |
if (s != sizeof hdr + len) { |
| 210 |
81 |
if (errno == EWOULDBLOCK) { |
| 211 |
0 |
H2S_Lock_VSLb(h2, SLT_SessError, |
| 212 |
0 |
"H2: stream %u: Hit idle_send_timeout", stream); |
| 213 |
0 |
} |
| 214 |
|
else { |
| 215 |
162 |
H2S_Lock_VSLb(h2, SLT_Debug, |
| 216 |
|
"H2: stream %u: write error s=%zd/%zu errno=%d", |
| 217 |
81 |
stream, s, sizeof hdr + len, errno); |
| 218 |
|
} |
| 219 |
|
/* |
| 220 |
|
* There is no point in being nice here, we will be unable |
| 221 |
|
* to send a GOAWAY once the code unrolls, so go directly |
| 222 |
|
* to the finale and be done with it. |
| 223 |
|
*/ |
| 224 |
81 |
h2->error = H2CE_PROTOCOL_ERROR; |
| 225 |
30375 |
} else if (len > 0) { |
| 226 |
23282 |
Lck_Lock(&h2->sess->mtx); |
| 227 |
23282 |
VSLb_bin(h2->vsl, SLT_H2TxBody, len, ptr); |
| 228 |
23282 |
Lck_Unlock(&h2->sess->mtx); |
| 229 |
23282 |
} |
| 230 |
30375 |
} |
| 231 |
|
|
| 232 |
|
static int64_t |
| 233 |
2024 |
h2_win_limit(const struct h2_req *r2, const struct h2_sess *h2) |
| 234 |
|
{ |
| 235 |
|
|
| 236 |
2024 |
CHECK_OBJ_NOTNULL(r2, H2_REQ_MAGIC); |
| 237 |
2024 |
CHECK_OBJ_NOTNULL(h2, H2_SESS_MAGIC); |
| 238 |
2024 |
CHECK_OBJ_NOTNULL(h2->req0, H2_REQ_MAGIC); |
| 239 |
|
|
| 240 |
2024 |
Lck_AssertHeld(&h2->sess->mtx); |
| 241 |
2024 |
return (vmin_t(int64_t, r2->t_window, h2->req0->t_window)); |
| 242 |
|
} |
| 243 |
|
|
| 244 |
|
static void |
| 245 |
2024 |
h2_win_charge(struct h2_req *r2, const struct h2_sess *h2, uint32_t w) |
| 246 |
|
{ |
| 247 |
2024 |
CHECK_OBJ_NOTNULL(r2, H2_REQ_MAGIC); |
| 248 |
2024 |
CHECK_OBJ_NOTNULL(h2, H2_SESS_MAGIC); |
| 249 |
2024 |
CHECK_OBJ_NOTNULL(h2->req0, H2_REQ_MAGIC); |
| 250 |
|
|
| 251 |
2024 |
Lck_AssertHeld(&h2->sess->mtx); |
| 252 |
2024 |
r2->t_window -= w; |
| 253 |
2024 |
h2->req0->t_window -= w; |
| 254 |
2024 |
} |
| 255 |
|
|
| 256 |
|
static int64_t |
| 257 |
3316 |
h2_do_window(struct worker *wrk, struct h2_req *r2, |
| 258 |
|
struct h2_sess *h2, int64_t wanted) |
| 259 |
|
{ |
| 260 |
3316 |
int64_t w = 0; |
| 261 |
|
|
| 262 |
3316 |
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); |
| 263 |
3316 |
CHECK_OBJ_NOTNULL(r2, H2_REQ_MAGIC); |
| 264 |
3316 |
CHECK_OBJ_NOTNULL(h2, H2_SESS_MAGIC); |
| 265 |
|
|
| 266 |
3316 |
if (wanted == 0) |
| 267 |
1132 |
return (0); |
| 268 |
|
|
| 269 |
2184 |
Lck_Lock(&h2->sess->mtx); |
| 270 |
2184 |
if (r2->t_window <= 0 || h2->req0->t_window <= 0) { |
| 271 |
440 |
r2->t_winupd = VTIM_real(); |
| 272 |
440 |
h2_send_rel_locked(h2, r2); |
| 273 |
|
|
| 274 |
440 |
assert(h2->winup_streams >= 0); |
| 275 |
440 |
h2->winup_streams++; |
| 276 |
|
|
| 277 |
880 |
while (r2->t_window <= 0 && h2_errcheck(r2, h2) == NULL) { |
| 278 |
440 |
r2->cond = &wrk->cond; |
| 279 |
440 |
(void)h2_cond_wait(r2->cond, h2, r2); |
| 280 |
440 |
r2->cond = NULL; |
| 281 |
|
} |
| 282 |
|
|
| 283 |
498 |
while (h2->req0->t_window <= 0 && h2_errcheck(r2, h2) == NULL) |
| 284 |
58 |
(void)h2_cond_wait(h2->winupd_cond, h2, r2); |
| 285 |
|
|
| 286 |
440 |
if (h2_errcheck(r2, h2) == NULL) { |
| 287 |
280 |
w = vmin_t(int64_t, h2_win_limit(r2, h2), wanted); |
| 288 |
280 |
h2_win_charge(r2, h2, w); |
| 289 |
280 |
assert (w > 0); |
| 290 |
280 |
} |
| 291 |
|
|
| 292 |
440 |
if (r2->error == H2SE_BROKE_WINDOW && |
| 293 |
80 |
h2->open_streams <= h2->winup_streams) { |
| 294 |
0 |
VSLb(h2->vsl, SLT_SessError, "H2: window bankrupt"); |
| 295 |
0 |
h2->error = r2->error = H2CE_BANKRUPT; |
| 296 |
0 |
} |
| 297 |
|
|
| 298 |
440 |
assert(h2->winup_streams > 0); |
| 299 |
440 |
h2->winup_streams--; |
| 300 |
|
|
| 301 |
440 |
h2_send_get_locked(wrk, h2, r2); |
| 302 |
440 |
} |
| 303 |
|
|
| 304 |
2184 |
if (w == 0 && h2_errcheck(r2, h2) == NULL) { |
| 305 |
1744 |
assert(r2->t_window > 0); |
| 306 |
1744 |
assert(h2->req0->t_window > 0); |
| 307 |
1744 |
w = h2_win_limit(r2, h2); |
| 308 |
1744 |
if (w > wanted) |
| 309 |
1464 |
w = wanted; |
| 310 |
1744 |
h2_win_charge(r2, h2, w); |
| 311 |
1744 |
assert (w > 0); |
| 312 |
1744 |
} |
| 313 |
2184 |
r2->t_winupd = 0; |
| 314 |
2184 |
Lck_Unlock(&h2->sess->mtx); |
| 315 |
2184 |
return (w); |
| 316 |
3316 |
} |
| 317 |
|
|
| 318 |
|
/* |
| 319 |
|
* This is the per-stream frame sender. |
| 320 |
|
* XXX: priority |
| 321 |
|
*/ |
| 322 |
|
|
| 323 |
|
static void |
| 324 |
8168 |
h2_send(struct worker *wrk, struct h2_req *r2, h2_frame ftyp, uint8_t flags, |
| 325 |
|
uint32_t len, const void *ptr, uint64_t *counter) |
| 326 |
|
{ |
| 327 |
|
struct h2_sess *h2; |
| 328 |
|
uint32_t mfs, tf; |
| 329 |
|
const char *p; |
| 330 |
|
uint8_t final_flags; |
| 331 |
|
|
| 332 |
8168 |
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); |
| 333 |
8168 |
CHECK_OBJ_NOTNULL(r2, H2_REQ_MAGIC); |
| 334 |
8168 |
h2 = r2->h2sess; |
| 335 |
8168 |
CHECK_OBJ_NOTNULL(h2, H2_SESS_MAGIC); |
| 336 |
8168 |
assert(len == 0 || ptr != NULL); |
| 337 |
8168 |
AN(counter); |
| 338 |
|
|
| 339 |
8168 |
AN(H2_SEND_HELD(h2, r2)); |
| 340 |
|
|
| 341 |
8168 |
if (h2_errcheck(r2, h2) != NULL) |
| 342 |
1406 |
return; |
| 343 |
|
|
| 344 |
6762 |
AN(ftyp); |
| 345 |
6762 |
AZ(flags & ~(ftyp->flags)); |
| 346 |
6762 |
if (r2->stream == 0) |
| 347 |
0 |
AZ(ftyp->act_szero); |
| 348 |
|
else |
| 349 |
6762 |
AZ(ftyp->act_snonzero); |
| 350 |
|
|
| 351 |
6762 |
Lck_Lock(&h2->sess->mtx); |
| 352 |
6762 |
mfs = h2->remote_settings.max_frame_size; |
| 353 |
6762 |
if (r2->counted && ( |
| 354 |
6762 |
(ftyp == H2_F_HEADERS && (flags & H2FF_HEADERS_END_STREAM)) || |
| 355 |
2596 |
(ftyp == H2_F_DATA && (flags & H2FF_DATA_END_STREAM)) || |
| 356 |
0 |
ftyp == H2_F_RST_STREAM |
| 357 |
|
)) { |
| 358 |
9712 |
assert(h2->open_streams > 0); |
| 359 |
3812 |
h2->open_streams--; |
| 360 |
3812 |
r2->counted = 0; |
| 361 |
3812 |
} |
| 362 |
6762 |
Lck_Unlock(&h2->sess->mtx); |
| 363 |
|
|
| 364 |
6762 |
if (ftyp->respect_window) { |
| 365 |
2596 |
tf = h2_do_window(wrk, r2, h2, (len > mfs) ? mfs : len); |
| 366 |
2596 |
if (h2_errcheck(r2, h2) != NULL) |
| 367 |
0 |
return; |
| 368 |
2596 |
AN(H2_SEND_HELD(h2, r2)); |
| 369 |
2596 |
} else |
| 370 |
4166 |
tf = mfs; |
| 371 |
|
|
| 372 |
6762 |
if (len <= tf) { |
| 373 |
6362 |
H2_Send_Frame(wrk, h2, ftyp, flags, len, r2->stream, ptr); |
| 374 |
6362 |
*counter += len; |
| 375 |
6362 |
} else { |
| 376 |
400 |
AN(ptr); |
| 377 |
400 |
p = ptr; |
| 378 |
400 |
final_flags = ftyp->final_flags & flags; |
| 379 |
400 |
flags &= ~ftyp->final_flags; |
| 380 |
400 |
do { |
| 381 |
1360 |
AN(ftyp->continuation); |
| 382 |
1360 |
if (!ftyp->respect_window) |
| 383 |
320 |
tf = mfs; |
| 384 |
1360 |
if (ftyp->respect_window && p != ptr) { |
| 385 |
1440 |
tf = h2_do_window(wrk, r2, h2, |
| 386 |
720 |
(len > mfs) ? mfs : len); |
| 387 |
720 |
if (h2_errcheck(r2, h2) != NULL) |
| 388 |
160 |
return; |
| 389 |
560 |
AN(H2_SEND_HELD(h2, r2)); |
| 390 |
560 |
} |
| 391 |
1200 |
if (tf < len) { |
| 392 |
1920 |
H2_Send_Frame(wrk, h2, ftyp, |
| 393 |
960 |
flags, tf, r2->stream, p); |
| 394 |
960 |
} else { |
| 395 |
240 |
if (ftyp->respect_window) |
| 396 |
160 |
assert(tf == len); |
| 397 |
240 |
tf = len; |
| 398 |
480 |
H2_Send_Frame(wrk, h2, ftyp, final_flags, tf, |
| 399 |
240 |
r2->stream, p); |
| 400 |
240 |
flags = 0; |
| 401 |
|
} |
| 402 |
1200 |
p += tf; |
| 403 |
1200 |
len -= tf; |
| 404 |
1200 |
*counter += tf; |
| 405 |
1200 |
ftyp = ftyp->continuation; |
| 406 |
1200 |
flags &= ftyp->flags; |
| 407 |
1200 |
final_flags &= ftyp->flags; |
| 408 |
1200 |
} while (h2->error == NULL && len > 0); |
| 409 |
|
} |
| 410 |
8168 |
} |
| 411 |
|
|
| 412 |
|
void |
| 413 |
2413 |
H2_Send_RST(struct worker *wrk, struct h2_sess *h2, const struct h2_req *r2, |
| 414 |
|
uint32_t stream, h2_error h2e) |
| 415 |
|
{ |
| 416 |
|
char b[4]; |
| 417 |
2413 |
h2_error h2e_rr = NULL; |
| 418 |
|
|
| 419 |
2413 |
CHECK_OBJ_NOTNULL(h2, H2_SESS_MAGIC); |
| 420 |
2413 |
CHECK_OBJ_NOTNULL(r2, H2_REQ_MAGIC); |
| 421 |
2413 |
AN(H2_SEND_HELD(h2, r2)); |
| 422 |
2413 |
AN(h2e); |
| 423 |
|
|
| 424 |
2413 |
H2S_Lock_VSLb(h2, SLT_Debug, "H2: stream %u: %s", stream, h2e->txt); |
| 425 |
2413 |
vbe32enc(b, h2e->val); |
| 426 |
|
|
| 427 |
2413 |
H2_Send_Frame(wrk, h2, H2_F_RST_STREAM, 0, sizeof b, stream, b); |
| 428 |
|
|
| 429 |
2413 |
if (h2_rapid_reset_check(wrk, h2, r2)) |
| 430 |
2160 |
h2e_rr = h2_rapid_reset_charge(wrk, h2, r2); |
| 431 |
2413 |
if (h2e_rr != NULL) |
| 432 |
40 |
h2->error = h2e_rr; |
| 433 |
2413 |
} |
| 434 |
|
|
| 435 |
|
void |
| 436 |
5840 |
H2_Send_GOAWAY(struct worker *wrk, struct h2_sess *h2, const struct h2_req *r2, |
| 437 |
|
h2_error h2e) |
| 438 |
|
{ |
| 439 |
|
char b[8]; |
| 440 |
|
|
| 441 |
5840 |
CHECK_OBJ_NOTNULL(h2, H2_SESS_MAGIC); |
| 442 |
5840 |
CHECK_OBJ_NOTNULL(r2, H2_REQ_MAGIC); |
| 443 |
5840 |
AN(H2_SEND_HELD(h2, r2)); |
| 444 |
5840 |
AN(h2e); |
| 445 |
|
|
| 446 |
5840 |
if (h2->goaway) |
| 447 |
0 |
return; |
| 448 |
|
|
| 449 |
5840 |
vbe32enc(b, h2->highest_stream); |
| 450 |
5840 |
vbe32enc(b + 4, h2e->val); |
| 451 |
5840 |
H2_Send_Frame(wrk, h2, H2_F_GOAWAY, 0, 8, 0, b); |
| 452 |
5840 |
h2->goaway = 1; |
| 453 |
5840 |
} |
| 454 |
|
|
| 455 |
|
void |
| 456 |
8168 |
H2_Send(struct worker *wrk, struct h2_req *r2, h2_frame ftyp, uint8_t flags, |
| 457 |
|
uint32_t len, const void *ptr, uint64_t *counter) |
| 458 |
|
{ |
| 459 |
8168 |
uint64_t dummy_counter = 0; |
| 460 |
|
h2_error h2e; |
| 461 |
|
|
| 462 |
8168 |
if (counter == NULL) |
| 463 |
2344 |
counter = &dummy_counter; |
| 464 |
|
|
| 465 |
8168 |
h2_send(wrk, r2, ftyp, flags, len, ptr, counter); |
| 466 |
|
|
| 467 |
8168 |
h2e = h2_errcheck(r2, r2->h2sess); |
| 468 |
8168 |
if (H2_ERROR_MATCH(h2e, H2SE_CANCEL)) |
| 469 |
200 |
H2_Send_RST(wrk, r2->h2sess, r2, r2->stream, h2e); |
| 470 |
8168 |
} |