1 |
root |
1.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 |
|
|
$cv->begin; my $wa = AE::io $a, 0, sub { $cv->end; $s |= 1 }; |
32 |
|
|
$cv->begin; 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->recv; |
45 |
|
|
|
46 |
|
|
print $s == 3 ? "" : "not ", "ok 4 # $s\n"; |
47 |
|
|
|
48 |
|
|
sysread $a, my $dummy, 1; |
49 |
|
|
|
50 |
|
|
$cv = AE::cv; |
51 |
|
|
$wt = AE::timer 0.1, 0, $cv; |
52 |
|
|
|
53 |
|
|
$s = 0; |
54 |
|
|
$cv->recv; |
55 |
|
|
|
56 |
|
|
print $s == 0 ? "" : "not ", "ok 5 # $s\n"; |
57 |
|
|
} |
58 |
|
|
|
59 |
|
|
# signal |
60 |
|
|
{ |
61 |
|
|
my $cv = AE::cv; |
62 |
|
|
my $wt = AE::timer 0.1, 0, $cv; |
63 |
|
|
my $s = 0; |
64 |
|
|
|
65 |
|
|
$cv->begin; my $wa = AE::signal INT => sub { $cv->end; $s |= 1 }; |
66 |
|
|
$cv->begin; my $wb = AE::signal INT => sub { $cv->end; $s |= 2 }; |
67 |
|
|
|
68 |
|
|
$cv->recv; |
69 |
|
|
|
70 |
|
|
print $s == 0 ? "" : "not ", "ok 6 # $s\n"; |
71 |
|
|
|
72 |
|
|
kill INT => $$; |
73 |
|
|
|
74 |
|
|
$cv = AE::cv; |
75 |
|
|
$wt = AE::timer 0.1, 0, $cv; |
76 |
|
|
|
77 |
|
|
$s = 0; |
78 |
|
|
$cv->recv; |
79 |
|
|
|
80 |
|
|
print $s == 3 ? "" : "not ", "ok 7 # $s\n"; |
81 |
|
|
|
82 |
|
|
$cv = AE::cv; |
83 |
|
|
$wt = AE::timer 0.1, 0, $cv; |
84 |
|
|
|
85 |
|
|
$s = 0; |
86 |
|
|
$cv->recv; |
87 |
|
|
|
88 |
|
|
print $s == 0 ? "" : "not ", "ok 8 # $s\n"; |
89 |
|
|
} |
90 |
|
|
|
91 |
|
|
$AnyEvent::MAX_SIGNAL_LATENCY = 0.2; |
92 |
|
|
|
93 |
|
|
# child |
94 |
|
|
{ |
95 |
|
|
my $cv = AE::cv; |
96 |
|
|
my $wt = AE::timer 0.1, 0, $cv; |
97 |
|
|
my $s = 0; |
98 |
|
|
|
99 |
|
|
my $pid = fork; |
100 |
|
|
|
101 |
|
|
unless ($pid) { |
102 |
|
|
sleep 2; |
103 |
|
|
exit 1; |
104 |
|
|
} |
105 |
|
|
|
106 |
|
|
my ($apid, $bpid, $astatus, $bstatus); |
107 |
|
|
|
108 |
|
|
$cv->begin; my $wa = AE::child $pid, sub { ($apid, $astatus) = @_; $cv->end; $s |= 1 }; |
109 |
|
|
$cv->begin; my $wb = AE::child $pid, sub { ($bpid, $bstatus) = @_; $cv->end; $s |= 2 }; |
110 |
|
|
|
111 |
|
|
$cv->recv; |
112 |
|
|
|
113 |
|
|
print $s == 0 ? "" : "not ", "ok 9 # $s\n"; |
114 |
|
|
|
115 |
|
|
kill 9, $pid; |
116 |
|
|
|
117 |
|
|
$cv = AE::cv; |
118 |
|
|
$wt = AE::timer 0.1, 0, $cv; |
119 |
|
|
|
120 |
|
|
$s = 0; |
121 |
|
|
$cv->recv; |
122 |
|
|
|
123 |
|
|
print $s == 3 ? "" : "not ", "ok 10 # $s\n"; |
124 |
|
|
print $apid == $pid && $bpid == $pid ? "" : "not ", "ok 11 # $apid == $bpid == $pid\n"; |
125 |
|
|
print $astatus == 9 && $bstatus == 9 ? "" : "not ", "ok 12 # $astatus == $bstatus == 9\n"; |
126 |
|
|
|
127 |
|
|
$cv = AE::cv; |
128 |
|
|
$wt = AE::timer 0.1, 0, $cv; |
129 |
|
|
|
130 |
|
|
$s = 0; |
131 |
|
|
$cv->recv; |
132 |
|
|
|
133 |
|
|
print $s == 0 ? "" : "not ", "ok 13 # $s\n"; |
134 |
|
|
} |
135 |
|
|
|
136 |
|
|
print "ok 14\n"; |
137 |
|
|
|
138 |
|
|
exit 0; |
139 |
|
|
|