This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 90c258ef2e4af747a47bbd1612e48dc26cf59e38
Author: Marco Casaroli <[email protected]>
AuthorDate: Thu Nov 26 08:37:58 2026 +0100

    net/local: Honour SO_RCVTIMEO in accept().
    
    A blocking accept() of a local stream socket waited for ever: it
    ignored the receive timeout (SO_RCVTIMEO).  Linux ends the wait after
    the timeout with EAGAIN.  Now local_waitlisten() waits at most for the
    receive timeout of the listener, over all its wake-ups, and returns
    EAGAIN when it expires.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 net/local/local_accept.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/net/local/local_accept.c b/net/local/local_accept.c
index 713fc473920..b7775177938 100644
--- a/net/local/local_accept.c
+++ b/net/local/local_accept.c
@@ -26,11 +26,13 @@
 
 #include <nuttx/config.h>
 
+#include <limits.h>
 #include <string.h>
 #include <errno.h>
 #include <assert.h>
 #include <nuttx/debug.h>
 
+#include <nuttx/clock.h>
 #include <nuttx/nuttx.h>
 #include <nuttx/queue.h>
 #include <nuttx/net/net.h>
@@ -48,20 +50,37 @@
 
 static int local_waitlisten(FAR struct local_conn_s *server)
 {
+  unsigned int timeout = _SO_TIMEOUT(server->lc_conn.s_rcvtimeo);
+  clock_t start = clock_systime_ticks();
+  clock_t elapsed;
   int ret;
 
-  /* Loop until a connection is requested or we receive a signal */
+  /* Loop until a connection is requested, we receive a signal, or the
+   * receive timeout (SO_RCVTIMEO) expires: EAGAIN, as Linux.
+   */
 
   while (dq_empty(&server->u.server.lc_waiters))
     {
       /* No.. wait for a connection or a signal */
 
       local_unlock();
-      ret = nxsem_wait(&server->lc_waitsem);
+      if (timeout == UINT_MAX)
+        {
+          ret = nxsem_wait(&server->lc_waitsem);
+        }
+      else
+        {
+          elapsed = clock_systime_ticks() - start;
+          ret = elapsed < MSEC2TICK(timeout) ?
+                nxsem_tickwait(&server->lc_waitsem,
+                               MSEC2TICK(timeout) - elapsed) :
+                -ETIMEDOUT;
+        }
+
       local_lock();
       if (ret < 0)
         {
-          return ret;
+          return ret == -ETIMEDOUT ? -EAGAIN : ret;
         }
     }
 

Reply via email to