sub
new
{
my
$class
=
shift
;
my
$active
= 0;
return
$class
->SUPER::new( \
$active
);
}
sub
add_handle($$)
{
my
$self
=
shift
;
my
$easy
=
shift
;
$$self
++;
$self
->SUPER::add_handle(
$easy
);
}
sub
get_one($)
{
my
$self
=
shift
;
if
(
my
@result
=
$self
->info_read() ) {
$self
->remove_handle(
$result
[ 1 ] );
return
@result
;
}
while
(
$$self
) {
my
$t
=
$self
->timeout;
if
(
$t
!= 0 ) {
$t
= 10000
if
$t
< 0;
my
(
$r
,
$w
,
$e
) =
$self
->fdset;
select
$r
,
$w
,
$e
,
$t
/ 1000;
}
my
$ret
=
$self
->perform();
if
(
$$self
!=
$ret
) {
$$self
=
$ret
;
if
(
my
@result
=
$self
->info_read() ) {
$self
->remove_handle(
$result
[ 1 ] );
return
@result
;
}
}
};
return
();
}
1;
sub
easy
{
my
$uri
=
shift
;
my
$share
=
shift
;
my
$easy
= Net::Curl::Easy->new( {
uri
=>
$uri
,
body
=>
''
} );
$easy
->setopt( Net::Curl::Easy::CURLOPT_VERBOSE(), 1 );
$easy
->setopt( Net::Curl::Easy::CURLOPT_URL(),
$uri
);
$easy
->setopt( Net::Curl::Easy::CURLOPT_WRITEHEADER(),
\
$easy
->{headers} );
$easy
->setopt( Net::Curl::Easy::CURLOPT_FILE(),
\
$easy
->{body} );
$easy
->setopt( Net::Curl::Easy::CURLOPT_SHARE(),
$share
);
$easy
->setopt( Net::Curl::Easy::CURLOPT_COOKIEFILE(),
q<>
);
return
$easy
;
}
my
$multi
= Multi::Simple->new();
my
@uri
= (
);
{
my
$share
= Net::Curl::Share->new();
$share
->setopt( CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE );
$multi
->add_handle( easy(
shift
(
@uri
),
$share
) );
}
my
$ret
= 0;
while
(
my
(
$msg
,
$easy
,
$result
) =
$multi
->get_one() ) {
print
"\nFinished downloading $easy->{uri}: $result:\n"
;
printf
"Body is %d bytes long\n"
,
length
$easy
->{body};
print
"="
x 80 .
"\n"
;
$ret
= 1
if
$result
;
$multi
->add_handle( easy(
shift
(
@uri
),
$easy
->share ) )
if
@uri
;
}
exit
$ret
;