Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add is_closing method to Mojo::Transaction::WebSocket
  • Loading branch information
kraih committed Jan 10, 2016
1 parent ca51074 commit 28b02d2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/Mojo/Channel/WebSocket.pm
Expand Up @@ -24,7 +24,7 @@ sub write {

my $tx = $self->{tx};
unless (length($tx->{write} // '')) {
$tx->{state} = $tx->{finished} ? 'finished' : 'read';
$tx->{state} = $tx->is_closing ? 'finished' : 'read';
$tx->emit('drain');
}

Expand Down
10 changes: 9 additions & 1 deletion lib/Mojo/Transaction/WebSocket.pm
Expand Up @@ -63,11 +63,13 @@ sub finish {
my $payload = $close->[0] ? pack('n', $close->[0]) : '';
$payload .= encode 'UTF-8', $close->[1] if defined $close->[1];
$close->[0] //= 1005;
$self->send([1, 0, 0, 0, CLOSE, $payload])->{finished} = 1;
$self->send([1, 0, 0, 0, CLOSE, $payload])->{closing} = 1;

return $self;
}

sub is_closing { !!shift->{closing} }

sub is_established { !!$_[0]{open} || !!$_[0]{masked} }

sub is_websocket {1}
Expand Down Expand Up @@ -382,6 +384,12 @@ Connection identifier.
Close WebSocket connection gracefully.
=head2 is_closing
my $bool = $ws->is_closing;
Check if WebSocket connection is currently being closed.
=head2 is_established
my $bool = $ws->is_established;
Expand Down

0 comments on commit 28b02d2

Please sign in to comment.