]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Add a few comments as suggested by Habbie
authorOtto Moerbeek <otto@drijf.net>
Wed, 11 Nov 2020 08:09:27 +0000 (09:09 +0100)
committerOtto Moerbeek <otto@drijf.net>
Wed, 11 Nov 2020 08:09:27 +0000 (09:09 +0100)
pdns/iputils.cc
pdns/pdns_recursor.cc

index 17aa12c74e9ace4fa1bd75713a71f9efc0824616..92d74c4e5b0f4d83647f06e9cfdc54a6fcabd493 100644 (file)
@@ -242,7 +242,8 @@ int sendOnNBSocket(int fd, const struct msghdr *msgh)
 {
   int sendErr = 0;
 #ifdef __OpenBSD__
-  for (int i = 0; i < 10; i++) {
+  // OpenBSD can and does return EAGIN on non-blocking datagram sockets
+  for (int i = 0; i < 10; i++) { // Arbitrary upper bound
     if (sendmsg(fd, msgh, 0) != -1) {
       sendErr = 0;
       break;
index 1ed48cb1f7f4ebaa99ecd9c2f9f4c5be281eafcd..c53c704e52ae442fc2c4feca83e7b67f923efd2b 100644 (file)
@@ -587,16 +587,18 @@ private:
       throw PDNSException("Making a socket for resolver (family = " + std::to_string(family) + "): " + stringerror());
     }
 
-#ifndef __OpenBSD__
+    // The loop below runs the body with [tries-1 tries-2 ... 1]. Last iteration with tries == 1 is special: it uses a kernel
+    // allocated UDP port.
+#if !defined( __OpenBSD__)
     int tries = 10;
 #else
-    int tries = 2; // hit the reliable kernel random case for OpenBSD, using sysctl net.inet.udp.baddynamic to exclude ports
+    int tries = 2; // hit the reliable kernel random case for OpenBSD immediately, using sysctl net.inet.udp.baddynamic to exclude ports
 #endif
     ComboAddress sin;
     while (--tries) {
       in_port_t port;
 
-      if (tries == 1) {  // fall back to kernel 'random'
+      if (tries == 1) {  // last iteration: fall back to kernel 'random'
         port = 0;
       } else {
         do {