Skip to content

Commit

Permalink
correct disconnect callback
Browse files Browse the repository at this point in the history
  • Loading branch information
typester committed Sep 16, 2009
1 parent a6ad35b commit 46ee0a9
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions lib/Plack/Impl/Danga/Socket.pm
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,13 @@ sub _response_handler {
$state_response->($res->[0], $res->[1]);

my $body = $res->[2];
my $disconnect_cb = sub {
$socket->watch_write(1);
$socket->{on_write_ready} = sub {
my ($socket) = @_;
$socket->write && $socket->close;
};
};

if ($HasAIO && Plack::Util::is_real_fh($body)) {
my $offset = 0;
Expand All @@ -214,7 +221,7 @@ sub _response_handler {
$offset += shift;
if ($offset >= $length) {
undef $sendfile;
$socket->close;
$disconnect_cb->();
}
else {
$sendfile->();
Expand All @@ -225,13 +232,18 @@ sub _response_handler {
}
elsif (ref $body eq 'GLOB') {
my $read = do { local $/; <$body> };
$socket->write($read);
$socket->close;
$body->close;

if ($socket->write($read)) {
$socket->close;
}
else {
$disconnect_cb->();
}
}
else {
Plack::Util::foreach( $body, sub { $socket->write($_[0]) } );
$socket->close;
$disconnect_cb->();
}
};
}
Expand Down

0 comments on commit 46ee0a9

Please sign in to comment.