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 f17aa7eec7cb843c10914dd20462659a96b43051
Author: zhanghongyu <[email protected]>
AuthorDate: Wed Nov 4 12:08:56 2026 +0800

    drivers/pipes: report POLLHUP on close only under buffer policy 0
    
    pipecommon_poll() reports POLLHUP only when the pipe is empty, has no
    writers and uses buffer policy 0.  pipecommon_close() reported it for
    every policy when the last writer went away, so the two disagreed.
    
    Under policy 1 the buffered data stays valid for the next reader, so
    losing the last writer is not an end-of-file condition.  This matters for
    AF_LOCAL datagram sockets, which open and close their sending FIFO for
    every packet: a receiver polling the FIFO saw POLLIN|POLLHUP for each
    datagram, and POLLHUP alone for a send that failed with EMSGSIZE, so a
    program that closes its socket on POLLHUP stopped after the first
    datagram.
    
    Apply the same policy-0 condition as pipecommon_poll().
    
    Signed-off-by: zhanghongyu <[email protected]>
---
 drivers/pipes/pipe_common.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/pipes/pipe_common.c b/drivers/pipes/pipe_common.c
index 60a9860e328..f96a574f335 100644
--- a/drivers/pipes/pipe_common.c
+++ b/drivers/pipes/pipe_common.c
@@ -345,9 +345,20 @@ int pipecommon_close(FAR struct file *filep)
 
           if (--dev->d_nwriters <= 0)
             {
-              /* Inform poll readers that other end closed. */
+              /* Inform poll readers that other end closed.  Match
+               * pipecommon_poll(), which reports POLLHUP only under
+               * buffer policy 0: under policy 1 the data stays valid for
+               * the next reader, so the loss of the last writer is not an
+               * end-of-file condition.  A datagram socket opens and closes
+               * its sending FIFO for every packet, so reporting POLLHUP
+               * here would flag a hangup on each datagram.
+               */
 
-              poll_notify(dev->d_fds, CONFIG_DEV_PIPE_NPOLLWAITERS, POLLHUP);
+              if (PIPE_IS_POLICY_0(dev->d_flags))
+                {
+                  poll_notify(dev->d_fds, CONFIG_DEV_PIPE_NPOLLWAITERS,
+                              POLLHUP);
+                }
 
               pipecommon_wakeup(&dev->d_rdsem);
             }

Reply via email to