1 | use POSIX (); |
1 | use POSIX (); |
2 | |
2 | |
3 | use AnyEvent; |
3 | no warnings; |
4 | use AnyEvent::Impl::Perl; |
|
|
5 | |
4 | |
6 | BEGIN { |
5 | BEGIN { |
7 | # check for broken perls |
6 | # check for broken perls |
8 | if ($^O =~ /mswin32/i) { |
7 | if ($^O =~ /mswin32/i) { |
9 | my $ok; |
8 | my $ok; |
10 | local $SIG{CHLD} = sub { $ok = 1 }; |
9 | local $SIG{CHLD} = sub { $ok = 1 }; |
11 | kill 'CHLD', 0; |
10 | kill 'CHLD', 0; |
12 | |
11 | |
13 | unless ($ok) { |
12 | unless ($ok) { |
14 | print <<EOF; |
13 | print <<EOF; |
15 | 1..0 # Your perl interpreter is badly BROKEN. Child watchers will not work, ever. Try upgrading to a newer perl or a working perl (cygwin's perl is known to work). If that is not an option, you should be able to use the remaining functionality of AnyEvent, but child watchers WILL NOT WORK. |
14 | 1..0 # SKIP Your perl interpreter is badly BROKEN. Child watchers will not work, ever. Try upgrading to a newer perl or a working perl (cygwin's perl is known to work). If that is not an option, you should be able to use the remaining functionality of AnyEvent, but child watchers WILL NOT WORK. |
16 | EOF |
15 | EOF |
17 | exit 0; |
16 | exit 0; |
18 | } |
17 | } |
19 | } |
18 | } |
20 | } |
19 | } |
21 | |
20 | |
22 | $| = 1; print "1..7\n"; |
21 | use AnyEvent; |
|
|
22 | BEGIN { require AnyEvent::Impl::Perl unless $ENV{PERL_ANYEVENT_MODEL} } |
23 | |
23 | |
24 | $AnyEvent::MAX_SIGNAL_LATENCY = 1; |
24 | $| = 1; print "1..50\n"; |
25 | |
25 | |
26 | print "ok 1\n"; |
26 | $AnyEvent::MAX_SIGNAL_LATENCY = 0.2; |
27 | |
27 | |
28 | AnyEvent::detect; # force-load event model |
28 | for my $it ("", 1, 2, 3, 4) { |
|
|
29 | print "ok ${it}1\n"; |
29 | |
30 | |
30 | my $pid = fork; |
31 | AnyEvent::detect; # force-load event model |
31 | |
32 | |
|
|
33 | my $pid = fork; |
|
|
34 | |
32 | defined $pid or die "unable to fork"; |
35 | defined $pid or die "unable to fork"; |
33 | |
36 | |
34 | # work around Tk bug until it has been fixed. |
37 | # work around Tk bug until it has been fixed. |
35 | #my $timer = AnyEvent->timer (after => 2, cb => sub { }); |
38 | #my $timer = AnyEvent->timer (after => 2, cb => sub { }); |
36 | |
39 | |
37 | my $cv = AnyEvent->condvar; |
40 | my $cv = AnyEvent->condvar; |
38 | |
41 | |
39 | unless ($pid) { |
42 | unless ($pid) { |
40 | print "ok 2\n"; |
43 | print "ok ${it}2\n"; |
41 | POSIX::_exit 3; |
44 | POSIX::_exit 3; |
42 | } |
45 | } |
43 | |
46 | |
44 | my $w = AnyEvent->child (pid => $pid, cb => sub { |
47 | my $w = AnyEvent->child (pid => $pid, cb => sub { |
45 | print $pid == $_[0] ? "" : "not ", "ok 3\ # $pid == $_[0]\n"; |
48 | print $pid == $_[0] ? "" : "not ", "ok ${it}3\ # $pid == $_[0]\n"; |
46 | print 3 == ($_[1] >> 8) ? "" : "not ", "ok 4 # 3 == $_[1] >> 8 ($_[1])\n"; |
49 | print 3 == ($_[1] >> 8) ? "" : "not ", "ok ${it}4 # 3 == $_[1] >> 8 ($_[1])\n"; |
47 | $cv->broadcast; |
50 | $cv->broadcast; |
48 | }); |
51 | }); |
49 | |
52 | |
50 | $cv->wait; |
53 | $cv->recv; |
51 | |
54 | |
52 | my $pid2 = fork || POSIX::_exit 7; |
55 | my $pid2 = fork || POSIX::_exit 7; |
53 | |
56 | |
54 | my $cv2 = AnyEvent->condvar; |
57 | my $cv2 = AnyEvent->condvar; |
55 | |
58 | |
56 | my $w2 = AnyEvent->child (pid => 0, cb => sub { |
59 | my $w2 = AnyEvent->child (pid => 0, cb => sub { |
57 | print $pid2 == $_[0] ? "" : "not ", "ok 5 # $pid2 == $_[0]\n"; |
60 | print $pid2 == $_[0] ? "" : "not ", "ok ${it}5 # $pid2 == $_[0]\n"; |
58 | print 7 == ($_[1] >> 8) ? "" : "not ", "ok 6 # 7 == $_[1] >> 8 ($_[1])\n"; |
61 | print 7 == ($_[1] >> 8) ? "" : "not ", "ok ${it}6 # 7 == $_[1] >> 8 ($_[1])\n"; |
59 | $cv2->broadcast; |
62 | $cv2->broadcast; |
60 | }); |
63 | }); |
61 | |
64 | |
62 | my $error = AnyEvent->timer (after => 5, cb => sub { |
65 | my $error = AnyEvent->timer (after => 5, cb => sub { |
63 | print <<EOF; |
66 | print <<EOF; |
64 | Bail out! No child exit detected. This is either a bug in AnyEvent or a bug in your Perl (mostly some windows distributions suffer from that): child watchers might not work properly on this platform. You can force installation of this module if you do not rely on child watchers, or you could upgrade to a working version of Perl for your platform.\n"; |
67 | Bail out! No child exit detected. This is either a bug in AnyEvent or a bug in your Perl (mostly some windows distributions suffer from that): child watchers might not work properly on this platform. You can force installation of this module if you do not rely on child watchers, or you could upgrade to a working version of Perl for your platform.\n"; |
65 | EOF |
68 | EOF |
66 | exit 0; |
69 | exit 0; |
67 | }); |
70 | }); |
68 | |
71 | |
69 | $cv2->wait; |
72 | $cv2->recv; |
70 | |
73 | |
71 | print "ok 7\n"; |
74 | print "ok ${it}7\n"; |
|
|
75 | print "ok ${it}8\n"; |
|
|
76 | print "ok ${it}9\n"; |
|
|
77 | print "ok ", $it*10+10, "\n"; |
|
|
78 | } |
72 | |
79 | |
73 | |
80 | |
74 | |
81 | |
75 | |
82 | |