Skip to content

Commit

Permalink
changed default WebSocket timeout of Mojo::UserAgent from 300 to 305 …
Browse files Browse the repository at this point in the history
…seconds
  • Loading branch information
kraih committed Dec 10, 2011
1 parent 6ae1534 commit 4f0d833
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 28 deletions.
2 changes: 2 additions & 0 deletions Changes
Expand Up @@ -10,6 +10,8 @@ This file documents the revision history for Perl extension Mojolicious.
- Added EXPERIMENTAL timeout attribute to Mojo::IOLoop::Stream.
- Changed default keep alive timeout of Mojo::UserAgent from 15 to 20
seconds.
- Changed default WebSocket timeout of Mojo::UserAgent from 300 to
305 seconds.
- Improved documentation.
- Improved unicode tests.
- Fixed inline template double encoding bug.
Expand Down
22 changes: 7 additions & 15 deletions lib/Mojo/IOLoop/Stream.pm
Expand Up @@ -27,12 +27,7 @@ sub DESTROY {
$self->_close;
}

sub new {
my $self = shift->SUPER::new;
$self->{handle} = shift;
$self->{buffer} = '';
return $self;
}
sub new { shift->SUPER::new(handle => shift, buffer => '', active => time) }

sub handle { shift->{handle} }

Expand Down Expand Up @@ -60,21 +55,18 @@ sub resume {
weaken $self;
$self->{timer} ||= $watcher->recurring(
'0.025' => sub {
return
unless $self && (time - ($self->{active} || time)) >= $self->timeout;
return unless $self && (time - ($self->{active})) >= $self->timeout;
$self->emit_safe('timeout') unless $self->{timed}++;
$self->_close;
}
);

# Start streaming
unless ($self->{streaming}++) {
return $watcher->watch(
$self->{handle},
sub { $self->_read },
sub { $self->_write }
);
}
return $watcher->watch(
$self->{handle},
sub { $self->_read },
sub { $self->_write }
) unless $self->{streaming}++;

# Resume streaming
return unless delete $self->{paused};
Expand Down
15 changes: 4 additions & 11 deletions lib/Mojo/Server/Daemon.pm
Expand Up @@ -100,12 +100,8 @@ sub _build_tx {

# Events
weaken $self;
$tx->on(
upgrade => sub {
my ($tx, $ws) = @_;
$self->{connections}->{$id}->{ws} = $ws->server_handshake;
}
);
$tx->on(upgrade =>
sub { $self->{connections}->{$id}->{ws} = pop->server_handshake });
$tx->on(
request => sub {
my $tx = shift;
Expand All @@ -114,12 +110,9 @@ sub _build_tx {
}
);

# New request on the connection
$c->{requests} ||= 0;
$c->{requests}++;

# Kept alive if we have more than one request on the connection
$tx->kept_alive(1) if $c->{requests} > 1;
$c->{requests} ||= 0;
$tx->kept_alive(1) if ++$c->{requests} > 1;

return $tx;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/UserAgent.pm
Expand Up @@ -26,7 +26,7 @@ has max_connections => 5;
has max_redirects => sub { $ENV{MOJO_MAX_REDIRECTS} || 0 };
has name => 'Mojolicious (Perl)';
has transactor => sub { Mojo::UserAgent::Transactor->new };
has websocket_timeout => 300;
has websocket_timeout => 305;

# Common HTTP methods
{
Expand Down Expand Up @@ -767,7 +767,7 @@ Note that this attribute is EXPERIMENTAL and might change without warning!
$ua = $ua->websocket_timeout(300);
Maximum amount of time in seconds a WebSocket connection can be inactive
before getting dropped, defaults to C<300>.
before getting dropped, defaults to C<305>.
=head1 METHODS
Expand Down

0 comments on commit 4f0d833

Please sign in to comment.