Skip to content

Commit

Permalink
use Net::Curl::Multi::wait() instead of select(), when available
Browse files Browse the repository at this point in the history
  • Loading branch information
creaktive committed May 13, 2013
1 parent 308e570 commit 86f28bb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions eg/async.pl
Expand Up @@ -8,6 +8,7 @@
package LWP::Protocol::Net::Curl;
use Coro::Select qw(select);
use LWP::Protocol::Net::Curl verbose => 0;
$LWP::Protocol::Net::Curl::use_select = 1;
}
use WWW::Mechanize;

Expand Down
16 changes: 12 additions & 4 deletions lib/LWP/Protocol/Net/Curl.pm
Expand Up @@ -98,6 +98,8 @@ our @implements =
{qw{ftp ftps gopher http https sftp scp}};
our %implements = map { $_ => 1 } @implements;

our $use_select = Net::Curl::Multi->can(q(wait)) ? 0 : 1;

=for Pod::Coverage
import
request
Expand Down Expand Up @@ -250,16 +252,22 @@ sub _fix_headers {
return $encoding;
}

# Wrap libcurl perform() in a non-blocking way
# Wrap libcurl perform() in a (potentially) non-blocking way
sub _perform_loop {
my ($multi) = @_;

my $running = 0;
do {
my ($r, $w, $e) = $multi->fdset;
my $timeout = $multi->timeout;
select($r, $w, $e, $timeout / 1000)
if $timeout > 9;

if ($running and $timeout > 9) {
if ($use_select) {
my ($r, $w, $e) = $multi->fdset;
select($r, $w, $e, $timeout / 1000);
} else {
$multi->wait($timeout);
}
}

$running = $multi->perform;
while (my (undef, $easy, $result) = $multi->info_read) {
Expand Down

0 comments on commit 86f28bb

Please sign in to comment.