Skip to content

Commit

Permalink
do not pass around transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 17, 2015
1 parent 7dfd839 commit f72aca6
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/Mojo/Server/Daemon.pm
Expand Up @@ -106,16 +106,17 @@ sub _close {
}

sub _finish {
my ($self, $id, $tx) = @_;
my ($self, $id) = @_;

# Always remove connection for WebSockets
my $c = $self->{connections}{$id};
return unless my $tx = $c->{tx};
return $self->_remove($id) if $tx->is_websocket;

# Finish transaction
$tx->server_close;

# Upgrade connection to WebSocket
my $c = $self->{connections}{$id};
if (my $ws = $c->{tx} = delete $c->{ws}) {

# Successful upgrade
Expand Down Expand Up @@ -197,8 +198,8 @@ sub _read {
if (($c->{requests} || 0) >= $self->max_requests) || $tx->req->error;

# Finish or start writing
if ($tx->is_finished) { $self->_finish($id, $tx) }
elsif ($tx->is_writing) { $self->_write($id) }
if ($tx->is_finished) { $self->_finish($id) }
elsif ($tx->is_writing) { $self->_write($id) }
}

sub _remove {
Expand Down Expand Up @@ -226,10 +227,10 @@ sub _write {
my $cb = sub { $self->_write($id) };
if ($tx->is_finished) {
if ($tx->has_subscribers('finish')) {
$cb = sub { $self->_finish($id, $tx) }
$cb = sub { $self->_finish($id) }
}
else {
$self->_finish($id, $tx);
$self->_finish($id);
return unless $c->{tx};
}
}
Expand Down

0 comments on commit f72aca6

Please sign in to comment.