feersum_conn.xs

filter: Statementstmt 70.9% 356 / 502 Branchbran 56.8% 308 / 542 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 63.6% 664 / 1044 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« feersum_tls.c.inc ↑ Summary feersum_core.c.inc »
1 MODULE = Feersum PACKAGE = Feersum::Connection::Handle
2  
3 PROTOTYPES: ENABLE
4  
5 int
6 fileno (feer_conn_handle *hdl)
7 CODE:
8 63 ▶ RETVAL = c->fd;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = c->fd; 61 2 63
9 OUTPUT:
10 RETVAL
11  
12 SV*
13 read (feer_conn_handle *hdl, SV *buf, size_t len, ...)
14 PROTOTYPE: $$$;$
15 PPCODE:
16 {
17 283 STRLEN buf_len = 0, src_len = 0;
18 ssize_t offset;
19 283 char *src_ptr = NULL;
20  
21 283 ▶ if (unlikely(items == 4) && SvOK(ST(3)) && SvIOK(ST(3)))
Branch: 3 branches
BranchTrueFalseTotal
if (unlikely(items == 4) && SvOK(ST(3)) && SvIOK(ST(3))) 2 281 283
if (unlikely(items == 4) && SvOK(ST(3)) && SvIOK(ST(3))) 2 0 2
if (unlikely(items == 4) && SvOK(ST(3)) && SvIOK(ST(3))) 2 0 2
22 2 offset = SvIV(ST(3));
23 else
24 281 offset = 0;
25  
26 trace("read fd=%d : request len=%"Sz_uf" off=%"Ssz_df"\n",
27 c->fd, (Sz)len, (Ssz)offset);
28  
29 283 ▶ if (unlikely(c->receiving <= RECEIVE_HEADERS))
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely(c->receiving <= RECEIVE_HEADERS)) 0 283 283
30 0 croak("can't call read() until the body begins to arrive");
31  
32 283 ▶ if (!SvPOK(buf)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvPOK(buf)) { 10 273 283
33 10 sv_setpvn(buf,"",0);
34 10 ▶ SvGROW(buf, len+1);
Branch: 2 branches
BranchTrueFalseTotal
SvGROW(buf, len+1); 10 0 10
SvGROW(buf, len+1); 6 4 10
35 }
36  
37 283 ▶ if (unlikely(SvREADONLY(buf)))
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely(SvREADONLY(buf))) 0 283 283
38 0 croak("buffer must not be read-only");
39  
40 283 ▶ if (unlikely(len == 0))
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely(len == 0)) 3 280 283
41 3 XSRETURN_IV(0); // assumes undef buffer got allocated to empty-string
42  
43 (void)SvPV(buf, buf_len);
44 280 ▶ if (likely(c->rbuf))
Branch: 1 branch
BranchTrueFalseTotal
if (likely(c->rbuf)) 277 3 280
45 554 src_ptr = SvPV(c->rbuf, src_len);
46  
47 280 ▶ if (unlikely(offset < 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely(offset < 0)) { 1 279 280
48 /* add rather than negate: -offset is UB at IV_MIN */
49 1 offset += c->received_cl;
50 1 ▶ if (offset < 0) offset = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (offset < 0) offset = 0; 0 1 1
51 }
52  
53 280 ▶ if (unlikely(offset > (ssize_t)src_len))
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely(offset > (ssize_t)src_len)) 0 280 280
54 0 offset = src_len;
55  
56 /* clamp before adding: len is a size_t, so len + offset can wrap under src_len */
57 280 ▶ if (unlikely(len > src_len))
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely(len > src_len)) 40 240 280
58 40 len = src_len;
59  
60 280 ▶ if (unlikely(len + offset > src_len))
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely(len + offset > src_len)) 1 279 280
61 1 len = src_len - offset;
62  
63 // never read past the body into a pipelined request; a definite length,
64 // not a positive one (Content-Length: 0 must clamp too). body_framed
65 // keeps a streaming connection, where the app owns every byte, out
66 280 ▶ if (c->expected_cl > 0
Branch: 1 branch
BranchTrueFalseTotal
if (c->expected_cl > 0 16 264 280
67 16 ▶ || (c->body_framed && c->receiving == RECEIVE_SHUTDOWN)) {
Branch: 2 branches
BranchTrueFalseTotal
|| (c->body_framed && c->receiving == RECEIVE_SHUTDOWN)) { 16 0 16
|| (c->body_framed && c->receiving == RECEIVE_SHUTDOWN)) { 16 0 16
68 280 ssize_t consumed = c->received_cl - (ssize_t)src_len;
69 280 ssize_t remaining_body = c->expected_cl - consumed - offset;
70 280 ▶ if (remaining_body <= 0)
Branch: 1 branch
BranchTrueFalseTotal
if (remaining_body <= 0) 25 255 280
71 25 XSRETURN_IV(0);
72 255 ▶ if ((ssize_t)len > remaining_body)
Branch: 1 branch
BranchTrueFalseTotal
if ((ssize_t)len > remaining_body) 1 254 255
73 1 len = (size_t)remaining_body;
74 }
75  
76 trace("read fd=%d : normalized len=%"Sz_uf" off=%"Ssz_df" src_len=%"Sz_uf"\n",
77 c->fd, (Sz)len, (Ssz)offset, (Sz)src_len);
78  
79 255 ▶ if (unlikely(!c->rbuf || src_len == 0 || offset >= c->received_cl)) {
Branch: 4 branches
BranchTrueFalseTotal
if (unlikely(!c->rbuf || src_len == 0 || offset >= c->received_cl)) { 255 0 255
if (unlikely(!c->rbuf || src_len == 0 || offset >= c->received_cl)) { 0 255 255
if (unlikely(!c->rbuf || src_len == 0 || offset >= c->received_cl)) { 255 0 255
if (unlikely(!c->rbuf || src_len == 0 || offset >= c->received_cl)) { 0 255 255
80 trace2("rbuf empty during read %d\n", c->fd);
81 0 ▶ if (c->receiving == RECEIVE_SHUTDOWN) {
Branch: 1 branch
BranchTrueFalseTotal
if (c->receiving == RECEIVE_SHUTDOWN) { 0 0 0
82 0 XSRETURN_IV(0);
83 }
84 else {
85 0 errno = EAGAIN;
86 0 XSRETURN_UNDEF;
87 }
88 }
89  
90 // items == 3: an explicit read($b, $len, 0) reads at an offset without
91 // advancing, so it must not take the steal path
92 255 ▶ if (likely(items == 3 && len == src_len && offset == 0)) {
Branch: 4 branches
BranchTrueFalseTotal
if (likely(items == 3 && len == src_len && offset == 0)) { 253 2 255
if (likely(items == 3 && len == src_len && offset == 0)) { 104 149 253
if (likely(items == 3 && len == src_len && offset == 0)) { 104 151 255
if (likely(items == 3 && len == src_len && offset == 0)) { 104 0 104
93 trace2("appending entire rbuf fd=%d\n", c->fd);
94 104 sv_2mortal(c->rbuf); // allow pv to be stolen
95 104 ▶ if (likely(buf_len == 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (likely(buf_len == 0)) { 102 2 104
96 102 sv_setsv(buf, c->rbuf);
97 }
98 else {
99 2 sv_catsv(buf, c->rbuf);
100 }
101 104 c->rbuf = NULL;
102 }
103 else {
104 151 src_ptr += offset;
105 trace2("appending partial rbuf fd=%d len=%"Sz_uf" off=%"Ssz_df" ptr=%p\n",
106 c->fd, len, offset, src_ptr);
107 151 ▶ SvGROW(buf, SvCUR(buf) + len);
Branch: 2 branches
BranchTrueFalseTotal
SvGROW(buf, SvCUR(buf) + len); 129 22 151
SvGROW(buf, SvCUR(buf) + len); 1 128 129
108 151 sv_catpvn(buf, src_ptr, len);
109 151 ▶ if (likely(items == 3)) {
Branch: 1 branch
BranchTrueFalseTotal
if (likely(items == 3)) { 149 2 151
110 // no offset param: consume; sv_chop needs a buffer we own
111 149 ▶ if (unlikely(SvREFCNT(c->rbuf) > 1 || SvREADONLY(c->rbuf))) {
Branch: 2 branches
BranchTrueFalseTotal
if (unlikely(SvREFCNT(c->rbuf) > 1 || SvREADONLY(c->rbuf))) { 149 0 149
if (unlikely(SvREFCNT(c->rbuf) > 1 || SvREADONLY(c->rbuf))) { 0 149 149
112 0 SV *copy = newSVsv(c->rbuf);
113 0 SvREFCNT_dec(c->rbuf);
114 0 c->rbuf = copy;
115 }
116 149 STRLEN cur_len = SvCUR(c->rbuf);
117 149 ▶ if (unlikely(len > cur_len)) len = cur_len;
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely(len > cur_len)) len = cur_len; 0 149 149
118 149 sv_chop(c->rbuf, SvPVX(c->rbuf) + len);
119 }
120 }
121  
122 255 XSRETURN_IV(len);
123 }
124  
125 SV *
126 getline (feer_conn_handle *hdl)
127 PROTOTYPE: $
128 PPCODE:
129 {
130 0 STRLEN src_len = 0;
131 0 const char *src_ptr = NULL;
132  
133 0 ▶ if (unlikely(c->receiving <= RECEIVE_HEADERS))
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely(c->receiving <= RECEIVE_HEADERS)) 0 0 0
134 0 croak("can't call getline() until the body begins to arrive");
135  
136 /* $/ as in core readline: separator, undef slurp, \N fixed, "" paragraph.
137 * Read it before snapshotting rbuf: FETCH can run app code that drains rbuf. */
138 0 STRLEN skip = 0, linelen = 0, trail = 0;
139 0 int have_record = 1;
140 0 SV *rs = PL_rs;
141 0 IV rs_rec = -1;
142 0 SV *rs_sep = NULL; /* a copy: FETCH may free $/ */
143 0 STRLEN rs_len = 0;
144 0 ▶ if (SvOK(rs)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(rs)) { 0 0 0
145 0 ▶ if (SvROK(rs)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(rs)) { 0 0 0
146 0 rs_rec = SvIV(SvRV(rs));
147 0 ▶ if (rs_rec < 1) rs_rec = 1; /* perl forbids \0 and negatives at assignment */
Branch: 1 branch
BranchTrueFalseTotal
if (rs_rec < 1) rs_rec = 1; /* perl forbids \0 and negatives at assignment */ 0 0 0
148 }
149 else {
150 0 const char *rs_ptr = SvPV_const(rs, rs_len);
151 0 rs_sep = sv_2mortal(newSVpvn(rs_ptr, rs_len));
152 }
153 }
154  
155 0 ▶ if (likely(c->rbuf))
Branch: 1 branch
BranchTrueFalseTotal
if (likely(c->rbuf)) 0 0 0
156 0 src_ptr = SvPV(c->rbuf, src_len);
157  
158 /* same body-boundary clamp as read() */
159 0 ssize_t avail = (ssize_t)src_len;
160 0 int body_done = 0;
161 0 ▶ if (c->expected_cl > 0
Branch: 1 branch
BranchTrueFalseTotal
if (c->expected_cl > 0 0 0 0
162 0 ▶ || (c->body_framed && c->receiving == RECEIVE_SHUTDOWN)) {
Branch: 2 branches
BranchTrueFalseTotal
|| (c->body_framed && c->receiving == RECEIVE_SHUTDOWN)) { 0 0 0
|| (c->body_framed && c->receiving == RECEIVE_SHUTDOWN)) { 0 0 0
163 0 ssize_t consumed = c->received_cl - (ssize_t)src_len;
164 0 ssize_t remaining_body = c->expected_cl - consumed;
165 0 ▶ if (remaining_body <= 0) { remaining_body = 0; body_done = 1; }
Branch: 1 branch
BranchTrueFalseTotal
if (remaining_body <= 0) { remaining_body = 0; body_done = 1; } 0 0 0
166 0 ▶ if (avail > remaining_body) avail = remaining_body;
Branch: 1 branch
BranchTrueFalseTotal
if (avail > remaining_body) avail = remaining_body; 0 0 0
167 }
168  
169 0 ▶ if (unlikely(avail <= 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely(avail <= 0)) { 0 0 0
170 /* streaming mode may yet deliver more; everything else is EOF */
171 0 ▶ if (!body_done && c->receiving != RECEIVE_SHUTDOWN)
Branch: 2 branches
BranchTrueFalseTotal
if (!body_done && c->receiving != RECEIVE_SHUTDOWN) 0 0 0
if (!body_done && c->receiving != RECEIVE_SHUTDOWN) 0 0 0
172 0 errno = EAGAIN;
173 0 XSRETURN_UNDEF;
174 }
175  
176 0 ▶ if (rs_rec >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (rs_rec >= 0) { 0 0 0
177 0 linelen = (rs_rec < (IV)avail) ? (STRLEN)rs_rec : (STRLEN)avail;
178 }
179 0 ▶ else if (!rs_sep) {
Branch: 1 branch
BranchTrueFalseTotal
else if (!rs_sep) { 0 0 0
180 0 linelen = (STRLEN)avail;
181 }
182 else {
183 0 const char *rs_ptr = SvPVX(rs_sep);
184 0 ▶ if (unlikely(rs_len == 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely(rs_len == 0)) { 0 0 0
185 /* paragraph mode: skip leading newlines, keep one "\n\n", eat the rest of the run */
186 0 ▶ while ((ssize_t)skip < avail && src_ptr[skip] == '\n')
Branch: 2 branches
BranchTrueFalseTotal
while ((ssize_t)skip < avail && src_ptr[skip] == '\n') 0 0 0
while ((ssize_t)skip < avail && src_ptr[skip] == '\n') 0 0 0
187 0 skip++;
188 0 ▶ if ((ssize_t)skip >= avail) {
Branch: 1 branch
BranchTrueFalseTotal
if ((ssize_t)skip >= avail) { 0 0 0
189 0 have_record = 0; /* nothing but separators: consume, EOF */
190 }
191 else {
192 0 const char *found = feer_memfind(src_ptr + skip,
193 0 (size_t)(avail - (ssize_t)skip), "\n\n", 2);
194 0 ▶ if (found) {
Branch: 1 branch
BranchTrueFalseTotal
if (found) { 0 0 0
195 0 linelen = (STRLEN)(found - (src_ptr + skip)) + 2;
196 0 while ((ssize_t)(skip + linelen + trail) < avail
197 0 ▶ && src_ptr[skip + linelen + trail] == '\n')
Branch: 2 branches
BranchTrueFalseTotal
&& src_ptr[skip + linelen + trail] == '\n') 0 0 0
&& src_ptr[skip + linelen + trail] == '\n') 0 0 0
198 0 trail++;
199 }
200 else {
201 0 linelen = (STRLEN)((size_t)avail - skip);
202 }
203 }
204 }
205 else {
206 0 const char *found = feer_memfind(src_ptr, (size_t)avail,
207 rs_ptr, rs_len);
208 0 linelen = found ? (STRLEN)(found - src_ptr) + rs_len
209 0 ▶ : (STRLEN)avail;
Branch: 1 branch
BranchTrueFalseTotal
: (STRLEN)avail; 0 0 0
210 }
211 }
212  
213 /* copy the record out before the ownership guard can swap rbuf */
214 0 ▶ SV *line = have_record ? newSVpvn(src_ptr + skip, linelen) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
SV *line = have_record ? newSVpvn(src_ptr + skip, linelen) : NULL; 0 0 0
215  
216 0 STRLEN eat = skip + linelen + trail;
217 0 ▶ if (likely(eat > 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (likely(eat > 0)) { 0 0 0
218 /* same ownership guard as read() */
219 0 ▶ if (unlikely(SvREFCNT(c->rbuf) > 1 || SvREADONLY(c->rbuf))) {
Branch: 2 branches
BranchTrueFalseTotal
if (unlikely(SvREFCNT(c->rbuf) > 1 || SvREADONLY(c->rbuf))) { 0 0 0
if (unlikely(SvREFCNT(c->rbuf) > 1 || SvREADONLY(c->rbuf))) { 0 0 0
220 0 SV *copy = newSVsv(c->rbuf);
221 0 SvREFCNT_dec(c->rbuf);
222 0 c->rbuf = copy;
223 }
224 0 sv_chop(c->rbuf, SvPVX(c->rbuf) + eat);
225 }
226  
227 trace("getline fd=%d skip=%"Sz_uf" len=%"Sz_uf" trail=%"Sz_uf"\n",
228 c->fd, (Sz)skip, (Sz)linelen, (Sz)trail);
229  
230 0 ▶ if (unlikely(!line)) {
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely(!line)) { 0 0 0
231 0 ▶ if (!body_done && c->receiving != RECEIVE_SHUTDOWN)
Branch: 2 branches
BranchTrueFalseTotal
if (!body_done && c->receiving != RECEIVE_SHUTDOWN) 0 0 0
if (!body_done && c->receiving != RECEIVE_SHUTDOWN) 0 0 0
232 0 errno = EAGAIN;
233 0 XSRETURN_UNDEF;
234 }
235 0 ▶ XPUSHs(sv_2mortal(line));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(line)); 0 0 0
236 }
237  
238 STRLEN
239 write (feer_conn_handle *hdl, ...)
240 PROTOTYPE: $;$
241 CODE:
242 {
243 42892 c->poll_writes_seen++;
244  
245 // a magic lvalue (substr, $1) has no value until fetched; resolve once,
246 // since a tied scalar would differ per SvPV
247 42892 ▶ if (unlikely(items == 2 && SvGMAGICAL(ST(1))))
Branch: 2 branches
BranchTrueFalseTotal
if (unlikely(items == 2 && SvGMAGICAL(ST(1)))) 42892 0 42892
if (unlikely(items == 2 && SvGMAGICAL(ST(1)))) 0 42892 42892
248 0 ST(1) = sv_2mortal(newSVsv(ST(1)));
249  
250 // HEAD: measure and discard. Before the state check: an H2 no-body
251 // response is already complete at start_response
252 42892 ▶ if (unlikely(c->no_resp_body)) {
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely(c->no_resp_body)) { 22 42870 42892
253 22 ▶ SV *b = (items == 2) ? ST(1) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
SV *b = (items == 2) ? ST(1) : &PL_sv_undef; 22 0 22
254 99 ▶ if (!b || !SvOK(b)) XSRETURN_IV(0);
Branch: 2 branches
BranchTrueFalseTotal
if (!b || !SvOK(b)) XSRETURN_IV(0); 22 0 22
if (!b || !SvOK(b)) XSRETURN_IV(0); 0 22 22
255 22 ▶ if (SvROK(b)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(b)) { 0 22 22
256 0 SV *refd = SvRV(b);
257 0 ▶ if (SvOK(refd) && SvPOK(refd)) b = refd;
Branch: 2 branches
BranchTrueFalseTotal
if (SvOK(refd) && SvPOK(refd)) b = refd; 0 0 0
if (SvOK(refd) && SvPOK(refd)) b = refd; 0 0 0
258 0 else croak("body must be a scalar, scalar ref or undef");
259 }
260 22 const char *bp = SvPV(b, RETVAL);
261 // report the downgraded length the GET twin would have written
262 22 ▶ if (unlikely(SvUTF8(b)))
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely(SvUTF8(b))) 0 22 22
263 0 RETVAL = SvCUR(feer_bytes_mortal(bp, RETVAL));
264 22 XSRETURN_UV(RETVAL);
265 }
266  
267 42870 ▶ if (unlikely(c->responding != RESPOND_STREAMING))
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely(c->responding != RESPOND_STREAMING)) 0 42870 42870
268 0 croak("can only call write in streaming mode");
269  
270 // !auto_cl is a body-less status (1xx/204/205/304); H2 handles it in its DATA provider
271 42870 ▶ if (unlikely(!c->auto_cl && !h2_is_stream(c)))
Branch: 2 branches
BranchTrueFalseTotal
if (unlikely(!c->auto_cl && !h2_is_stream(c))) 55 42815 42870
if (unlikely(!c->auto_cl && !h2_is_stream(c))) 55 0 55
272 55 XSRETURN_IV(0);
273  
274 42815 ▶ SV *body = (items == 2) ? ST(1) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
SV *body = (items == 2) ? ST(1) : &PL_sv_undef; 42815 0 42815
275 42815 ▶ if (unlikely(!body || !SvOK(body)))
Branch: 2 branches
BranchTrueFalseTotal
if (unlikely(!body || !SvOK(body))) 42815 0 42815
if (unlikely(!body || !SvOK(body))) 0 42815 42815
276 0 XSRETURN_IV(0);
277  
278 trace("write fd=%d c=%p, body=%p\n", c->fd, c, body);
279 42815 ▶ if (SvROK(body)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(body)) { 1 42814 42815
280 1 SV *refd = SvRV(body);
281 1 ▶ if (SvOK(refd) && SvPOK(refd)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvOK(refd) && SvPOK(refd)) { 0 1 1
if (SvOK(refd) && SvPOK(refd)) { 0 0 0
282 0 body = refd;
283 }
284 else {
285 1 croak("body must be a scalar, scalar ref or undef");
286 }
287 }
288 // downgrade once so every path queues the same bytes and RETVAL matches the wire
289 42814 ▶ if (unlikely(SvUTF8(body))) {
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely(SvUTF8(body))) { 0 42814 42814
290 STRLEN blen;
291 0 const char *bp = SvPV(body, blen);
292 0 body = feer_bytes_mortal(bp, blen);
293 }
294 (void)SvPV(body, RETVAL);
295  
296 42814 ▶ if (!h2_try_write_chunk(aTHX_ c, body)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!h2_try_write_chunk(aTHX_ c, body)) { 42814 0 42814
297 42814 ▶ if (c->use_chunked)
Branch: 1 branch
BranchTrueFalseTotal
if (c->use_chunked) 42392 422 42814
298 42392 add_chunk_sv_to_wbuf(c, body);
299 else
300 422 add_raw_body_to_wbuf(c, body);
301  
302 42814 conn_write_ready(c);
303 }
304 }
305 OUTPUT:
306 RETVAL
307  
308 void
309 write_array (feer_conn_handle *hdl, AV *abody)
310 PROTOTYPE: $$
311 PPCODE:
312 {
313 2 c->poll_writes_seen++;
314  
315 // before the state check, as in write()
316 2 ▶ if (unlikely(c->no_resp_body))
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely(c->no_resp_body)) 0 2 2
317 0 XSRETURN_EMPTY;
318  
319 2 ▶ if (unlikely(c->responding != RESPOND_STREAMING))
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely(c->responding != RESPOND_STREAMING)) 0 2 2
320 0 croak("can only call write_array in streaming mode");
321  
322 2 ▶ if (unlikely(!c->auto_cl && !h2_is_stream(c)))
Branch: 2 branches
BranchTrueFalseTotal
if (unlikely(!c->auto_cl && !h2_is_stream(c))) 0 2 2
if (unlikely(!c->auto_cl && !h2_is_stream(c))) 0 0 0
323 0 XSRETURN_EMPTY;
324  
325 trace("write_array fd=%d c=%p, abody=%p\n", c->fd, c, abody);
326  
327 2 I32 amax = av_len(abody);
328  
329 2 ▶ if (h2_is_stream(c)) {
Branch: 1 branch
BranchTrueFalseTotal
if (h2_is_stream(c)) { 0 2 2
330 0 ▶ for (I32 i = 0; i <= amax; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (I32 i = 0; i <= amax; i++) { 0 0 0
331 0 SV *sv = fetch_av_normal(aTHX_ abody, i);
332 0 ▶ if (likely(sv)) h2_try_write_chunk(aTHX_ c, sv);
Branch: 1 branch
BranchTrueFalseTotal
if (likely(sv)) h2_try_write_chunk(aTHX_ c, sv); 0 0 0
333 }
334 0 XSRETURN_EMPTY;
335 }
336  
337 2 ▶ if (c->use_chunked) {
Branch: 1 branch
BranchTrueFalseTotal
if (c->use_chunked) { 2 0 2
338 12 ▶ for (I32 i = 0; i <= amax; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (I32 i = 0; i <= amax; i++) { 10 2 12
339 10 SV *sv = fetch_av_normal(aTHX_ abody, i);
340 10 ▶ if (likely(sv)) add_chunk_sv_to_wbuf(c, sv);
Branch: 1 branch
BranchTrueFalseTotal
if (likely(sv)) add_chunk_sv_to_wbuf(c, sv); 8 2 10
341 }
342 }
343 else {
344 0 ▶ for (I32 i = 0; i <= amax; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (I32 i = 0; i <= amax; i++) { 0 0 0
345 0 SV *sv = fetch_av_normal(aTHX_ abody, i);
346 0 ▶ if (likely(sv)) add_raw_body_to_wbuf(c, sv);
Branch: 1 branch
BranchTrueFalseTotal
if (likely(sv)) add_raw_body_to_wbuf(c, sv); 0 0 0
347 }
348 }
349  
350 2 conn_write_ready(c);
351 }
352  
353 void
354 sendfile (feer_conn_handle *hdl, SV *fh, ...)
355 PROTOTYPE: $$;$$
356 PPCODE:
357 {
358 #ifdef __linux__
359 16 c->poll_writes_seen++;
360  
361 16 ▶ if (h2_is_stream(c))
Branch: 1 branch
BranchTrueFalseTotal
if (h2_is_stream(c)) 0 16 16
362 0 croak("sendfile not supported for HTTP/2 streams (use write instead)");
363 16 ▶ if (unlikely(c->responding != RESPOND_STREAMING))
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely(c->responding != RESPOND_STREAMING)) 0 16 16
364 0 croak("sendfile: can only call after start_streaming()");
365  
366 // HEAD or a body-less status: accept the call, transmit nothing
367 16 ▶ if (unlikely(c->no_resp_body || !c->auto_cl))
Branch: 2 branches
BranchTrueFalseTotal
if (unlikely(c->no_resp_body || !c->auto_cl)) 16 0 16
if (unlikely(c->no_resp_body || !c->auto_cl)) 2 14 16
368 2 XSRETURN_EMPTY;
369  
370 14 int file_fd = -1;
371 14 off_t offset = 0;
372 14 size_t length = 0;
373  
374 14 ▶ if (SvIOK(fh)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvIOK(fh)) { 0 14 14
375 0 file_fd = SvIV(fh);
376 }
377 28 ▶ else if (SvROK(fh) && SvTYPE(SvRV(fh)) == SVt_PVGV) {
Branch: 2 branches
BranchTrueFalseTotal
else if (SvROK(fh) && SvTYPE(SvRV(fh)) == SVt_PVGV) { 14 0 14
else if (SvROK(fh) && SvTYPE(SvRV(fh)) == SVt_PVGV) { 14 0 14
378 14 IO *io = GvIOp(SvRV(fh));
379 14 ▶ if (io && IoIFP(io)) {
Branch: 2 branches
BranchTrueFalseTotal
if (io && IoIFP(io)) { 14 0 14
if (io && IoIFP(io)) { 13 1 14
380 13 file_fd = PerlIO_fileno(IoIFP(io));
381 }
382 }
383 0 ▶ else if (SvTYPE(fh) == SVt_PVGV) {
Branch: 1 branch
BranchTrueFalseTotal
else if (SvTYPE(fh) == SVt_PVGV) { 0 0 0
384 0 IO *io = GvIOp(fh);
385 0 ▶ if (io && IoIFP(io)) {
Branch: 2 branches
BranchTrueFalseTotal
if (io && IoIFP(io)) { 0 0 0
if (io && IoIFP(io)) { 0 0 0
386 0 file_fd = PerlIO_fileno(IoIFP(io));
387 }
388 }
389  
390 14 ▶ if (file_fd < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (file_fd < 0) 1 13 14
391 1 croak("sendfile: invalid file handle");
392  
393 struct stat st;
394 13 ▶ if (fstat(file_fd, &st) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (fstat(file_fd, &st) < 0) 0 13 13
395 0 croak("sendfile: fstat failed: %s", strerror(errno));
396  
397 13 ▶ if (!S_ISREG(st.st_mode))
Branch: 1 branch
BranchTrueFalseTotal
if (!S_ISREG(st.st_mode)) 1 12 13
398 1 croak("sendfile: not a regular file");
399  
400 12 ▶ if (items >= 3 && SvOK(ST(2))) {
Branch: 2 branches
BranchTrueFalseTotal
if (items >= 3 && SvOK(ST(2))) { 7 5 12
if (items >= 3 && SvOK(ST(2))) { 7 0 7
401 7 IV offset_iv = SvIV(ST(2));
402 7 ▶ if (offset_iv < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (offset_iv < 0) 1 6 7
403 1 croak("sendfile: offset must be non-negative");
404 6 offset = (off_t)offset_iv;
405 }
406  
407 11 ▶ if (st.st_size == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (st.st_size == 0) { 1 10 11
408 1 XSRETURN_EMPTY;
409 }
410 10 ▶ if (offset >= st.st_size)
Branch: 1 branch
BranchTrueFalseTotal
if (offset >= st.st_size) 1 9 10
411 1 croak("sendfile: offset out of range");
412  
413 9 ▶ if (items >= 4 && SvOK(ST(3))) {
Branch: 2 branches
BranchTrueFalseTotal
if (items >= 4 && SvOK(ST(3))) { 2 7 9
if (items >= 4 && SvOK(ST(3))) { 2 0 2
414 2 UV length_uv = SvUV(ST(3));
415 // portable SSIZE_MAX: a length >= 2^63 would go negative on cast
416 2 ▶ if (length_uv > (UV)((~(size_t)0) >> 1))
Branch: 1 branch
BranchTrueFalseTotal
if (length_uv > (UV)((~(size_t)0) >> 1)) 0 2 2
417 0 croak("sendfile: length too large");
418 2 length = (size_t)length_uv;
419 2 ▶ if (length > (size_t)(st.st_size - offset))
Branch: 1 branch
BranchTrueFalseTotal
if (length > (size_t)(st.st_size - offset)) 2 0 2
420 2 croak("sendfile: offset + length exceeds file size");
421 } else {
422 7 length = st.st_size - offset;
423 }
424  
425 7 ▶ if (length == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (length == 0) 0 7 7
426 0 XSRETURN_EMPTY;
427  
428 trace("sendfile setup: fd=%d file_fd=%d off=%ld len=%zu\n",
429 c->fd, file_fd, (long)offset, length);
430  
431 // sendfile writes the file verbatim and cannot chunk-frame it; checked
432 // last so the file-validity errors above stay specific
433 7 ▶ if (unlikely(c->use_chunked))
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely(c->use_chunked)) 1 6 7
434 1 croak("sendfile: needs an explicit Content-Length "
435 "(a chunked response cannot frame a raw file transfer)");
436  
437 // the file counts against the app's Content-Length like any body bytes
438 6 ▶ if (c->resp_cl_enforced) {
Branch: 1 branch
BranchTrueFalseTotal
if (c->resp_cl_enforced) { 6 0 6
439 6 ▶ if (length > c->resp_cl_owed)
Branch: 1 branch
BranchTrueFalseTotal
if (length > c->resp_cl_owed) 0 6 6
440 0 length = c->resp_cl_owed;
441 6 ▶ if (length == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (length == 0) 0 6 6
442 0 XSRETURN_EMPTY;
443 }
444  
445 6 ▶ CLOSE_SENDFILE_FD(c);
Branch: 2 branches
BranchTrueFalseTotal
CLOSE_SENDFILE_FD(c); 0 6 6
CLOSE_SENDFILE_FD(c); 0 0 0
446 // dup: the caller may close its handle
447 #ifdef F_DUPFD_CLOEXEC
448 6 c->sendfile_fd = fcntl(file_fd, F_DUPFD_CLOEXEC, 0);
449 #else
450 c->sendfile_fd = dup(file_fd);
451 if (c->sendfile_fd >= 0 && fcntl(c->sendfile_fd, F_SETFD, FD_CLOEXEC) < 0) {
452 int saved_errno = errno;
453 CLOSE_SENDFILE_FD(c);
454 errno = saved_errno;
455 }
456 #endif
457 6 ▶ if (c->sendfile_fd < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (c->sendfile_fd < 0) 0 6 6
458 0 croak("sendfile: dup failed: %s", strerror(errno));
459  
460 // only once the dup succeeded: a failed one queues no body bytes
461 6 ▶ if (c->resp_cl_enforced)
Branch: 1 branch
BranchTrueFalseTotal
if (c->resp_cl_enforced) 6 0 6
462 6 c->resp_cl_owed -= length;
463  
464 6 c->sendfile_off = offset;
465 6 c->sendfile_remain = length;
466  
467 6 conn_write_ready(c);
468 6 XSRETURN_EMPTY;
469 #else
470 PERL_UNUSED_VAR(fh);
471 croak("sendfile: only supported on Linux");
472 #endif
473 }
474  
475 int
476 seek (feer_conn_handle *hdl, ssize_t offset, ...)
477 PROTOTYPE: $$;$
478 CODE:
479 {
480 13 int whence = SEEK_CUR;
481 13 ▶ if (items == 3 && SvOK(ST(2)) && SvIOK(ST(2)))
Branch: 3 branches
BranchTrueFalseTotal
if (items == 3 && SvOK(ST(2)) && SvIOK(ST(2))) 13 0 13
if (items == 3 && SvOK(ST(2)) && SvIOK(ST(2))) 13 0 13
if (items == 3 && SvOK(ST(2)) && SvIOK(ST(2))) 13 0 13
482 13 whence = SvIV(ST(2));
483  
484 trace("seek fd=%d offset=%"Ssz_df" whence=%d\n", c->fd, offset, whence);
485  
486 // bytes of this request's body still in rbuf (-1: no framing info, no
487 // clamp); seeking past the body would chop into a pipelined request
488 13 ssize_t body_avail = -1;
489 13 ▶ if (c->rbuf && (c->expected_cl > 0
Branch: 2 branches
BranchTrueFalseTotal
if (c->rbuf && (c->expected_cl > 0 13 0 13
if (c->rbuf && (c->expected_cl > 0 2 11 13
490 2 ▶ || (c->body_framed && c->receiving == RECEIVE_SHUTDOWN))) {
Branch: 2 branches
BranchTrueFalseTotal
|| (c->body_framed && c->receiving == RECEIVE_SHUTDOWN))) { 2 0 2
|| (c->body_framed && c->receiving == RECEIVE_SHUTDOWN))) { 2 0 2
491 13 ssize_t consumed = c->received_cl - (ssize_t)SvCUR(c->rbuf);
492 13 body_avail = c->expected_cl - consumed;
493 13 ▶ if (body_avail < 0) body_avail = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (body_avail < 0) body_avail = 0; 0 13 13
494 }
495  
496 13 ▶ if (unlikely(!c->rbuf)) {
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely(!c->rbuf)) { 0 13 13
497 0 RETVAL = 0;
498 }
499 13 ▶ else if (offset == 0) {
Branch: 1 branch
BranchTrueFalseTotal
else if (offset == 0) { 2 11 13
500 2 RETVAL = 1;
501 }
502 11 ▶ else if (offset > 0 && (whence == SEEK_CUR || whence == SEEK_SET)) {
Branch: 3 branches
BranchTrueFalseTotal
else if (offset > 0 && (whence == SEEK_CUR || whence == SEEK_SET)) { 6 5 11
else if (offset > 0 && (whence == SEEK_CUR || whence == SEEK_SET)) { 2 4 6
else if (offset > 0 && (whence == SEEK_CUR || whence == SEEK_SET)) { 2 0 2
503 STRLEN len;
504 6 const char *str = SvPV_const(c->rbuf, len);
505 6 ▶ if (body_avail >= 0 && offset > body_avail)
Branch: 2 branches
BranchTrueFalseTotal
if (body_avail >= 0 && offset > body_avail) 6 0 6
if (body_avail >= 0 && offset > body_avail) 2 4 6
506 2 offset = body_avail;
507 6 ▶ if (offset > len)
Branch: 1 branch
BranchTrueFalseTotal
if (offset > len) 0 6 6
508 0 offset = len;
509 6 ▶ if (offset > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (offset > 0) { 5 1 6
510 // sv_chop needs a buffer we own
511 5 ▶ if (SvREFCNT(c->rbuf) > 1 || SvREADONLY(c->rbuf)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvREFCNT(c->rbuf) > 1 || SvREADONLY(c->rbuf)) { 5 0 5
if (SvREFCNT(c->rbuf) > 1 || SvREADONLY(c->rbuf)) { 0 5 5
512 0 SV *copy = newSVsv(c->rbuf);
513 0 SvREFCNT_dec(c->rbuf);
514 0 c->rbuf = copy;
515 0 str = SvPV_const(c->rbuf, len);
516 }
517 5 sv_chop(c->rbuf, str + offset);
518 }
519 6 RETVAL = 1; // clamped to the body end is still a successful seek
520 }
521 8 ▶ else if (offset < 0 && whence == SEEK_END) {
Branch: 2 branches
BranchTrueFalseTotal
else if (offset < 0 && whence == SEEK_END) { 5 0 5
else if (offset < 0 && whence == SEEK_END) { 3 2 5
522 STRLEN len;
523 3 const char *str = SvPV_const(c->rbuf, len);
524 // SEEK_END is the end of the body, not of rbuf
525 3 ▶ if (body_avail >= 0 && (STRLEN)body_avail < len)
Branch: 2 branches
BranchTrueFalseTotal
if (body_avail >= 0 && (STRLEN)body_avail < len) 3 0 3
if (body_avail >= 0 && (STRLEN)body_avail < len) 1 2 3
526 1 len = (STRLEN)body_avail;
527 3 offset += len; // can't be > len since block is offset<0
528 3 ▶ if (offset == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (offset == 0) { 0 3 3
529 0 RETVAL = 1;
530 }
531 3 ▶ else if (offset > 0) {
Branch: 1 branch
BranchTrueFalseTotal
else if (offset > 0) { 2 1 3
532 2 ▶ if (SvREFCNT(c->rbuf) > 1 || SvREADONLY(c->rbuf)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvREFCNT(c->rbuf) > 1 || SvREADONLY(c->rbuf)) { 2 0 2
if (SvREFCNT(c->rbuf) > 1 || SvREADONLY(c->rbuf)) { 0 2 2
533 0 SV *copy = newSVsv(c->rbuf);
534 0 SvREFCNT_dec(c->rbuf);
535 0 c->rbuf = copy;
536 0 str = SvPV_const(c->rbuf, len);
537 }
538 2 sv_chop(c->rbuf, str + offset);
539 2 RETVAL = 1;
540 }
541 else {
542 1 RETVAL = 0;
543 }
544 }
545 else {
546 2 RETVAL = 0;
547 }
548 }
549 OUTPUT:
550 RETVAL
551  
552 int
553 close (feer_conn_handle *hdl)
554 PROTOTYPE: $
555 ALIAS:
556 Feersum::Connection::Reader::close = 1
557 Feersum::Connection::Writer::close = 2
558 CODE:
559 {
560 assert(ix && "close() must be called via Reader::close or Writer::close");
561 266 RETVAL = feersum_close_handle(aTHX_ c, (ix == 2));
562 266 ▶ SvUVX(hdl_sv) = 0;
Branch: 1 branch
BranchTrueFalseTotal
SvUVX(hdl_sv) = 0; 11 255 266
563 }
564 OUTPUT:
565 RETVAL
566  
567 void
568 _poll_cb (feer_conn_handle *hdl, SV *cb)
569 PROTOTYPE: $$
570 ALIAS:
571 Feersum::Connection::Reader::poll_cb = 1
572 Feersum::Connection::Writer::poll_cb = 2
573 PPCODE:
574 {
575 115 ▶ if (unlikely(ix < 1 || ix > 2))
Branch: 2 branches
BranchTrueFalseTotal
if (unlikely(ix < 1 || ix > 2)) 115 0 115
if (unlikely(ix < 1 || ix > 2)) 0 115 115
576 0 croak("can't call _poll_cb directly");
577  
578 115 bool is_read = (ix == 1);
579 115 ▶ SV **cb_slot = is_read ? &c->poll_read_cb : &c->poll_write_cb;
Branch: 1 branch
BranchTrueFalseTotal
SV **cb_slot = is_read ? &c->poll_read_cb : &c->poll_write_cb; 41 74 115
580  
581 115 ▶ if (*cb_slot != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (*cb_slot != NULL) { 25 90 115
582 25 SvREFCNT_dec(*cb_slot);
583 25 *cb_slot = NULL;
584 }
585  
586 115 ▶ if (!SvOK(cb)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(cb)) { 25 90 115
587 trace("unset poll_cb ix=%d\n", ix);
588 25 ▶ if (is_read && c->receiving == RECEIVE_STREAMING) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_read && c->receiving == RECEIVE_STREAMING) { 16 9 25
if (is_read && c->receiving == RECEIVE_STREAMING) { 0 16 16
589 /* not back to RECEIVE_BODY: that means "buffer, then dispatch"
590 * and would dispatch this request a second time */
591 0 ▶ if (c->expected_cl > 0 && c->received_cl < c->expected_cl) {
Branch: 2 branches
BranchTrueFalseTotal
if (c->expected_cl > 0 && c->received_cl < c->expected_cl) { 0 0 0
if (c->expected_cl > 0 && c->received_cl < c->expected_cl) { 0 0 0
592 /* the rest of the body will never be drained: no reuse */
593 0 c->is_keepalive = 0;
594 }
595 0 finish_receiving(c);
596 }
597 25 return;
598 }
599 90 ▶ else if (unlikely(!IsCodeRef(cb)))
Branch: 2 branches
BranchTrueFalseTotal
else if (unlikely(!IsCodeRef(cb))) 90 0 90
else if (unlikely(!IsCodeRef(cb))) 0 90 90
600 0 croak("must supply a code reference to poll_cb");
601  
602 90 *cb_slot = newSVsv(cb);
603  
604 // the callback can drop the installing handle's last ref; hold the conn
605 90 SvREFCNT_inc_void_NN(c->self);
606  
607 90 ▶ if (is_read) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_read) { 25 65 90
608 // only a socket takeover streams bytes beyond the HTTP body
609 25 ▶ if (c->io_taken && (c->receiving == RECEIVE_BODY
Branch: 2 branches
BranchTrueFalseTotal
if (c->io_taken && (c->receiving == RECEIVE_BODY 0 25 25
if (c->io_taken && (c->receiving == RECEIVE_BODY 0 0 0
610 0 ▶ || c->receiving == RECEIVE_SHUTDOWN)) {
Branch: 1 branch
BranchTrueFalseTotal
|| c->receiving == RECEIVE_SHUTDOWN)) { 0 0 0
611 // the app owns the byte stream now; unsetting the reader drops back
612 // to RECEIVE_SHUTDOWN, where the read clamp would strand rbuf bytes
613 0 c->body_framed = 0;
614 0 change_receiving_state(c, RECEIVE_STREAMING);
615 }
616 // body already complete: call even at EOF, pump while the cb progresses
617 50 ▶ if (!c->io_taken || (c->rbuf && SvCUR(c->rbuf) > 0)) {
Branch: 3 branches
BranchTrueFalseTotal
if (!c->io_taken || (c->rbuf && SvCUR(c->rbuf) > 0)) { 0 25 25
if (!c->io_taken || (c->rbuf && SvCUR(c->rbuf) > 0)) { 0 0 0
if (!c->io_taken || (c->rbuf && SvCUR(c->rbuf) > 0)) { 0 0 0
618 STRLEN prev;
619 do {
620 157 ▶ prev = c->rbuf ? SvCUR(c->rbuf) : 0;
Branch: 1 branch
BranchTrueFalseTotal
prev = c->rbuf ? SvCUR(c->rbuf) : 0; 157 0 157
621 157 call_poll_callback(c, 0); // 0 = read callback
622 141 ▶ } while (c->poll_read_cb && c->rbuf && SvCUR(c->rbuf) > 0
Branch: 2 branches
BranchTrueFalseTotal
} while (c->poll_read_cb && c->rbuf && SvCUR(c->rbuf) > 0 141 0 141
} while (c->poll_read_cb && c->rbuf && SvCUR(c->rbuf) > 0 141 0 141
623 141 ▶ && SvCUR(c->rbuf) < prev
Branch: 1 branch
BranchTrueFalseTotal
&& SvCUR(c->rbuf) < prev 132 9 141
624 289 ▶ && (!c->io_taken || c->receiving < RECEIVE_SHUTDOWN));
Branch: 3 branches
BranchTrueFalseTotal
&& (!c->io_taken || c->receiving < RECEIVE_SHUTDOWN)); 141 16 157
&& (!c->io_taken || c->receiving < RECEIVE_SHUTDOWN)); 132 0 132
&& (!c->io_taken || c->receiving < RECEIVE_SHUTDOWN)); 0 0 0
625 }
626 else {
627 #ifdef FEERSUM_HAS_H2
628 // H2 bodies arrive via nghttp2, never a socket watcher; a
629 // pseudo-conn's read_ev_io is zeroed and arming it pins the conn
630 if (likely(!c->is_h2_stream))
631 #endif
632 0 start_read_watcher(c);
633 }
634 /* no more input; a retained cb can pin the conn in a cycle
635 * c -> cb -> env -> psgi.input -> c */
636 25 ▶ if (!c->io_taken && c->poll_read_cb) {
Branch: 2 branches
BranchTrueFalseTotal
if (!c->io_taken && c->poll_read_cb) { 25 0 25
if (!c->io_taken && c->poll_read_cb) { 9 16 25
637 9 SV *done_cb = c->poll_read_cb;
638 9 c->poll_read_cb = NULL;
639 9 SvREFCNT_dec(done_cb);
640 }
641 }
642 else {
643 65 conn_write_ready(c);
644 }
645  
646 90 SvREFCNT_dec(c->self);
647 }
648  
649 SV*
650 on_eof (feer_conn_handle *hdl, ...)
651 PROTOTYPE: $;$
652 ALIAS:
653 Feersum::Connection::Writer::on_eof = 1
654 CODE:
655 {
656 106 ▶ if (unlikely(ix != 1))
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely(ix != 1)) 0 106 106
657 0 croak("on_eof is a writer method");
658  
659 106 ▶ if (items == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (items == 2) { 73 33 106
660 73 SV *cb = ST(1);
661 73 ▶ if (c->on_eof_cb != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (c->on_eof_cb != NULL) { 17 56 73
662 17 SvREFCNT_dec(c->on_eof_cb);
663 17 c->on_eof_cb = NULL;
664 }
665 /* a reinstall from the callback stays inert: refiring could only recurse */
666 73 ▶ if (!c->in_on_eof)
Branch: 1 branch
BranchTrueFalseTotal
if (!c->in_on_eof) 72 1 73
667 72 c->on_eof_fired = 0;
668 73 ▶ if (SvOK(cb)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(cb)) { 65 8 73
669 65 ▶ if (unlikely(!IsCodeRef(cb)))
Branch: 2 branches
BranchTrueFalseTotal
if (unlikely(!IsCodeRef(cb))) 57 8 65
if (unlikely(!IsCodeRef(cb))) 0 57 57
670 8 croak("must supply a code reference to on_eof");
671 57 c->on_eof_cb = newSVsv(cb);
672 /* EOF may predate the install (a coalesced close_notify) */
673 57 ▶ if (!c->in_on_eof)
Branch: 1 branch
BranchTrueFalseTotal
if (!c->in_on_eof) 56 1 57
674 56 feersum_maybe_fire_on_eof(c);
675 }
676 else {
677 trace("unset on_eof\n");
678 }
679 }
680 98 ▶ RETVAL = c->on_eof_cb ? newSVsv(c->on_eof_cb) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = c->on_eof_cb ? newSVsv(c->on_eof_cb) : &PL_sv_undef; 74 24 98
681 }
682 OUTPUT:
683 RETVAL
684  
685 SV*
686 response_guard (feer_conn_handle *hdl, ...)
687 PROTOTYPE: $;$
688 CODE:
689 206 ▶ RETVAL = feersum_conn_guard(aTHX_ c, (items==2) ? ST(1) : NULL);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = feersum_conn_guard(aTHX_ c, (items==2) ? ST(1) : NULL); 205 1 206
690 OUTPUT:
691 RETVAL
692  
693 void
694 return_from_psgix_io (feer_conn_handle *hdl, SV *io_sv)
695 PROTOTYPE: $$
696 PPCODE:
697 {
698 1 SSize_t cnt = feersum_return_from_io(aTHX_ c, io_sv, "return_from_psgix_io");
699 1 ▶ mXPUSHi(cnt);
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHi(cnt); 0 1 1
700 }
701  
702 MODULE = Feersum PACKAGE = Feersum::Connection
703  
704 PROTOTYPES: ENABLE
705  
706 SV *
707 start_streaming (struct feer_conn *c, SV *message, AV *headers)
708 PROTOTYPE: $$\@
709 CODE:
710 /* flattened here, not in start_response: the PSGI paths flatten
711 * before their framing scan; croaking is safe under the handler's G_EVAL */
712 69 headers = feersum_flatten_headers(aTHX_ headers);
713 69 ▶ if (unlikely(!headers)) croak_sv(ERRSV);
Branch: 2 branches
BranchTrueFalseTotal
if (unlikely(!headers)) croak_sv(ERRSV); 0 69 69
if (unlikely(!headers)) croak_sv(ERRSV); 0 0 0
714 69 feersum_start_response(aTHX_ c, message, headers, 1, 0);
715 68 RETVAL = new_feer_conn_handle(aTHX_ c, 1); // RETVAL gets mortalized
716 OUTPUT:
717 RETVAL
718  
719 int
720 is_http11 (struct feer_conn *c)
721 CODE:
722 7 ▶ RETVAL = c->is_http11;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = c->is_http11; 0 7 7
723 OUTPUT:
724 RETVAL
725  
726 size_t
727 send_response (struct feer_conn *c, SV* message, AV *headers, SV *body)
728 PROTOTYPE: $$\@$
729 CODE:
730 /* a magic lvalue (substr, $1) has no value yet */
731 596 ▶ if (unlikely(SvGMAGICAL(body)))
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely(SvGMAGICAL(body))) 0 596 596
732 0 body = sv_2mortal(newSVsv(body));
733 596 ▶ if (unlikely(!SvOK(body)))
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely(!SvOK(body))) 0 596 596
734 0 croak("can't send_response with an undef body");
735 /* screen before start_response: once the header block is queued a
736 * croak can no longer become a 500 */
737 596 ▶ if (unlikely(SvROK(body))) {
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely(SvROK(body))) { 327 269 596
738 327 SV *refd = SvRV(body);
739 327 ▶ if (!(SvOK(refd) && !SvROK(refd)) && SvTYPE(refd) != SVt_PVAV)
Branch: 3 branches
BranchTrueFalseTotal
if (!(SvOK(refd) && !SvROK(refd)) && SvTYPE(refd) != SVt_PVAV) 217 110 327
if (!(SvOK(refd) && !SvROK(refd)) && SvTYPE(refd) != SVt_PVAV) 0 217 217
if (!(SvOK(refd) && !SvROK(refd)) && SvTYPE(refd) != SVt_PVAV) 9 101 110
740 9 croak("body must be a scalar, scalar reference or array reference");
741 }
742 /* see start_streaming: flattened here, not in start_response */
743 587 headers = feersum_flatten_headers(aTHX_ headers);
744 587 ▶ if (unlikely(!headers)) croak_sv(ERRSV);
Branch: 2 branches
BranchTrueFalseTotal
if (unlikely(!headers)) croak_sv(ERRSV); 0 587 587
if (unlikely(!headers)) croak_sv(ERRSV); 0 0 0
745 587 feersum_start_response(aTHX_ c, message, headers, 0, 0);
746 /* an H2 stream reset between dispatch and response leaves the
747 * pseudo-conn in RESPOND_SHUTDOWN, and write_whole_body would croak */
748 569 ▶ if (unlikely(c->responding >= RESPOND_SHUTDOWN)) XSRETURN_UV(0);
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely(c->responding >= RESPOND_SHUTDOWN)) XSRETURN_UV(0); 0 569 569
749 569 RETVAL = feersum_write_whole_body(aTHX_ c, body);
750 OUTPUT:
751 RETVAL
752  
753 SV*
754 _continue_streaming_psgi (struct feer_conn *c, SV *psgi_response)
755 PROTOTYPE: $\@
756 CODE:
757 {
758 AV *av;
759 308 int len = 0;
760  
761 308 ▶ if (IsArrayRef(psgi_response)) {
Branch: 2 branches
BranchTrueFalseTotal
if (IsArrayRef(psgi_response)) { 308 0 308
if (IsArrayRef(psgi_response)) { 306 2 308
762 306 av = (AV*)SvRV(psgi_response);
763 306 len = av_len(av) + 1;
764 }
765  
766 308 ▶ if (len == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (len == 3) { 31 277 308
767 // 0: don't allow another code-ref
768 31 feersum_handle_psgi_response(aTHX_ c, psgi_response, 0);
769 31 RETVAL = &PL_sv_undef;
770 }
771 277 ▶ else if (len == 2) {
Branch: 1 branch
BranchTrueFalseTotal
else if (len == 2) { 268 9 277
772 /* a responder runs later, from a timer, with no G_EVAL above it:
773 * every failure here goes through call_died, never croak */
774 268 SV **msg_p = av_fetch(av, 0, 0);
775 268 SV **hdrs_p = av_fetch(av, 1, 0);
776 268 ▶ if (unlikely(!msg_p || !hdrs_p || !*msg_p || !*hdrs_p)) {
Branch: 6 branches
BranchTrueFalseTotal
if (unlikely(!msg_p || !hdrs_p || !*msg_p || !*hdrs_p)) { 263 5 268
if (unlikely(!msg_p || !hdrs_p || !*msg_p || !*hdrs_p)) { 0 263 263
if (unlikely(!msg_p || !hdrs_p || !*msg_p || !*hdrs_p)) { 263 5 268
if (unlikely(!msg_p || !hdrs_p || !*msg_p || !*hdrs_p)) { 0 263 263
if (unlikely(!msg_p || !hdrs_p || !*msg_p || !*hdrs_p)) { 263 5 268
if (unlikely(!msg_p || !hdrs_p || !*msg_p || !*hdrs_p)) { 0 263 263
777 5 ▶ sv_setpvs(ERRSV, "PSGI response starter got a hole in its array-ref");
Branch: 1 branch
BranchTrueFalseTotal
sv_setpvs(ERRSV, "PSGI response starter got a hole in its array-ref"); 5 0 5
778 5 call_died(aTHX_ c, "PSGI request");
779 5 XSRETURN_UNDEF;
780 }
781 263 SV *message = *msg_p;
782 263 SV *headers = *hdrs_p;
783 263 ▶ if (unlikely(!IsArrayRef(headers))) {
Branch: 2 branches
BranchTrueFalseTotal
if (unlikely(!IsArrayRef(headers))) { 256 7 263
if (unlikely(!IsArrayRef(headers))) { 0 256 256
784 7 ▶ sv_setpvs(ERRSV, "PSGI headers must be an array ref");
Branch: 1 branch
BranchTrueFalseTotal
sv_setpvs(ERRSV, "PSGI headers must be an array ref"); 7 0 7
785 7 call_died(aTHX_ c, "PSGI request");
786 7 XSRETURN_UNDEF;
787 }
788 /* flatten first: the framing scan indexes AvARRAY directly, which a
789 * tied array may leave NULL */
790 256 AV *hdr_av = feersum_flatten_headers(aTHX_ (AV*)SvRV(headers));
791 256 ▶ if (unlikely(!hdr_av)) {
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely(!hdr_av)) { 0 256 256
792 0 call_died(aTHX_ c, "PSGI request");
793 0 XSRETURN_UNDEF;
794 }
795 256 ▶ if (unlikely((av_len(hdr_av) + 1) % 2 == 1)) {
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely((av_len(hdr_av) + 1) % 2 == 1)) { 8 248 256
796 8 ▶ sv_setpvs(ERRSV, "PSGI headers must be an even-length array");
Branch: 1 branch
BranchTrueFalseTotal
sv_setpvs(ERRSV, "PSGI headers must be an even-length array"); 8 0 8
797 8 call_died(aTHX_ c, "PSGI request");
798 8 XSRETURN_UNDEF;
799 }
800 {
801 248 const char *serr = feersum_check_psgi_status(aTHX_ message);
802 248 ▶ if (!serr)
Branch: 1 branch
BranchTrueFalseTotal
if (!serr) 248 0 248
803 248 serr = feersum_check_response_framing(aTHX_ message, hdr_av);
804 248 ▶ if (unlikely(serr)) {
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely(serr)) { 7 241 248
805 7 ▶ sv_setpv(ERRSV, serr);
Branch: 1 branch
BranchTrueFalseTotal
sv_setpv(ERRSV, serr); 7 0 7
806 7 call_died(aTHX_ c, "PSGI request");
807 7 XSRETURN_UNDEF;
808 }
809 }
810 /* no G_EVAL above a responder: route through call_died, never croak */
811 241 ▶ if (unlikely(c->responding != RESPOND_NOT_STARTED)) {
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely(c->responding != RESPOND_NOT_STARTED)) { 1 240 241
812 1 ▶ sv_setpvs(ERRSV, "PSGI responder called after the response "
Branch: 1 branch
BranchTrueFalseTotal
sv_setpvs(ERRSV, "PSGI responder called after the response " 1 0 1
813 "had already started");
814 1 call_died(aTHX_ c, "PSGI request");
815 1 XSRETURN_UNDEF;
816 }
817 240 ▶ if (unlikely(c->io_taken)) {
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely(c->io_taken)) { 0 240 240
818 0 ▶ sv_setpvs(ERRSV, "PSGI app took psgix.io and then used the "
Branch: 1 branch
BranchTrueFalseTotal
sv_setpvs(ERRSV, "PSGI app took psgix.io and then used the " 0 0 0
819 "responder; call return_from_psgix_io first");
820 0 call_died(aTHX_ c, "PSGI request");
821 0 XSRETURN_UNDEF;
822 }
823 240 feersum_start_response(aTHX_ c, message, hdr_av, 1, 1);
824 240 RETVAL = new_feer_conn_handle(aTHX_ c, 1); // RETVAL gets mortalized
825 }
826 else {
827 /* no G_EVAL above a responder: call_died, not croak */
828 9 ▶ sv_setpvs(ERRSV, "PSGI response starter expects a 2 or 3 element array-ref");
Branch: 1 branch
BranchTrueFalseTotal
sv_setpvs(ERRSV, "PSGI response starter expects a 2 or 3 element array-ref"); 9 0 9
829 9 call_died(aTHX_ c, "PSGI request");
830 9 XSRETURN_UNDEF;
831 }
832 }
833 OUTPUT:
834 RETVAL
835  
836 void
837 force_http10 (struct feer_conn *c)
838 PROTOTYPE: $
839 ALIAS:
840 force_http11 = 1
841 PPCODE:
842 11 c->is_http11 = ix;
843  
844 SV *
845 env (struct feer_conn *c)
846 PROTOTYPE: $
847 CODE:
848 387 ▶ if (unlikely(!c->req))
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely(!c->req)) 1 386 387
849 1 croak("Cannot build the environment: no active request");
850 386 RETVAL = newRV_noinc((SV*)feersum_env(aTHX_ c));
851 OUTPUT:
852 RETVAL
853  
854 SV *
855 method (struct feer_conn *c)
856 PROTOTYPE: $
857 CODE:
858 29 struct feer_req *r = c->req;
859 29 ▶ if (unlikely(!r))
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely(!r)) 1 28 29
860 1 croak("Cannot access request method: no active request");
861 #ifdef FEERSUM_HAS_H2
862 RETVAL = feersum_env_method_h2(aTHX_ c, r);
863 #else
864 28 RETVAL = feersum_env_method(aTHX_ r);
865 #endif
866 OUTPUT:
867 RETVAL
868  
869 SV *
870 uri (struct feer_conn *c)
871 PROTOTYPE: $
872 CODE:
873 2 struct feer_req *r = c->req;
874 2 ▶ if (unlikely(!r))
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely(!r)) 0 2 2
875 0 croak("Cannot access request URI: no active request");
876 2 RETVAL = feersum_env_uri(aTHX_ r);
877 OUTPUT:
878 RETVAL
879  
880 SV *
881 protocol (struct feer_conn *c)
882 PROTOTYPE: $
883 CODE:
884 2 struct feer_req *r = c->req;
885 2 ▶ if (unlikely(!r))
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely(!r)) 0 2 2
886 0 croak("Cannot access request protocol: no active request");
887 2 RETVAL = SvREFCNT_inc_simple_NN(feersum_env_protocol(aTHX_ r));
888 OUTPUT:
889 RETVAL
890  
891 SV *
892 path (struct feer_conn *c)
893 PROTOTYPE: $
894 CODE:
895 48 struct feer_req *r = c->req;
896 48 ▶ if (unlikely(!r))
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely(!r)) 0 48 48
897 0 croak("Cannot access request path: no active request");
898 48 RETVAL = SvREFCNT_inc_simple_NN(feersum_env_path(aTHX_ r));
899 OUTPUT:
900 RETVAL
901  
902 SV *
903 query (struct feer_conn *c)
904 PROTOTYPE: $
905 CODE:
906 14 struct feer_req *r = c->req;
907 14 ▶ if (unlikely(!r))
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely(!r)) 0 14 14
908 0 croak("Cannot access request query: no active request");
909 14 RETVAL = SvREFCNT_inc_simple_NN(feersum_env_query(aTHX_ r));
910 OUTPUT:
911 RETVAL
912  
913 SV *
914 remote_address (struct feer_conn *c)
915 PROTOTYPE: $
916 CODE:
917 14 RETVAL = SvREFCNT_inc_simple_NN(feersum_env_addr(aTHX_ c));
918 OUTPUT:
919 RETVAL
920  
921 SV *
922 remote_port (struct feer_conn *c)
923 PROTOTYPE: $
924 CODE:
925 3 RETVAL = SvREFCNT_inc_simple_NN(feersum_env_port(aTHX_ c));
926 OUTPUT:
927 RETVAL
928  
929 SV *
930 proxy_tlvs (struct feer_conn *c)
931 PROTOTYPE: $
932 CODE:
933 3 ▶ RETVAL = c->proxy_tlvs ? SvREFCNT_inc(c->proxy_tlvs) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = c->proxy_tlvs ? SvREFCNT_inc(c->proxy_tlvs) : &PL_sv_undef; 1 2 3
934 OUTPUT:
935 RETVAL
936  
937 SV *
938 trailers (struct feer_conn *c)
939 PROTOTYPE: $
940 CODE:
941 1 ▶ RETVAL = c->trailers ? newRV_inc((SV*)c->trailers) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = c->trailers ? newRV_inc((SV*)c->trailers) : &PL_sv_undef; 0 1 1
942 OUTPUT:
943 RETVAL
944  
945 SV *
946 client_address (struct feer_conn *c)
947 PROTOTYPE: $
948 CODE:
949 {
950 8 SV *fwd = NULL;
951 8 ▶ if (c->cached_use_reverse_proxy && c->req)
Branch: 2 branches
BranchTrueFalseTotal
if (c->cached_use_reverse_proxy && c->req) 5 3 8
if (c->cached_use_reverse_proxy && c->req) 5 0 5
952 5 fwd = extract_forwarded_addr(aTHX_ c->req);
953 8 ▶ RETVAL = fwd ? fwd : SvREFCNT_inc_simple_NN(feersum_env_addr(aTHX_ c));
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = fwd ? fwd : SvREFCNT_inc_simple_NN(feersum_env_addr(aTHX_ c)); 5 3 8
954 }
955 OUTPUT:
956 RETVAL
957  
958 SV *
959 url_scheme (struct feer_conn *c)
960 PROTOTYPE: $
961 CODE:
962 {
963 11 RETVAL = feer_determine_url_scheme(aTHX_ c);
964 11 ▶ if (!RETVAL) RETVAL = newSVpvs("http");
Branch: 1 branch
BranchTrueFalseTotal
if (!RETVAL) RETVAL = newSVpvs("http"); 6 5 11
965 }
966 OUTPUT:
967 RETVAL
968  
969 ssize_t
970 content_length (struct feer_conn *c)
971 PROTOTYPE: $
972 CODE:
973 23 ▶ RETVAL = c->expected_cl;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = c->expected_cl; 17 6 23
974 OUTPUT:
975 RETVAL
976  
977 SV *
978 input (struct feer_conn *c)
979 PROTOTYPE: $
980 CODE:
981 14 ▶ if (likely(c->expected_cl > 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (likely(c->expected_cl > 0)) { 13 1 14
982 13 RETVAL = new_feer_conn_handle(aTHX_ c, 0);
983 } else {
984 1 RETVAL = &PL_sv_undef;
985 }
986 OUTPUT:
987 RETVAL
988  
989 SV *
990 headers (struct feer_conn *c, int norm = 0)
991 PROTOTYPE: $;$
992 CODE:
993 7 struct feer_req *r = c->req;
994 7 ▶ if (unlikely(!r))
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely(!r)) 0 7 7
995 0 croak("Cannot access request headers: no active request");
996 7 RETVAL = newRV_noinc((SV*)feersum_env_headers(aTHX_ r, norm));
997 OUTPUT:
998 RETVAL
999  
1000 SV *
1001 header (struct feer_conn *c, SV *name)
1002 PROTOTYPE: $$
1003 CODE:
1004 10 struct feer_req *r = c->req;
1005 10 ▶ if (unlikely(!r))
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely(!r)) 0 10 10
1006 0 croak("Cannot access request header: no active request");
1007 10 RETVAL = feersum_env_header(aTHX_ r, name);
1008 OUTPUT:
1009 RETVAL
1010  
1011 int
1012 fileno (struct feer_conn *c)
1013 CODE:
1014 10 ▶ RETVAL = c->fd;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = c->fd; 6 4 10
1015 OUTPUT:
1016 RETVAL
1017  
1018 SV *
1019 io (struct feer_conn *c)
1020 CODE:
1021 16 RETVAL = feersum_env_io(aTHX_ c);
1022 OUTPUT:
1023 RETVAL
1024  
1025 void
1026 return_from_io (struct feer_conn *c, SV *io_sv)
1027 PROTOTYPE: $$
1028 PPCODE:
1029 {
1030 7 SSize_t cnt = feersum_return_from_io(aTHX_ c, io_sv, "return_from_io");
1031 4 ▶ mXPUSHi(cnt);
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHi(cnt); 0 4 4
1032 }
1033  
1034 bool
1035 is_keepalive (struct feer_conn *c)
1036 CODE:
1037 4 ▶ RETVAL = c->is_keepalive;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = c->is_keepalive; 2 2 4
1038 OUTPUT:
1039 RETVAL
1040  
1041 SV*
1042 response_guard (struct feer_conn *c, ...)
1043 PROTOTYPE: $;$
1044 CODE:
1045 3 ▶ RETVAL = feersum_conn_guard(aTHX_ c, (items == 2) ? ST(1) : NULL);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = feersum_conn_guard(aTHX_ c, (items == 2) ? ST(1) : NULL); 2 1 3
1046 OUTPUT:
1047 RETVAL
1048  
1049 void
1050 DESTROY (struct feer_conn *c)
1051 PPCODE:
1052 {
1053 unsigned i;
1054 1448 int fd = c->fd;
1055 trace("DESTROY connection fd=%d c=%p\n", fd, c);
1056  
1057 // global destruction: refcounts are unreliable and c->server may already
1058 // be gone, so only close the fd (before feer_conn_set_busy, which writes
1059 // through c->server)
1060 1448 ▶ if (unlikely(PL_phase == PERL_PHASE_DESTRUCT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (unlikely(PL_phase == PERL_PHASE_DESTRUCT)) { 299 1149 1448
1061 299 safe_close_conn(c, "close at destruction");
1062 299 return;
1063 }
1064  
1065 1149 feer_conn_set_busy(c);
1066  
1067 // no refcount decs for the watchers: DESTROY already owns the teardown
1068 1149 ▶ if (ev_is_active(&c->read_ev_io)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ev_is_active(&c->read_ev_io)) { 0 1149 1149
1069 0 ev_io_stop(feersum_ev_loop, &c->read_ev_io);
1070 }
1071 1149 ▶ if (ev_is_active(&c->write_ev_io)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ev_is_active(&c->write_ev_io)) { 0 1149 1149
1072 0 ev_io_stop(feersum_ev_loop, &c->write_ev_io);
1073 }
1074 1149 ▶ if (ev_is_active(&c->read_ev_timer)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ev_is_active(&c->read_ev_timer)) { 0 1149 1149
1075 0 ev_timer_stop(feersum_ev_loop, &c->read_ev_timer);
1076 }
1077 1149 ▶ if (ev_is_active(&c->header_ev_timer)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ev_is_active(&c->header_ev_timer)) { 0 1149 1149
1078 0 ev_timer_stop(feersum_ev_loop, &c->header_ev_timer);
1079 }
1080 1149 ▶ if (ev_is_active(&c->write_ev_timer)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ev_is_active(&c->write_ev_timer)) { 0 1149 1149
1081 0 ev_timer_stop(feersum_ev_loop, &c->write_ev_timer);
1082 }
1083  
1084 1149 SvREFCNT_dec(c->rbuf);
1085 1149 SvREFCNT_dec(c->rbuf_spare);
1086 1149 SvREFCNT_dec((SV*)c->trailers);
1087 1149 SvREFCNT_dec(c->proxy_tlvs);
1088  
1089 1149 ▶ if (c->wbuf_rinq) {
Branch: 1 branch
BranchTrueFalseTotal
if (c->wbuf_rinq) { 12 1137 1149
1090 struct iomatrix *m;
1091 24 ▶ while ((m = (struct iomatrix *)rinq_shift(&c->wbuf_rinq)) != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
while ((m = (struct iomatrix *)rinq_shift(&c->wbuf_rinq)) != NULL) { 12 12 24
1092 25 ▶ for (i=0; i < m->count; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i < m->count; i++) 13 12 25
1093 13 SvREFCNT_dec(m->sv[i]);
1094 12 ▶ IOMATRIX_FREE(m);
Branch: 1 branch
BranchTrueFalseTotal
IOMATRIX_FREE(m); 12 0 12
1095 }
1096 }
1097  
1098 1149 free_request(c);
1099 #ifdef FEERSUM_HAS_H2
1100 if (c->h2_session)
1101 feer_h2_free_session(c);
1102 #endif
1103 #ifdef FEERSUM_HAS_TLS
1104 #ifdef FEERSUM_HAS_H2
1105 if (!c->is_h2_stream)
1106 #endif
1107 1149 feer_tls_free_conn(c);
1108 #endif
1109 1149 SvREFCNT_dec(c->remote_addr);
1110 1149 SvREFCNT_dec(c->remote_port);
1111  
1112 1149 safe_close_conn(c, "close at destruction");
1113  
1114 1149 feersum_release_io_body(aTHX_ c);
1115 1149 SvREFCNT_dec(c->poll_write_cb);
1116 1149 SvREFCNT_dec(c->poll_read_cb);
1117 1149 SvREFCNT_dec(c->on_eof_cb);
1118 /* NULL before dec: the guard's DESTROY may touch the connection */
1119 1149 { SV *g = c->ext_guard; c->ext_guard = NULL; SvREFCNT_dec(g); }
1120 /* logs a response that never completed and always releases the captured SVs */
1121 1149 feer_emit_access_log(aTHX_ c);
1122  
1123 {
1124 1149 struct feer_server *server = c->server;
1125 1149 server->active_conns--;
1126 #ifdef FEERSUM_HAS_H2
1127 if (c->is_h2_stream) server->active_h2_streams--;
1128 #endif
1129 1149 SvREFCNT_dec(server->self); // release server ref held since new_feer_conn
1130  
1131 1149 feer_server_resume_capacity(server);
1132  
1133 1149 ▶ if (unlikely(server->shutting_down && server->active_conns <= 0)) {
Branch: 2 branches
BranchTrueFalseTotal
if (unlikely(server->shutting_down && server->active_conns <= 0)) { 4 1145 1149
if (unlikely(server->shutting_down && server->active_conns <= 0)) { 2 2 4
1134 2 ev_idle_stop(feersum_ev_loop, &server->ei);
1135 2 ev_prepare_stop(feersum_ev_loop, &server->ep);
1136 2 ev_check_stop(feersum_ev_loop, &server->ec);
1137 #ifdef FEERSUM_HAS_TLS
1138 2 ev_timer_stop(feersum_ev_loop, &server->tls_wbuf_trim_w);
1139 #endif
1140  
1141 trace3("... was last conn, going to try shutdown\n");
1142 2 ▶ if (server->shutdown_cb_cv)
Branch: 1 branch
BranchTrueFalseTotal
if (server->shutdown_cb_cv) 2 0 2
1143 2 invoke_shutdown_cb(aTHX_ server);
1144 }
1145 }
1146 }
1147  
« feersum_tls.c.inc ↑ Summary feersum_core.c.inc »