Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
rename server_open -> opened and server_close -> closed
  • Loading branch information
jberger committed Jan 9, 2016
1 parent 79de237 commit 08325e1
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 39 deletions.
2 changes: 1 addition & 1 deletion lib/Mojo/Channel/HTTP.pm
@@ -1,7 +1,7 @@
package Mojo::Channel::HTTP;
use Mojo::Base 'Mojo::Channel';

sub close { shift->{tx}->server_close }
sub close { shift->{tx}->closed }

sub is_server { 0 }

Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Channel/WebSocket.pm
Expand Up @@ -3,7 +3,7 @@ use Mojo::Base 'Mojo::Channel';

use Mojo::WebSocket 'parse_frame';

sub close { shift->{tx}->server_close }
sub close { shift->{tx}->closed }

sub read {
my ($self, $chunk) = @_;
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Server/CGI.pm
Expand Up @@ -38,7 +38,7 @@ sub run {
return undef unless $tx->is_empty || _write($res, 'get_body_chunk');

# Finish transaction
$tx->server_close;
$tx->closed;

return $res->code;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/Mojo/Server/Daemon.pm
Expand Up @@ -107,7 +107,7 @@ sub _close {
my ($self, $id) = @_;

# Finish gracefully
if (my $tx = $self->{connections}{$id}{tx}) { $tx->server_close }
if (my $tx = $self->{connections}{$id}{tx}) { $tx->closed }

delete $self->{connections}{$id};
}
Expand All @@ -121,7 +121,7 @@ sub _finish {
return $self->_remove($id) if $tx->is_websocket;

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

# Upgrade connection to WebSocket
if (my $ws = $tx->next) {
Expand All @@ -132,11 +132,11 @@ sub _finish {
= Mojo::Channel::WebSocket::Server->new(tls => $c->{tls}, tx => $ws);
weaken $self;
$ws->on(resume => sub { $self->_write($id) });
$ws->server_open;
$ws->opened;
}

# Failed upgrade
else { $ws->server_close }
else { $ws->closed }
}

# Close connection if necessary
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Server/PSGI.pm
Expand Up @@ -44,7 +44,7 @@ package Mojo::Server::PSGI::_IO;
use Mojo::Base -base;

# Finish transaction
sub close { shift->{tx}->server_close }
sub close { shift->{tx}->closed }

sub getline {
my $self = shift;
Expand Down
19 changes: 10 additions & 9 deletions lib/Mojo/Transaction.pm
Expand Up @@ -10,6 +10,8 @@ has [
has req => sub { Mojo::Message::Request->new };
has res => sub { Mojo::Message::Response->new };

sub closed { shift->_state(qw(finished finish)) }

sub connection {
my $self = shift;
return $self->emit(connection => $self->{connection} = shift) if @_;
Expand All @@ -36,8 +38,7 @@ sub remote_address {
: $self->original_remote_address;
}

sub resume { shift->_state(qw(write resume)) }
sub server_close { shift->_state(qw(finished finish)) }
sub resume { shift->_state(qw(write resume)) }

sub success { $_[0]->error ? undef : $_[0]->res }

Expand Down Expand Up @@ -155,6 +156,13 @@ HTTP response, defaults to a L<Mojo::Message::Response> object.
L<Mojo::Transaction> inherits all methods from L<Mojo::EventEmitter> and
implements the following new ones.
=head2 closed
$tx->closed;
Transaction closed server-side, used to implement web servers such as
L<Mojo::Server::Daemon>.
=head2 connection
my $id = $tx->connection;
Expand Down Expand Up @@ -211,13 +219,6 @@ Same as L</"original_remote_address"> or the last value of the
C<X-Forwarded-For> header if L</"req"> has been performed through a reverse
proxy.
=head2 server_close
$tx->server_close;
Transaction closed server-side, used to implement web servers such as
L<Mojo::Server::Daemon>.
=head2 success
my $res = $tx->success;
Expand Down
45 changes: 23 additions & 22 deletions lib/Mojo/Transaction/WebSocket.pm
Expand Up @@ -48,6 +48,12 @@ sub build_message {
return build_frame $self->masked, @$frame;
}

sub closed {
my $self = shift;
$self->{state} = 'finished';
return $self->emit(finish => $self->{close} ? (@{$self->{close}}) : 1006);
}

sub connection { shift->handshake->connection }

sub finish {
Expand Down Expand Up @@ -76,6 +82,9 @@ sub new {
return $self;
}


sub opened { shift->{open}++ }

sub protocol { shift->res->headers->sec_websocket_protocol }

sub remote_address { shift->handshake->remote_address }
Expand All @@ -98,14 +107,6 @@ sub send {
return $self->emit('resume');
}

sub server_close {
my $self = shift;
$self->{state} = 'finished';
return $self->emit(finish => $self->{close} ? (@{$self->{close}}) : 1006);
}

sub server_open { shift->{open}++ }

sub with_compression {
my $self = shift;

Expand Down Expand Up @@ -360,6 +361,13 @@ and implements the following new ones.
Build WebSocket message.
=head2 closed
$ws->closed;
Transaction closed server-side, used to implement web servers such as
L<Mojo::Server::Daemon>.
=head2 connection
my $id = $ws->connection;
Expand Down Expand Up @@ -414,6 +422,13 @@ Construct a new L<Mojo::Transaction::WebSocket> object and subscribe to
L</"frame"> event with default message parser, which also handles C<PING> and
C<CLOSE> frames automatically.
=head2 opened
$ws->opened;
WebSocket connection established server-side, used to implement web servers such
as L<Mojo::Server::Daemon>.
=head2 protocol
my $proto = $ws->protocol;
Expand Down Expand Up @@ -465,20 +480,6 @@ will be invoked once all data has been written.
# Send "Ping" frame
$ws->send([1, 0, 0, 0, 9, 'Hello World!']);
=head2 server_close
$ws->server_close;
Transaction closed server-side, used to implement web servers such as
L<Mojo::Server::Daemon>.
=head2 server_open
$ws->server_open;
WebSocket connection established server-side, used to implement web servers such
as L<Mojo::Server::Daemon>.
=head2 with_compression
$ws->with_compression;
Expand Down

0 comments on commit 08325e1

Please sign in to comment.