Skip to content

Commit

Permalink
added timeout support
Browse files Browse the repository at this point in the history
  • Loading branch information
hidekiy committed Feb 5, 2010
1 parent 55e7238 commit cbf0d1e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/Plack/Server/AnyEvent.pm
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ sub new {
host => undef,
port => undef,
no_delay => 1,
timeout => 300,
@args,
}, $class;
}
Expand Down Expand Up @@ -81,9 +82,14 @@ sub _accept_handler {
}

my $headers = "";
my $timeout_timer = AE::timer($self->{timeout}, 0, sub {
close $sock;
}) if $self->{timeout};

my $try_parse = sub {
if ( $self->_try_read_headers($sock, $headers) ) {
undef $timeout_timer;

my $env = {
SERVER_PORT => $self->{prepared_port},
SERVER_NAME => $self->{prepared_host},
Expand Down Expand Up @@ -136,6 +142,8 @@ sub _accept_handler {
sub _try_read_headers {
my ( $self, $sock, undef ) = @_;

return unless defined fileno $sock;

# FIXME add a timer to manage read timeouts
local $/ = "\012";

Expand Down

1 comment on commit cbf0d1e

@miyagawa
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the merge! (my internet connection was pretty bad ... if you asked some questions over IRC private, then let me know again)

I removed ContentLength since this server doesn't support keep-alive ... now it's even faster :)

Please sign in to comment.