Fix caching bug with PTR records

Attempt to fix callback occurring immediately by calling it via AddTimer


git-svn-id: https://svn.perl.org/qpsmtpd/trunk@590 958fd67b-6ff1-0310-b445-bb7760255be9
This commit is contained in:
Matt Sergeant 2005-12-30 19:35:10 +00:00
parent 7cc114edd5
commit 9c8df69be1

View File

@ -73,9 +73,12 @@ sub _query {
$asker->run_callback("NXDNS", $host);
return 1;
}
if (exists $self->{cache}{$type}{$host}) {
if (exists($self->{cache}{$type}{$host}) &&
$self->{cache_timeout}{$type}{$host} >= $now) {
# print "CACHE HIT!\n";
$asker->run_callback($self->{cache}{$type}{$host}, $host);
$self->AddTimer(0, sub {
$asker->run_callback($self->{cache}{$type}{$host}, $host);
});
return 1;
}
@ -209,8 +212,11 @@ sub event_read {
foreach my $rr ($packet->answer) {
if (my $host_method = $type_to_host{$rr->type}) {
my $host = $rr->$host_method;
$self->{cache}{$rr->type}{$query} = $host;
$self->{cache_timeout}{$rr->type}{$query} = $now + $rr->ttl;
my $type = $rr->type;
$type = 'A' if $type eq 'PTR';
# print "DNS Lookup $type $query = $host; TTL = ", $rr->ttl, "\n";
$self->{cache}{$type}{$query} = $host;
$self->{cache_timeout}{$type}{$query} = $now + $rr->ttl;
$qobj->run_callback($host);
}
elsif ($rr->type eq "MX") {