Skip to content

Commit

Permalink
improved Mojo::IOLoop::Server to use address and port for descriptor …
Browse files Browse the repository at this point in the history
…inheritance
  • Loading branch information
kraih committed Jan 15, 2014
1 parent 701af99 commit 1c14dda
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 3 additions & 1 deletion Changes
@@ -1,5 +1,5 @@

4.68 2014-01-13
4.68 2014-01-15
- Removed deprecated http_proxy attribute from Mojo::UserAgent.
- Removed deprecated https_proxy attribute from Mojo::UserAgent.
- Removed deprecated name attribute from Mojo::UserAgent.
Expand All @@ -8,6 +8,8 @@
- Removed deprecated app_url method from Mojo::UserAgent.
- Removed deprecated detect_proxy method from Mojo::UserAgent.
- Removed deprecated need_proxy method from Mojo::UserAgent.
- Improved Mojo::IOLoop::Server to use address and port for descriptor
inheritance.
- Improved list of available commands to be alphabetical. (jberger)

4.67 2014-01-11
Expand Down
8 changes: 5 additions & 3 deletions lib/Mojo/IOLoop/Server.pm
Expand Up @@ -33,7 +33,7 @@ has reactor => sub {

sub DESTROY {
my $self = shift;
if (my $port = $self->{port}) { $ENV{MOJO_REUSE} =~ s/(?:^|\,)${port}:\d+// }
$ENV{MOJO_REUSE} =~ s/(?:^|\,)$self->{reuse}:\d+// if $self->{reuse};
return unless my $reactor = $self->reactor;
$self->stop if $self->{handle};
$reactor->remove($_) for values %{$self->{handles}};
Expand All @@ -50,7 +50,9 @@ sub listen {
my $args = ref $_[0] ? $_[0] : {@_};

# Look for reusable file descriptor
my $reuse = my $port = $self->{port} = $args->{port} || 3000;
my $port = $args->{port} || 3000;
my $address = $args->{address} || '0.0.0.0';
my $reuse = $self->{reuse} = "$address:$port";
$ENV{MOJO_REUSE} ||= '';
my $fd;
if ($ENV{MOJO_REUSE} =~ /(?:^|\,)${reuse}:(\d+)/) { $fd = $1 }
Expand All @@ -70,7 +72,7 @@ sub listen {
else {
my %options = (
Listen => $args->{backlog} // SOMAXCONN,
LocalAddr => $args->{address} || '0.0.0.0',
LocalAddr => $address,
LocalPort => $port,
ReuseAddr => 1,
ReusePort => $args->{reuse},
Expand Down
6 changes: 4 additions & 2 deletions t/mojo/ioloop.t
Expand Up @@ -156,9 +156,11 @@ $loop->client(
$connected = 1;
}
);
like $ENV{MOJO_REUSE}, qr/(?:^|\,)${port}:/, 'file descriptor can be reused';
like $ENV{MOJO_REUSE}, qr/(?:^|\,)127\.0\.0\.1:${port}:/,
'file descriptor can be reused';
$loop->start;
unlike $ENV{MOJO_REUSE}, qr/(?:^|\,)${port}:/, 'environment is clean';
unlike $ENV{MOJO_REUSE}, qr/(?:^|\,)127\.0\.0\.1:${port}:/,
'environment is clean';
ok $connected, 'connected';
$err = undef;
$loop->client(
Expand Down

0 comments on commit 1c14dda

Please sign in to comment.