Skip to content

Commit

Permalink
improved event loop compatibility of Mojo::Server::PSGI
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Mar 9, 2012
1 parent 5124f25 commit 4c4a1f6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -3,6 +3,7 @@ This file documents the revision history for Perl extension Mojolicious.
2.58 2012-03-09 00:00:00
- Added support for MOJO_LISTEN environment variable.
- Removed listen attribute from Mojo::Server::Morbo.
- Improved event loop compatibility of Mojo::Server::PSGI.
- Improved documentation.
- Improved tests.
- Fixed Mojo::URL object handling bug in url_for.
Expand Down
21 changes: 8 additions & 13 deletions lib/Mojo/Server/PSGI.pm
Expand Up @@ -68,21 +68,16 @@ sub close { shift->{tx}->server_close }
sub getline {
my $self = shift;

# Blocking read
my $res = $self->{tx}->res;
while (1) {
my $chunk = $res->get_body_chunk($self->{offset} //= 0);
# No content yet, try again later
my $chunk = $self->{tx}->res->get_body_chunk($self->{offset} //= 0);
return '' unless defined $chunk;

# No content yet, try again
sleep 1 and next unless defined $chunk;
# End of content
return unless length $chunk;

# End of content
return unless length $chunk;

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

1;
Expand Down

0 comments on commit 4c4a1f6

Please sign in to comment.