Revision: | 1.17 |
Committed: | Wed Dec 29 04:16:35 2010 UTC (13 years, 7 months ago) by root |
Content type: | application/x-troff |
Branch: | MAIN |
CVS Tags: | rel-7_05, rel-7_07, rel-7_01, rel-7_02, rel-7_03, rel-7_08, rel-7_09, rel-7_16, rel-7_13, rel-7_11, rel-6_0, rel-6_1, rel-6_11, rel-6_12, rel-6_13, rel-7_15, rel-7_14, rel-7_12, rel-6_02, rel-6_01, rel-7_0, rel-5_3, rel-7_04, rel-5_31, rel-6_14, HEAD |
Changes since 1.16: | +2 -2 lines |
Log Message: | first round of ioasync rewrite |
# | User | Rev | Content |
---|---|---|---|
1 | elmex | 1.1 | #!/opt/perl/bin/perl |
2 | root | 1.9 | |
3 | elmex | 1.1 | use strict; |
4 | root | 1.9 | |
5 | root | 1.17 | use AnyEvent; |
6 | BEGIN { require AnyEvent::Impl::Perl unless $ENV{PERL_ANYEVENT_MODEL} } | ||
7 | elmex | 1.7 | use AnyEvent::Handle; |
8 | root | 1.12 | use AnyEvent::Socket; |
9 | elmex | 1.1 | |
10 | my $lbytes; | ||
11 | my $rbytes; | ||
12 | |||
13 | elmex | 1.7 | print "1..2\n"; |
14 | |||
15 | elmex | 1.1 | my $cv = AnyEvent->condvar; |
16 | |||
17 | elmex | 1.7 | my $hdl; |
18 | root | 1.9 | my $port; |
19 | elmex | 1.7 | |
20 | root | 1.12 | my $w = tcp_server undef, undef, |
21 | root | 1.9 | sub { |
22 | my ($fh, $host, $port) = @_; | ||
23 | |||
24 | $hdl = AnyEvent::Handle->new (fh => $fh, on_eof => sub { $cv->broadcast }); | ||
25 | |||
26 | root | 1.14 | $hdl->push_read (chunk => 6, sub { |
27 | root | 1.9 | my ($hdl, $data) = @_; |
28 | |||
29 | if ($data eq "TEST\015\012") { | ||
30 | print "ok 1 - server received client data\n"; | ||
31 | } else { | ||
32 | print "not ok 1 - server received bad client data\n"; | ||
33 | } | ||
34 | |||
35 | $hdl->push_write ("BLABLABLA\015\012"); | ||
36 | }); | ||
37 | }, sub { | ||
38 | root | 1.15 | $port = $_[2]; |
39 | elmex | 1.7 | |
40 | root | 1.9 | 0 |
41 | }; | ||
42 | elmex | 1.7 | |
43 | root | 1.16 | my $clhdl; $clhdl = AnyEvent::Handle->new ( |
44 | connect => [localhost => $port], | ||
45 | on_eof => sub { $cv->broadcast }, | ||
46 | ); | ||
47 | elmex | 1.6 | |
48 | root | 1.16 | $clhdl->push_write ("TEST\015\012"); |
49 | $clhdl->push_read (line => sub { | ||
50 | my ($clhdl, $line) = @_; | ||
51 | elmex | 1.7 | |
52 | root | 1.16 | if ($line eq 'BLABLABLA') { |
53 | print "ok 2 - client received response\n"; | ||
54 | } else { | ||
55 | print "not ok 2 - client received bad response\n"; | ||
56 | } | ||
57 | elmex | 1.7 | |
58 | root | 1.16 | $cv->broadcast; |
59 | }); | ||
60 | elmex | 1.1 | |
61 | $cv->wait; |