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