]> granicus.if.org Git - pdns/commitdiff
pdns_notify: Implement 60 second timeout
authorAki Tuomi <cmouse@cmouse.fi>
Fri, 30 Nov 2018 11:55:32 +0000 (13:55 +0200)
committerAki Tuomi <cmouse@cmouse.fi>
Thu, 3 Jan 2019 15:51:49 +0000 (17:51 +0200)
pdns/notify.cc

index 270aaad3640e9470b26f338a90abcb285ef4a98c..d4457714532f3d4f5bce4ae82234247e6942827e 100644 (file)
@@ -121,11 +121,32 @@ try
     }
 
     char buffer[1500];
+    fd_set rfds;
+    FD_ZERO(&rfds);
+    FD_SET(sock, &rfds);
+    int len;
+    struct timeval tv;
+    bool timeout = true;
+
+    for(int tries=0; tries<60; tries++) {
+      tv.tv_sec = 1;
+      tv.tv_usec = 0;
+      if ((len = select(sock+1, &rfds, NULL, &rfds, &tv)) > 0) {
+        len = recv(sock, buffer, sizeof(buffer), 0);
+        timeout = false;
+        break;
+      }
+    }
 
-    int len=recv(sock, buffer, sizeof(buffer),0);
     if(len < 0) {
       cerr<<"Unable to receive notification response from PowerDNS: "+stringerror()<<endl;
       continue;
+    } else if (timeout) {
+      cerr<<"Unable to receive notification response from PowerDNS: Timed out"<<endl;
+      continue;
+    } else if (len == 0) {
+      cerr<<"Unable to receive notification response from PowerDNS: EOF"<<endl;
+      continue;
     }
 
     string packet(buffer, len);