AnyEvent-FDpasser
view release on metacpan or search on metacpan
lib/AnyEvent/FDpasser.pm view on Meta::CPAN
sub enter_full_descriptor_table_state {
my ($self) = @_;
return if $self->{full_descriptor_table_state};
$self->{full_descriptor_table_state} = 1;
undef $self->{iwatcher};
my $watcher; $watcher = AE::timer 0.05, 0.5, sub {
$self->setup_fh_duped;
if (exists $self->{fh_duped}) {
undef $watcher;
delete $self->{full_descriptor_table_state};
$self->try_to_recv;
}
};
}
t/basic_filesystem.t view on Meta::CPAN
$passer->push_recv_fh(sub {
my $fh = shift;
my $text = <$fh>;
is($text, "some data 2\n", "send fh from child -> parent ok");
unlink($path);
$done_cv->send;
});
};
};
} else {
my $watcher; $watcher = AE::timer 0.5, 0, sub {
undef $watcher;
my $passer = AnyEvent::FDpasser->new( fh => AnyEvent::FDpasser::fdpasser_connect($path), );
$passer->push_recv_fh(sub {
my ($fh) = @_;
print $fh "some data 1\n";
close($fh);
pipe my $rfh, my $wfh;
t/buffer_exercise.t view on Meta::CPAN
if (!fork) {
$passer->i_am_child;
for my $i (1..3) {
pipe my $rfh, my $wfh;
print $wfh "hello $i\n";
$passer->push_send_fh($rfh);
}
my $watcher; $watcher = AE::timer 0.1, 0, sub {
undef $watcher;
pipe my $rfh, my $wfh;
print $wfh "hello 4\n";
$passer->push_send_fh($rfh);
pipe my $rfh, my $wfh;
print $wfh "hello 5\n";
$passer->push_send_fh($wfh);
$passer->push_recv_fh(sub {
t/buffer_exercise.t view on Meta::CPAN
$passer->i_am_parent;
for my $i (1..2) {
$passer->push_recv_fh(sub {
my ($fh) = @_;
my $text = <$fh>;
is($text, "hello $i\n", "got pipe $i");
});
}
my $watcher; $watcher = AE::timer 0.15, 0, sub {
undef $watcher;
$passer->push_recv_fh(sub {
my ($fh) = @_;
my $text = <$fh>;
is($text, "hello 3\n", "got pipe 3");
});
$passer->push_recv_fh(sub {
my ($fh) = @_;
t/child_dies.t view on Meta::CPAN
print $wfh "hooray\n";
$passer->push_send_fh($rfh);
$passer->push_recv_fh(sub {
ok(0, "received fh?");
$done_cv->send;
});
} else {
$passer->i_am_child;
my $watcher; $watcher = AE::timer 0.02, 0, sub {
undef $watcher;
$done_cv->send;
};
}
$done_cv->recv;
t/full_descriptor_table.t view on Meta::CPAN
my $text = <$fh>;
is($text, "hooray\n", 'got 30');
$done_cv->send;
});
} else {
$passer->i_am_child;
my $next_desc = 1;
my @descriptors;
my $watcher; $watcher = AE::timer 0.5, 0.5, sub {
$watcher;
close($_) foreach (@descriptors);
@descriptors = ();
};
BSD::Resource::setrlimit('RLIMIT_NOFILE', 20, 20);
for my $curr (1 .. 30) {
$passer->push_recv_fh(sub {
my $fh = shift;
t/recv_before_send.t view on Meta::CPAN
use AnyEvent::Strict;
use AnyEvent::FDpasser;
use Test::More tests => 3;
## The point of this test is to verify that push_recv_fh can be called before
## there is any fh waiting to be received and the process will not block.
## WARNING: this test relied on timers and is not fully deterministic
my $passer = AnyEvent::FDpasser->new;
my $done_cv = AE::cv;
if (fork) {
$passer->i_am_parent;
my $start_time = Time::HiRes::time;
my $nonblocking_check;
my $watcher; $watcher = AE::timer 0.05, 0, sub {
undef $watcher;
$nonblocking_check = 1;
ok(Time::HiRes::time < $start_time + 0.08, 'happened on time');
};
$passer->push_recv_fh(sub {
my $fh = shift;
undef $watcher;
ok($nonblocking_check, "happened in right order");
my $text = <$fh>;
is($text, "hooray\n", 'got data');
$done_cv->send;
});
} else {
$passer->i_am_child;
my $watcher; $watcher = AE::timer 0.1, 0, sub {
undef $watcher;
pipe my $rfh, my $wfh;
print $wfh "hooray\n";
$passer->push_send_fh($rfh, sub { $done_cv->send; });
};
}
$done_cv->recv;
t/send_before_recv.t view on Meta::CPAN
use AnyEvent::Strict;
use AnyEvent::FDpasser;
use Test::More tests => 2;
## The point of this test is to verify that push_send_fh can be called before
## there is any process on the other end calling push_recv_fh and the process
## will not block.
## WARNING: this test relied on timers and is not fully deterministic
my $passer = AnyEvent::FDpasser->new;
my $done_cv = AE::cv;
if (fork) {
$passer->i_am_parent;
my $start_time = Time::HiRes::time;
pipe my $rfh, my $wfh;
print $wfh "hooray\n";
$passer->push_send_fh($rfh);
my $watcher; $watcher = AE::timer 0.1, 0, sub {
undef $watcher;
ok(Time::HiRes::time < $start_time + 0.18, 'happened on time');
};
$passer->push_recv_fh(sub {
my $fh = shift;
my $text = <$fh>;
is($text, "hooray\n", 'got data');
$done_cv->send;
});
} else {
$passer->i_am_child;
my $watcher; $watcher = AE::timer 0.2, 0, sub {
undef $watcher;
pipe my $rfh, my $wfh;
print $wfh "hooray\n";
$passer->push_send_fh($rfh, sub { $done_cv->send; });
};
}
$done_cv->recv;
( run in 3.919 seconds using v1.01-cache-2.11-cpan-49f99fa48dc )