… | |
… | |
2 | |
2 | |
3 | use strict; |
3 | use strict; |
4 | |
4 | |
5 | use AnyEvent::Impl::Perl; |
5 | use AnyEvent::Impl::Perl; |
6 | use AnyEvent::Handle; |
6 | use AnyEvent::Handle; |
7 | use Test::More tests => 3; |
7 | use Test::More tests => 8; |
8 | use Socket; |
8 | use Socket; |
9 | |
9 | |
10 | { |
10 | { |
11 | my $cv = AnyEvent->condvar; |
11 | my $cv = AnyEvent->condvar; |
12 | |
12 | |
13 | socketpair my $rd, my $wr, AF_UNIX, SOCK_STREAM, PF_UNSPEC; |
13 | socketpair my $rd, my $wr, AF_UNIX, SOCK_STREAM, PF_UNSPEC; |
14 | |
14 | |
15 | my $rd_ae = AnyEvent::Handle->new ( |
15 | my $rd_ae = AnyEvent::Handle->new ( |
16 | fh => $rd, |
16 | fh => $rd, |
|
|
17 | on_error => sub { |
|
|
18 | ok ($! == Errno::EPIPE); |
|
|
19 | }, |
17 | on_eof => sub { $cv->broadcast }, |
20 | on_eof => sub { $cv->broadcast }, |
18 | ); |
21 | ); |
19 | |
22 | |
20 | my $concat; |
23 | my $concat; |
21 | |
24 | |
22 | $rd_ae->push_read_line (sub { |
25 | $rd_ae->push_read (line => sub { |
23 | is ($_[1], "A", 'A line was read correctly'); |
26 | is ($_[1], "A", 'A line was read correctly'); |
24 | my $cb; $cb = sub { |
27 | my $cb; $cb = sub { |
25 | $concat .= $_[1]; |
28 | $concat .= $_[1]; |
26 | $_[0]->push_read_line ($cb); |
29 | $_[0]->push_read (line => $cb); |
27 | }; |
30 | }; |
28 | $_[0]->push_read_line ($cb); |
31 | $_[0]->push_read (line => $cb); |
29 | }); |
32 | }); |
30 | |
33 | |
31 | syswrite $wr, "A\nBC\nDEF\nG\n" . ("X" x 113) . "\n"; |
34 | syswrite $wr, "A\012BC\012DEF\012G\012" . ("X" x 113) . "\012"; |
32 | close $wr; |
35 | close $wr; |
33 | |
36 | |
34 | $cv->wait; |
37 | $cv->wait; |
35 | is ($concat, "BCDEFG" . ("X" x 113), 'first lines were read correctly'); |
38 | is ($concat, "BCDEFG" . ("X" x 113), 'initial lines were read correctly'); |
36 | } |
39 | } |
37 | |
40 | |
38 | { |
41 | { |
39 | my $cv = AnyEvent->condvar; |
42 | my $cv = AnyEvent->condvar; |
40 | |
43 | |
… | |
… | |
45 | my $rd_ae = |
48 | my $rd_ae = |
46 | AnyEvent::Handle->new ( |
49 | AnyEvent::Handle->new ( |
47 | fh => $rd, |
50 | fh => $rd, |
48 | on_eof => sub { $cv->broadcast }, |
51 | on_eof => sub { $cv->broadcast }, |
49 | on_read => sub { |
52 | on_read => sub { |
50 | $_[0]->push_read_line (sub { |
53 | $_[0]->push_read (line => sub { |
51 | $concat .= "$_[1]:"; |
54 | $concat .= "$_[1]:"; |
52 | }); |
55 | }); |
53 | } |
56 | } |
54 | ); |
57 | ); |
55 | |
58 | |
56 | my $wr_ae = new AnyEvent::Handle fh => $wr, on_eof => sub { die }; |
59 | my $wr_ae = new AnyEvent::Handle fh => $wr, on_eof => sub { die }; |
57 | |
60 | |
58 | $wr_ae->push_write ("A\nBC\nDEF\nG\n" . ("X" x 113) . "\n"); |
|
|
59 | undef $wr; |
61 | undef $wr; |
|
|
62 | undef $rd; |
|
|
63 | |
|
|
64 | $wr_ae->push_write (netstring => "0:xx,,"); |
|
|
65 | $wr_ae->push_write (netstring => ""); |
|
|
66 | $wr_ae->push_write (storable => [4,3,2]); |
|
|
67 | $wr_ae->push_write (packstring => "w", "hallole" x 99999); # try to exhaust socket buffer here |
|
|
68 | $wr_ae->push_write ("A\012BC\012DEF\nG\012" . ("X" x 113) . "\012"); |
60 | undef $wr_ae; |
69 | undef $wr_ae; |
|
|
70 | |
|
|
71 | $rd_ae->push_read (netstring => sub { is ($_[1], "0:xx,,") }); |
|
|
72 | $rd_ae->push_read (netstring => sub { is ($_[1], "") }); |
|
|
73 | $rd_ae->push_read (storable => "w", sub { is ("@{$_[1]}", "4 3 2") }); |
|
|
74 | $rd_ae->push_read (packstring => "w", sub { is ($_[1], "hallole" x 99999) }); |
61 | |
75 | |
62 | $cv->wait; |
76 | $cv->wait; |
63 | |
77 | |
64 | is ($concat, "A:BC:DEF:G:" . ("X" x 113) . ":", 'second lines were read correctly'); |
78 | is ($concat, "A:BC:DEF:G:" . ("X" x 113) . ":", 'second set of lines were read correctly'); |
65 | } |
79 | } |
|
|
80 | |