ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/handle/02_write.t
Revision: 1.4
Committed: Wed May 21 14:27:58 2008 UTC (16 years, 1 month ago) by elmex
Content type: application/x-troff
Branch: MAIN
Changes since 1.3: +5 -6 lines
Log Message:
fixed bug in write test

File Contents

# User Rev Content
1 elmex 1.1 #!perl
2     use strict;
3 root 1.2 use AnyEvent::Impl::Perl;
4 elmex 1.1 use AnyEvent::Handle;
5     use Socket;
6    
7 elmex 1.3 print "1..7\n";
8    
9 elmex 1.1 my $cv = AnyEvent->condvar;
10    
11     socketpair my $rd, my $wr, AF_UNIX, SOCK_STREAM, PF_UNSPEC;
12    
13 elmex 1.3 my $rd_ae =
14     AnyEvent::Handle->new (
15     fh => $rd,
16     on_eof => sub {
17     warn "reader got EOF";
18     $cv->broadcast
19     }
20     );
21    
22     my $wr_ae =
23     AnyEvent::Handle->new (
24     fh => $wr,
25     on_eof => sub {
26     warn "writer got EOF\n";
27     $cv->broadcast
28     }
29     );
30 elmex 1.1
31     my $dat = '';
32    
33 elmex 1.3 $rd_ae->push_read_chunk (5132, sub {
34 elmex 1.1 my ($rd_ae, $data) = @_;
35     $dat = substr $data, 0, 2;
36     $dat .= substr $data, -5;
37 elmex 1.3
38     print "ok 4 - first read chunk\n";
39     $wr_ae->push_write ("A" x 5000);
40     $wr_ae->on_drain (sub {
41     my ($wr_ae) = @_;
42     $wr_ae->on_drain;
43 elmex 1.4 print "ok 5 - fourth write\n";
44 elmex 1.3
45 elmex 1.4 $rd_ae->push_read_chunk (1, sub {
46     print "ok 6 - second read chunk\n";
47     $cv->broadcast
48     });
49 elmex 1.3 });
50 elmex 1.1 });
51    
52 elmex 1.3 $wr_ae->push_write ("A" x 5000);
53     $wr_ae->push_write ("X" x 130);
54 elmex 1.1
55 elmex 1.3 # and now some extreme CPS action:
56     $wr_ae->on_drain (sub {
57     my ($wr_ae) = @_;
58     $wr_ae->on_drain;
59     print "ok 1 - first write\n";
60    
61     $wr_ae->push_write ("Y");
62     $wr_ae->on_drain (sub {
63     my ($wr_ae) = @_;
64     $wr_ae->on_drain;
65     print "ok 2 - second write\n";
66    
67     $wr_ae->push_write ("Z");
68     $wr_ae->on_drain (sub {
69     my ($wr_ae) = @_;
70     $wr_ae->on_drain;
71     print "ok 3 - third write\n";
72     });
73     });
74     });
75 elmex 1.1
76     $cv->wait;
77    
78 elmex 1.3 if ($dat eq "AAXXXYZ") {
79     print "ok 7 - received data\n";
80     } else {
81     warn "dat was '$dat'\n";
82     print "not ok 7 - received data\n";
83     }