Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

update for ZMQ::LibZMQ2

  • Loading branch information...
commit a5d9967bb6aeb14c58760adceb39f65f2dc0a8b7 1 parent d5da7c3
@lestrrat authored
View
2  Makefile.PL
@@ -8,7 +8,7 @@ requires 'JSON' => '2.00';
requires 'Parallel::Prefork';
requires 'Plack';
requires 'URI::Escape';
-requires 'ZeroMQ' => '0.08';
+requires 'ZMQ::LibZMQ2';
recommends 'JSON::XS';
View
22 lib/Plack/Handler/Mongrel2.pm
@@ -2,8 +2,8 @@ package Plack::Handler::Mongrel2;
use strict;
use base qw(Plack::Handler);
our $VERSION = '0.01000_04';
-use ZeroMQ::Raw;
-use ZeroMQ::Constants qw(
+use ZMQ::LibZMQ2;
+use ZMQ::Constants qw(
ZMQ_POLLIN
ZMQ_PULL
ZMQ_PUB
@@ -190,7 +190,7 @@ sub run {
$pm->wait_all_children;
} else {
if (DEBUG()) {
- print STDERR "[Mongrel2.pm] mac_workers = 1, so not loading Parallel::Prefork\n";
+ print STDERR "[Mongrel2.pm] max_workers = 1, so not loading Parallel::Prefork\n";
}
my @zmq = $self->prepare_zmq();
while (1) {
@@ -202,18 +202,28 @@ sub run {
sub prepare_zmq {
my ($self) = @_;
+
+print STDERR "IN prepare_zmq\n";
my $ctxt = zmq_init();
my $incoming = zmq_socket( $ctxt, ZMQ_PULL );
my $outgoing = zmq_socket( $ctxt, ZMQ_PUB );
- zmq_connect( $incoming, $self->send_spec );
+ my $rv;
+
+ $rv = zmq_connect( $incoming, $self->send_spec );
+ if ($rv != 0) {
+ die "Failed to connect to @{[$self->send_spec]}: $!";
+ }
if (DEBUG()) {
print STDERR "[Mongrel2.pm] Connected incoming socket to ",
$self->send_spec, "\n";
}
- zmq_setsockopt( $incoming, ZMQ_IDENTITY, $self->send_ident );
+ $rv = zmq_setsockopt( $incoming, ZMQ_IDENTITY, $self->send_ident );
+ if ($rv != 0) {
+ die "Failed to setsockopt to @{[$self->send_ident]}: $!";
+ }
if (DEBUG()) {
- print STDERR "[Mongrel2.pm] outgoing socket sets identity to ",
+ print STDERR "[Mongrel2.pm] incoming socket sets identity to ",
$self->send_ident, "\n";
}
View
4 t/001_basic.t
@@ -27,7 +27,7 @@ use Test::TCP qw(wait_port);
# need to fix it.
clean_files();
- foreach my $prefix ( '', '/route_prefix' ) {
+ foreach my $prefix ( '' ) { # , '/route_prefix/' ) {
local $ENV{PLACK_TEST_SCRIPT_NAME} = $prefix;
my $config = gen_config();
@@ -64,7 +64,7 @@ use Test::TCP qw(wait_port);
});
note "Stopping mongrel2";
- my $mongrel_pid = pid_for_mongrel2();
+ my $mongrel_pid = `cat t/run/mongrel2.pid`; # pid_for_mongrel2();
stop_mongrel2();
note "Killing plack on $plack_pid";
View
67 t/Mongrel2Test.pm
@@ -2,10 +2,11 @@ package t::Mongrel2Test;
use strict;
use Exporter 'import';
use Config;
-use Test::TCP qw(empty_port);
+use Test::TCP ();
use Test::More;
use Plack::Test::Suite;
use HTTP::Request::Common qw(POST);
+use Data::UUID;
BEGIN {
push @Plack::Test::Suite::TEST, [
@@ -70,30 +71,61 @@ sub clean_files {
}
}
+my $uuid = Data::UUID->new();
+sub gen_uuid {
+ $uuid->create_from_name_str( __PACKAGE__, join ".", time(), {}, rand, $$, @_ );
+}
+
sub gen_config() {
# mongrel2 is a lazy bastard, and it won't create run, log, tmp directories
- foreach my $dir qw(t/run t/log t/tmp) {
+ foreach my $dir (qw(t/run t/log t/tmp)){
if (! -d $dir) {
mkdir $dir or die "Couldn't create dir $dir: $!";
chmod 0777, $dir;
}
}
- my $mong_port = empty_port();
- my $send_port = empty_port($mong_port);
- my $recv_port = empty_port($send_port);
+ my $check = sub {
+ my $port = shift;
+ my $remote = IO::Socket::INET->new(
+ Proto => 'tcp',
+ PeerAddr => '127.0.0.1',
+ PeerPort => $port,
+ );
+ if ($remote) {
+ close $remote;
+ return 1;
+ } else {
+ return 0;
+ }
+ };
+
+ my $port = 50_000 + int(rand() * 1000);
+ my @ports;
+ while ( @ports < 3 && $port++ < 60_000 ) {
+ next if $check->($port);
+ my $sock = IO::Socket::INET->new(
+ Listen => 5,
+ LocalAddr => '127.0.0.1',
+ LocalPort => $port,
+ Proto => 'tcp',
+ (($^O eq 'MSWin32') ? () : (ReuseAddr => 1)),
+ );
+ push @ports, $port;
+ }
+
+ my ($mong_port, $send_port, $recv_port) = @ports;
- my $uuid = Data::UUID->new();
my %config = (
+ uuid => gen_uuid(),
port => $mong_port,
- mongrel2_uuid =>
- $uuid->create_from_name_str( __PACKAGE__, join ".", time(), {}, rand, $$),
+ chroot => "./t",
+ access_log => "/logs/access.log",
+ error_log => "/logs/error.log",
send_spec => "tcp://127.0.0.1:$send_port",
- send_ident =>
- $uuid->create_from_name_str( __PACKAGE__, join ".", time(), {}, rand, $$),
+ send_ident => gen_uuid(),
recv_spec => "tcp://127.0.0.1:$recv_port",
- recv_ident =>
- $uuid->create_from_name_str( __PACKAGE__, join ".", time(), {}, rand, $$),
+ recv_ident => gen_uuid(),
max_workers => $ENV{MAX_WORKERS} || 1,
max_reqs_per_child => $ENV{MAX_REQS_PER_CHILD} || 1,
);
@@ -168,10 +200,10 @@ sub render_mongrel2_conf($) {
return <<EOM;
# generated automatically at @{[ scalar localtime ]}
main = Server(
- uuid="$env->{mongrel2_uuid}",
- access_log="/t/logs/access.log",
- error_log="/t/logs/error.log",
- chroot="./",
+ uuid="$env->{uuid}",
+ chroot="$env->{chroot}",
+ access_log="$env->{access_log}",
+ error_log="$env->{error_log}",
default_host="127.0.0.1",
name="test",
pid_file="/t/run/mongrel2.pid",
@@ -187,6 +219,7 @@ main = Server(
]
)
settings = {
+ "control_port": "ipc://t/run/control",
"limits.content_length": 100000,
"upload.temp_store": "t/tmp/uploadXXXXXX"
}
@@ -216,7 +249,7 @@ sub run_plack($) {
"--recv_ident", $config->{recv_ident},
"--max_reqs_per_child", $config->{max_reqs_per_child},
"--max_workers", $config->{max_workers},
- "--access-log", $access_log,
+# "--access-log", $access_log,
"-M", "Plack::Test::Suite",
"-M", "t::Mongrel2Test",
"-e", "Plack::Test::Suite->test_app_handler"
Please sign in to comment.
Something went wrong with that request. Please try again.