Skip to content

Commit

Permalink
improved PSGI backend slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 5, 2011
1 parent c1a5c22 commit 60cda9d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 23 deletions.
15 changes: 3 additions & 12 deletions lib/Mojo/Server/CGI.pm
Expand Up @@ -41,10 +41,7 @@ sub run {
my $chunk = $res->get_start_line_chunk($offset);

# No start line yet, try again
unless (defined $chunk) {
sleep 1;
next;
}
sleep 1 and next unless defined $chunk;

# End of start line
last unless length $chunk;
Expand All @@ -66,10 +63,7 @@ sub run {
my $chunk = $res->get_header_chunk($offset);

# No headers yet, try again
unless (defined $chunk) {
sleep 1;
next;
}
sleep 1 and next unless defined $chunk;

# End of headers
last unless length $chunk;
Expand All @@ -86,10 +80,7 @@ sub run {
my $chunk = $res->get_body_chunk($offset);

# No content yet, try again
unless (defined $chunk) {
sleep 1;
next;
}
sleep 1 and next unless defined $chunk;

# End of content
last unless length $chunk;
Expand Down
16 changes: 5 additions & 11 deletions lib/Mojo/Server/PSGI.pm
Expand Up @@ -64,26 +64,20 @@ sub getline {
my $self = shift;

# Blocking read
my $offset = $self->{offset} //= 0;
my $res = $self->{tx}->res;
while (1) {
my $chunk = $self->{tx}->res->get_body_chunk($offset);
my $chunk = $res->get_body_chunk($self->{offset} //= 0);

# No content yet, try again
unless (defined $chunk) {
sleep 1;
next;
}
sleep 1 and next unless defined $chunk;

# End of content
last unless length $chunk;
return unless length $chunk;

# Content
$offset += length $chunk;
$self->{offset} = $offset;
$self->{offset} += length $chunk;
return $chunk;
}

return;
}

1;
Expand Down

0 comments on commit 60cda9d

Please sign in to comment.