cURL / Mailing Lists / curl-library / Single Mail

curl-library

can't get curl dns cache to work

From: Phillip Stevens <pj2k_at_hotmail.com>
Date: Thu, 04 Apr 2002 00:35:24 +1000

Hi all,

I'm having trouble manipulating the curl dns cache. The cache seems to be
turned
on by default, however it doesn't seem to be timing out by default. If I
indefinitely
request a web page via a perl script and then I kill the dns server during
the
process, the perl script will continue to retrieve the page indefinitely
(does not
fail after 60 seconds). I let the script run for several minutes, it was
still
retrieving the page successfully.

Neither CURLOPT_DNS_CACHE_TIMEOUT or CURLOPT_DNS_USE_GLOBAL_CACHE seems to
have any effect. If I change the timeout to 10 seconds nothing changes. The
cache
doesn't time out. I must be doing something wrong.

libcurl 7.9.5 is being used, with curleasy 1.20

Any help would be appreciated.

Thank you.

use strict;
use Curl::easy;

# Init the curl session
my $curl= Curl::easy::init();
if(!$curl) {
    die "curl init failed!\n";
}

Curl::easy::setopt($curl, CURLOPT_DNS_CACHE_TIMEOUT, 10);

$::errbuf="";
Curl::easy::setopt($curl, CURLOPT_ERRORBUFFER, "::errbuf");

my $count;
while ($count<100){
        $count++;

        my $url = "http://domain.com";

        Curl::easy::setopt($curl, CURLOPT_URL, $url);

        sub body_callback {
            my ($chunk,$handle)=@_;
            push @$handle, $chunk;
            return length($chunk); # OK
        }
        Curl::easy::setopt($curl, CURLOPT_WRITEFUNCTION, \&body_callback);

        my @body;

        Curl::easy::setopt($curl, CURLOPT_FILE, \@body);

        if (Curl::easy::perform($curl) != 0) {
            print "Failed :$::errbuf\n";
        };

        print join("",@body);

};

# Cleanup
Curl::easy::cleanup($curl);

_________________________________________________________________
MSN Photos is the easiest way to share and print your photos:
http://photos.msn.com/support/worldwide.aspx
Received on 2002-04-03