Skip to content

Commit

Permalink
fixed bug in Mojolicious::Controller where sending a WebSocket messag…
Browse files Browse the repository at this point in the history
…e would cause multiple resume events
  • Loading branch information
kraih committed Dec 3, 2014
1 parent bbe375e commit f490ac9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 2 additions & 0 deletions Changes
Expand Up @@ -2,6 +2,8 @@
5.68 2014-12-02
- Improved Mojo::DOM::CSS performance significantly.
- Fixed deprecation warnings in get command.
- Fixed bug in Mojolicious::Controller where sending a WebSocket message
would cause multiple resume events.

5.67 2014-11-27
- Improved overall performance by deserializing sessions only on demand.
Expand Down
14 changes: 6 additions & 8 deletions lib/Mojolicious/Controller.pm
Expand Up @@ -188,16 +188,16 @@ sub render_to_string { shift->render(@_, 'mojo.to_string' => 1) }
sub rendered {
my ($self, $status) = @_;

# Disable auto rendering and make sure we have a status
my $res = $self->render_later->res;
# Make sure we have a status
my $res = $self->res;
$res->code($status || 200) if $status || !$res->code;

# Finish transaction
my $stash = $self->stash;
unless ($stash->{'mojo.finished'}++) {

# Stop timer
my $app = $self->app;
# Disable auto rendering and stop timer
my $app = $self->render_later->app;
if (my $started = delete $stash->{'mojo.started'}) {
my $elapsed = sprintf '%f',
Time::HiRes::tv_interval($started, [Time::HiRes::gettimeofday()]);
Expand Down Expand Up @@ -249,7 +249,7 @@ sub send {
Carp::croak 'No WebSocket connection to send message to'
unless $tx->is_websocket;
$tx->send($msg, $cb ? sub { shift; $self->$cb(@_) } : ());
return $self->rendered(101);
return $self;
}

sub session {
Expand Down Expand Up @@ -821,9 +821,7 @@ L<Mojolicious::Plugin::DefaultHelpers/"accepts">.
$c = $c->send($chars => sub {...});
Send message or frame non-blocking via WebSocket, the optional drain callback
will be invoked once all data has been written. Note that this method will
automatically respond to WebSocket handshake requests with a C<101> response
status.
will be invoked once all data has been written.
# Send "Text" message
$c->send('I ♥ Mojolicious!');
Expand Down
2 changes: 1 addition & 1 deletion t/mojo/websocket.t
Expand Up @@ -54,7 +54,7 @@ websocket '/socket' => sub {
$c->send(Mojo::IOLoop->stream($c->tx->connection)->timeout);
$c->finish(1000 => 'I ♥ Mojolicious!');
}
);
)->rendered(101);
};

websocket '/early_start' => sub {
Expand Down

0 comments on commit f490ac9

Please sign in to comment.