ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/handle/01_readline.t
(Generate patch)

Comparing AnyEvent/t/handle/01_readline.t (file contents):
Revision 1.4 by root, Sat May 3 12:17:35 2008 UTC vs.
Revision 1.9 by root, Fri Jun 6 10:49:20 2008 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines