All pastes #886489 Raw Edit

Unnamed

public text v1 · immutable
#886489 ·published 2008-01-31 18:35 UTC
rendered paste body
    my $sel = IO::Select->new;
    my $res = Net::DNS::Resolver->new;

    while (scalar @domains > 0) {
	my @active = $sel->handles;
	while ($#active < $DNS_SOCK_MAX - 1) {
	    # queue up a query for this domain.
	    my $d = pop(@domains);
	    $sel->add($res->bgsend($d, "A"));
	    $sel->add($res->bgsend($d, "MX"));
	    @active = $sel->handles;
	}
	my @ready = $sel->can_read($timeout);
	if (@ready) {
	    foreach my $sock (@ready) {
		my $packet = $res->bgread($sock);
		if ($packet->header->ancount) {
		    my @q = $packet->question;
		    if ($q[0]->qtype eq "A" || $q[0]->qtype eq "MX") {
			my $d = $q[0]->qname;
			delete $SENDERS{$d};
		    }
		}
		# Check for the other sockets.
		$sel->remove($sock);
		$sock = undef;
	    }
	} else {
	    # nothing for now.
	}
    }
    @domains = undef;

    my $timedout = 0;
    my @ready;
    while($timedout < 4 && $sel->handles && (@ready = $sel->can_read($timeout))) {
	if (@ready) {
	    foreach my $sock (@ready) {
		my $packet = $res->bgread($sock);
		if ($packet->header->ancount) {
		    my @q = $packet->question;
		    if ($q[0]->qtype eq "A" || $q[0]->qtype eq "MX") {
			my $d = $q[0]->qname;
			delete $SENDERS{$d};
		    }
		}
		# Check for the other sockets.
		$sel->remove($sock);
		$sock = undef;
	    }
	} else {
	    $timedout++;
	}
    }