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