Branch Coverage

blib/lib/Starlight/Server.pm
Criterion Covered Total %
branch 136 312 43.5


line true false branch
58 104 0 exists &Errno::EINTR ? :
59 104 0 exists &Errno::EAGAIN ? :
60 104 0 exists &Errno::EWOULDBLOCK ? :
103 1 97 defined $args{'min_reqs_per_child'} ? :
0 98 defined $args{'err_respawn_interval'} ? :
112 0 98 if ($^O eq "MSWin32")
115 0 0 if ($v[1] * 1000 + $v[2] < 6002)
120 0 98 if ($args{'max_workers'} and $args{'max_workers'} > 1)
139 0 6 if ($self->{'socket'} and $self->{'port'})
143 0 6 if ($self->{'socket'} and $self->{'ssl'})
147 6 91 if ($self->{'socket'})
149 0 6 unless &try(sub { require IO::Socket::UNIX; 1; } )
154 91 0 if ($self->{'ipv6'})
158 0 91 if ($self->{'ssl'})
160 0 0 unless &try(sub { require IO::Socket::SSL; 1; } )
168 0 91 if $self->{'ssl'}
169 91 0 if $self->{'ipv6'}
185 6 91 $self->{'socket'} ? :
189 0 97 $self->{'ssl'} ? :
190 6 91 $self->{'socket'} ? :
194 0 97 unless ($self->{'listen_sock'} ||= $class->new(%args))
199 0 97 unless $self->{'quiet'}
206 91 6 if ($^O eq "linux" and $self->{'_listen_sock_is_tcp'})
208 91 0 if setsockopt $self->{'listen_sock'}, 6, 9, 1
211 6 91 if ($self->{'_listen_sock_is_unix'} and not $args{'Local'} =~ /^\0/)
230 66 0 if $self->{'can_exit'}
233 0 0 if $is_keepalive and $self->{'can_exit'} or $self->{'term_received'} > 1
241 0 101 unless (my($conn, $peer) = $self->{'listen_sock'}->accept)
247 100 1 if ($self->{'_listen_sock_is_tcp'})
248 0 100 if (Socket::sockaddr_family(getsockname $conn) == 10) { }
255 100 0 if (&try(sub { 1; } ))
257 0 100 unless ($conn->setsockopt(6, 1, 1))
264 0 101 if ($conn->isa("IO::Socket::SSL"))
265 0 0 unless ($conn->accept_SSL)
267 0 0 if $!
268 0 0 if $IO::Socket::SSL::SSL_ERROR
276 0 101 unless ($conn->blocking(0))
298 0 101 $self->{'ssl'} ? :
306 0 0 if ($may_keepalive and $max_reqs_per_child and $proc_req_count >= $max_reqs_per_child)
309 0 101 if length $pipelined_buf
316 23 78 if ($env->{'psgix.harakiri.commit'})
320 78 0 unless $keepalive
337 101 0 defined $prebuf ? :
340 0 101 if ($rlen = length $prebuf) { }
347 0 101 $is_keepalive ? :
9 92 unless $rlen = $self->read_timeout($conn, \$buf, 131072 - length($buf), length $buf, $is_keepalive ? $self->{'keepalive_timeout'} : $self->{'timeout'})
351 92 0 if ($reqlen >= 0)
355 0 92 if ($use_keepalive)
356 0 0 if ($protocol eq 'HTTP/1.1') { }
357 0 0 if (my $c = $env->{'HTTP_CONNECTION'})
358 0 0 if $c =~ /^\s*close\s*/i
362 0 0 if (my $c = $env->{'HTTP_CONNECTION'}) { }
363 0 0 unless $c =~ /^\s*keep-alive\s*/i
372 5 87 if (my $cl = $env->{'CONTENT_LENGTH'}) { }
1 86 elsif ($chunked) { }
376 4 2 if (length $buf) { }
381 1 1 unless $self->read_timeout($conn, \$chunk, $cl, 0, $self->{'timeout'})
393 1 3 if (length $buf) { }
398 0 3 unless $self->read_timeout($conn, \$chunk, 65536, 0, $self->{'timeout'})
405 1 99 if ($chunk_len == 0) { }
1 98 elsif (length $chunk_buffer < $chunk_len + 2) { }
419 0 86 if ($buf =~ /^(?:GET|HEAD)/)
426 0 91 if ($env->{'HTTP_EXPECT'})
427 0 0 if ($env->{'HTTP_EXPECT'} eq '100-continue') { }
428 0 0 unless $self->write_all($conn, "HTTP/1.1 100 Continue\r\n\r\n")
439 0 0 if ($reqlen == -2) { }
0 0 elsif ($reqlen == -1) { }
449 88 3 if (ref $res eq 'ARRAY') { }
3 0 elsif (ref $res eq 'CODE') { }
460 0 91 if ($self->{'term_received'})
478 0 104 unless defined $v
480 0 104 if ($lck eq 'connection') { }
481 0 0 if $$use_keepalive_r and lc $v ne "keep-alive"
488 90 1 unless (exists $send_headers{'server'})
491 91 0 unless (exists $send_headers{'date'})
497 89 2 if (defined $protocol and $protocol eq 'HTTP/1.1') { }
498 4 85 if (defined $send_headers{'content-length'} or defined $send_headers{'transfer-encoding'}) { }
84 1 elsif (not Plack::Util::status_with_no_entity_body($status_code)) { }
506 89 0 unless $$use_keepalive_r
510 0 2 if ($$use_keepalive_r)
511 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))) { }
523 0 2 if $$use_keepalive_r
524 2 0 unless $$use_keepalive_r
530 81 2 if (defined $body and ref $body eq "ARRAY" and @$body == 1 and defined $body->[0] and length $body->[0] < 8192)
538 78 3 if ($use_chunked)
548 0 10 unless $self->write_all($conn, join("", @lines), $self->{'timeout'})
550 8 2 if (defined $body) { }
553 3 5 ref $body eq 'ARRAY' ? :
557 10 0 unless ($failed)
560 7 3 if ($use_chunked)
562 0 7 unless $len
564 2 5 if ($body_count == 0)
570 0 10 unless $self->write_all($conn, $buf, $self->{'timeout'})
574 2 6 if $use_chunked and not $completed
578 5 0 if ($use_chunked)
580 1 4 unless $len
586 2 0 if $use_chunked
595 6 100 unless ($is_write or delete $self->{'_is_deferred_accept'})
601 109 106 if ($is_write) { }
602 109 0 if $ret = syswrite($sock, $buf, $len, $off)
605 96 10 if $ret = sysread($sock, $$buf, $len, $off)
608 10 0 if (defined $ret or $! != 4 and $! != 11 and $! != 11)
618 0 6 if ($is_write) { }
626 6 0 if $nfound
627 0 0 if $timeout <= 0
649 0 109 unless my $ret = $self->write_timeout($sock, $buf, $len, $off, $timeout)
664 0 95 if ($^O eq "MSWin32")
666 0 0 if $self->{$arg}
671 0 95 if ($self->{'pid'})
673 0 0 if (defined *Fcntl::O_EXCL{'CODE'}) { }
674 0 0 unless sysopen $pidfh, $pidfile, 193
677 0 0 unless open $pidfh, ">", $pidfile
681 0 95 if (defined $self->{'error_log'})
682 0 0 unless open STDERR, ">>", $self->{'error_log'}
685 0 95 if ($self->{'daemonize'})
687 0 0 unless chdir "File::Spec"->rootdir
689 0 0 unless open my $devnull, "+>", "File::Spec"->devnull
691 0 0 unless open STDIN, ">&", $devnull
692 0 0 unless open STDOUT, ">&", $devnull
694 0 0 unless defined(my $pid = fork)
695 0 0 if ($pid)
696 0 0 if ($self->{'pid'} and $pid)
697 0 0 unless print $pidfh "$pid\n"
699 0 0 unless open STDERR, ">&", $devnull
704 0 0 if $pidfh
706 0 0 if ($Config::Config{'d_setsid'})
707 0 0 unless POSIX::setsid()
710 0 0 unless (defined $self->{'error_log'})
711 0 0 unless open STDERR, ">&", $devnull
715 0 95 if ($pidfile)
725 0 95 if (defined $self->{'group'})
726 0 0 unless ($Config::Config{'d_setegid'})
729 0 0 if ($self->_get_gid($self->{'group'}) ne $Starlight::Server::EGID)
735 0 95 if (defined $self->{'user'})
736 0 0 unless ($Config::Config{'d_seteuid'})
739 0 0 if ($self->_get_uid($self->{'user'}) ne $Starlight::Server::EUID)
745 0 95 if (defined $self->{'umask'})
746 0 0 unless ($Config::Config{'d_umask'})
760 0 0 if ($user =~ /^(\d+)$/) { }
767 0 0 unless defined $uid
777 0 0 if ($group =~ /^\d+$/) { }
781 0 0 unless defined $id
786 0 0 unless @gid
795 0 0 unless eval { do { POSIX::setuid($uid) } }
796 0 0 if ($Starlight::Server::UID != $uid or $Starlight::Server::EUID != $uid)
798 0 0 if ($Starlight::Server::UID != $uid)
811 0 0 unless eval { do { $Starlight::Server::EGID = $gids } }
813 0 0 unless eval { do { POSIX::setgid($gid) } }
814 0 0 unless (grep {$gid == $_;} split(/\s+/, $Starlight::Server::GID, 0))
823 814 793 if $t
829 0 880 unless defined $pid
831 87 793 if ($pid == 0) { }
833 23 0 unless eval { do { $SIG{'CHLD'} = "DEFAULT"; $self->accept_loop($app, $self->_calc_reqs_per_child) } }
837 0 23 if $@
848 10000 87 if (my $min = $self->{'min_reqs_per_child'}) { }