read_udp_packets: bail out loop on bad sockets
authorGisle Vanem <gvanem@broadpark.no>
Sat, 30 Jun 2012 21:44:00 +0000 (23:44 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Sat, 30 Jun 2012 21:44:00 +0000 (23:44 +0200)
I can see that recvfrom() in ares_process.c many times is called with
'udp_socket' == ARES_SOCKET_BAD. The code takes care not to call
recv/recvfrom with ARES_SOCKET_BAD in the outer-loop. So should the
inner-loop.

ares_process.c

index 79a999f..ad0fea1 100644 (file)
@@ -472,16 +472,22 @@ static void read_udp_packets(ares_channel channel, fd_set *read_fds,
       /* To reduce event loop overhead, read and process as many
        * packets as we can. */
       do {
+        if (server->udp_socket == ARES_SOCKET_BAD)
+          count = 0;
+
+        else {
 #ifdef HAVE_RECVFROM
-        if (server->addr.family == AF_INET)
-          fromlen = sizeof(from.sa4);
-        else
-          fromlen = sizeof(from.sa6);
-        count = (ssize_t)recvfrom(server->udp_socket, (void *)buf, sizeof(buf),
-                                  0, &from.sa, &fromlen);
+          if (server->addr.family == AF_INET)
+            fromlen = sizeof(from.sa4);
+          else
+            fromlen = sizeof(from.sa6);
+          count = (ssize_t)recvfrom(server->udp_socket, (void *)buf, sizeof(buf),
+                                    0, &from.sa, &fromlen);
 #else
-        count = sread(server->udp_socket, buf, sizeof(buf));
+          count = sread(server->udp_socket, buf, sizeof(buf));
 #endif
+        }
+
         if (count == -1 && try_again(SOCKERRNO))
           continue;
         else if (count <= 0)