Re: Perl HTTP Tiny non configurable Timeout
On Fri, Aug 05, 2016 at 05:01:10PM -0400, sven falempin wrote: > Base perl got a deprecated HTTP Tiny code (0.29), > one can use a package but base may enjoy the correction > around or a better one. I'm planning to update perl in base after I get mod_perl working under a version > 5.20, which hopefully won't be too far in the future. Doing that will update IO::Socket::IP to 0.37 which includes the Timeout options. > # Annoyingly IO::Socket's connect() is where the timeout logic is > > Index: IP.pm > === > RCS file: /cvs/src/gnu/usr.bin/perl/cpan/IO-Socket-IP/lib/IO/Socket/IP.pm,v > retrieving revision 1.1.1.1 > diff -u -p -r1.1.1.1 IP.pm > --- IP.pm 17 Nov 2014 20:52:48 - 1.1.1.1 > +++ IP.pm 5 Aug 2016 20:53:17 - > @@ -1,13 +1,13 @@ > # You may distribute under the terms of either the GNU General Public > License > # or the Artistic License (the same terms as Perl itself) > # > -# (C) Paul Evans, 2010-2014 -- leon...@leonerd.org.uk > +# (C) Paul Evans, 2010-2015 -- leon...@leonerd.org.uk > > package IO::Socket::IP; > # $VERSION needs to be set before use base 'IO::Socket' > # - https://rt.cpan.org/Ticket/Display.html?id=92107 > BEGIN { > - $VERSION = '0.29'; > + $VERSION = '0.38'; > } > > use strict; > @@ -31,7 +31,7 @@ use Socket 1.97 qw( > my $AF_INET6 = eval { Socket::AF_INET6() }; # may not be defined > my $AI_ADDRCONFIG = eval { Socket::AI_ADDRCONFIG() } || 0; > use POSIX qw( dup2 ); > -use Errno qw( EINVAL EINPROGRESS EISCONN ); > +use Errno qw( EINVAL EINPROGRESS EISCONN ENOTCONN ETIMEDOUT EWOULDBLOCK ); > > use constant HAVE_MSWIN32 => ( $^O eq "MSWin32" ); > > @@ -265,6 +265,22 @@ If true, set the C sockopt > > If true, set the C sockopt > > +=item Sockopts => ARRAY > + > +An optional array of other socket options to apply after the three listed > +above. The value is an ARRAY containing 2- or 3-element ARRAYrefs. Each > inner > +array relates to a single option, giving the level and option name, and an > +optional value. If the value element is missing, it will be given the > value of > +a platform-sized integer 1 constant (i.e. suitable to enable most of the > +common boolean options). > + > +For example, both options given below are equivalent to setting > C. > + > + Sockopts => [ > +[ SOL_SOCKET, SO_REUSEADDR ], > +[ SOL_SOCKET, SO_REUSEADDR, pack( "i", 1 ) ], > + ] > + > =item V6Only => BOOL > > If defined, set the C sockopt when creating C > sockets > @@ -304,6 +320,22 @@ If defined but false, the socket will be > it will default to blocking mode. See the NON-BLOCKING section below for > more > detail. > > +=item Timeout => NUM > + > +If defined, gives a maximum time in seconds to block per Ccall > +when in blocking mode. If missing, no timeout is applied other than that > +provided by the underlying operating system. When in non-blocking mode this > +parameter is ignored. > + > +Note that if the hostname resolves to multiple address candidates, the same > +timeout will apply to each connection attempt individually, rather than to > the > +operation as a whole. Further note that the timeout does not apply to the > +initial hostname resolve operation, if connecting by hostname. > + > +This behviour is copied inspired by C; for more fine > grained > +control over connection timeouts, consider performing a nonblocking connect > +directly. > + > =back > > If neither C nor C hints are provided, a default of > @@ -380,6 +412,12 @@ sub _io_socket_ip__configure > 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}; > } > @@ -425,11 +463,17 @@ sub _io_socket_ip__configure >ref $info eq "ARRAY" or croak "Expected 'LocalAddrInfo' to be an > ARRAY ref"; >@localinfos = @$info; > } > - elsif( defined $arg->{LocalHost} or defined $arg->{LocalService} ) { > + elsif( defined $arg->{LocalHost} or > + defined $arg->{LocalService} or > + HAVE_MSWIN32 and $arg->{Listen} ) { ># Either may be undef >my $host = $arg->{LocalHost}; >my $service = $arg->{LocalService}; > > + unless ( defined $host or defined $service ) { > + $service = 0; > + } > + >local $1; # Placate a taint-related bug; [perl #67962] >defined $service and $service =~ s/\((\d+)\)$// and > my $fallback_port = $1; > @@ -476,14 +520,27 @@ sub _io_socket_ip__configure >} > } > > + my $INT_1 = pack "i", 1; > + > my @sockopts_enabled; > - push @sockopts_enabled, SO_REUSEADDR if $arg->{ReuseAddr}; > - push @sockopts_enabled, SO_REUSEPORT if
Perl HTTP Tiny non configurable Timeout
Base perl got a deprecated HTTP Tiny code (0.29), one can use a package but base may enjoy the correction around or a better one. # Annoyingly IO::Socket's connect() is where the timeout logic is Index: IP.pm === RCS file: /cvs/src/gnu/usr.bin/perl/cpan/IO-Socket-IP/lib/IO/Socket/IP.pm,v retrieving revision 1.1.1.1 diff -u -p -r1.1.1.1 IP.pm --- IP.pm 17 Nov 2014 20:52:48 - 1.1.1.1 +++ IP.pm 5 Aug 2016 20:53:17 - @@ -1,13 +1,13 @@ # You may distribute under the terms of either the GNU General Public License # or the Artistic License (the same terms as Perl itself) # -# (C) Paul Evans, 2010-2014 -- leon...@leonerd.org.uk +# (C) Paul Evans, 2010-2015 -- leon...@leonerd.org.uk package IO::Socket::IP; # $VERSION needs to be set before use base 'IO::Socket' # - https://rt.cpan.org/Ticket/Display.html?id=92107 BEGIN { - $VERSION = '0.29'; + $VERSION = '0.38'; } use strict; @@ -31,7 +31,7 @@ use Socket 1.97 qw( my $AF_INET6 = eval { Socket::AF_INET6() }; # may not be defined my $AI_ADDRCONFIG = eval { Socket::AI_ADDRCONFIG() } || 0; use POSIX qw( dup2 ); -use Errno qw( EINVAL EINPROGRESS EISCONN ); +use Errno qw( EINVAL EINPROGRESS EISCONN ENOTCONN ETIMEDOUT EWOULDBLOCK ); use constant HAVE_MSWIN32 => ( $^O eq "MSWin32" ); @@ -265,6 +265,22 @@ If true, set the C sockopt If true, set the C sockopt +=item Sockopts => ARRAY + +An optional array of other socket options to apply after the three listed +above. The value is an ARRAY containing 2- or 3-element ARRAYrefs. Each inner +array relates to a single option, giving the level and option name, and an +optional value. If the value element is missing, it will be given the value of +a platform-sized integer 1 constant (i.e. suitable to enable most of the +common boolean options). + +For example, both options given below are equivalent to setting C. + + Sockopts => [ +[ SOL_SOCKET, SO_REUSEADDR ], +[ SOL_SOCKET, SO_REUSEADDR, pack( "i", 1 ) ], + ] + =item V6Only => BOOL If defined, set the C sockopt when creating C sockets @@ -304,6 +320,22 @@ If defined but false, the socket will be it will default to blocking mode. See the NON-BLOCKING section below for more detail. +=item Timeout => NUM + +If defined, gives a maximum time in seconds to block per Ccall +when in blocking mode. If missing, no timeout is applied other than that +provided by the underlying operating system. When in non-blocking mode this +parameter is ignored. + +Note that if the hostname resolves to multiple address candidates, the same +timeout will apply to each connection attempt individually, rather than to the +operation as a whole. Further note that the timeout does not apply to the +initial hostname resolve operation, if connecting by hostname. + +This behviour is copied inspired by C; for more fine grained +control over connection timeouts, consider performing a nonblocking connect +directly. + =back If neither C nor C hints are provided, a default of @@ -380,6 +412,12 @@ sub _io_socket_ip__configure 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}; } @@ -425,11 +463,17 @@ sub _io_socket_ip__configure ref $info eq "ARRAY" or croak "Expected 'LocalAddrInfo' to be an ARRAY ref"; @localinfos = @$info; } - elsif( defined $arg->{LocalHost} or defined $arg->{LocalService} ) { + elsif( defined $arg->{LocalHost} or + defined $arg->{LocalService} or + HAVE_MSWIN32 and $arg->{Listen} ) { # Either may be undef my $host = $arg->{LocalHost}; my $service = $arg->{LocalService}; + unless ( defined $host or defined $service ) { + $service = 0; + } + local $1; # Placate a taint-related bug; [perl #67962] defined $service and $service =~ s/\((\d+)\)$// and my $fallback_port = $1; @@ -476,14 +520,27 @@ sub _io_socket_ip__configure } } + my $INT_1 = pack "i", 1; + my @sockopts_enabled; - push @sockopts_enabled, SO_REUSEADDR if $arg->{ReuseAddr}; - push @sockopts_enabled, SO_REUSEPORT if $arg->{ReusePort}; - push @sockopts_enabled, SO_BROADCAST if $arg->{Broadcast}; + push @sockopts_enabled, [ SOL_SOCKET, SO_REUSEADDR, $INT_1 ] if $arg->{ReuseAddr}; + push @sockopts_enabled, [ SOL_SOCKET, SO_REUSEPORT, $INT_1 ] if $arg->{ReusePort}; + push @sockopts_enabled, [ SOL_SOCKET, SO_BROADCAST, $INT_1 ] if $arg->{Broadcast}; + + if( my $sockopts = $arg->{Sockopts} ) { + ref $sockopts eq "ARRAY" or croak "Expected 'Sockopts' to be an ARRAY ref"; + foreach ( @$sockopts ) { + ref $_ eq "ARRAY" or croak "Bad Sockopts item -