MojoX-HTTP-Async
view release on metacpan or search on metacpan
'Test::TCP' => 2.19,
'Test::More' => 1.302183,
'FindBin' => 1.51,
'Net::EmptyPort' => 0,
},
requires => {
'perl' => 5.020,
'POSIX' => 1.76,
'Time::HiRes' => 1.9741,
'Socket' => 2.030,
'IO::Socket::SSL' => 2.072,
'Fcntl' => 1.13,
'Carp' => 1.42,
'List::Util' => 1.4602,
'Mojolicious' => 7.59,
'Mojo::Message::Request' => 0,
'Mojo::Message::Response' => 0,
'Mojo::Transaction::HTTP' => 0,
'Mojo::URL' => 0,
'URI' => 1.73,
'Errno' => 1.28,
"configure" : {
"requires" : {
"Module::Build" : "0.4220"
}
},
"runtime" : {
"requires" : {
"Carp" : "1.42",
"Errno" : "1.28",
"Fcntl" : "1.13",
"IO::Socket::SSL" : "2.072",
"List::Util" : "1.4602",
"Mojo::Message::Request" : "0",
"Mojo::Message::Response" : "0",
"Mojo::Transaction::HTTP" : "0",
"Mojo::URL" : "0",
"Mojolicious" : "7.59",
"POSIX" : "1.76",
"Scalar::Util" : "1.4602",
"Socket" : "2.03",
"Time::HiRes" : "1.9741",
version: '1.4'
name: MojoX-HTTP-Async
provides:
MojoX::HTTP::Async:
file: lib/MojoX/HTTP/Async.pm
version: '0.14'
requires:
Carp: '1.42'
Errno: '1.28'
Fcntl: '1.13'
IO::Socket::SSL: '2.072'
List::Util: '1.4602'
Mojo::Message::Request: '0'
Mojo::Message::Response: '0'
Mojo::Transaction::HTTP: '0'
Mojo::URL: '0'
Mojolicious: '7.59'
POSIX: '1.76'
Scalar::Util: '1.4602'
Socket: '2.03'
Time::HiRes: '1.9741'
By default it's equal to 5. Sets the maximum amount of slots. These
slot will be filled one by one if required.
ssl
By default it's equal to 0 (means HTTP). Sets the scheme of requests:
HTTP or HTTPS.
ssl_opts
It's a HashRef with options to control SSL Layer. See IO::Socket::SSL
constructor arguments for details.
connect_timeout
By default it's equal to 1. Sets connection timeout in seconds.
If it's equal to 0, then there will be no timeout restrictions.
request_timeout
###### slots
By default it's equal to 5. Sets the maximum amount of slots.
These slot will be filled one by one if required.
###### ssl
By default it's equal to 0 (means HTTP).
Sets the scheme of requests: HTTP or HTTPS.
###### ssl_opts
It's a HashRef with options to control SSL Layer.
See the "IO::Socket::SSL" constructor arguments for details.
###### connect_timeout
By default it's equal to 1.
Sets connection timeout in seconds.
If it's equal to 0, then there will be no timeout restrictions.
###### request_timeout
By default it's equal to 1. Sets the time in seconds with granular
accuracy as micro seconds.
lib/MojoX/HTTP/Async.pm view on Meta::CPAN
This module is distributed under terms of Artistic Perl 5 license.
=cut
use 5.020;
use warnings;
use bytes ();
use Socket qw/ inet_aton pack_sockaddr_in AF_INET SOCK_STREAM SOL_SOCKET SO_KEEPALIVE SO_OOBINLINE IPPROTO_TCP TCP_KEEPIDLE TCP_KEEPINTVL TCP_KEEPCNT /;
#use IO::Socket::IP ();
use IO::Socket::SSL ();
use Fcntl qw/ F_SETFL O_NONBLOCK FD_CLOEXEC O_NOINHERIT /;
use experimental qw/ signatures /;
use Carp qw/ croak /;
use List::Util qw/ first /;
use Time::HiRes qw/ time /;
use Mojo::Message::Request ();
use Mojo::Message::Response ();
use Mojo::Transaction::HTTP ();
use URI ();
use Scalar::Util qw/ blessed /;
lib/MojoX/HTTP/Async.pm view on Meta::CPAN
These slot will be filled one by one if required.
=item ssl
By default it's equal to 0 (means HTTP).
Sets the scheme of requests: HTTP or HTTPS.
=item ssl_opts
It's a HashRef with options to control SSL Layer.
See C<IO::Socket::SSL> constructor arguments for details.
=item connect_timeout
By default it's equal to 1.
Sets connection timeout in seconds.
If it's equal to 0, then there will be no timeout restrictions.
=item request_timeout
lib/MojoX/HTTP/Async.pm view on Meta::CPAN
if (exists($sol_tcp_opts->{'tcp_keepcnt'})) {
setsockopt($socket, $SOL_TCP, TCP_KEEPCNT, $sol_tcp_opts->{'tcp_keepcnt'}) || croak("setsockopt error has occurred while setting TCP_KEEPCNT: $!");
}
}
}
$slot->{'connected_ts'} = time();
$slot->{'reader'} = $slot->{'writer'} = $slot->{'socket'} = $socket;
$slot->{'sock_no'} = fileno($socket);
if ($self->{'ssl'}) {
my $ssl_socket = IO::Socket::SSL->new_from_fd($socket, ($self->{'ssl_opts'} // {})->%*);
croak("error=$!, ssl_error=" . $IO::Socket::SSL::SSL_ERROR) if (!$ssl_socket);
$ssl_socket->blocking(0); # just to be sure
$slot->{'reader'} = $slot->{'writer'} = $ssl_socket;
}
}
sub _connect_slot ($self, $slot) {
my $timeout = $self->{'connect_timeout'};
if ($timeout > 0) {
eval {
t/lib/Test/Utils.pm view on Meta::CPAN
package Test::Utils;
use 5.020;
use strict;
use warnings;
use experimental qw/ signatures /;
use Exporter qw/ import /;
use Test::TCP ();
use Socket qw/ inet_aton sockaddr_in pack_sockaddr_in AF_INET SOCK_STREAM INADDR_ANY /;
use IO::Socket::SSL ();
use Net::EmptyPort qw/ empty_port /;
use FindBin qw/ $Bin /;
use constant {
# IS_LINUX => ($^O eq 'linux') ? 1 : 0,
# IS_DARWIN => ($^O eq 'darwin') 1 ? : 0,
# IS_WIN => ($^O eq 'MSWin32') ? 1 : 0,
IS_NOT_WIN => ($^O ne 'MSWin32') ? 1 : 0,
IS_NOT_WIN_AND_NOT_MACOS => ($^O ne 'MSWin32' && $^O ne 'darwin') ? 1 : 0,
};
t/lib/Test/Utils.pm view on Meta::CPAN
return $server;
}
sub get_listen_socket ($host, $port, $is_ssl = 0) {
my $socket;
my $QUEUE_LENGTH = 3;
if ($is_ssl) {
$socket = IO::Socket::SSL->new(
'LocalAddr' => $host,
'LocalPort' => $port,
'Listen' => $QUEUE_LENGTH,
'SSL_cert_file' => "${Bin}/certs/server-cert.pem",
'SSL_key_file' => "${Bin}/certs/server-key.pem",
'SSL_passwd_cb' => sub { 1234 },
) or die "Can't create socket on port ${port}: $!";
} else {
my $my_addr = sockaddr_in($port, INADDR_ANY);
use warnings;
use experimental qw/ signatures /;
use bytes ();
use lib 'lib/', 't/lib';
use Test::More ('import' => [qw/ done_testing is ok use_ok plan /]);
use Test::Utils qw/ get_listen_socket start_server notify_parent /;
use Time::HiRes qw/ sleep /;
use IO::Socket::SSL qw/ SSL_VERIFY_NONE /;
my $host = '127.0.0.1';
my $processed_slots = 0;
my $request_timeout = 7.2;
my $connect_timeout = 6;
my $inactivity_timeout = 6.5;
BEGIN { use_ok('MojoX::HTTP::Async') };
'02' => "HTTP/1.1 200 OK\r\nContent-Length: 10\r\n\r\n9876543210",
);
notify_parent();
while (1) {
my $pid;
my $client = $socket->accept();
die("failed to accept or SSL handshake: ${!}, ${IO::Socket::SSL::SSL_ERROR}") if $!;
sleep(0.1) && next if !$client;
if ($pid = fork()) { # parent
sleep(0.05);
} elsif ($pid == 0) { # child
close($socket);
local $| = 1; # autoflush
my $rh = '';
( run in 0.551 second using v1.01-cache-2.11-cpan-4d50c553e7e )