[RFC] Improve libnl non-blocking behaviour

Thomas Graf tgraf at suug.ch
Tue Apr 2 06:02:59 EDT 2013


Holger,

On 02/25/13 at 06:33pm, Holger Eitzenberger wrote:
> I noticed that nl_recvmsgs_default() does return 0 instead of
> -NLE_AGAIN when looping on a non-blocking file descriptor.  And in
> nl_recv() I see this:
> 
> 	if (errno == EAGAIN || errno == EWOULDBLOCK) {                           
> 		NL_DBG(3, "recvmsg() returned EAGAIN||EWOULDBLOCK,
> 					aborting\n");     
> 		retval = 0;                                                          
> 		goto abort;                                                          
> 	}                                                                        
> 
> Is this intended?

I gave this some thought over the last couple of weeks. It's obvious
that returning -NLE_AGAIN is the right thing to do but there was a
chance of regressions.

I can't see how somebody can rely on it returning 0 though without an
obvious risk for a infinite loop. Therefore I commited the following
to the tree:

commit 375a6294a41e003f873821a01d947f0ecfaf76d4
Author: Thomas Graf <tgraf at suug.ch>
Date:   Tue Apr 2 11:58:18 2013 +0200

    nl: Return -NLE_AGAIN if non-blocking socket would block
    
    Previously 0 was returned which gave the caller no chance of detecting
    when a non-blocking socket would block. If a caller intends to never
    see an error message it should utilize poll()/select() to only read
    when the socket has pending data or information.
    
    Reported-by: Holger Eitzenberger <holger at eitzenberger.org>
    Signed-off-by: Thomas Graf <tgraf at suug.ch>

diff --git a/lib/nl.c b/lib/nl.c
index fa43c56..0445e35 100644
--- a/lib/nl.c
+++ b/lib/nl.c
@@ -627,11 +627,6 @@ retry:
                        NL_DBG(3, "recvmsg() returned EINTR, retrying\n");
                        goto retry;
                }
-               if (errno == EAGAIN || errno == EWOULDBLOCK) {
-                       NL_DBG(3, "recvmsg() returned EAGAIN||EWOULDBLOCK, aborting\n");
-                       retval = 0;
-                       goto abort;
-               }
                retval = -nl_syserr2nlerr(errno);
                goto abort;
        }





More information about the libnl mailing list