… | |
… | |
12 | exit 0; |
12 | exit 0; |
13 | } |
13 | } |
14 | } |
14 | } |
15 | } |
15 | } |
16 | |
16 | |
|
|
17 | $^W = 0; # 5.8.6 bugs |
|
|
18 | |
17 | use AnyEvent; |
19 | use AnyEvent; |
18 | use AnyEvent::Util; |
20 | use AnyEvent::Util; |
19 | BEGIN { require AnyEvent::Impl::Perl unless $ENV{PERL_ANYEVENT_MODEL} } |
21 | BEGIN { require AnyEvent::Impl::Perl unless $ENV{PERL_ANYEVENT_MODEL} } |
20 | |
22 | |
21 | $| = 1; print "1..14\n"; |
23 | $| = 1; print "1..15\n"; |
22 | |
24 | |
23 | print "ok 1\n"; |
25 | print "ok 1\n"; |
24 | |
26 | |
25 | my ($a, $b) = AnyEvent::Util::portable_socketpair; |
27 | my ($a, $b) = AnyEvent::Util::portable_socketpair; |
26 | |
28 | |
27 | # I/O write |
29 | # I/O write |
28 | { |
30 | { |
29 | my $cv = AE::cv; |
31 | my $cv = AE::cv; |
30 | my $wt = AE::timer 0.1, 0, $cv; |
32 | my $wt = AE::timer 1, 0, $cv; |
31 | my $s = 0; |
33 | my $s = 0; |
32 | |
34 | |
33 | $cv->begin; my $wa = AE::io $a, 1, sub { $cv->end; $s |= 1 }; |
35 | $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 }; |
36 | $cv->begin; my $wb = AE::io $a, 1, sub { $cv->end; $s |= 2 }; |
35 | |
37 | |
… | |
… | |
39 | } |
41 | } |
40 | |
42 | |
41 | # I/O read |
43 | # I/O read |
42 | { |
44 | { |
43 | my $cv = AE::cv; |
45 | my $cv = AE::cv; |
44 | my $wt = AE::timer 0.1, 0, $cv; |
46 | my $wt = AE::timer 0.01, 0, $cv; |
45 | my $s = 0; |
47 | my $s = 0; |
46 | |
48 | |
47 | my $wa = AE::io $a, 0, sub { $cv->end; $s |= 1 }; |
49 | my $wa = AE::io $a, 0, sub { $cv->end; $s |= 1 }; |
48 | my $wb = AE::io $a, 0, sub { $cv->end; $s |= 2 }; |
50 | my $wb = AE::io $a, 0, sub { $cv->end; $s |= 2 }; |
49 | |
51 | |
… | |
… | |
52 | print $s == 0 ? "" : "not ", "ok 3 # $s\n"; |
54 | print $s == 0 ? "" : "not ", "ok 3 # $s\n"; |
53 | |
55 | |
54 | syswrite $b, "x"; |
56 | syswrite $b, "x"; |
55 | |
57 | |
56 | $cv = AE::cv; |
58 | $cv = AE::cv; |
57 | $wt = AE::timer 0.1, 0, $cv; |
59 | $wt = AE::timer 1, 0, $cv; |
58 | |
60 | |
59 | $s = 0; |
61 | $s = 0; |
60 | $cv->begin; |
62 | $cv->begin; |
61 | $cv->begin; |
63 | $cv->begin; |
62 | $cv->recv; |
64 | $cv->recv; |
… | |
… | |
64 | print $s == 3 ? "" : "not ", "ok 4 # $s\n"; |
66 | print $s == 3 ? "" : "not ", "ok 4 # $s\n"; |
65 | |
67 | |
66 | sysread $a, my $dummy, 1; |
68 | sysread $a, my $dummy, 1; |
67 | |
69 | |
68 | $cv = AE::cv; |
70 | $cv = AE::cv; |
69 | $wt = AE::timer 0.1, 0, $cv; |
71 | $wt = AE::timer 0.01, 0, $cv; |
70 | |
72 | |
71 | $s = 0; |
73 | $s = 0; |
72 | $cv->recv; |
74 | $cv->recv; |
73 | |
75 | |
74 | print $s == 0 ? "" : "not ", "ok 5 # $s\n"; |
76 | print $s == 0 ? "" : "not ", "ok 5 # $s\n"; |
75 | } |
77 | } |
76 | |
78 | |
77 | # signal |
79 | # signal |
78 | { |
80 | { |
79 | my $cv = AE::cv; |
81 | my $cv = AE::cv; |
80 | my $wt = AE::timer 0.1, 0, $cv; |
82 | my $wt = AE::timer 0.01, 0, $cv; |
81 | my $s = 0; |
83 | my $s = 0; |
82 | |
84 | |
83 | $cv->begin; my $wa = AE::signal INT => sub { $cv->end; $s |= 1 }; |
85 | $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 }; |
86 | $cv->begin; my $wb = AE::signal INT => sub { $cv->end; $s |= 2 }; |
85 | |
87 | |
… | |
… | |
88 | print $s == 0 ? "" : "not ", "ok 6 # $s\n"; |
90 | print $s == 0 ? "" : "not ", "ok 6 # $s\n"; |
89 | |
91 | |
90 | kill INT => $$; |
92 | kill INT => $$; |
91 | |
93 | |
92 | $cv = AE::cv; |
94 | $cv = AE::cv; |
93 | $wt = AE::timer 0.1, 0, $cv; |
95 | $wt = AE::timer 0.2, 0, $cv; # maybe OS X needs more time here? |
94 | |
96 | |
95 | $s = 0; |
97 | $s = 0; |
96 | $cv->recv; |
98 | $cv->recv; |
97 | |
99 | |
98 | print $s == 3 ? "" : "not ", "ok 7 # $s\n"; |
100 | print $s == 3 ? "" : "not ", "ok 7 # $s\n"; |
99 | |
101 | |
100 | $cv = AE::cv; |
102 | $cv = AE::cv; |
101 | $wt = AE::timer 0.1, 0, $cv; |
103 | $wt = AE::timer 0.01, 0, $cv; |
102 | |
104 | |
103 | $s = 0; |
105 | $s = 0; |
104 | $cv->recv; |
106 | $cv->recv; |
105 | |
107 | |
106 | print $s == 0 ? "" : "not ", "ok 8 # $s\n"; |
108 | print $s == 0 ? "" : "not ", "ok 8 # $s\n"; |
… | |
… | |
109 | $AnyEvent::MAX_SIGNAL_LATENCY = 0.2; |
111 | $AnyEvent::MAX_SIGNAL_LATENCY = 0.2; |
110 | |
112 | |
111 | # child |
113 | # child |
112 | { |
114 | { |
113 | my $cv = AE::cv; |
115 | my $cv = AE::cv; |
114 | my $wt = AE::timer 0.1, 0, $cv; |
116 | my $wt = AE::timer 0.01, 0, $cv; |
115 | my $s = 0; |
117 | my $s = 0; |
116 | |
118 | |
117 | my $pid = fork; |
119 | my $pid = fork; |
118 | |
120 | |
119 | unless ($pid) { |
121 | unless ($pid) { |
… | |
… | |
131 | print $s == 0 ? "" : "not ", "ok 9 # $s\n"; |
133 | print $s == 0 ? "" : "not ", "ok 9 # $s\n"; |
132 | |
134 | |
133 | kill 9, $pid; |
135 | kill 9, $pid; |
134 | |
136 | |
135 | $cv = AE::cv; |
137 | $cv = AE::cv; |
136 | $wt = AE::timer 0.1, 0, $cv; |
138 | $wt = AE::timer 0.2, 0, $cv; # cygwin needs ages for this |
137 | |
139 | |
138 | $s = 0; |
140 | $s = 0; |
139 | $cv->recv; |
141 | $cv->recv; |
140 | |
142 | |
141 | print $s == 3 ? "" : "not ", "ok 10 # $s\n"; |
143 | print $s == 3 ? "" : "not ", "ok 10 # $s\n"; |
142 | print $apid == $pid && $bpid == $pid ? "" : "not ", "ok 11 # $apid == $bpid == $pid\n"; |
144 | 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"; |
145 | print $astatus == 9 && $bstatus == 9 ? "" : "not ", "ok 12 # $astatus == $bstatus == 9\n"; |
144 | |
146 | |
145 | $cv = AE::cv; |
147 | $cv = AE::cv; |
146 | $wt = AE::timer 0.1, 0, $cv; |
148 | $wt = AE::timer 0.01, 0, $cv; |
147 | |
149 | |
148 | $s = 0; |
150 | $s = 0; |
149 | $cv->recv; |
151 | $cv->recv; |
150 | |
152 | |
151 | print $s == 0 ? "" : "not ", "ok 13 # $s\n"; |
153 | print $s == 0 ? "" : "not ", "ok 13 # $s\n"; |
152 | } |
154 | } |
153 | |
155 | |
|
|
156 | # timers (don't laugh, some event loops are more broken...) |
|
|
157 | { |
|
|
158 | my $cv = AE::cv; |
|
|
159 | my $wt = AE::timer 1, 0, $cv; |
|
|
160 | my $s = 0; |
|
|
161 | |
|
|
162 | $cv->begin; my $wa = AE::timer 0 , 0, sub { $cv->end; $s |= 1 }; |
|
|
163 | $cv->begin; my $wb = AE::timer 0 , 0, sub { $cv->end; $s |= 2 }; |
|
|
164 | $cv->begin; my $wc = AE::timer 0.01, 0, sub { $cv->end; $s |= 4 }; |
|
|
165 | |
|
|
166 | $cv->recv; |
|
|
167 | |
|
|
168 | print $s == 7 ? "" : "not ", "ok 14 # $s\n"; |
|
|
169 | } |
|
|
170 | |
154 | print "ok 14\n"; |
171 | print "ok 15\n"; |
155 | |
172 | |
156 | exit 0; |
173 | exit 0; |
157 | |
174 | |