Branch Coverage

blib/lib/Monoceros/Server.pm
Criterion Covered Total %
branch 183 350 52.2


line true false branch
51 0 83 if (defined $ENV{'SERVER_STARTER_PORT'})
53 0 0 if ($hostport =~ /(.*):(\d+)/) { }
59 0 0 unless $listen_sock = "IO::Socket::INET"->new("Proto", "tcp")
62 0 0 unless $listen_sock->fdopen($fd, "w")
68 22 144 if defined $args{$_}
101 0 83 defined $args{'socket_path'} ? :
3 80 exists $args{'keepalive'} && !$args{'keepalive'} ? :
0 83 defined $args{'max_readahead_reqs'} ? :
0 83 defined $args{'min_readahead_reqs'} ? :
0 83 defined $args{'min_reqs_per_child'} ? :
0 83 defined $args{'err_respawn_interval'} ? :
0 83 defined $listen_sock ? :
111 0 83 if (my $path = $self->{'socket_path'}) { }
112 0 0 if (-S $path)
114 0 0 unless unlink $path
119 0 0 unless $self->{'listen_sock'} = "IO::Socket::UNIX"->new("Listen", 4096, "Local", $path)
131 0 83 unless $self->{'listen_sock'} ||= "IO::Socket::INET"->new("Listen", 4096, "LocalPort", $self->{'port'}, "LocalAddr", $self->{'host'}, "Proto", "tcp", "ReuseAddr", 1)
135 83 0 if ($^O eq "linux" and not $self->{'use_unix_domain'})
137 83 0 if setsockopt $self->{'listen_sock'}, 6, 9, 1
156 0 333 unless my(@pair) = &portable_socketpair()
165 0 83 unless my(@fdpass_sock) = &portable_socketpair()
181 12 71 if ($pid) { }
71 0 elsif (defined $pid) { }
200 0 0 unless (exists $self->{'sockets'}{$sockid})
208 0 0 unless (exists $self->{'sockets'}{$sockid})
211 0 0 if (_getpeername($self->{'sockets'}{$sockid}[1], my $addr) < 0)
219 0 0 unless ($ret)
220 0 0 if ($! == 11 or $! == 11 or $! == 4)
244 47 83 if $stats eq $prev_stats and @_
254 0 57 unless $buf
255 57 0 if ($buf =~ /total=(\d+)&/)
256 0 57 if $1 >= $self->{'max_keepalive_connection'}
282 0 12 if (not $close_all && $i < 4) { }
0 12 elsif ($i >= 4) { }
295 32 12 if ($kid >= 0 and $j < 60) { }
0 12 elsif ($j >= 60) { }
310 0 13 if keys %{$$self{"sockets"};}
325 0 0 if ($self->{'sockets'}{$key}[4] == 0 and $self->{'sockets'}{$key}[3] == 0 and $time - $self->{'sockets'}{$key}[2] > $self->{'timeout'}) { }
0 0 elsif ($self->{'sockets'}{$key}[4] == 0 and $self->{'sockets'}{$key}[3] > 0 and $time - $self->{'sockets'}{$key}[2] > $self->{'keepalive_timeout'}) { }
347 0 37 unless $sock
357 281261 0 if ($state->{'state'} eq "cmd")
359 0 0 if (not defined $ret and $! == 4 || $! == 11 || $! == 11)
362 0 281261 unless (defined $ret)
366 281261 0 if (defined $buf and length $buf == 0)
370 0 0 if length $state->{'buf'} < 28
376 0 0 if ($method eq 'push') { }
0 0 elsif ($method eq 'keep') { }
0 0 elsif ($method eq 'clos') { }
382 0 0 if (exists $self->{'sockets'}{$sockid})
398 0 0 if ($state->{'state'} eq "recv_fd")
400 0 0 if ($fd < 0 and $! == 4 || $! == 11 || $! == 11)
404 0 0 if ($fd <= 0)
448 0 71 if (defined $self->{'err_respawn_interval'})
456 160 275 if ($self->{'workers'}{$wid}{'running'} and $self->{'workers'}{$wid}{'running'} == $exit_pid)
465 343 548 unless ($self->{'workers'}{$wid}{'running'})
474 285 0 if (defined $next) { }
487 0 58 unless $next
489 58 196 if $wid == $next
496 0 58 unless open $self->{'stats_fh'}, "<", $self->{'stats_filename'}
519 0 35 if $self->{'term_received'} > 1
533 35 252 if $self->{'term_received'} and not $next_conn
535 0 252 if ($next_conn and $next_conn->{'buf'}) { }
542 74 178 if ($next_conn)
547 187 65 if (select($rfd, undef, undef, 1) > 0)
550 200 247 if (not defined $rfd or vec $rfd, $try_read_fd, 1)
551 74 126 if ($next_conn and fileno $next_conn->{'fh'} == $try_read_fd)
560 178 74 unless ($conn)
564 0 149 if ($conn and $next_conn and $conn != $next_conn)
568 0 252 if (not $conn and $next_conn)
576 103 149 unless $conn
597 149 0 if $ENV{'HARNESS_ACTIVE'}
600 0 149 if (exists $conn->{'buf'}) { }
606 0 149 if (not defined $ret and $! == 11 || $! == 11 || $! == 4) { }
54 95 elsif (defined $ret and $ret == 0) { }
613 4 50 unless $conn->{'direct'}
619 0 95 if $self->{'term_received'} or $self->{'stop_accept'}
620 1 94 if $self->{'disable_keepalive'}
627 18 77 if ($env->{'psgix.harakiri.commit'})
633 3 92 unless ($keepalive)
636 0 3 unless $conn->{'direct'}
641 0 92 if (defined $pipelined_buf and length $pipelined_buf)
648 74 18 if ($conn->{'reqs'} < $max_readahead_reqs and $proc_req_count <= $max_reqs_per_child)
663 0 13 if $children_left
675 18 0 if ($conn->{'direct'}) { }
680 0 0 if not defined $ret and $! != 11 and $! != 11 and $! != 4
695 106 7 if (fileno $sock == fileno $self->{'listen_sock'}) { }
7 0 elsif (fileno $sock == fileno $self->{'fdpass_sock'}[1]) { }
697 0 106 if ($have_accept4) { }
702 71 35 if $peer
704 0 0 if (not $peer and ($! != 4 and $! != 11 and $! != 11 and $! != 29))
708 35 71 unless $peer
709 71 0 unless ($self->{'use_unix_domain'})
710 0 71 unless setsockopt $fh, 6, 1, 1
714 0 71 if ($self->{'use_unix_domain'}) { }
732 0 0 if ($fd < 0 and ($! != 4 and $! != 11 and $! != 11 and $! != 29))
735 3 4 if $fd <= 0
737 0 4 if (_getpeername($fd, $peer) < 0)
740 0 4 unless open my $fh, '>>&=' . $fd
743 0 4 if ($self->{'use_unix_domain'}) { }
760 103 75 unless $conn
774 95 1 if (defined $prebuf) { }
783 1 0 $is_keepalive ? :
1 0 unless $rlen = $self->read_timeout($conn, \$buf, 131072 - length($buf), length $buf, $is_keepalive ? $self->{'keepalive_timeout'} : $self->{'timeout'})
787 94 1 if ($reqlen >= 0)
790 93 1 if ($use_keepalive)
791 92 1 if ($protocol eq 'HTTP/1.1') { }
792 12 80 if (my $c = $env->{'HTTP_CONNECTION'})
793 0 12 if $c =~ /^\s*close\s*/i
798 0 1 if (my $c = $env->{'HTTP_CONNECTION'}) { }
799 0 0 unless $c =~ /^\s*keep-alive\s*/i
805 57 36 if ($use_keepalive and $reqs <= 1)
811 5 89 if (my $cl = $env->{'CONTENT_LENGTH'}) { }
1 88 elsif ($chunked) { }
815 1 5 if (length $buf) { }
821 1 4 unless $self->read_timeout($conn, \$chunk, $cl, 0, $self->{'timeout'})
834 0 1 if (length $buf) { }
840 0 1 unless $self->read_timeout($conn, \$chunk, 65536, 0, $self->{'timeout'})
847 1 15 if ($chunk_len == 0) { }
0 15 elsif (length $chunk_buffer < $chunk_len + 2) { }
862 0 88 if ($buf =~ /^(?:GET|HEAD)/)
869 0 93 if ($env->{'HTTP_EXPECT'})
870 0 0 if ($env->{'HTTP_EXPECT'} eq '100-continue') { }
871 0 0 unless $self->write_all($conn, "HTTP/1.1 100 Continue\r\n\r\n")
882 1 0 if ($reqlen == -2) { }
0 0 elsif ($reqlen == -1) { }
890 90 3 if (ref $res eq 'ARRAY') { }
3 0 elsif (ref $res eq 'CODE') { }
916 0 106 if ($lck eq 'connection') { }
917 0 0 if $$use_keepalive_r and lc $v ne "keep-alive"
924 93 0 unless (exists $send_headers{'server'})
927 93 0 unless (exists $send_headers{'date'})
933 0 93 if ($protocol eq 'HTTP/1.0') { }
93 0 elsif ($protocol eq 'HTTP/1.1') { }
934 0 0 if ($$use_keepalive_r)
935 0 0 if (defined $send_headers{'content-length'} or defined $send_headers{'transfer-encoding'}) { }
0 0 elsif (not Plack::Util::status_with_no_entity_body($status_code) and defined(my $cl = Plack::Util::content_length($body))) { }
947 0 0 if $$use_keepalive_r
948 0 0 unless $$use_keepalive_r
951 4 89 if (defined $send_headers{'content-length'} or defined $send_headers{'transfer-encoding'}) { }
88 1 elsif (not Plack::Util::status_with_no_entity_body($status_code)) { }
958 1 92 unless $$use_keepalive_r
965 83 3 if (defined $body and ref $body eq "ARRAY" and @$body == 1 and length $body->[0] < 8192)
969 82 1 if ($use_chunked)
976 0 83 unless $len
980 0 0 if ($have_sendfile and not $use_chunked and defined $body and ref $body ne "ARRAY" and fileno $body)
986 0 0 if ($^O eq "linux" and not $self->{'use_unix_domain'})
987 0 0 if setsockopt $conn, 6, 3, 1
991 0 0 unless $self->write_all($conn, join("", @lines), $self->{'timeout'})
994 0 0 if ($use_cork and $$use_keepalive_r and not $self->{'use_unix_domain'})
1001 0 10 unless $self->write_all($conn, join("", @lines), $self->{'timeout'})
1003 8 2 if (defined $body) { }
1006 3 5 ref $body eq 'ARRAY' ? :
1010 10 0 unless ($failed)
1013 7 3 if ($use_chunked)
1015 0 7 unless $len
1017 2 5 if ($body_count == 0)
1023 0 10 unless $self->write_all($conn, $buf, $self->{'timeout'})
1027 2 6 if $use_chunked and not $completed
1032 5 0 if ($use_chunked)
1034 1 4 unless $len
1040 2 0 if $use_chunked
1048 0 116 if (defined $min) { }
1060 1 6 unless ($is_write or delete $self->{'_is_deferred_accept'})
1065 111 10 if ($is_write and $is_write == 1) { }
0 10 elsif ($is_write and $is_write == 2) { }
1066 111 0 if $ret = syswrite($sock, $buf, $len, $off)
1069 0 0 if $ret = Sys::Sendfile::sendfile($sock, $buf, $len)
1071 0 0 if defined $ret and $ret == 0 and $! == 11
1073 5 5 if $ret = sysread($sock, $$buf, $len, $off)
1076 2 3 unless (not defined $ret and $! == 4 || $! == 11 || $! == 11)
1086 0 4 if ($is_write) { }
1094 4 0 if $nfound
1095 0 0 if $timeout <= 0
1109 0 0 unless my $ret = $self->sendfile_timeout($sock, $fh, $len, $off, $timeout)
1112 0 0 if $cl != $off