1 | #!perl |
1 | #!perl |
|
|
2 | |
|
|
3 | # actually tests a few other read/write types as well |
2 | |
4 | |
3 | use strict; |
5 | use strict; |
4 | |
6 | |
5 | use AnyEvent::Impl::Perl; |
7 | use AnyEvent; |
|
|
8 | BEGIN { require AnyEvent::Impl::Perl unless $ENV{PERL_ANYEVENT_MODEL} } |
6 | use AnyEvent::Handle; |
9 | use AnyEvent::Handle; |
7 | use Test::More tests => 7; |
10 | use Test::More tests => 8; |
8 | use Socket; |
11 | use Socket; |
|
|
12 | use Errno; |
9 | |
13 | |
10 | { |
14 | { |
11 | my $cv = AnyEvent->condvar; |
15 | my $cv = AnyEvent->condvar; |
12 | |
16 | |
13 | socketpair my $rd, my $wr, AF_UNIX, SOCK_STREAM, PF_UNSPEC; |
17 | socketpair my $rd, my $wr, AF_UNIX, SOCK_STREAM, PF_UNSPEC; |
14 | |
18 | |
15 | my $rd_ae = AnyEvent::Handle->new ( |
19 | my $rd_ae = AnyEvent::Handle->new ( |
16 | fh => $rd, |
20 | fh => $rd, |
17 | on_error => sub { |
21 | on_error => sub { |
18 | ok ($! == Errno::EPIPE); |
22 | ok ($! == &Errno::EPIPE); |
|
|
23 | $cv->broadcast; |
19 | }, |
24 | }, |
20 | on_eof => sub { $cv->broadcast }, |
25 | on_eof => sub { |
|
|
26 | ok (0, "got eof"); |
|
|
27 | }, |
21 | ); |
28 | ); |
22 | |
29 | |
23 | my $concat; |
30 | my $concat; |
24 | |
31 | |
25 | $rd_ae->push_read (line => sub { |
32 | $rd_ae->push_read (line => sub { |
… | |
… | |
61 | undef $wr; |
68 | undef $wr; |
62 | undef $rd; |
69 | undef $rd; |
63 | |
70 | |
64 | $wr_ae->push_write (netstring => "0:xx,,"); |
71 | $wr_ae->push_write (netstring => "0:xx,,"); |
65 | $wr_ae->push_write (netstring => ""); |
72 | $wr_ae->push_write (netstring => ""); |
66 | $wr_ae->push_write (packstring => "w", "hallole" x 99); |
73 | $wr_ae->push_write (storable => [4,3,2]); |
|
|
74 | $wr_ae->push_write (packstring => "w", "hallole" x 99999); # try to exhaust socket buffer here |
67 | $wr_ae->push_write ("A\nBC\nDEF\nG\n" . ("X" x 113) . "\n"); |
75 | $wr_ae->push_write ("A\012BC\012DEF\nG\012" . ("X" x 113) . "\012"); |
68 | undef $wr_ae; |
76 | undef $wr_ae; |
69 | |
77 | |
70 | $rd_ae->push_read (netstring => sub { is ($_[1], "0:xx,,"); }); |
78 | $rd_ae->push_read (netstring => sub { is ($_[1], "0:xx,,") }); |
71 | $rd_ae->push_read (netstring => sub { is ($_[1], ""); }); |
79 | $rd_ae->push_read (netstring => sub { is ($_[1], "") }); |
|
|
80 | $rd_ae->push_read (storable => "w", sub { is ("@{$_[1]}", "4 3 2") }); |
72 | $rd_ae->push_read (packstring => "w", sub { is ($_[1], "hallole" x 99); }); |
81 | $rd_ae->push_read (packstring => "w", sub { is ($_[1], "hallole" x 99999) }); |
73 | |
82 | |
74 | $cv->wait; |
83 | $cv->wait; |
75 | |
84 | |
76 | is ($concat, "A:BC:DEF:G:" . ("X" x 113) . ":", 'second lines were read correctly'); |
85 | is ($concat, "A:BC:DEF:G:" . ("X" x 113) . ":", 'second set of lines were read correctly'); |
77 | } |
86 | } |
78 | |
87 | |