drivers/pipe: fix POLLHUP handling in poll()

For POLICY_0, when a pipe only has a reader and no writer,
if the pipe is empty, set POLLHUP.

For POLICY_1, when a pipe only has a reader but no writer,
if the pipe is empty, POLLHUP will not be set.

This change corrects poll() behavior to match the two pipe policies.
No API changes.

Signed-off-by: yukangzhi <yukangzhi@xiaomi.com>
This commit is contained in:
yukangzhi
2025-07-10 11:50:13 +08:00
committed by Donny(董九柱)
parent ccf660ce10
commit bcddaa59a9

View File

@@ -731,9 +731,13 @@ int pipecommon_poll(FAR struct file *filep, FAR struct pollfd *fds,
eventset |= POLLIN;
}
/* Notify the POLLHUP event if the pipe is empty and no writers */
/* Notify the POLLHUP event if the pipe is empty,
* while no writers and policy 0.
*/
if (nbytes == 0 && dev->d_nwriters <= 0)
if (nbytes == 0 &&
dev->d_nwriters <= 0 &&
PIPE_IS_POLICY_0(dev->d_flags))
{
eventset |= POLLHUP;
}