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

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

commit e45a7d791a1b5f3577f9054cb82cd183a33b43f9
Author: Marco Casaroli <[email protected]>
AuthorDate: Wed Nov 25 19:23:15 2026 +0100

    net/tcp: Report no EPOLLOUT edge for a poll of the device alone.
    
    An epoll set keeps its poll set up across its waits (POLLALWAYS), and
    each notification of the socket can be an event for it.
    tcp_poll_eventhandler() set POLLOUT on every callback when the socket
    could send, also for TCP_POLL.  With TCP_POLL the device asks the
    connection for data to send; this does not change the state of the
    socket.  So an EPOLLOUT | EPOLLET waiter on an idle connection got an
    event when the device polled it, for example when another connection
    on the same device sent data.
    
    For an epoll set, only an ACK, new data, a connection or a closed peer
    now reports POLLOUT.  The setup of the poll already reports that the
    socket is writable.  poll() and select() do not change: they are woken
    once and tear their poll down.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 net/tcp/tcp_netpoll.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/net/tcp/tcp_netpoll.c b/net/tcp/tcp_netpoll.c
index 45881b62445..aa4c19fdc5d 100644
--- a/net/tcp/tcp_netpoll.c
+++ b/net/tcp/tcp_netpoll.c
@@ -161,7 +161,10 @@ static uint32_t tcp_poll_eventhandler(FAR struct 
net_driver_s *dev,
           eventset |= POLLIN | POLLRDHUP | POLLERR | POLLHUP;
         }
 
-      /* A poll is a sign that we are free to send data. */
+      /* A poll is a sign that we are free to send data.  An epoll set
+       * (POLLALWAYS) stays set up: a poll of the device alone (TCP_POLL)
+       * does not change the socket, and reports no POLLOUT to it.
+       */
 
       /* Wake up poll() speculatively on TCP_ACKDATA.
        * Note: our event handler is usually executed before
@@ -170,11 +173,14 @@ static uint32_t tcp_poll_eventhandler(FAR struct 
net_driver_s *dev,
        * this callback to be inserted after psock_send_eventhandler.
        */
 
-      else if (psock_tcp_cansend(info->conn) >= 0
+      else if (((info->fds->events & POLLALWAYS) == 0 ||
+                (flags & (TCP_ACKDATA | TCP_CONNECTED | TCP_NEWDATA |
+                          TCP_BACKLOG | TCP_RXCLOSE)) != 0) &&
+               (psock_tcp_cansend(info->conn) >= 0
 #if defined(CONFIG_NET_TCP_WRITE_BUFFERS)
-               || (flags & TCP_ACKDATA) != 0
+                || (flags & TCP_ACKDATA) != 0
 #endif
-              )
+              ))
         {
           eventset |= POLLOUT;
         }

Reply via email to