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