Skip to content

Commit

Permalink
re-tweak the ipv6 stuff *AGAIN* so it checks Socket.pm for getaddrinf…
Browse files Browse the repository at this point in the history
…o to be future-compatible with 5.14
  • Loading branch information
apocalypse committed Apr 20, 2011
1 parent a12120d commit e57754a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
14 changes: 12 additions & 2 deletions lib/POE/Component/Server/TCP.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,9 +10,19 @@ use Socket qw(INADDR_ANY inet_ntoa inet_aton AF_INET AF_UNIX PF_UNIX);
use Errno qw(ECONNABORTED ECONNRESET); use Errno qw(ECONNABORTED ECONNRESET);


BEGIN { BEGIN {
eval "use Socket::GetAddrInfo qw(:newapi getaddrinfo)"; # under perl-5.6.2 the warning "leaks" from the eval, while newer versions don't...
# it's due to Exporter.pm behaving differently, so we have to shut it up
no warnings 'redefine';
local *Carp::carp = sub { die @_ };

# Socket::GetAddrInfo provides getaddrinfo where earlier Perls' Socket don't.
eval { Socket->import('getaddrinfo') };
if ($@) { if ($@) {
*getaddrinfo = sub { Carp::confess("Unable to use IPv6: Socket::GetAddrInfo not available") }; # :newapi is legacy, but we include it to be sure in case the user has an old version of GAI
eval { require Socket::GetAddrInfo; Socket::GetAddrInfo->import( qw(:newapi getaddrinfo) ) };
if ($@) {
*getaddrinfo = sub { Carp::confess("Unable to use IPv6: Socket::GetAddrInfo not available") };
}
} }
} }


Expand Down
39 changes: 18 additions & 21 deletions lib/POE/Wheel/SocketFactory.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -51,32 +51,29 @@ sub MY_SOCKET_SELECTED () { 12 }
# If IPv6 support can't be loaded, then provide dummies so the code at # If IPv6 support can't be loaded, then provide dummies so the code at
# least compiles. Suggested in rt.cpan.org 27250. # least compiles. Suggested in rt.cpan.org 27250.
BEGIN { BEGIN {
eval "use Socket::GetAddrInfo qw(:newapi getaddrinfo getnameinfo)"; # under perl-5.6.2 the warning "leaks" from the eval, while newer versions don't...
if ($@) { # it's due to Exporter.pm behaving differently, so we have to shut it up
*getaddrinfo = sub { Carp::confess("Unable to use IPv6: Socket::GetAddrInfo not available") }; no warnings 'redefine';
*getnameinfo = sub { Carp::confess("Unable to use IPv6: Socket::GetAddrInfo not available") }; local *Carp::carp = sub { die @_ };
}


# Socket6 provides AF_INET6 and PF_INET6 where earlier Perls' Socket don't. # Socket::GetAddrInfo provides getaddrinfo where earlier Perls' Socket don't.
{ eval { Socket->import( qw(getaddrinfo getnameinfo) ) };
# under perl-5.6.2 the warning "leaks" from the eval, while newer versions don't... if ($@) {
# it's due to Exporter.pm behaving differently, so we have to shut it up # :newapi is legacy, but we include it to be sure in case the user has an old version of GAI
no warnings 'redefine'; eval { require Socket::GetAddrInfo; Socket::GetAddrInfo->import( qw(:newapi getaddrinfo getnameinfo) ) };
local *Carp::carp = sub { die @_ };
eval { require Socket; Socket->import('AF_INET6') };
if ($@) { if ($@) {
eval { require Socket6; Socket6->import('AF_INET6') }; *getaddrinfo = sub { Carp::confess("Unable to use IPv6: Socket::GetAddrInfo not available") };
if ($@) { *getnameinfo = sub { Carp::confess("Unable to use IPv6: Socket::GetAddrInfo not available") };
*AF_INET6 = sub { Carp::confess("Unable to use IPv6: Socket6 not available") };
}
} }
}


eval { require Socket; Socket->import('PF_INET6') }; # Socket6 provides AF_INET6 and PF_INET6 where earlier Perls' Socket don't.
eval { Socket->import( qw(AF_INET6 PF_INET6) ) };
if ($@) {
eval { require Socket6; Socket6->import( qw(AF_INET6 PF_INET6) ) };
if ($@) { if ($@) {
eval { require Socket6; Socket6->import('PF_INET6') }; *AF_INET6 = sub { Carp::confess("Unable to use IPv6: Socket6 not available") };
if ($@) { *PF_INET6 = sub { Carp::confess("Unable to use IPv6: Socket6 not available") };
*PF_INET6 = sub { Carp::confess("Unable to use IPv6: Socket6 not available") };
}
} }
} }
} }
Expand Down

0 comments on commit e57754a

Please sign in to comment.