Skip to content

Commit

Permalink
renamed accepting method to acceptor
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Nov 27, 2012
1 parent ba5388f commit 3150e6a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 33 deletions.
15 changes: 7 additions & 8 deletions lib/Mojo/IOLoop.pm
Expand Up @@ -32,7 +32,7 @@ $SIG{PIPE} = 'IGNORE';
# Initialize singleton reactor early
__PACKAGE__->singleton->reactor;

sub accepting {
sub acceptor {
my ($self, $server) = @_;
$self = $self->singleton unless ref $self;

Expand Down Expand Up @@ -156,7 +156,7 @@ sub server {
);
$server->listen(@_);

return $self->accepting($server);
return $self->acceptor($server);
}

sub singleton { state $loop ||= shift->SUPER::new }
Expand Down Expand Up @@ -444,14 +444,13 @@ processes. Note that exceptions in this callback are not captured.
L<Mojo::IOLoop> inherits all methods from L<Mojo::Base> and implements the
following new ones.
=head2 C<accepting>
=head2 C<acceptor>
my $server = Mojo::IOLoop->accepting($id);
my $server = $loop->accepting($id);
my $id = $loop->accepting(Mojo::IOLoop::Server->new);
my $server = Mojo::IOLoop->acceptor($id);
my $server = $loop->acceptor($id);
my $id = $loop->acceptor(Mojo::IOLoop::Server->new);
Get L<Mojo::IOLoop::Server> object for id or start accepting connections from
object.
Get L<Mojo::IOLoop::Server> object for id or turn object into an acceptor.
=head2 C<client>
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/Server/Daemon.pm
Expand Up @@ -59,7 +59,7 @@ sub start {
# Resume accepting connections
my $loop = $self->ioloop;
if (my $accepting = $self->{accepting}) {
push @$accepting, $loop->accepting(delete $self->{servers}{$_})
push @$accepting, $loop->acceptor(delete $self->{servers}{$_})
for keys %{$self->{servers}};
}

Expand All @@ -75,7 +75,7 @@ sub stop {

my $loop = $self->ioloop;
while (my $id = shift @{$self->{accepting}}) {
$self->{servers}{$id} = my $server = $loop->accepting($id);
$self->{servers}{$id} = my $server = $loop->acceptor($id);
$loop->remove($id);
$server->stop;
}
Expand Down
21 changes: 21 additions & 0 deletions t/mojo/app.t
Expand Up @@ -200,4 +200,25 @@ ok $local_port > 0, 'has local port';
ok $remote_address, 'has local address';
ok $remote_port > 0, 'has local port';

# Throttling
$port = Mojo::IOLoop->generate_port;
my $daemon = Mojo::Server::Daemon->new(app => $app,
listen => ["http://127.0.0.1:$port"]);
$daemon->start;
$tx = $ua->get("http://127.0.0.1:$port/throttle1" => {Connection => 'close'});
ok $tx->success, 'successful';
is $tx->res->code, 200, 'right status';
is $tx->res->body, 'Your Mojo is working!', 'right content';
$daemon->stop;
$tx = $ua->inactivity_timeout(0.5)
->get("http://127.0.0.1:$port/throttle2" => {Connection => 'close'});
ok !$tx->success, 'not successful';
is $tx->error, 'Inactivity timeout', 'right error';
$daemon->start;
$tx = $ua->inactivity_timeout(10)
->get("http://127.0.0.1:$port/throttle3" => {Connection => 'close'});
ok $tx->success, 'successful';
is $tx->res->code, 200, 'right status';
is $tx->res->body, 'Your Mojo is working!', 'right content';

done_testing();
2 changes: 1 addition & 1 deletion t/mojo/ioloop.t
Expand Up @@ -87,7 +87,7 @@ $id = $loop->server(
$loop->stop;
}
);
$loop->accepting($id)->on(accept => sub { $handle2 = pop });
$loop->acceptor($id)->on(accept => sub { $handle2 = pop });
$id2 = $loop->client((address => 'localhost', port => $port) => sub { });
$loop->start;
$loop->remove($id);
Expand Down
22 changes: 0 additions & 22 deletions t/mojo/user_agent.t
Expand Up @@ -10,7 +10,6 @@ use Test::More;
use IO::Compress::Gzip 'gzip';
use Mojo::IOLoop;
use Mojo::Message::Request;
use Mojo::Server::Daemon;
use Mojo::UserAgent;
use Mojolicious::Lite;

Expand Down Expand Up @@ -495,25 +494,4 @@ $tx = $ua->get("http://localhost:$port/");
ok !$tx->success, 'not successful';
is $tx->error, 'Premature connection close', 'right error';

# Inactivity timeout (throttling)
$port = Mojo::IOLoop->generate_port;
my $daemon = Mojo::Server::Daemon->new(app => app,
listen => ["http://127.0.0.1:$port"]);
$daemon->start;
$tx = $ua->get("http://127.0.0.1:$port" => {Connection => 'close'});
ok $tx->success, 'successful';
is $tx->res->code, 200, 'right status';
is $tx->res->body, 'works!', 'right content';
$daemon->stop;
$tx = $ua->inactivity_timeout(0.5)
->get("http://127.0.0.1:$port" => {Connection => 'close'});
ok !$tx->success, 'not successful';
is $tx->error, 'Inactivity timeout', 'right error';
$daemon->start;
$tx = $ua->inactivity_timeout(10)
->get("http://127.0.0.1:$port" => {Connection => 'close'});
ok $tx->success, 'successful';
is $tx->res->code, 200, 'right status';
is $tx->res->body, 'works!', 'right content';

done_testing();

0 comments on commit 3150e6a

Please sign in to comment.