Skip to content

Commit

Permalink
no need to generate port for test server
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed May 11, 2014
1 parent bf5cd13 commit 401f98e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 15 deletions.
6 changes: 2 additions & 4 deletions lib/Mojo/IOLoop/Client.pm
Expand Up @@ -3,6 +3,7 @@ use Mojo::Base 'Mojo::EventEmitter';

use Errno 'EINPROGRESS';
use IO::Socket::INET;
use Mojo::IOLoop;
use Scalar::Util 'weaken';
use Socket qw(IPPROTO_TCP SO_ERROR TCP_NODELAY);

Expand All @@ -18,10 +19,7 @@ use constant TLS => $ENV{MOJO_NO_TLS}
use constant TLS_READ => TLS ? IO::Socket::SSL::SSL_WANT_READ() : 0;
use constant TLS_WRITE => TLS ? IO::Socket::SSL::SSL_WANT_WRITE() : 0;

has reactor => sub {
require Mojo::IOLoop;
Mojo::IOLoop->singleton->reactor;
};
has reactor => sub { Mojo::IOLoop->singleton->reactor };

sub DESTROY { shift->_cleanup }

Expand Down
6 changes: 2 additions & 4 deletions lib/Mojo/IOLoop/Server.pm
Expand Up @@ -5,6 +5,7 @@ use Carp 'croak';
use File::Basename 'dirname';
use File::Spec::Functions 'catfile';
use IO::Socket::INET;
use Mojo::IOLoop;
use Scalar::Util 'weaken';
use Socket qw(IPPROTO_TCP TCP_NODELAY);

Expand All @@ -26,10 +27,7 @@ my $CERT = catfile dirname(__FILE__), 'server.crt';
my $KEY = catfile dirname(__FILE__), 'server.key';

has multi_accept => 50;
has reactor => sub {
require Mojo::IOLoop;
Mojo::IOLoop->singleton->reactor;
};
has reactor => sub { Mojo::IOLoop->singleton->reactor };

sub DESTROY {
my $self = shift;
Expand Down
6 changes: 2 additions & 4 deletions lib/Mojo/IOLoop/Stream.pm
Expand Up @@ -2,12 +2,10 @@ package Mojo::IOLoop::Stream;
use Mojo::Base 'Mojo::EventEmitter';

use Errno qw(EAGAIN ECONNRESET EINTR EPIPE EWOULDBLOCK);
use Mojo::IOLoop;
use Scalar::Util 'weaken';

has reactor => sub {
require Mojo::IOLoop;
Mojo::IOLoop->singleton->reactor;
};
has reactor => sub { Mojo::IOLoop->singleton->reactor };

sub DESTROY { shift->close }

Expand Down
6 changes: 3 additions & 3 deletions lib/Mojo/UserAgent/Server.pm
Expand Up @@ -39,10 +39,10 @@ sub _restart {
);
weaken $server->{app};
delete $self->{port} if $full;
die "Couldn't find a free TCP port for application.\n"
unless my $port = $self->{port} ||= Mojo::IOLoop->generate_port;
my $port = $self->{port} ? ":$self->{port}" : '';
$self->{proto} = $proto ||= 'http';
$server->listen(["$proto://127.0.0.1:$port"])->start;
$self->{port} = $server->listen(["$proto://127.0.0.1$port"])
->start->ioloop->acceptor($server->acceptors->[0])->handle->sockport;
}

1;
Expand Down

0 comments on commit 401f98e

Please sign in to comment.