1 |
root |
1.3 |
BEGIN { |
2 |
|
|
# check for broken perls |
3 |
|
|
if ($^O =~ /mswin32/i) { |
4 |
|
|
my $ok; |
5 |
|
|
local $SIG{CHLD} = sub { $ok = 1 }; |
6 |
|
|
kill 'CHLD', 0; |
7 |
|
|
|
8 |
|
|
unless ($ok) { |
9 |
|
|
print <<EOF; |
10 |
|
|
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. |
11 |
|
|
EOF |
12 |
|
|
exit 0; |
13 |
|
|
} |
14 |
|
|
} |
15 |
|
|
} |
16 |
|
|
|
17 |
root |
1.1 |
use AnyEvent; |
18 |
|
|
use AnyEvent::Util; |
19 |
|
|
BEGIN { require AnyEvent::Impl::Perl unless $ENV{PERL_ANYEVENT_MODEL} } |
20 |
|
|
|
21 |
|
|
$| = 1; print "1..14\n"; |
22 |
|
|
|
23 |
|
|
print "ok 1\n"; |
24 |
|
|
|
25 |
|
|
my ($a, $b) = AnyEvent::Util::portable_socketpair; |
26 |
|
|
|
27 |
|
|
# I/O write |
28 |
|
|
{ |
29 |
|
|
my $cv = AE::cv; |
30 |
|
|
my $wt = AE::timer 0.1, 0, $cv; |
31 |
|
|
my $s = 0; |
32 |
|
|
|
33 |
|
|
$cv->begin; my $wa = AE::io $a, 1, sub { $cv->end; $s |= 1 }; |
34 |
|
|
$cv->begin; my $wb = AE::io $a, 1, sub { $cv->end; $s |= 2 }; |
35 |
|
|
|
36 |
|
|
$cv->recv; |
37 |
|
|
|
38 |
|
|
print $s == 3 ? "" : "not ", "ok 2 # $s\n"; |
39 |
|
|
} |
40 |
|
|
|
41 |
|
|
# I/O read |
42 |
|
|
{ |
43 |
|
|
my $cv = AE::cv; |
44 |
|
|
my $wt = AE::timer 0.1, 0, $cv; |
45 |
|
|
my $s = 0; |
46 |
|
|
|
47 |
root |
1.2 |
my $wa = AE::io $a, 0, sub { $cv->end; $s |= 1 }; |
48 |
|
|
my $wb = AE::io $a, 0, sub { $cv->end; $s |= 2 }; |
49 |
root |
1.1 |
|
50 |
|
|
$cv->recv; |
51 |
|
|
|
52 |
|
|
print $s == 0 ? "" : "not ", "ok 3 # $s\n"; |
53 |
|
|
|
54 |
|
|
syswrite $b, "x"; |
55 |
|
|
|
56 |
|
|
$cv = AE::cv; |
57 |
|
|
$wt = AE::timer 0.1, 0, $cv; |
58 |
|
|
|
59 |
|
|
$s = 0; |
60 |
root |
1.2 |
$cv->begin; |
61 |
|
|
$cv->begin; |
62 |
root |
1.1 |
$cv->recv; |
63 |
|
|
|
64 |
|
|
print $s == 3 ? "" : "not ", "ok 4 # $s\n"; |
65 |
|
|
|
66 |
|
|
sysread $a, my $dummy, 1; |
67 |
|
|
|
68 |
|
|
$cv = AE::cv; |
69 |
|
|
$wt = AE::timer 0.1, 0, $cv; |
70 |
|
|
|
71 |
|
|
$s = 0; |
72 |
|
|
$cv->recv; |
73 |
|
|
|
74 |
|
|
print $s == 0 ? "" : "not ", "ok 5 # $s\n"; |
75 |
|
|
} |
76 |
|
|
|
77 |
|
|
# signal |
78 |
|
|
{ |
79 |
|
|
my $cv = AE::cv; |
80 |
|
|
my $wt = AE::timer 0.1, 0, $cv; |
81 |
|
|
my $s = 0; |
82 |
|
|
|
83 |
|
|
$cv->begin; my $wa = AE::signal INT => sub { $cv->end; $s |= 1 }; |
84 |
|
|
$cv->begin; my $wb = AE::signal INT => sub { $cv->end; $s |= 2 }; |
85 |
|
|
|
86 |
|
|
$cv->recv; |
87 |
|
|
|
88 |
|
|
print $s == 0 ? "" : "not ", "ok 6 # $s\n"; |
89 |
|
|
|
90 |
|
|
kill INT => $$; |
91 |
|
|
|
92 |
|
|
$cv = AE::cv; |
93 |
|
|
$wt = AE::timer 0.1, 0, $cv; |
94 |
|
|
|
95 |
|
|
$s = 0; |
96 |
|
|
$cv->recv; |
97 |
|
|
|
98 |
|
|
print $s == 3 ? "" : "not ", "ok 7 # $s\n"; |
99 |
|
|
|
100 |
|
|
$cv = AE::cv; |
101 |
|
|
$wt = AE::timer 0.1, 0, $cv; |
102 |
|
|
|
103 |
|
|
$s = 0; |
104 |
|
|
$cv->recv; |
105 |
|
|
|
106 |
|
|
print $s == 0 ? "" : "not ", "ok 8 # $s\n"; |
107 |
|
|
} |
108 |
|
|
|
109 |
|
|
$AnyEvent::MAX_SIGNAL_LATENCY = 0.2; |
110 |
|
|
|
111 |
|
|
# child |
112 |
|
|
{ |
113 |
|
|
my $cv = AE::cv; |
114 |
|
|
my $wt = AE::timer 0.1, 0, $cv; |
115 |
|
|
my $s = 0; |
116 |
|
|
|
117 |
|
|
my $pid = fork; |
118 |
|
|
|
119 |
|
|
unless ($pid) { |
120 |
|
|
sleep 2; |
121 |
|
|
exit 1; |
122 |
|
|
} |
123 |
|
|
|
124 |
|
|
my ($apid, $bpid, $astatus, $bstatus); |
125 |
|
|
|
126 |
|
|
$cv->begin; my $wa = AE::child $pid, sub { ($apid, $astatus) = @_; $cv->end; $s |= 1 }; |
127 |
|
|
$cv->begin; my $wb = AE::child $pid, sub { ($bpid, $bstatus) = @_; $cv->end; $s |= 2 }; |
128 |
|
|
|
129 |
|
|
$cv->recv; |
130 |
|
|
|
131 |
|
|
print $s == 0 ? "" : "not ", "ok 9 # $s\n"; |
132 |
|
|
|
133 |
|
|
kill 9, $pid; |
134 |
|
|
|
135 |
|
|
$cv = AE::cv; |
136 |
|
|
$wt = AE::timer 0.1, 0, $cv; |
137 |
|
|
|
138 |
|
|
$s = 0; |
139 |
|
|
$cv->recv; |
140 |
|
|
|
141 |
|
|
print $s == 3 ? "" : "not ", "ok 10 # $s\n"; |
142 |
|
|
print $apid == $pid && $bpid == $pid ? "" : "not ", "ok 11 # $apid == $bpid == $pid\n"; |
143 |
|
|
print $astatus == 9 && $bstatus == 9 ? "" : "not ", "ok 12 # $astatus == $bstatus == 9\n"; |
144 |
|
|
|
145 |
|
|
$cv = AE::cv; |
146 |
|
|
$wt = AE::timer 0.1, 0, $cv; |
147 |
|
|
|
148 |
|
|
$s = 0; |
149 |
|
|
$cv->recv; |
150 |
|
|
|
151 |
|
|
print $s == 0 ? "" : "not ", "ok 13 # $s\n"; |
152 |
|
|
} |
153 |
|
|
|
154 |
|
|
print "ok 14\n"; |
155 |
|
|
|
156 |
|
|
exit 0; |
157 |
|
|
|