Skip to content

Commit

Permalink
added the ability to run multiple parallel ioloops that block each
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 12, 2010
1 parent 8565fa5 commit 5b55035
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Changes
Expand Up @@ -25,6 +25,8 @@ This file documents the revision history for Perl extension Mojo.
- Added version command.
- Added after_build_tx plugin hook.
- Added timer support to Mojo::IOLoop.
- Added the ability to run multiple parallel ioloops that block each
other.
- Made all Mojolicious after_* plugin hooks run in reverse order.
- Made param decoding more defensive and allow malformed data to pass
through for debugging.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Client.pm
Expand Up @@ -19,7 +19,7 @@ use Socket;
__PACKAGE__->attr([qw/app default_cb tls_ca_file tls_verify_cb/]);
__PACKAGE__->attr([qw/continue_timeout max_keep_alive_connections/] => 5);
__PACKAGE__->attr(cookie_jar => sub { Mojo::CookieJar->new });
__PACKAGE__->attr(ioloop => sub { Mojo::IOLoop->new });
__PACKAGE__->attr(ioloop => sub { Mojo::IOLoop->singleton });
__PACKAGE__->attr(keep_alive_timeout => 15);
__PACKAGE__->attr(max_redirects => 0);

Expand Down
12 changes: 8 additions & 4 deletions lib/Mojo/IOLoop.pm
Expand Up @@ -59,13 +59,11 @@ __PACKAGE__->attr(
# Singleton
our $LOOP;

# Instantiate singleton
sub new {
my $self = $LOOP ||= shift->SUPER::new(@_);
my $self = shift->SUPER::new(@_);

# Signals
# Ignore pipe
$SIG{PIPE} = 'IGNORE';
$SIG{HUP} = sub { $self->_running(0) };

return $self;
}
Expand Down Expand Up @@ -299,6 +297,8 @@ sub remote_info {
return {address => $socket->peerhost, port => $socket->peerport};
}

sub singleton { $LOOP ||= shift->new(@_) }

sub start {
my $self = shift;

Expand Down Expand Up @@ -950,6 +950,10 @@ following new ones.
my $info = $loop->remote_info($id);
=head2 C<singleton>
my $loop = Mojo::IOLoop->singleton;
=head2 C<start>
$loop->start;
Expand Down
5 changes: 4 additions & 1 deletion lib/Mojo/Server/Daemon.pm
Expand Up @@ -18,7 +18,7 @@ use Scalar::Util qw/isweak weaken/;
use Sys::Hostname 'hostname';

__PACKAGE__->attr([qw/group listen listen_queue_size user/]);
__PACKAGE__->attr(ioloop => sub { Mojo::IOLoop->new });
__PACKAGE__->attr(ioloop => sub { Mojo::IOLoop->singleton });
__PACKAGE__->attr(keep_alive_timeout => 15);
__PACKAGE__->attr(
lock_file => sub {
Expand Down Expand Up @@ -65,6 +65,9 @@ sub prepare_ioloop {

# Max clients
$self->ioloop->max_connections($self->max_clients);

# Stop ioloop on HUP
$SIG{HUP} = sub { $self->ioloop->stop };
}

sub prepare_lock_file {
Expand Down

0 comments on commit 5b55035

Please sign in to comment.