Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed SocketFactory to support ipv6 host names rather than
presentation (human readable numeric) addresses. Added the test program I forgot when the initial support went in.
- Loading branch information
Showing
2 changed files
with
121 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
#!/usr/bin/perl -w | ||
# $Id$ | ||
|
||
# Exercises Client and Server TCP components, which exercise | ||
# SocketFactory in AF_INET6 mode. | ||
|
||
use strict; | ||
use lib qw(./lib ../lib); | ||
use TestSetup; | ||
use Socket; | ||
use Socket6; | ||
|
||
# Turn on all asserts. | ||
sub POE::Kernel::ASSERT_DEFAULT () { 1 } | ||
use POE qw( Component::Client::TCP Component::Server::TCP ); | ||
|
||
my $tcp_server_port = 31909; | ||
|
||
# Congratulations! We made it this far! | ||
test_setup(5); | ||
ok(1); | ||
|
||
############################################################################### | ||
# Start the TCP server. | ||
|
||
POE::Component::Server::TCP->new | ||
( Port => $tcp_server_port, | ||
Address => '::1', | ||
Domain => AF_INET6, | ||
Alias => 'server', | ||
ClientConnected => \&server_got_connect, | ||
ClientInput => \&server_got_input, | ||
ClientFlushed => \&server_got_flush, | ||
ClientDisconnected => \&server_got_disconnect, | ||
ClientError => \&server_got_error, | ||
); | ||
|
||
sub server_got_connect { | ||
my $heap = $_[HEAP]; | ||
$heap->{server_test_one} = 1; | ||
$heap->{flush_count} = 0; | ||
$heap->{put_count} = 0; | ||
} | ||
|
||
sub server_got_input { | ||
my ($heap, $line) = @_[HEAP, ARG0]; | ||
$line =~ tr/a-zA-Z/n-za-mN-ZA-M/; # rot13 | ||
$heap->{client}->put($line); | ||
$heap->{put_count}++; | ||
} | ||
|
||
sub server_got_flush { | ||
$_[HEAP]->{flush_count}++; | ||
} | ||
|
||
sub server_got_disconnect { | ||
my $heap = $_[HEAP]; | ||
ok_if(2, $heap->{put_count} == $heap->{flush_count}); | ||
} | ||
|
||
sub server_got_error { | ||
# Shush a warning. | ||
} | ||
|
||
############################################################################### | ||
# Start the TCP client. | ||
|
||
POE::Component::Client::TCP->new | ||
( RemoteAddress => '::1', | ||
RemotePort => $tcp_server_port, | ||
Domain => AF_INET6, | ||
Connected => \&client_got_connect, | ||
ServerInput => \&client_got_input, | ||
ServerFlushed => \&client_got_flush, | ||
Disconnected => \&client_got_disconnect, | ||
); | ||
|
||
sub client_got_connect { | ||
my $heap = $_[HEAP]; | ||
$heap->{flush_count} = 0; | ||
$heap->{put_count} = 1; | ||
$heap->{server}->put( '1: this is a test' ); | ||
} | ||
|
||
sub client_got_input { | ||
my ($kernel, $heap, $line) = @_[KERNEL, HEAP, ARG0]; | ||
|
||
if ($line =~ s/^1: //) { | ||
$heap->{put_count}++; | ||
$heap->{server}->put( '2: ' . $line ); | ||
} | ||
elsif ($line =~ s/^2: //) { | ||
&ok_if(3, $line eq 'this is a test'); | ||
$kernel->post(server => "shutdown"); | ||
$kernel->yield("shutdown"); | ||
} | ||
} | ||
|
||
sub client_got_flush { | ||
$_[HEAP]->{flush_count}++; | ||
} | ||
|
||
sub client_got_disconnect { | ||
my $heap = $_[HEAP]; | ||
ok_if(4, $heap->{put_count} == $heap->{flush_count}); | ||
} | ||
|
||
### main loop | ||
|
||
$poe_kernel->run(); | ||
|
||
ok(5); | ||
results; | ||
|
||
exit; |