Skip to content

Commit

Permalink
Fixed SocketFactory to support ipv6 host names rather than
Browse files Browse the repository at this point in the history
presentation (human readable numeric) addresses.  Added the test
program I forgot when the initial support went in.
  • Loading branch information
rcaputo committed Aug 29, 2002
1 parent 64c395f commit 5dd8568
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/POE/Wheel/SocketFactory.pm
Expand Up @@ -685,11 +685,11 @@ sub new {

# Resolve the bind address.
$bind_address =
Socket6::inet_pton($self->[MY_SOCKET_DOMAIN], $bind_address);
Socket6::gethostbyname2($bind_address, $self->[MY_SOCKET_DOMAIN]);
unless (defined $bind_address) {
$! = EADDRNOTAVAIL;
$poe_kernel->yield( $event_failure,
"inet_pton", $!+0, $!, $self->[MY_UNIQUE_ID]
"gethostbyname2", $!+0, $!, $self->[MY_UNIQUE_ID]
);
return $self;
}
Expand Down Expand Up @@ -799,10 +799,10 @@ sub new {
}
elsif ($abstract_domain eq DOM_INET6) {
$connect_address =
Socket6::inet_pton( $self->[MY_SOCKET_DOMAIN],
$params{RemoteAddress}
);
$error_tag = "inet_pton";
Socket6::gethostbyname2( $params{RemoteAddress},
$self->[MY_SOCKET_DOMAIN]
);
$error_tag = "gethostbyname2";
}
else {
die "unknown domain $abstract_domain";
Expand Down
115 changes: 115 additions & 0 deletions tests/29_sockfact6.t
@@ -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;

0 comments on commit 5dd8568

Please sign in to comment.