Subject: | WWW::Curl::Multi gets same url for each handle (even if each handle was configured with its own url) |
I've applied all fixes mentioned here in bug database to make ::Multi
fetch something. But it turns out to fetch same URL for each handle
(irregarding of URL each of the handles was configured for).
I've run strace to see what it actually fetches - it really does send
request to the same URL.
I've spent 4 hours trying different combinations, nothing helps..
I've tried perl-5.10 and perl 5.8.8 (self compiled with all defaults; no
threads support). This is on linux x86 (redhat 7.3 and centos 3).
libcurl version tried were 7.16 and 7.8.2.
Subject: | multi2.pl |
#!/usr/test/perl-5.10.0/bin/perl
use strict;use warnings;
use WWW::Curl::Easy;
use WWW::Curl::Multi;
my %easy;
my %easy_props;
my $easy_jobs_id;
my $active_handles = 0;
sub _add_job
{
my ($url,$rvar) = @_;
my $curl_id = ++$easy_jobs_id;
$easy{$curl_id} = WWW::Curl::Easy->new;
$easy{$curl_id}->setopt(CURLOPT_PRIVATE,$curl_id);
$easy{$curl_id}->setopt(CURLOPT_HEADERFUNCTION, sub { return length($_[0]); });
$easy{$curl_id}->setopt(CURLOPT_URL, $url);
$easy_props{$curl_id} = { 'data', $rvar, 'url', $url };
$easy{$curl_id}->setopt(CURLOPT_WRITEFUNCTION,
sub { my $t = shift; $$rvar .= $t; return length($t); } );
}
sub run_jobs
{
my $curlm = WWW::Curl::Multi->new;
foreach ( values %easy)
{
$curlm->add_handle($_);
$active_handles++;
};
while ($active_handles) {
my $active_transfers = $curlm->perform;
if ($active_transfers != $active_handles) {
while (my ($id,$return_value) = $curlm->info_read) {
if ($id) {
$active_handles--;
my $actual_easy_handle = $easy{$id};
print STDERR "got content for $easy_props{$id}->{url}\n" .
"${$easy_props{$id}->{data}}\n\n";
delete $easy{$id};
} else {
print STDERR "info read returned $id and $return_value\n";
};
}
}
}
}
my $v1 = '';
my $v2 = '';
_add_job("http://apple.com",\$v1);
_add_job("http://www.ft.com",\$v2);
run_jobs();