ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/handle/01_readline.t
Revision: 1.11
Committed: Fri Jun 6 11:05:16 2008 UTC (16 years, 1 month ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: rel-4_151, rel-4_152, rel-4_23, rel-4_21, rel-4_15, rel-4_231, rel-4_232, rel-4_22, rel-4_161, rel-4_160, rel-4_2
Changes since 1.10: +4 -1 lines
Log Message:
*** empty log message ***

File Contents

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