Subject: Re: [Patch] ares_process.c

Re: [Patch] ares_process.c

From: Gisle Vanem <gvanem_at_broadpark.no>
Date: Wed, 27 Jun 2012 13:01:38 +0200

"Daniel Stenberg" <daniel_at_haxx.se> wrote:

> ... doesn't a bad socket make count turn negative when recvfrom() detects
> that?

Sure, but it's not nice IMHO. The code takes care not to call recv/recvfrom
with ARES_SOCKET_BAD in the outer-loop. So should the inner-loop IMHO.
I suggest something like:

--- Git-latest\ares_process.c 2012-06-24 19:37:50 +0000
+++ ares_process.c 2012-06-26 18:17:56 +0000
@@ -472,16 +472,22 @@
       /* 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)

--gv
Received on 2012-06-27