9
9
use warnings FATAL => 'all';
11
use Apache::Connection ();
11
use Apache2::Connection ();
12
12
use APR::Socket ();
14
use Apache::Const -compile => 'OK';
15
use APR::Const -compile => qw(TIMEUP);
14
use Apache2::Const -compile => 'OK';
15
use APR::Const -compile => qw(SO_NONBLOCK);
17
18
use constant BUFF_LEN => 1024;
20
my Apache::Connection $c = shift;
21
my Apache2::Connection $c = shift;
21
22
my APR::Socket $socket = $c->client_socket;
23
# XXX: workaround to a problem on some platforms (solaris, bsd,
24
# etc), where Apache 2.0.49+ forgets to set the blocking mode on
26
BEGIN { use APR::Const -compile => qw(SO_NONBLOCK) }
27
$c->client_socket->opt_set(APR::SO_NONBLOCK => 0);
24
# starting from Apache 2.0.49 several platforms require you to set
25
# the socket to a blocking IO mode
26
$c->client_socket->opt_set(APR::Const::SO_NONBLOCK, 0);
29
28
# set timeout (20 sec) so later we can do error checking on
30
29
# read/write timeouts
31
30
$socket->timeout_set(20_000_000);
34
my $buff = eval { $socket->recv(BUFF_LEN) };
34
my $rlen = eval { $socket->recv($buff, BUFF_LEN) };
36
die "timed out, giving up: $@" if $@ == APR::TIMEUP;
36
die "timed out, giving up: $@" if APR::Status::is_TIMEUP($@);
40
last unless length $buff; # EOF
40
last unless $rlen; # EOF
42
42
my $wlen = eval { $socket->send($buff) };
44
die "timed out, giving up: $@" if $@ == APR::TIMEUP;
44
die "timed out, giving up: $@" if APR::Status::is_TIMEUP($@);
47
last if $wlen != length $buff; # write failure?