ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/handle/01_readline.t
Revision: 1.12
Committed: Thu Aug 21 23:48:35 2008 UTC (15 years, 10 months ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: rel-4_91, rel-4_412, rel-4_81, rel-4_83, rel-4_82, rel-4_86, rel-4_352, rel-5_112, rel-4_351, rel-5_251, rel-0_85, rel-4_331, rel-4_233, rel-4_8, rel-4_234, rel-4_4, rel-5_261, rel-5_271, rel-5_28, rel-5_29, rel-5_21, rel-5_22, rel-5_23, rel-5_24, rel-5_26, rel-5_27, rel-5_1, rel-5_0, rel-5_2, rel-5_201, rel-5_202, rel-5_111, rel-4_881, rel-4_411, rel-4_9, rel-5_01, rel-4_45, rel-4_41, rel-4_42, rel-4_88, rel-4_3, rel-5_11, rel-5_12, rel-4_31, rel-4_32, rel-4_33, rel-4_34, rel-4_35
Changes since 1.11: +4 -1 lines
Log Message:
4.233

File Contents

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