ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/handle/01_readline.t
Revision: 1.9
Committed: Fri Jun 6 10:49:20 2008 UTC (16 years, 1 month ago) by root
Content type: application/x-troff
Branch: MAIN
Changes since 1.8: +2 -2 lines
Log Message:
*** empty log message ***

File Contents

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