Subject: Re: Test for EAGAIN

Re: Test for EAGAIN

From: William Ahern <william_at_25thandclement.com>
Date: 2006-04-03

On Fri, Mar 31, 2006 at 06:53:57PM -0800, William Ahern wrote:
> About a year ago I sent in a patch to make UDP non-blocking. In my comment I
> said that the patch wasn't complete and we needed to add EAGAIN/EWOULDBLOCK
> tests.
>
> We forgot to do that, and I didn't catch it till yesterday.
>
> I'll try to put together a patch, unless somebody beats me to it. This is
> just an FYI.

Here's a patch against 1.3.0, inline and attacked.

Index: ares_process.c
===================================================================
--- ares_process.c (revision 17446)
+++ ares_process.c (working copy)
@@ -135,7 +135,8 @@
           free(vec);
           if (wcount < 0)
             {
- handle_error(channel, i, now);
+ if (errno != EAGAIN)
+ handle_error(channel, i, now);
               continue;
             }
 
@@ -168,7 +169,8 @@
 
           if (scount < 0)
             {
- handle_error(channel, i, now);
+ if (errno != EAGAIN)
+ handle_error(channel, i, now);
               continue;
             }
 
@@ -216,7 +218,8 @@
                        2 - server->tcp_buffer_pos, 0);
           if (count <= 0)
             {
- handle_error(channel, i, now);
+ if (!(count == -1 && errno == EAGAIN))
+ handle_error(channel, i, now);
               continue;
             }
 
@@ -242,7 +245,8 @@
                        server->tcp_length - server->tcp_buffer_pos, 0);
           if (count <= 0)
             {
- handle_error(channel, i, now);
+ if (!(count == -1 && errno == EAGAIN))
+ handle_error(channel, i, now);
               continue;
             }
 
@@ -281,8 +285,10 @@
         continue;
 
       count = recv(server->udp_socket, buf, sizeof(buf), 0);
- if (count <= 0)
- handle_error(channel, i, now);
+ if (count == -1 && errno == EAGAIN)
+ continue;
+ else if (count <= 0)
+ handle_error(channel, i, now); /* Should we continue, too? */
 
       process_answer(channel, buf, count, i, 0, now);
     }
@@ -467,6 +473,7 @@
         }
       if (send(server->udp_socket, query->qbuf, query->qlen, 0) == -1)
         {
+ /* XXX: Are we guaranteed never to get EAGAIN? */
           query->skip_server[query->server] = 1;
           next_server(channel, query, now);
           return;

Received on Mon Apr 3 01:37:54 2006