Branch Coverage

feersum_core.c.inc
Criterion Covered Total %
branch 255 384 66.4


line true false branch
7 0 188 if (elt == NULL) return NULL;
9 4 184 if (unlikely(SvMAGICAL(sv))) sv = sv_2mortal(newSVsv(sv));
10 3 185 if (unlikely(!SvOK(sv))) return NULL;
12 6 179 if (unlikely(SvROK(sv))) sv = SvRV(sv);
23 792 241 if (!c->wbuf_rinq) {
32 0 241 if (m->count >= FEERSUM_IOMATRIX_SIZE) {
37 792 241 if (add_iomatrix) {
39 699 93 IOMATRIX_ALLOC(m);
56 1 337 if (unlikely(SvMAGICAL(sv))) {
59 0 337 else if (unlikely(SvPADTMP(sv))) {
64 0 0 if (SvFLAGS(sv) == (SVs_PADTMP|SVf_POK|SVp_POK)) {
74 0 0 (void)SvOK_off(sv);
131 20 40 if (!c->use_chunked) return; // nothing required unless chunked encoding
151 0 59 if (unlikely(len == 0)) return; /* skip: "0\r\n\r\n" is the terminal chunk */
253 662 0 if (likely(is_tcp)) {
254 0 662 if (unlikely(setsockopt(fd, SOL_TCP, TCP_NODELAY, &flags, sizeof(int))))
272 6 0 if (likely(c->cached_is_tcp)) {
288 0 8 PUSHMARK(SP);
293 8 0 if (SvTRUE(ERRSV))
1 7 if (SvTRUE(ERRSV))
294 1 0 sv_setsv(ERRSV, &PL_sv_undef);
296 0 8 FREETMPS;
303 614 662 if (unlikely(c->fd < 0))
315 0 662 CLOSE_SENDFILE_FD(c);
0 0 CLOSE_SENDFILE_FD(c);
319 68 594 if (c->tls && c->tls_handshake_done) {
51 17 if (c->tls && c->tls_handshake_done) {
323 51 0 if (closebuf.off > 0) {
335 0 662 if (unlikely(close(c->fd) < 0))
346 662 0 SvUPGRADE(self, SVt_PVMG); // ensures sv_bless doesn't reallocate
347 662 0 SvGROW(self, sizeof(struct feer_conn));
662 0 SvGROW(self, sizeof(struct feer_conn));
374 161 501 c->receiving = srvr->use_proxy_protocol ? RECEIVE_PROXY_HEADER : RECEIVE_HEADERS;
378 68 594 if (lsnr->tls_ctx_ref) {
428 0 1544 if (unlikely(!sv_isa(rv,"Feersum::Connection")))
444 0 679 if (unlikely(!SvROK(rv))) croak("Expected a reference");
447 679 0 if (likely(
434 245 if (likely(
434 0 if (likely(
679 0 if (likely(
453 88 591 if (uv == 0) {
454 15 73 if (can_croak) croak("Operation not allowed: Handle is closed.");
460 0 0 if (can_croak)
471 79 316 sv_bless(sv, is_writer ? feer_conn_writer_stash : feer_conn_reader_stash);
491 3520 220 for (int i = 0; i < FEER_MAX_LISTENERS; i++) {
504 220 0 SvUPGRADE(self, SVt_PVMG);
505 220 0 SvGROW(self, sizeof(struct feer_server));
220 0 SvGROW(self, sizeof(struct feer_server));
526 27489 33 if (sv_isa(rv, "Feersum")) {
530 33 0 if (SvPOK(rv) && strEQ(SvPV_nolen(rv), "Feersum")) {
33 0 if (SvPOK(rv) && strEQ(SvPV_nolen(rv), "Feersum")) {
531 0 33 if (unlikely(!default_server))
549 12 145 if (unlikely(ev_is_active(&c->read_ev_io)))
558 889 135 if (unlikely(!ev_is_active(&c->read_ev_io)))
567 120 21 if (likely(!ev_is_active(&c->read_ev_timer))) {
577 918 115 if (unlikely(!ev_is_active(&c->read_ev_timer)))
587 122 531 if (unlikely(ev_is_active(&c->write_ev_io)))
596 290 531 if (unlikely(!ev_is_active(&c->write_ev_io)))
605 788 1 if (c->cached_write_timeout <= 0.0) return;
606 1 0 if (likely(!ev_is_active(&c->write_ev_timer))) {
616 841 1 if (unlikely(!ev_is_active(&c->write_ev_timer)))
625 1003 788 if (unlikely(!ev_is_active(&c->header_ev_timer)))
635 0 145 if (timeout <= 0.0) return;
663 34 1731 if (c->idle_rinq_node) {
672 0 36 if (c->idle_rinq_node) return; // already idle
681 9 2 if (!srvr->idle_keepalive_rinq) return 0;
684 0 2 if (unlikely(!c)) return 0;
719 553 390 while (server->request_ready_rinq) {
722 0 553 if (unlikely(!c)) break;
726 525 28 if (likely(c->wbuf_rinq)) {
748 0 163 if (unlikely(revents & EV_ERROR)) {
754 161 2 if (!srvr->shutting_down) {
755 247 161 for (int i = 0; i < srvr->n_listeners; i++) {
757 169 78 if (!ev_is_active(&lsnr->accept_w) && !lsnr->pause_flags) {
169 0 if (!ev_is_active(&lsnr->accept_w) && !lsnr->pause_flags) {
770 0 5164 if (unlikely(revents & EV_ERROR)) {
777 390 4774 if (server->request_ready_rinq)
787 0 386 if (unlikely(revents & EV_ERROR)) {
793 0 386 if (server->request_ready_rinq)
824 142 590 if (c->is_keepalive && c->rbuf) {
136 6 if (c->is_keepalive && c->rbuf) {
828 14 122 if (body_total > 0) {
831 5 9 if (remaining > 0 && remaining <= (ssize_t)SvCUR(c->rbuf)) {
5 0 if (remaining > 0 && remaining <= (ssize_t)SvCUR(c->rbuf)) {
839 142 590 if (c->is_keepalive) {
843 136 6 if (c->rbuf) { pipelined = SvCUR(c->rbuf); }
844 142 0 if (likely(c->req)) {
845 36 106 if (likely(pipelined == 0) && c->req->buf && c->rbuf) {
36 0 if (likely(pipelined == 0) && c->req->buf && c->rbuf) {
30 6 if (likely(pipelined == 0) && c->req->buf && c->rbuf) {
852 0 30 if (SvLEN(c->rbuf) > READ_BUFSZ * 4)
855 112 0 } else if (c->req->buf) {
861 106 36 if (unlikely(pipelined > 0 && c->is_http11)) {
106 0 if (unlikely(pipelined > 0 && c->is_http11)) {
863 106 0 if (c->pipeline_depth <= MAX_PIPELINE_DEPTH) {
879 0 590 if (c->responding != RESPOND_SHUTDOWN)
896 0 732 if (unlikely(revents & EV_ERROR && !(revents & EV_WRITE))) {
0 0 if (unlikely(revents & EV_ERROR && !(revents & EV_WRITE))) {
902 23 709 if (unlikely(!c->wbuf_rinq)) {
903 3 20 if (unlikely(c->responding >= RESPOND_SHUTDOWN))
908 0 20 if (c->sendfile_fd >= 0)
912 0 20 if (!c->poll_write_cb) {
914 0 0 if (c->responding == RESPOND_STREAMING)
922 11 9 if (c->poll_write_cb_is_io_handle)
928 0 20 if (unlikely(!c->wbuf_rinq)) goto try_write_again;
931 708 1 else if (c->cached_wbuf_low_water > 0
932 0 1 && c->wbuf_len <= c->cached_wbuf_low_water
933 0 1 && c->responding == RESPOND_STREAMING && c->poll_write_cb) {
0 1 && c->responding == RESPOND_STREAMING && c->poll_write_cb) {
934 0 1 if (c->poll_write_cb_is_io_handle)
943 3 726 if (c->sendfile_fd >= 0)
959 0 729 if (iov_count > IOV_MAX) iov_count = IOV_MAX;
962 652 77 if (iov_count == 1) {
970 0 729 if (unlikely(wrote <= 0)) {
971 0 0 if (likely(errno == EAGAIN || errno == EINTR))
0 0 if (likely(errno == EAGAIN || errno == EINTR))
974 0 0 CLOSE_SENDFILE_FD(c);
0 0 CLOSE_SENDFILE_FD(c);
985 968 729 for (i = m->offset; i < m->count && consume; i++) {
968 0 for (i = m->offset; i < m->count && consume; i++) {
987 0 968 if (unlikely(v->iov_len > wrote)) {
1000 865 103 if (m->sv[i]) {
1007 729 0 if (likely(m->offset >= m->count)) {
1010 729 0 IOMATRIX_FREE(m);
1011 729 0 if (!c->wbuf_rinq) {
1014 3 726 if (c->sendfile_fd >= 0)
1020 0 0 if (c->cached_wbuf_low_water > 0
1021 0 0 && c->wbuf_len <= c->cached_wbuf_low_water
1022 0 0 && c->responding == RESPOND_STREAMING && c->poll_write_cb) {
0 0 && c->responding == RESPOND_STREAMING && c->poll_write_cb) {
1039 3 0 if (sent > 0) {
1042 3 0 if (c->sendfile_remain == 0) {
1043 3 0 CLOSE_SENDFILE_FD(c);
0 3 CLOSE_SENDFILE_FD(c);
1051 0 0 else if (sent == 0) {
1053 0 0 CLOSE_SENDFILE_FD(c);
0 0 CLOSE_SENDFILE_FD(c);
1055 0 0 if (c->responding == RESPOND_STREAMING) {
1062 0 0 if (errno == EAGAIN || errno == EINTR) {
0 0 if (errno == EAGAIN || errno == EINTR) {
1068 0 0 CLOSE_SENDFILE_FD(c);
0 0 CLOSE_SENDFILE_FD(c);
1092 14 36 if (c->poll_write_cb) goto try_write_again;
1124 21 133 if (len < 8)
1128 0 133 if (memcmp(buf, PROXY_V1_PREFIX, PROXY_V1_PREFIX_LEN) != 0)
1134 2949 103 for (STRLEN i = PROXY_V1_PREFIX_LEN; i < search_len - 1; i++) {
1135 30 2919 if (buf[i] == '\r' && buf[i+1] == '\n') {
30 0 if (buf[i] == '\r' && buf[i+1] == '\n') {
1141 103 30 if (!crlf) {
1142 1 102 if (len >= PROXY_V1_MAX_LINE)
1156 1 29 if (strncmp(p, "UNKNOWN", 7) == 0 && (p[7] == '\0' || p[7] == ' ')) {
0 1 if (strncmp(p, "UNKNOWN", 7) == 0 && (p[7] == '\0' || p[7] == ' ')) {
0 0 if (strncmp(p, "UNKNOWN", 7) == 0 && (p[7] == '\0' || p[7] == ' ')) {
1165 26 3 if (strncmp(p, "TCP4 ", 5) == 0) {
1167 2 1 } else if (strncmp(p, "TCP6 ", 5) == 0) {
1180 0 28 if (sscanf(p, "%45s %45s %d %d", src_addr, dst_addr, &src_port, &dst_port) != 4) {
1186 28 0 if (src_port < 0 || src_port > 65535 || dst_port < 0 || dst_port > 65535) {
27 1 if (src_port < 0 || src_port > 65535 || dst_port < 0 || dst_port > 65535) {
27 0 if (src_port < 0 || src_port > 65535 || dst_port < 0 || dst_port > 65535) {
0 27 if (src_port < 0 || src_port > 65535 || dst_port < 0 || dst_port > 65535) {
1194 2 25 if (is_ipv6) {
1197 0 2 if (inet_pton(AF_INET6, src_addr, &sa6->sin6_addr) != 1) {
1204 1 24 if (inet_pton(AF_INET, src_addr, &sa4->sin_addr) != 1) {
1225 3 103 if (len < PROXY_V2_HDR_MIN)
1229 19 84 if (memcmp(buf, PROXY_V2_SIG, PROXY_V2_SIG_LEN) != 0)
1237 27 57 if (version != PROXY_V2_VERSION)
1246 3 54 if (unlikely(addr_len > 4096)) { /* spec allows 65535, cap for sanity */
1253 4 50 if (len < total_len)
1257 1 49 if (command == PROXY_V2_CMD_LOCAL) {
1264 0 49 if (command != PROXY_V2_CMD_PROXY) {
1271 46 3 if (family == PROXY_V2_FAM_INET) {
1273 0 46 if (addr_len < PROXY_V2_ADDR_V4_LEN)
1289 1 2 } else if (family == PROXY_V2_FAM_INET6) {
1291 0 1 if (addr_len < PROXY_V2_ADDR_V6_LEN)
1305 1 1 } else if (family == PROXY_V2_FAM_UNSPEC) {
1308 1 0 } else if (family == PROXY_V2_FAM_UNIX) {
1314 0 1 if (addr_len < PROXY_V2_ADDR_UNIX_LEN)
1323 46 3 if (family == PROXY_V2_FAM_INET) addr_size = PROXY_V2_ADDR_V4_LEN;
1324 1 2 else if (family == PROXY_V2_FAM_INET6) addr_size = PROXY_V2_ADDR_V6_LEN;
1325 1 1 else if (family == PROXY_V2_FAM_UNIX) addr_size = PROXY_V2_ADDR_UNIX_LEN;
1327 24 25 if (addr_len > addr_size) {
1337 89 3 while (tlv_remaining >= 3) { // minimum TLV: 1 type + 2 length
1340 1 88 if (++tlv_count > 64) {
1348 20 68 if (tlv_remaining < 3 + (size_t)tlv_len) {
1358 2 66 if (tlv_type == PP2_TYPE_SSL && tlv_len >= 5) {
2 0 if (tlv_type == PP2_TYPE_SSL && tlv_len >= 5) {
1364 68 0 if (tlv_type != PP2_TYPE_NOOP) {
1377 0 3 if (HvKEYS(tlv_hv) > 0) {
3 0 if (HvKEYS(tlv_hv) > 0) {
1393 0 290 if (SvCUR(c->rbuf) == 0)
1398 154 136 if (first == 'P') {
1400 106 30 } else if (first == 0x0D) {