Non-blocking https client
use Net::HTTPS::NB; use IO::Select; use strict; my $s = Net::HTTPS::NB->new(Host => "pause.perl.org") || die $@; $s->write_request(GET => "/"); my $sel = IO::Select->new($s); READ_HEADER: { die "Header timeout" unless $sel->can_read(10); my($code, $mess, %h) = $s->read_response_headers; redo READ_HEADER unless $code; } while (1) { die "Body timeout" unless $sel->can_read(10); my $buf; my $n = $s->read_entity_body($buf, 1024); last unless $n; print $buf; }
use strict; use Net::HTTPS::NB; use IO::Select;
my $sock = Net::HTTPS::NB->new(Host => 'encrypted.google.com', Blocking => 0); my $sele = IO::Select->new($sock);
until ($sock->connected) { if ($HTTPS_ERROR == HTTPS_WANT_READ) { $sele->can_read(); } elsif($HTTPS_ERROR == HTTPS_WANT_WRITE) { $sele->can_write(); } else { die 'Unknown error: ', $HTTPS_ERROR; } }
See `examples' subdirectory for more examples.
Same interface as Net::HTTPS but it will never try multiple reads when the read_response_headers() or read_entity_body() methods are invoked. In addition allows non-blocking connect.
Imported by default
HTTPS_WANT_READ HTTPS_WANT_WRITE
Imported by default
$HTTPS_ERROR
Same as Net::HTTPS::new, but in addition allows `Blocking' parameter. By setting this parameter to 0 you can perform non-blocking connect. See connected() to determine when connection completed.
Returns true value when connection completed (https handshake done). Otherwise returns false. In this case you can check $HTTPS_ERROR to determine what handshake need for, read or write. $HTTPS_ERROR could be \s-1HTTPS_WANT_READ\s0 or \s-1HTTPS_WANT_WRITE\s0 respectively. See \*(L"\s-1SYNOPSIS\s0\*(R".
As opposed to Net::HTTPS where blocking method consciously broken you can set socket blocking. For example you can return socket to blocking state after non-blocking connect.
Net::HTTP, Net::HTTP::NB
Copyright 2011-2013 Oleg G <[email protected]>.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.