Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
added experimental accepts attribute to Mojo::IOLoop::Server
  • Loading branch information
kraih committed Sep 25, 2011
1 parent e21a3bc commit 4371068
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -6,6 +6,7 @@ This file documents the revision history for Perl extension Mojolicious.
- Added EXPERIMENTAL group function to Mojolicious::Lite.
- Added EXPERIMENTAL build_frame and parse_frame methods to
Mojo::Transaction::WebSocket.
- Added EXPERIMENTAL accepts attribute to Mojo::IOLoop::Server.
- Added EXPERIMENTAL profile helper.
- Added EXPERIMENTAL binary support to Mojo::Transaction::WebSocket.
- Updated WebSocket implementation to ietf-15.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/IOLoop.pm
Expand Up @@ -405,7 +405,7 @@ sub _listening {
if (my $cb = $self->on_lock) { return unless $self->$cb(!$i) }

# Check if multi-accept is desirable and start listening
$_->resume($max > 1 ? 10 : 1) for values %$servers;
$_->accepts($max > 1 ? 10 : 1)->resume for values %$servers;
$self->{listening} = 1;
}

Expand Down
16 changes: 12 additions & 4 deletions lib/Mojo/IOLoop/Server.pm
Expand Up @@ -66,6 +66,7 @@ AnqxHi90n/p912ynLg2SjBq+03GaECeGzC/QqKK2gtA=
-----END RSA PRIVATE KEY-----
EOF

has accepts => 10;
has iowatcher => sub {
require Mojo::IOLoop;
Mojo::IOLoop->singleton->iowatcher;
Expand Down Expand Up @@ -168,10 +169,10 @@ sub pause {
}

sub resume {
my ($self, $accepts) = @_;
my $self = shift;
weaken $self;
$self->iowatcher->add($self->{handle},
on_readable => sub { $self->_accept for 1 .. $accepts });
on_readable => sub { $self->_accept for 1 .. $self->accepts });
}

sub _accept {
Expand Down Expand Up @@ -273,7 +274,7 @@ Mojo::IOLoop::Server - IOLoop socket server
$server->listen(port => 3000);
# Start and stop accepting connections
$server->resume(1);
$server->resume;
$server->pause;
=head1 DESCRIPTION
Expand All @@ -294,6 +295,13 @@ Emitted for each accepted connection.
L<Mojo::IOLoop::Server> implements the following attributes.
=head2 C<accepts>
my $accepts = $server->accepts;
$server = $server->accepts(10);
Number of connections to accept at once, defaults to C<10>.
=head2 C<iowatcher>
my $watcher = $server->iowatcher;
Expand Down Expand Up @@ -363,7 +371,7 @@ Stop accepting connections.
=head2 C<resume>
$server->resume(10);
$server->resume;
Start accepting connections.
Expand Down

0 comments on commit 4371068

Please sign in to comment.