Skip to content

Commit

Permalink
finish transactions a little more consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 9, 2016
1 parent c319e7d commit ca8316a
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions lib/Mojo/Server/Daemon.pm
Expand Up @@ -119,23 +119,21 @@ sub _finish {
return $self->_remove($id) if $tx->is_websocket;

# Finish transaction
$tx->server_close;
delete($c->{tx})->server_close;

# Upgrade connection to WebSocket
if (my $ws = $c->{tx} = $tx->next) {
if (my $ws = $tx->next) {

# Successful upgrade
if ($ws->handshake($tx->next(undef))->res->code == 101) {
$c->{tx} = $ws;
weaken $self;
$ws->on(resume => sub { $self->_write($id) });
$ws->server_open;
}

# Failed upgrade
else {
delete $c->{tx};
$ws->server_close;
}
else { $ws->server_close }
}

# Close connection if necessary
Expand Down

0 comments on commit ca8316a

Please sign in to comment.