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.8 |
}, |
23 |
|
|
on_eof => sub { $cv->broadcast }, |
24 |
root |
1.4 |
); |
25 |
|
|
|
26 |
elmex |
1.2 |
my $concat; |
27 |
elmex |
1.1 |
|
28 |
root |
1.7 |
$rd_ae->push_read (line => sub { |
29 |
root |
1.4 |
is ($_[1], "A", 'A line was read correctly'); |
30 |
|
|
my $cb; $cb = sub { |
31 |
|
|
$concat .= $_[1]; |
32 |
root |
1.7 |
$_[0]->push_read (line => $cb); |
33 |
root |
1.4 |
}; |
34 |
root |
1.7 |
$_[0]->push_read (line => $cb); |
35 |
elmex |
1.2 |
}); |
36 |
|
|
|
37 |
root |
1.8 |
syswrite $wr, "A\012BC\012DEF\012G\012" . ("X" x 113) . "\012"; |
38 |
root |
1.4 |
close $wr; |
39 |
elmex |
1.2 |
|
40 |
|
|
$cv->wait; |
41 |
root |
1.8 |
is ($concat, "BCDEFG" . ("X" x 113), 'initial lines were read correctly'); |
42 |
elmex |
1.2 |
} |
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 |
root |
1.4 |
fh => $rd, |
54 |
|
|
on_eof => sub { $cv->broadcast }, |
55 |
|
|
on_read => sub { |
56 |
root |
1.6 |
$_[0]->push_read (line => sub { |
57 |
root |
1.4 |
$concat .= "$_[1]:"; |
58 |
|
|
}); |
59 |
elmex |
1.2 |
} |
60 |
|
|
); |
61 |
|
|
|
62 |
root |
1.4 |
my $wr_ae = new AnyEvent::Handle fh => $wr, on_eof => sub { die }; |
63 |
|
|
|
64 |
root |
1.8 |
undef $wr; |
65 |
|
|
undef $rd; |
66 |
|
|
|
67 |
root |
1.6 |
$wr_ae->push_write (netstring => "0:xx,,"); |
68 |
root |
1.8 |
$wr_ae->push_write (netstring => ""); |
69 |
root |
1.10 |
$wr_ae->push_write (storable => [4,3,2]); |
70 |
root |
1.9 |
$wr_ae->push_write (packstring => "w", "hallole" x 99999); # try to exhaust socket buffer here |
71 |
root |
1.10 |
$wr_ae->push_write ("A\012BC\012DEF\nG\012" . ("X" x 113) . "\012"); |
72 |
root |
1.4 |
undef $wr_ae; |
73 |
elmex |
1.1 |
|
74 |
root |
1.10 |
$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 |
root |
1.6 |
|
79 |
elmex |
1.2 |
$cv->wait; |
80 |
elmex |
1.1 |
|
81 |
root |
1.10 |
is ($concat, "A:BC:DEF:G:" . ("X" x 113) . ":", 'second set of lines were read correctly'); |
82 |
elmex |
1.2 |
} |
83 |
root |
1.8 |
|