djbdns/090-tinydns-one-second.patch

41 lines
835 B
Diff
Raw Permalink Normal View History

--- a/tdlookup.c
+++ b/tdlookup.c
@@ -280,15 +280,24 @@ static int doit(char *q,char qtype[2])
int respond(char *q,char qtype[2],char ip[4])
{
- int fd;
+ static struct tai cdb_valid = { 0 };
+ static int fd = -1;
+ struct tai one_second;
int r;
char key[6];
tai_now(&now);
- fd = open_read("data.cdb");
- if (fd == -1) return 0;
- cdb_init(&c,fd);
-
+ if (tai_less(&cdb_valid, &now)) {
+ if (fd != -1) {
+ cdb_free(&c);
+ close(fd);
+ }
+ fd = open_read("data.cdb");
+ if (fd == -1) return 0;
+ cdb_init(&c,fd);
+ tai_uint(&one_second, 1);
+ tai_add(&cdb_valid, &now, &one_second);
+ }
byte_zero(clientloc,2);
key[0] = 0;
key[1] = '%';
@@ -312,7 +321,5 @@ int respond(char *q,char qtype[2],char i
r = doit(q,qtype);
- cdb_free(&c);
- close(fd);
return r;
}