include/hyperman/hm_stream.h

filter: Statementstmt 80.6% 183 / 227 Branchbran 63.3% 129 / 240 (28 uncoverable) Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 71.7% 312 / 467 (28 uncoverable) CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/hyperman/hm_quic.h ↑ Summary include/hyperman/hm_sa.h »
1 #ifndef HM_STREAM_H
2 #define HM_STREAM_H
3  
4 /* ABI v6 stream handles: one transport-neutral way to write a response body
5 * a piece at a time.
6 *
7 * hm_detach hands over a file descriptor, and that is why it refuses HTTP/2
8 * and TLS. Those refusals are right, not gaps: an h2 stream is one of many on
9 * a shared connection, so no fd means "this stream", and a TLS session's
10 * state belongs to the server rather than to the socket. The seam that works
11 * on every transport is therefore a HANDLE, and this file is it - one
12 * registry with a transport branch inside, so a caller never tests the
13 * protocol.
14 *
15 * Included from hm_core.h after hm_http2.h, because it is built on both
16 * halves: hm_start_stream / hm_stream_write / hm_stream_close for HTTP/1.1
17 * and the nghttp2 data provider for HTTP/2.
18 *
19 * The handle belongs to whoever opened it, from stream_open until
20 * stream_close. Nothing else ever frees one - a connection that goes away
21 * only MARKS its handles dead and fires their abort callbacks, so a write
22 * arriving afterwards is an error return and not a read of freed memory.
23 * Every entry point validates the pointer by finding it on the live list
24 * first, which is also what keeps a recycled address from being mistaken for
25 * the handle that used to live there. */
26  
27 #define HM_STREAM_H1 0
28 #define HM_STREAM_H2 1
29  
30 typedef struct hm_stream {
31 UV serial; /* names the handle in diagnostics; the list
32 * membership is what proves it is live */
33 hm_loop *loop;
34 int fd;
35 UV cid; /* connection generation (the detach ticket) */
36 int64_t sid; /* h2 stream id, or -1 for HTTP/1.1 */
37 unsigned char kind; /* HM_STREAM_H1 / HM_STREAM_H2 */
38 unsigned char dead; /* the stream is gone */
39 unsigned char paused; /* over the high-water mark */
40 unsigned char aborted; /* the abort callback has already fired */
41 hm_abi_stream_cb drain_cb; void *drain_ud;
42 hm_abi_stream_cb abort_cb; void *abort_ud;
43 hm_abi_stream_data_cb data_cb; void *data_ud; /* v8, the read half */
44 struct hm_stream *next;
45 } hm_stream;
46  
47 static hm_stream *hm_streams = NULL;
48 static UV hm_stream_serials = 0;
49  
50 /* Live iff it is on the list. A pointer that is not is either already
51 * closed or was never a handle, and either way must not be dereferenced. */
52 2142 static hm_stream *hm_stream_of(void *h) {
53 hm_stream *s;
54 2142 ▶ if (!h) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!h) return NULL; 3 2139 2142
55 2139 ▶ for (s = hm_streams; s; s = s->next) if ((void *)s == h) return s; /* # uncoverable condition right count:1 class:ignore_covered_err */
Branch: 2 branches
BranchTrueFalseTotal
for (s = hm_streams; s; s = s->next) if ((void *)s == h) return s; /* # uncoverable condition right count:1 class:ignore_covered_err */ 2131 0 2131
for (s = hm_streams; s; s = s->next) if ((void *)s == h) return s; /* # uncoverable condition right count:1 class:ignore_covered_err */ 2131 8 2139
56 8 return NULL;
57 }
58  
59 /* The connection this handle names, or NULL if it has been closed or the fd
60 * was reused - the generation check is the whole point of carrying cid. */
61 4175 static hm_conn *hm_stream_conn(hm_stream *s) {
62 hm_conn *c;
63 /*
64 # uncoverable branch true class:ignore_covered_err
65 # uncoverable condition left count:1 class:ignore_covered_err
66 # uncoverable condition left count:2 class:ignore_covered_err
67 # uncoverable condition left count:3 class:ignore_covered_err */
68 4175 ▶ if (!s->loop || s->fd < 0 || s->fd >= HM_MAXFD) return NULL;
Branch: 3 branches
BranchTrueFalseTotal
if (!s->loop || s->fd < 0 || s->fd >= HM_MAXFD) return NULL; 4175 0 4175
if (!s->loop || s->fd < 0 || s->fd >= HM_MAXFD) return NULL; 4175 0 4175
if (!s->loop || s->fd < 0 || s->fd >= HM_MAXFD) return NULL; 0 4175 4175
69 4175 c = s->loop->conns[s->fd];
70 /*
71 # uncoverable condition right count:1 class:ignore_covered_err
72 # uncoverable condition right count:2 class:ignore_covered_err
73 # uncoverable condition right count:3 class:ignore_covered_err */
74 4175 ▶ return (c && c->id == s->cid && !c->detached) ? c : NULL;
Branch: 3 branches
BranchTrueFalseTotal
return (c && c->id == s->cid && !c->detached) ? c : NULL; 4175 0 4175
return (c && c->id == s->cid && !c->detached) ? c : NULL; 4175 0 4175
return (c && c->id == s->cid && !c->detached) ? c : NULL; 4175 0 4175
75 }
76  
77 1 static void hm_stream_mark_dead(hm_stream *s) {
78 1 ▶ if (s->dead) return;
Branch: 1 branch
BranchTrueFalseTotal
if (s->dead) return; 0 1 1
79 1 s->dead = 1;
80 1 ▶ if (s->paused) { s->paused = 0; hm_stream_paused_n--; }
Branch: 1 branch
BranchTrueFalseTotal
if (s->paused) { s->paused = 0; hm_stream_paused_n--; } 0 1 1
81 }
82  
83 /* Fire every pending abort callback. Each one may close its own handle, or
84 * anyone else's, so the list is re-scanned from the top after every call
85 * rather than walked with a saved next pointer. */
86 12 static void hm_stream_fire_aborts(pTHX) {
87 12 int again = 1;
88 37 ▶ while (again) {
Branch: 1 branch
BranchTrueFalseTotal
while (again) { 13 12 25
89 hm_stream *s;
90 13 again = 0;
91 25 ▶ for (s = hm_streams; s; s = s->next) {
Branch: 1 branch
BranchTrueFalseTotal
for (s = hm_streams; s; s = s->next) { 13 12 25
92 13 ▶ if (s->dead && !s->aborted && s->abort_cb) {
Branch: 3 branches
BranchTrueFalseTotal
if (s->dead && !s->aborted && s->abort_cb) { 3 10 13
if (s->dead && !s->aborted && s->abort_cb) { 1 2 3
if (s->dead && !s->aborted && s->abort_cb) { 1 0 1
93 1 hm_abi_stream_cb cb = s->abort_cb;
94 1 void *ud = s->abort_ud;
95 1 s->aborted = 1;
96 1 cb(aTHX_ (void *)s, ud);
97 1 again = 1;
98 1 break;
99 }
100 }
101 }
102 12 }
103  
104 /* A whole connection went away (close, or a detach handing the fd on). */
105 12 static void hm_stream_conn_gone(pTHX_ int fd, UV id) {
106 hm_stream *s;
107 /*
108 # uncoverable branch true
109 # uncoverable condition left count:1 class:ignore_covered_err */
110 12 ▶ if (!hm_stream_live_n) return;
Branch: 1 branch
BranchTrueFalseTotal
if (!hm_stream_live_n) return; 0 12 12
111 24 ▶ for (s = hm_streams; s; s = s->next)
Branch: 1 branch
BranchTrueFalseTotal
for (s = hm_streams; s; s = s->next) 12 12 24
112 12 ▶ if (s->fd == fd && s->cid == id) hm_stream_mark_dead(s);
Branch: 2 branches
BranchTrueFalseTotal
if (s->fd == fd && s->cid == id) hm_stream_mark_dead(s); 2 10 12
if (s->fd == fd && s->cid == id) hm_stream_mark_dead(s); 1 1 2
113 12 hm_stream_fire_aborts(aTHX);
114 }
115  
116 /* One h2 stream out of many went away - the peer reset it, or it finished. */
117 0 static void hm_stream_h2_gone(pTHX_ int fd, UV id, int64_t sid) {
118 hm_stream *s;
119 0 ▶ if (!hm_stream_live_n) return;
Branch: 1 branch
BranchTrueFalseTotal
if (!hm_stream_live_n) return; 0 0 0
120 0 ▶ for (s = hm_streams; s; s = s->next)
Branch: 1 branch
BranchTrueFalseTotal
for (s = hm_streams; s; s = s->next) 0 0 0
121 /*
122 # uncoverable condition right count:1 class:ignore_covered_err
123 # uncoverable condition right count:3 class:ignore_covered_err */
124 0 ▶ if (s->fd == fd && s->cid == id && s->sid == sid) hm_stream_mark_dead(s);
Branch: 3 branches
BranchTrueFalseTotal
if (s->fd == fd && s->cid == id && s->sid == sid) hm_stream_mark_dead(s); 0 0 0
if (s->fd == fd && s->cid == id && s->sid == sid) hm_stream_mark_dead(s); 0 0 0
if (s->fd == fd && s->cid == id && s->sid == sid) hm_stream_mark_dead(s); 0 0 0
125 0 hm_stream_fire_aborts(aTHX);
126 }
127  
128 /* What is still waiting to leave on behalf of this handle.
129 *
130 * For HTTP/1.1 that is the connection's unwritten output. For HTTP/2 it is
131 * that PLUS what the stream itself is holding: nghttp2 frames a body only as
132 * fast as the peer's flow-control window allows, and everything it has not
133 * been allowed to frame yet sits in the stream's own buffer, which the
134 * connection's does not count. Measuring the connection alone, a write was
135 * never answered "full" over HTTP/2 and a producer never paused: the whole
136 * body was held for a client that had not asked for it yet. */
137 static size_t hm_stream_h2_held(hm_conn *c, int64_t sid);
138  
139 2074 static size_t hm_stream_held(hm_stream *s, hm_conn *c) {
140 2074 size_t held = c->wlen - c->woff;
141 2074 ▶ if (s->kind == HM_STREAM_H2) held += hm_stream_h2_held(c, s->sid);
Branch: 1 branch
BranchTrueFalseTotal
if (s->kind == HM_STREAM_H2) held += hm_stream_h2_held(c, s->sid); 0 2074 2074
142 2074 return held;
143 }
144  
145 /* Below this a paused HTTP/2 producer is restarted. Half the mark it was
146 * stopped at, so it is not woken to write one frame and stopped again. */
147 #define HM_STREAM_LOWAT (HM_ABI_STREAM_HIWAT / 2)
148  
149 /* Output that was over the high-water mark has gone out. Same re-scan rule
150 * as the aborts: a drain callback's whole job is to write more. */
151 1 static void hm_stream_drained(pTHX_ hm_conn *c) {
152 1 int again = 1;
153 1 hm_loop *loop = c->loop;
154 1 int fd = c->fd;
155 1 UV id = c->id;
156 692 ▶ while (again) {
Branch: 1 branch
BranchTrueFalseTotal
while (again) { 690 1 691
157 hm_stream *s;
158 690 again = 0;
159 /*
160 # uncoverable branch true class:ignore_covered_err
161 # uncoverable condition left count:1 class:ignore_covered_err
162 # uncoverable condition left count:2 class:ignore_covered_err */
163 690 ▶ if (loop->conns[fd] != c || c->id != id) return; /* a callback closed it */
Branch: 2 branches
BranchTrueFalseTotal
if (loop->conns[fd] != c || c->id != id) return; /* a callback closed it */ 690 0 690
if (loop->conns[fd] != c || c->id != id) return; /* a callback closed it */ 0 690 690
164 690 ▶ for (s = hm_streams; s; s = s->next) {
Branch: 1 branch
BranchTrueFalseTotal
for (s = hm_streams; s; s = s->next) { 689 1 690
165 /*
166 # uncoverable branch false class:ignore_covered_err
167 # uncoverable condition right count:1 class:ignore_covered_err
168 # uncoverable condition right count:2 class:ignore_covered_err
169 # uncoverable condition right count:3 class:ignore_covered_err */
170 689 ▶ if (s->paused && s->fd == fd && s->cid == id) {
Branch: 3 branches
BranchTrueFalseTotal
if (s->paused && s->fd == fd && s->cid == id) { 689 0 689
if (s->paused && s->fd == fd && s->cid == id) { 689 0 689
if (s->paused && s->fd == fd && s->cid == id) { 689 0 689
171 hm_abi_stream_cb cb;
172 void *ud;
173 /* an HTTP/2 stream is ready when ITS output has gone, which
174 * the connection's buffer emptying does not say */
175 689 ▶ if (s->kind == HM_STREAM_H2
Branch: 1 branch
BranchTrueFalseTotal
if (s->kind == HM_STREAM_H2 0 689 689
176 0 ▶ && hm_stream_held(s, c) > (size_t)HM_STREAM_LOWAT)
Branch: 1 branch
BranchTrueFalseTotal
&& hm_stream_held(s, c) > (size_t)HM_STREAM_LOWAT) 0 0 0
177 0 continue;
178 689 cb = s->drain_cb;
179 689 ud = s->drain_ud;
180 689 s->paused = 0;
181 689 hm_stream_paused_n--;
182 689 again = 1;
183 /*
184 # uncoverable branch false class:ignore_covered_err
185 # uncoverable condition right count:1 class:ignore_covered_err */
186 689 ▶ if (cb) cb(aTHX_ (void *)s, ud);
Branch: 1 branch
BranchTrueFalseTotal
if (cb) cb(aTHX_ (void *)s, ud); 689 0 689
187 689 break;
188 }
189 }
190 }
191 }
192  
193 /* Take a handle off the registry without freeing it. Ending a body can close
194 * the connection underneath us - EOF-delimited HTTP/1.1 always does - and a
195 * handle that is deliberately finishing must not then be told its stream went
196 * away. So stream_close unlinks first, ends the body, and frees afterwards. */
197 19 static void hm_stream_unlink(hm_stream *s) {
198 19 hm_stream **pp = &hm_streams;
199 /*
200 # uncoverable branch false class:ignore_covered_err
201 # uncoverable condition right count:1 class:ignore_covered_err */
202 19 ▶ while (*pp) {
Branch: 1 branch
BranchTrueFalseTotal
while (*pp) { 19 0 19
203 /*
204 # uncoverable branch false
205 # uncoverable condition right count:1 class:ignore_covered_err */
206 19 ▶ if (*pp == s) { *pp = s->next; break; }
Branch: 1 branch
BranchTrueFalseTotal
if (*pp == s) { *pp = s->next; break; } 19 0 19
207 0 pp = &(*pp)->next; /* # uncoverable statement */
208 }
209 19 s->next = NULL;
210 19 ▶ if (s->paused) { s->paused = 0; hm_stream_paused_n--; }
Branch: 1 branch
BranchTrueFalseTotal
if (s->paused) { s->paused = 0; hm_stream_paused_n--; } 1 18 19
211 19 hm_stream_live_n--;
212 19 }
213  
214 /* ---- the HTTP/2 half ---------------------------------------------------- */
215  
216 #ifdef HM_HAVE_NGHTTP2
217  
218 static hm_h2_stream *hm_stream_h2_st(hm_conn *c, int64_t sid) {
219 hm_h2_sess *s;
220 /*
221 # uncoverable branch true class:ignore_covered_err
222 # uncoverable condition left count:1 class:ignore_covered_err
223 # uncoverable condition left count:2 class:ignore_covered_err
224 # uncoverable condition left count:3 class:ignore_covered_err */
225 if (!c->h2 || sid < 0 || sid > 0x7fffffff) return NULL;
226 s = (hm_h2_sess *)c->h2;
227 return (hm_h2_stream *)nghttp2_session_get_stream_user_data(s->session,
228 (int32_t)sid);
229 }
230  
231 /* The body bytes this stream has been given and nghttp2 has not yet framed. */
232 static size_t hm_stream_h2_held(hm_conn *c, int64_t sid) {
233 hm_h2_stream *st = hm_stream_h2_st(c, sid);
234 STRLEN blen;
235 /*
236 # uncoverable branch true class:ignore_covered_err
237 # uncoverable condition left count:1 class:ignore_covered_err
238 # uncoverable condition left count:2 class:ignore_covered_err */
239 if (!st || !st->resp_body) return 0;
240 blen = SvCUR(st->resp_body);
241 return blen > st->resp_off ? (size_t)(blen - st->resp_off) : 0;
242 }
243  
244 /* Submit status + headers now, with a data provider that defers until there
245 * are bytes. hm_h2_submit_response already drops hop-by-hop names and hands
246 * the rest to nghttp2 as nghttp2_nv[], which is why headers travel as a list
247 * all the way down here instead of as a byte string. */
248 static int hm_stream_h2_begin(pTHX_ hm_conn *c, int64_t sid, int status,
249 SV *headers) {
250 hm_h2_sess *s = (hm_h2_sess *)c->h2;
251 hm_h2_stream *st = hm_stream_h2_st(c, sid);
252 AV *hav = (headers && SvROK(headers) && SvTYPE(SvRV(headers)) == SVt_PVAV)
253 ? (AV *)SvRV(headers) : NULL;
254 /*
255 # uncoverable branch true
256 # uncoverable condition left count:1 class:ignore_covered_err */
257 if (!st) return 0;
258 /*
259 # uncoverable branch true
260 # uncoverable condition left count:1 class:ignore_covered_err */
261 if (st->status) return 0; /* a response has already been submitted */
262 /*
263 # uncoverable branch true class:ignore_covered_err
264 # uncoverable condition left count:1 class:ignore_covered_err */
265 if (st->resp_body) { SvREFCNT_dec(st->resp_body); st->resp_body = NULL; }
266 hm_h2_src_free(aTHX_ st);
267 st->resp_body = newSVpvs("");
268 st->blen = 0;
269 st->producing = 1;
270 st->prod_done = 0;
271 hm_h2_submit_response(aTHX_ s, st, status, hav);
272 hm_h2_flush_send(aTHX_ s);
273 return 1;
274 }
275  
276 static int hm_stream_h2_feed(pTHX_ hm_conn *c, int64_t sid,
277 const char *buf, STRLEN len, int done) {
278 hm_h2_sess *s = (hm_h2_sess *)c->h2;
279 hm_h2_stream *st = hm_stream_h2_st(c, sid);
280 /*
281 # uncoverable branch true
282 # uncoverable condition left count:1 class:ignore_covered_err */
283 if (!st) return 0;
284 if (len) {
285 sv_catpvn(st->resp_body, buf, len);
286 st->blen += len;
287 c->loop->bytes_out += len;
288 }
289 if (done) st->prod_done = 1;
290 nghttp2_session_resume_data(s->session, (int32_t)sid);
291 hm_h2_flush_send(aTHX_ s);
292 return 1;
293 }
294  
295 /* Park trailers on a stream for hm_h2_body_end to send at EOF. This has to
296 * happen before the closing feed: that feed resumes the data provider, and
297 * the provider can reach EOF synchronously inside the flush. The list is
298 * owned from here on, and freed at once if the stream has already gone. */
299 static int hm_stream_h2_owe_trailers(pTHX_ hm_conn *c, int64_t sid, AV *trailers) {
300 hm_h2_stream *st = hm_stream_h2_st(c, sid);
301 /*
302 # uncoverable branch true
303 # uncoverable condition left count:1 class:ignore_covered_err */
304 if (!st) { SvREFCNT_dec((SV *)trailers); return 0; }
305 /*
306 # uncoverable branch true class:ignore_covered_err */
307 if (st->trailers_owed) SvREFCNT_dec((SV *)st->trailers_owed);
308 st->trailers_owed = trailers;
309 return 1;
310 }
311  
312 /* Kill one stream and leave the rest of the connection alone. INTERNAL_ERROR
313 * is the code for "the server failed", which is what an aborted producer is;
314 * a client that has already had the headers reports the response as
315 * incomplete rather than as a short success. */
316 static int hm_stream_h2_reset(pTHX_ hm_conn *c, int64_t sid) {
317 hm_h2_sess *s = (hm_h2_sess *)c->h2;
318 hm_h2_stream *st = hm_stream_h2_st(c, sid);
319 /*
320 # uncoverable branch true
321 # uncoverable condition left count:1 class:ignore_covered_err */
322 if (!st) return 0;
323 st->producing = 0; /* the data provider must stop deferring */
324 st->prod_done = 1;
325 nghttp2_submit_rst_stream(s->session, NGHTTP2_FLAG_NONE, (int32_t)sid,
326 NGHTTP2_INTERNAL_ERROR);
327 hm_h2_flush_send(aTHX_ s);
328 return 1;
329 }
330  
331 /* What an Extended CONNECT stream was sent before its read half existed.
332 * Requests are dispatched after nghttp2_session_mem_recv returns, so a DATA
333 * frame read in the same burst as the CONNECT headers is parsed first, and
334 * with no handle to take it, it was buffered as the request body. Handed
335 * over, owned by the caller, and the stream forgets it. Not while the
336 * stream's handler is still running: it has not wired its events yet, and
337 * hm_h2_dispatch hands the bytes over when it returns. */
338 static SV *hm_stream_h2_take_early(pTHX_ hm_conn *c, int64_t sid) {
339 hm_h2_stream *st = hm_stream_h2_st(c, sid);
340 SV *b;
341 PERL_UNUSED_CONTEXT;
342 /*
343 # uncoverable condition left count:1 class:ignore_covered_err
344 # uncoverable condition left count:2 class:ignore_covered_err
345 # uncoverable condition left count:3 class:ignore_covered_err
346 # uncoverable condition left count:5 class:ignore_covered_err */
347 if (!st || !st->tunnel || st->in_app
348 || !st->body || !SvCUR(st->body)) return NULL;
349 b = st->body;
350 st->body = NULL;
351 return b;
352 }
353  
354 #else /* !HM_HAVE_NGHTTP2: there is no h2 transport to branch to */
355  
356 0 static int hm_stream_h2_begin(pTHX_ hm_conn *c, int64_t sid, int status,
357 SV *headers) {
358 PERL_UNUSED_CONTEXT;
359 (void)c; (void)sid; (void)status; (void)headers;
360 0 return 0;
361 }
362 0 static int hm_stream_h2_feed(pTHX_ hm_conn *c, int64_t sid,
363 const char *buf, STRLEN len, int done) {
364 PERL_UNUSED_CONTEXT;
365 (void)c; (void)sid; (void)buf; (void)len; (void)done;
366 0 return 0;
367 }
368 0 static int hm_stream_h2_reset(pTHX_ hm_conn *c, int64_t sid) {
369 PERL_UNUSED_CONTEXT;
370 (void)c; (void)sid;
371 0 return 0;
372 }
373 0 static SV *hm_stream_h2_take_early(pTHX_ hm_conn *c, int64_t sid) {
374 PERL_UNUSED_CONTEXT;
375 (void)c; (void)sid;
376 0 return NULL;
377 }
378 0 static int hm_stream_h2_owe_trailers(pTHX_ hm_conn *c, int64_t sid, AV *trailers) {
379 (void)c; (void)sid;
380 0 SvREFCNT_dec((SV *)trailers);
381 0 return 0;
382 }
383 0 static size_t hm_stream_h2_held(hm_conn *c, int64_t sid) {
384 (void)c; (void)sid;
385 0 return 0;
386 }
387  
388 #endif /* HM_HAVE_NGHTTP2 */
389  
390 /* psgix.hyperman.stream -> (fd, generation, stream id). 1 if the env carried
391 * a well-formed ticket. Shared by the two doors so they cannot drift. */
392 22 static int hm_stream_ticket(pTHX_ SV *env, int *fd, UV *id, int64_t *sid) {
393 HV *ehv;
394 AV *tick;
395 SV **e, **fsv, **isv, **ssv;
396 /*
397 # uncoverable branch true class:ignore_covered_err
398 # uncoverable condition left count:1 class:ignore_covered_err
399 # uncoverable condition left count:2 class:ignore_covered_err
400 # uncoverable condition left count:3 class:ignore_covered_err */
401 22 ▶ if (!(env && SvROK(env) && SvTYPE(SvRV(env)) == SVt_PVHV)) return 0;
Branch: 3 branches
BranchTrueFalseTotal
if (!(env && SvROK(env) && SvTYPE(SvRV(env)) == SVt_PVHV)) return 0; 22 0 22
if (!(env && SvROK(env) && SvTYPE(SvRV(env)) == SVt_PVHV)) return 0; 22 0 22
if (!(env && SvROK(env) && SvTYPE(SvRV(env)) == SVt_PVHV)) return 0; 0 22 22
402 22 ehv = (HV *)SvRV(env);
403 22 e = hv_fetchs(ehv, "psgix.hyperman.stream", 0);
404 /*
405 # uncoverable condition left count:2 class:ignore_covered_err
406 # uncoverable condition left count:3 class:ignore_covered_err
407 # uncoverable condition left count:4 class:ignore_covered_err */
408 22 ▶ if (!(e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVAV)) return 0;
Branch: 4 branches
BranchTrueFalseTotal
if (!(e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVAV)) return 0; 21 1 22
if (!(e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVAV)) return 0; 21 0 21
if (!(e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVAV)) return 0; 21 0 21
if (!(e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVAV)) return 0; 0 21 21
409 21 tick = (AV *)SvRV(*e);
410 21 fsv = av_fetch(tick, 0, 0);
411 21 isv = av_fetch(tick, 1, 0);
412 21 ssv = av_fetch(tick, 2, 0);
413 /*
414 # uncoverable branch true class:ignore_covered_err
415 # uncoverable condition left count:1 class:ignore_covered_err
416 # uncoverable condition left count:2 class:ignore_covered_err
417 # uncoverable condition left count:3 class:ignore_covered_err
418 # uncoverable condition left count:4 class:ignore_covered_err */
419 21 ▶ if (!(fsv && *fsv && isv && *isv)) return 0;
Branch: 4 branches
BranchTrueFalseTotal
if (!(fsv && *fsv && isv && *isv)) return 0; 21 0 21
if (!(fsv && *fsv && isv && *isv)) return 0; 21 0 21
if (!(fsv && *fsv && isv && *isv)) return 0; 21 0 21
if (!(fsv && *fsv && isv && *isv)) return 0; 0 21 21
420 21 *fd = (int)SvIV(*fsv);
421 21 *id = SvUV(*isv);
422 /*
423 # uncoverable condition right count:1 class:ignore_covered_err
424 # uncoverable condition right count:2 class:ignore_covered_err */
425 21 ▶ *sid = (ssv && *ssv) ? (int64_t)SvIV(*ssv) : -1;
Branch: 2 branches
BranchTrueFalseTotal
*sid = (ssv && *ssv) ? (int64_t)SvIV(*ssv) : -1; 21 0 21
*sid = (ssv && *ssv) ? (int64_t)SvIV(*ssv) : -1; 21 0 21
426 21 return 1;
427 }
428  
429 /* ---- the entry points behind the ABI table ------------------------------ */
430  
431 22 static void *hm_stream_open(pTHX_ void *vl, int fd, UV id, int64_t sid,
432 int status, SV *headers) {
433 22 ▶ hm_loop *loop = vl ? (hm_loop *)vl : hm_cur_loop; /* # uncoverable condition right count:1 class:ignore_covered_err */
Branch: 1 branch
BranchTrueFalseTotal
hm_loop *loop = vl ? (hm_loop *)vl : hm_cur_loop; /* # uncoverable condition right count:1 class:ignore_covered_err */ 22 0 22
434 /*
435 # uncoverable condition right count:1 class:ignore_covered_err
436 # uncoverable condition right count:2 class:ignore_covered_err
437 # uncoverable condition right count:3 class:ignore_covered_err */
438 22 ▶ hm_conn *c = (loop && fd >= 0 && fd < HM_MAXFD) ? loop->conns[fd] : NULL;
Branch: 3 branches
BranchTrueFalseTotal
hm_conn *c = (loop && fd >= 0 && fd < HM_MAXFD) ? loop->conns[fd] : NULL; 22 0 22
hm_conn *c = (loop && fd >= 0 && fd < HM_MAXFD) ? loop->conns[fd] : NULL; 22 0 22
hm_conn *c = (loop && fd >= 0 && fd < HM_MAXFD) ? loop->conns[fd] : NULL; 22 0 22
439 hm_stream *s;
440 /*
441 # uncoverable condition left count:2 class:ignore_covered_err
442 # uncoverable condition left count:3 class:ignore_covered_err */
443 22 ▶ if (!(c && c->id == id) || c->detached) return NULL;
Branch: 3 branches
BranchTrueFalseTotal
if (!(c && c->id == id) || c->detached) return NULL; 20 2 22
if (!(c && c->id == id) || c->detached) return NULL; 20 0 20
if (!(c && c->id == id) || c->detached) return NULL; 0 20 20
444 20 ▶ if (sid >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (sid >= 0) { 0 20 20
445 /*
446 # uncoverable branch true
447 # uncoverable condition left count:1 class:ignore_covered_err */
448 0 ▶ if (!c->h2) return NULL; /* not a multiplexed conn */
Branch: 1 branch
BranchTrueFalseTotal
if (!c->h2) return NULL; /* not a multiplexed conn */ 0 0 0
449 /*
450 # uncoverable branch true
451 # uncoverable condition left count:1 class:ignore_covered_err */
452 0 ▶ if (!hm_stream_h2_begin(aTHX_ c, sid, status, headers)) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!hm_stream_h2_begin(aTHX_ c, sid, status, headers)) return NULL; 0 0 0
453 } else {
454 /*
455 # uncoverable branch true
456 # uncoverable condition left count:1 class:ignore_covered_err */
457 20 ▶ if (c->h2) return NULL; /* h2 needs a stream id */
Branch: 1 branch
BranchTrueFalseTotal
if (c->h2) return NULL; /* h2 needs a stream id */ 0 20 20
458 /* The response has to be deferred already - a psgi.streaming
459 * coderef, or a handler parked on a Future. A synchronous handler's
460 * return value is still coming, and it would be serialised on top of
461 * the body being streamed here; refusing is the only honest answer,
462 * and it is one the caller can act on.
463 *
464 * Except for a 101. An upgrade has no body for a return value to
465 * land on top of: the connection becomes a tunnel (c->tunnel),
466 * hm_process drops what the handler returns exactly as it drops the
467 * sentinel a detach leaves, and what the peer sends from here on
468 * goes to the handle's read half. That is what lets a WebSocket run
469 * over TLS, which conn_detach refuses. */
470 20 ▶ if (!c->awaiting && status != 101) return NULL;
Branch: 2 branches
BranchTrueFalseTotal
if (!c->awaiting && status != 101) return NULL; 7 13 20
if (!c->awaiting && status != 101) return NULL; 1 6 7
471 /*
472 # uncoverable branch true
473 # uncoverable condition left count:1 class:ignore_covered_err */
474 19 ▶ if (c->stream_open) return NULL; /* one response per request */
Branch: 1 branch
BranchTrueFalseTotal
if (c->stream_open) return NULL; /* one response per request */ 0 19 19
475 19 ▶ if (status == 101) {
Branch: 1 branch
BranchTrueFalseTotal
if (status == 101) { 9 10 19
476 /* Parked before the headers go out: keepalive is off, and a
477 * flush on a connection that is neither keeping alive nor
478 * parked closes it as soon as it drains. 2 marks a tunnel
479 * opened inside the handler, whose request is still on the
480 * parser's plate; hm_process finishes with it and makes it 1. */
481 9 ▶ c->tunnel = c->awaiting ? 1 : 2;
Branch: 1 branch
BranchTrueFalseTotal
c->tunnel = c->awaiting ? 1 : 2; 3 6 9
482 9 c->awaiting = 1;
483 }
484 /*
485 # uncoverable branch true
486 # uncoverable condition left count:1 class:ignore_covered_err */
487 19 ▶ if (hm_start_stream(aTHX_ fd, id, status, headers) <= 0) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (hm_start_stream(aTHX_ fd, id, status, headers) <= 0) return NULL; 0 19 19
488 }
489 /*
490 # uncoverable branch true
491 # uncoverable condition left count:1 class:ignore_covered_err */
492 19 ▶ if (loop->conns[fd] != c) return NULL; /* the flush closed it */
Branch: 1 branch
BranchTrueFalseTotal
if (loop->conns[fd] != c) return NULL; /* the flush closed it */ 0 19 19
493 19 s = (hm_stream *)hm_xcalloc(1, sizeof(hm_stream));
494 19 s->serial = ++hm_stream_serials;
495 19 s->loop = loop;
496 19 s->fd = fd;
497 19 s->cid = id;
498 19 s->sid = sid;
499 19 s->kind = sid >= 0 ? HM_STREAM_H2 : HM_STREAM_H1;
500 19 s->next = hm_streams;
501 19 hm_streams = s;
502 19 hm_stream_live_n++;
503 19 return (void *)s;
504 }
505  
506 /* Backpressure is measured on the connection's unwritten output, which is
507 * the same quantity on both transports: for h2 nghttp2 has already framed
508 * what it could and the rest is sitting in the same wbuf. */
509 2074 static int hm_stream_pressure(hm_stream *s, hm_conn *c) {
510 2074 ▶ if (hm_stream_held(s, c) <= (size_t)HM_ABI_STREAM_HIWAT)
Branch: 1 branch
BranchTrueFalseTotal
if (hm_stream_held(s, c) <= (size_t)HM_ABI_STREAM_HIWAT) 1384 690 2074
511 1384 return HM_ABI_STREAM_OK;
512 /*
513 # uncoverable branch false class:ignore_covered_err
514 # uncoverable condition right count:1 class:ignore_covered_err */
515 690 ▶ if (!s->paused) { s->paused = 1; hm_stream_paused_n++; }
Branch: 1 branch
BranchTrueFalseTotal
if (!s->paused) { s->paused = 1; hm_stream_paused_n++; } 690 0 690
516 690 return HM_ABI_STREAM_FULL;
517 }
518  
519 2077 static int hm_stream_write_h(pTHX_ void *h, const char *buf, STRLEN len) {
520 2077 hm_stream *s = hm_stream_of(h);
521 hm_conn *c;
522 2077 ▶ if (!s) return HM_ABI_STREAM_STALE;
Branch: 1 branch
BranchTrueFalseTotal
if (!s) return HM_ABI_STREAM_STALE; 2 2075 2077
523 /*
524 # uncoverable branch true class:ignore_covered_err
525 # uncoverable condition left count:1 class:ignore_covered_err
526 # uncoverable condition left count:2 class:ignore_covered_err
527 # uncoverable condition right count:2 class:ignore_covered_err */
528 2075 ▶ if (!buf && len) return HM_ABI_STREAM_ARG;
Branch: 2 branches
BranchTrueFalseTotal
if (!buf && len) return HM_ABI_STREAM_ARG; 0 2075 2075
if (!buf && len) return HM_ABI_STREAM_ARG; 0 0 0
529 2075 ▶ if (s->dead) return HM_ABI_STREAM_GONE;
Branch: 1 branch
BranchTrueFalseTotal
if (s->dead) return HM_ABI_STREAM_GONE; 1 2074 2075
530 2074 c = hm_stream_conn(s);
531 /*
532 # uncoverable branch true
533 # uncoverable condition left count:1 class:ignore_covered_err */
534 2074 ▶ if (!c) { hm_stream_mark_dead(s); return HM_ABI_STREAM_GONE; }
Branch: 1 branch
BranchTrueFalseTotal
if (!c) { hm_stream_mark_dead(s); return HM_ABI_STREAM_GONE; } 0 2074 2074
535 2074 ▶ if (s->kind == HM_STREAM_H2) {
Branch: 1 branch
BranchTrueFalseTotal
if (s->kind == HM_STREAM_H2) { 0 2074 2074
536 /*
537 # uncoverable branch true
538 # uncoverable condition left count:1 class:ignore_covered_err */
539 0 ▶ if (!hm_stream_h2_feed(aTHX_ c, s->sid, buf, len, 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!hm_stream_h2_feed(aTHX_ c, s->sid, buf, len, 0)) { 0 0 0
540 0 hm_stream_mark_dead(s); /* # uncoverable statement */
541 0 return HM_ABI_STREAM_GONE; /* # uncoverable statement */
542 }
543 /*
544 # uncoverable branch false class:ignore_covered_err
545 # uncoverable condition right count:1 class:ignore_covered_err */
546 2074 ▶ } else if (len) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (len) { 2074 0 2074
547 /* The same framing the Writer gets (chunked, counted or raw): one
548 * function decides, so a handle and a writer on the same connection
549 * cannot disagree. */
550 /*
551 # uncoverable branch false class:ignore_covered_err
552 # uncoverable condition right count:1 class:ignore_covered_err */
553 2074 ▶ if (hm_stream_body_put(aTHX_ c, buf, len)) hm_flush(aTHX_ c);
Branch: 1 branch
BranchTrueFalseTotal
if (hm_stream_body_put(aTHX_ c, buf, len)) hm_flush(aTHX_ c); 2074 0 2074
554 }
555 /* Either flush can close the connection; re-read it rather than trusting
556 * the pointer we came in with. */
557 2074 c = hm_stream_conn(s);
558 /*
559 # uncoverable branch true
560 # uncoverable condition left count:1 class:ignore_covered_err */
561 2074 ▶ if (!c) { hm_stream_mark_dead(s); return HM_ABI_STREAM_GONE; }
Branch: 1 branch
BranchTrueFalseTotal
if (!c) { hm_stream_mark_dead(s); return HM_ABI_STREAM_GONE; } 0 2074 2074
562 2074 return hm_stream_pressure(s, c);
563 }
564  
565 /* End the body behind a handle. `trailers` is a list from hm_trailers_build
566 * or NULL, and is consumed on every path, stale handle and dead connection
567 * included, so no caller has to track what became of it. */
568 19 static int hm_stream_finish_h(pTHX_ void *h, AV *trailers) {
569 19 hm_stream *s = hm_stream_of(h);
570 hm_conn *c;
571 19 int r = HM_ABI_STREAM_OK;
572 19 ▶ if (!s) {
Branch: 1 branch
BranchTrueFalseTotal
if (!s) { 2 17 19
573 2 ▶ if (trailers) SvREFCNT_dec((SV *)trailers);
Branch: 1 branch
BranchTrueFalseTotal
if (trailers) SvREFCNT_dec((SV *)trailers); 1 1 2
574 2 return HM_ABI_STREAM_STALE;
575 }
576 17 ▶ c = s->dead ? NULL : hm_stream_conn(s);
Branch: 1 branch
BranchTrueFalseTotal
c = s->dead ? NULL : hm_stream_conn(s); 16 1 17
577 17 hm_stream_unlink(s);
578 17 ▶ if (!c) r = HM_ABI_STREAM_GONE;
Branch: 1 branch
BranchTrueFalseTotal
if (!c) r = HM_ABI_STREAM_GONE; 1 16 17
579 16 ▶ else if (s->kind == HM_STREAM_H2) {
Branch: 1 branch
BranchTrueFalseTotal
else if (s->kind == HM_STREAM_H2) { 0 16 16
580 0 ▶ if (trailers) {
Branch: 1 branch
BranchTrueFalseTotal
if (trailers) { 0 0 0
581 0 (void)hm_stream_h2_owe_trailers(aTHX_ c, s->sid, trailers);
582 0 trailers = NULL;
583 }
584 /*
585 # uncoverable branch true class:ignore_covered_err
586 # uncoverable condition left count:1 class:ignore_covered_err */
587 0 ▶ if (!hm_stream_h2_feed(aTHX_ c, s->sid, NULL, 0, 1))
Branch: 1 branch
BranchTrueFalseTotal
if (!hm_stream_h2_feed(aTHX_ c, s->sid, NULL, 0, 1)) 0 0 0
588 0 r = HM_ABI_STREAM_GONE; /* # uncoverable statement */
589 } else {
590 16 hm_stream_finish(aTHX_ s->fd, s->cid, 0, trailers); /* borrows */
591 }
592 17 ▶ if (trailers) SvREFCNT_dec((SV *)trailers);
Branch: 1 branch
BranchTrueFalseTotal
if (trailers) SvREFCNT_dec((SV *)trailers); 0 17 17
593 17 free(s);
594 17 return r;
595 }
596  
597 15 static int hm_stream_close_h(pTHX_ void *h) {
598 15 return hm_stream_finish_h(aTHX_ h, NULL);
599 }
600  
601 /* The v10 table entry. Liveness first, so a pointer that is not a handle is
602 * STALE whatever travels with it and is never looked at. Then the list, so
603 * a refused list leaves a live handle open and the caller's (hm_abi.h): a
604 * body is not ended by a list that was never going to be sent. */
605 3 static int hm_abi_stream_close_trailers(pTHX_ void *h, SV *given) {
606 SV *err;
607 AV *trailers;
608 3 ▶ if (!hm_stream_of(h)) return HM_ABI_STREAM_STALE;
Branch: 1 branch
BranchTrueFalseTotal
if (!hm_stream_of(h)) return HM_ABI_STREAM_STALE; 3 0 3
609 0 trailers = hm_trailers_build(aTHX_ given, &err);
610 0 ▶ if (err) return HM_ABI_STREAM_ARG; /* a mortal, freed with the scope */
Branch: 1 branch
BranchTrueFalseTotal
if (err) return HM_ABI_STREAM_ARG; /* a mortal, freed with the scope */ 0 0 0
611 0 return hm_stream_finish_h(aTHX_ h, trailers);
612 }
613  
614 /* The other ending: stop the body in a way the peer can tell apart from
615 * having finished. See stream_abort in hm_abi.h for why a clean close is the
616 * wrong answer for a producer that failed.
617 *
618 * Unlinked before anything is sent, for the same reason stream_close is:
619 * resetting fires the machinery that reports a stream as gone, and a handle
620 * deliberately ending must not be told its stream went away. */
621 4 static int hm_stream_abort_h(pTHX_ void *h) {
622 4 hm_stream *s = hm_stream_of(h);
623 hm_conn *c;
624 4 int r = HM_ABI_STREAM_OK;
625 4 ▶ if (!s) return HM_ABI_STREAM_STALE;
Branch: 1 branch
BranchTrueFalseTotal
if (!s) return HM_ABI_STREAM_STALE; 2 2 4
626 2 ▶ c = s->dead ? NULL : hm_stream_conn(s); /* # uncoverable condition right count:1 class:ignore_covered_err */
Branch: 1 branch
BranchTrueFalseTotal
c = s->dead ? NULL : hm_stream_conn(s); /* # uncoverable condition right count:1 class:ignore_covered_err */ 2 0 2
627 2 hm_stream_unlink(s);
628 /*
629 # uncoverable branch true
630 # uncoverable condition left count:1 class:ignore_covered_err */
631 2 ▶ if (!c) r = HM_ABI_STREAM_GONE;
Branch: 1 branch
BranchTrueFalseTotal
if (!c) r = HM_ABI_STREAM_GONE; 0 2 2
632 2 ▶ else if (s->kind == HM_STREAM_H2) {
Branch: 1 branch
BranchTrueFalseTotal
else if (s->kind == HM_STREAM_H2) { 0 2 2
633 /*
634 # uncoverable branch true class:ignore_covered_err
635 # uncoverable condition left count:1 class:ignore_covered_err */
636 0 ▶ if (!hm_stream_h2_reset(aTHX_ c, s->sid)) r = HM_ABI_STREAM_GONE;
Branch: 1 branch
BranchTrueFalseTotal
if (!hm_stream_h2_reset(aTHX_ c, s->sid)) r = HM_ABI_STREAM_GONE; 0 0 0
637 }
638 else {
639 /* An EOF-delimited body ends at the close, so a graceful close is
640 * indistinguishable from success and a reset is the only signal
641 * left. SO_LINGER with a zero timeout is what turns close(2) into
642 * an RST; queued output goes with it, which is the cost of being
643 * able to say the response is not to be trusted. Where the host's
644 * TCP ignores a zero linger (Cygwin, GNU/Hurd) the peer gets a FIN,
645 * and there is nothing else to send: t/41 probes the host before
646 * asserting the reset. */
647 struct linger lg;
648 2 lg.l_onoff = 1;
649 2 lg.l_linger = 0;
650 2 (void)hm_os_setsockopt(s->fd, SOL_SOCKET, SO_LINGER, &lg,
651 (socklen_t)sizeof lg);
652 2 c->keepalive = 0;
653 2 c->awaiting = 0; /* it is not waiting for a response any more */
654 2 hm_close(aTHX_ s->loop, c);
655 }
656 2 free(s);
657 2 return r;
658 }
659  
660 15 static int hm_stream_on_drain(pTHX_ void *h, hm_abi_stream_cb cb, void *ud) {
661 15 hm_stream *s = hm_stream_of(h);
662 PERL_UNUSED_CONTEXT;
663 15 ▶ if (!s) return HM_ABI_STREAM_STALE;
Branch: 1 branch
BranchTrueFalseTotal
if (!s) return HM_ABI_STREAM_STALE; 1 14 15
664 14 s->drain_cb = cb;
665 14 s->drain_ud = ud;
666 14 return HM_ABI_STREAM_OK;
667 }
668  
669 9 static int hm_stream_on_data(pTHX_ void *h, hm_abi_stream_data_cb cb, void *ud) {
670 9 hm_stream *s = hm_stream_of(h);
671 /*
672 # uncoverable branch true
673 # uncoverable condition left count:1 class:ignore_covered_err */
674 9 ▶ if (!s) return HM_ABI_STREAM_STALE;
Branch: 1 branch
BranchTrueFalseTotal
if (!s) return HM_ABI_STREAM_STALE; 0 9 9
675 9 s->data_cb = cb;
676 9 s->data_ud = ud;
677 /* A settled HTTP/1.1 tunnel (tunnel == 1) may already hold bytes the
678 * peer sent before the read half was registered - which is the norm on
679 * the deferred path, where the request line is already consumed and only
680 * the post-upgrade payload is left in rbuf. Hand them over now rather
681 * than wait for the peer to send again. NOT tunnel == 2: there the
682 * request headers are still in rbuf, and hm_process delivers the
683 * leftover once it has stripped them. Cleared first - the callback may
684 * close the stream, and with it the connection. */
685 /*
686 # uncoverable condition right count:1 class:ignore_covered_err
687 # uncoverable condition right count:3 class:ignore_covered_err */
688 18 ▶ if (cb && s->kind == HM_STREAM_H1 && !s->dead) {
Branch: 3 branches
BranchTrueFalseTotal
if (cb && s->kind == HM_STREAM_H1 && !s->dead) { 9 0 9
if (cb && s->kind == HM_STREAM_H1 && !s->dead) { 9 0 9
if (cb && s->kind == HM_STREAM_H1 && !s->dead) { 9 0 9
689 9 hm_conn *c = hm_stream_conn(s);
690 /*
691 # uncoverable condition right count:1 class:ignore_covered_err
692 # uncoverable condition right count:3 class:ignore_covered_err */
693 9 ▶ if (c && c->tunnel == 1 && c->rlen) {
Branch: 3 branches
BranchTrueFalseTotal
if (c && c->tunnel == 1 && c->rlen) { 9 0 9
if (c && c->tunnel == 1 && c->rlen) { 3 6 9
if (c && c->tunnel == 1 && c->rlen) { 3 0 3
694 3 size_t n = c->rlen;
695 3 c->rlen = 0;
696 3 cb(aTHX_ (void *)s, c->rbuf, n, 0, ud);
697 }
698 }
699 /* The h2 counterpart of tunnel == 1: a handle opened after the handler
700 * returned (it parked on a Future) takes what the stream was sent
701 * before it. A handle opened inside the handler gets its bytes from
702 * hm_h2_dispatch once the handler has returned. */
703 /*
704 # uncoverable branch false class:ignore_covered_err
705 # uncoverable condition right count:1 class:ignore_covered_err
706 # uncoverable condition right count:2 class:ignore_covered_err
707 # uncoverable condition right count:3 class:ignore_covered_err */
708 0 ▶ else if (cb && s->kind == HM_STREAM_H2 && !s->dead) {
Branch: 3 branches
BranchTrueFalseTotal
else if (cb && s->kind == HM_STREAM_H2 && !s->dead) { 0 0 0
else if (cb && s->kind == HM_STREAM_H2 && !s->dead) { 0 0 0
else if (cb && s->kind == HM_STREAM_H2 && !s->dead) { 0 0 0
709 0 hm_conn *c = hm_stream_conn(s);
710 0 ▶ SV *b = c ? hm_stream_h2_take_early(aTHX_ c, s->sid) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */
Branch: 1 branch
BranchTrueFalseTotal
SV *b = c ? hm_stream_h2_take_early(aTHX_ c, s->sid) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */ 0 0 0
711 0 ▶ if (b) {
Branch: 1 branch
BranchTrueFalseTotal
if (b) { 0 0 0
712 0 cb(aTHX_ (void *)s, SvPVX(b), SvCUR(b), 0, ud);
713 0 SvREFCNT_dec(b);
714 }
715 }
716 9 return HM_ABI_STREAM_OK;
717 }
718  
719 /* Request bytes for a stream, if a handle on it wants them. 1 when one took
720 * them, so the transport knows not to buffer into psgi.input as well - a
721 * tunnelled stream never ends, and buffering it would grow forever.
722 *
723 * Looked up by (fd, generation, stream id) rather than held on the h2/h3
724 * stream, so the transports need to know nothing about handles. */
725 12 static int hm_stream_deliver(pTHX_ int fd, UV cid, int64_t sid,
726 const char *buf, STRLEN len, int fin) {
727 hm_stream *s;
728 12 ▶ if (!hm_stream_live_n) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (!hm_stream_live_n) return 0; 0 12 12
729 12 ▶ for (s = hm_streams; s; s = s->next) {
Branch: 1 branch
BranchTrueFalseTotal
for (s = hm_streams; s; s = s->next) { 12 0 12
730 /*
731 # uncoverable condition right count:1 class:ignore_covered_err
732 # uncoverable condition right count:3 class:ignore_covered_err
733 # uncoverable condition right count:4 class:ignore_covered_err */
734 12 ▶ if (s->fd == fd && s->cid == cid && s->sid == sid && s->data_cb) {
Branch: 4 branches
BranchTrueFalseTotal
if (s->fd == fd && s->cid == cid && s->sid == sid && s->data_cb) { 12 0 12
if (s->fd == fd && s->cid == cid && s->sid == sid && s->data_cb) { 12 0 12
if (s->fd == fd && s->cid == cid && s->sid == sid && s->data_cb) { 12 0 12
if (s->fd == fd && s->cid == cid && s->sid == sid && s->data_cb) { 12 0 12
735 12 hm_abi_stream_data_cb cb = s->data_cb;
736 12 void *ud = s->data_ud;
737 12 cb(aTHX_ (void *)s, buf, len, fin, ud);
738 12 return 1;
739 }
740 }
741 0 return 0;
742 }
743  
744 15 static int hm_stream_on_abort(pTHX_ void *h, hm_abi_stream_cb cb, void *ud) {
745 15 hm_stream *s = hm_stream_of(h);
746 15 ▶ if (!s) return HM_ABI_STREAM_STALE;
Branch: 1 branch
BranchTrueFalseTotal
if (!s) return HM_ABI_STREAM_STALE; 1 14 15
747 14 s->abort_cb = cb;
748 14 s->abort_ud = ud;
749 /* Already dead: fire now rather than never. Same contract as
750 * future_on_ready on a settled future - registering after the event is
751 * not a way to miss it. */
752 /*
753 # uncoverable branch true class:ignore_covered_err
754 # uncoverable condition left count:1 class:ignore_covered_err
755 # uncoverable condition right count:1 class:ignore_covered_err
756 # uncoverable condition left count:2 class:ignore_covered_err
757 # uncoverable condition left count:3 class:ignore_covered_err
758 # uncoverable condition right count:3 class:ignore_covered_err */
759 14 ▶ if (cb && s->dead && !s->aborted) {
Branch: 3 branches
BranchTrueFalseTotal
if (cb && s->dead && !s->aborted) { 14 0 14
if (cb && s->dead && !s->aborted) { 0 14 14
if (cb && s->dead && !s->aborted) { 0 0 0
760 0 s->aborted = 1; /* # uncoverable statement */
761 0 cb(aTHX_ (void *)s, ud); /* # uncoverable statement */
762 }
763 14 return HM_ABI_STREAM_OK;
764 }
765  
766 #endif /* HM_STREAM_H */
« include/hyperman/hm_quic.h ↑ Summary include/hyperman/hm_sa.h »