Skip Menu |

This queue is for tickets about the IO-Socket-IP CPAN distribution.

Report information
The Basics
Id: 92930
Status: resolved
Priority: 0/
Queue: IO-Socket-IP

People
Owner: Nobody in particular
Requestors: DOHERTY [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 0.37



Subject: Clearer error messages for PeerHost/Port/Service and Listen
I was trying to create a listening socket, and mistakenly provided PeerHost and PeerPort. I got the error "Cannot Listen with a PeerHost" -- but then after removing PeerHost, I got the error "Expected 'PeerHost'". That's pretty confusing -- do you want PeerHost or not?! The problem is that I should have been using *Local*Peer/Host instead, but the error message could be more helpful. In particular, it should clarify that PeerHost & PeerPort are expected to come together -- if you give one, you're expected to give the other. It might also be nice to mention that Peer* doesn't make sense if you're also specifying Listen. Only PeerHost is mentioned in the current error message -- but AFAICT, PeerPort doesn't make sense either.
Indeed; it's messy. Furthermore, it doesn't mind the combination of Listen + Peer* if the peer address doesn't resolve; it only complains if it actually gets any candidate addrinfos. $ perl -MIO::Socket::IP -E 'IO::Socket::IP->new(Listen=>1, PeerHost=>"xxBORK", PeerPort=>"123")' $ perl -MIO::Socket::IP -E 'IO::Socket::IP->new(Listen=>1, PeerHost=>"localhost", PeerPort=>"123")' Cannot Listen with a PeerHost at -e line 1. I think I'll neaten this all up and check for some invalid combinations of args much earlier; so it doesn't rely on resolution of names. -- Paul Evans
$ perl -Mblib -MIO::Socket::IP -E 'IO::Socket::IP->new(Listen=>1, PeerHost=>"xxBORK", PeerPort=>123)' Cannot Listen with a peer address at -e line 1. $ perl -Mblib -MIO::Socket::IP -E 'IO::Socket::IP->new(Listen=>1, PeerHost=>"xxBORK")' Cannot Listen with a peer address at -e line 1. $ perl -Mblib -MIO::Socket::IP -E 'IO::Socket::IP->new(Listen=>1, PeerPort=>123)' Cannot Listen with a peer address at -e line 1. There. -- Paul Evans
Subject: rt92930.patch
=== modified file 'lib/IO/Socket/IP.pm' --- lib/IO/Socket/IP.pm 2015-03-12 19:43:03 +0000 +++ lib/IO/Socket/IP.pm 2015-03-12 20:38:02 +0000 @@ -396,6 +396,12 @@ my @localinfos; my @peerinfos; + my $listenqueue = $arg->{Listen}; + if( defined $listenqueue and + ( defined $arg->{PeerHost} || defined $arg->{PeerService} || defined $arg->{PeerAddrInfo} ) ) { + croak "Cannot Listen with a peer address"; + } + if( defined $arg->{GetAddrInfoFlags} ) { $hints{flags} = $arg->{GetAddrInfoFlags}; } @@ -503,10 +509,6 @@ push @sockopts_enabled, SO_REUSEPORT if $arg->{ReusePort}; push @sockopts_enabled, SO_BROADCAST if $arg->{Broadcast}; - my $listenqueue = $arg->{Listen}; - - croak "Cannot Listen with a PeerHost" if defined $listenqueue and @peerinfos; - my $blocking = $arg->{Blocking}; defined $blocking or $blocking = 1;
Released in 0.37 -- Paul Evans