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 dc37944d948a59e8126176abddaf809f746e91e3
Author: Marco Casaroli <[email protected]>
AuthorDate: Fri Nov 20 17:12:24 2026 +0100

    net/udp: Do not lose the wakeup of a send that waits on the send limit.
    
    With CONFIG_NET_SEND_BUFSIZE > 0, psock_udp_sendto() compares the queued
    bytes with the limit while it holds the connection lock, and then waits
    on sndsem.  conn_dev_sem_timedwait() releases the lock before the wait.
    udp_sendbuffer_notify() posted sndsem only when a thread already waited
    on it (count < 0), so a write buffer that was sent between the release
    of the lock and the wait did not wake the sender.  If no other datagram
    was queued, the sender waited until its SO_SNDTIMEO time-out, or for
    ever.
    
    Post also when the count is 0, as in TCP.  A count that no sender waited
    for only makes a sender check the limit once more.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 net/udp/udp_sendto_buffered.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/net/udp/udp_sendto_buffered.c b/net/udp/udp_sendto_buffered.c
index 0b066890900..e66b40ef09a 100644
--- a/net/udp/udp_sendto_buffered.c
+++ b/net/udp/udp_sendto_buffered.c
@@ -1041,8 +1041,13 @@ void udp_sendbuffer_notify(FAR struct udp_conn_s *conn)
 {
   int val = 0;
 
+  /* Post also when no thread waits yet: a sender can be between its check
+   * of the limit and its wait, with the locks released.  A count that no
+   * sender waited for only makes a sender check the limit once more.
+   */
+
   nxsem_get_value(&conn->sndsem, &val);
-  if (val < 0)
+  if (val <= 0)
     {
       nxsem_post(&conn->sndsem);
     }

Reply via email to