From dbaf8a92b42ffec67228ada5dd66ecd649d14e55 Mon Sep 17 00:00:00 2001 From: ligd Date: Wed, 20 Oct 2021 12:25:30 +0800 Subject: [PATCH] pipe: pipe close should notify block writting, and write will return -EPIPE Signed-off-by: ligd --- drivers/pipes/pipe_common.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/pipes/pipe_common.c b/drivers/pipes/pipe_common.c index 28f218b868..7a639078f2 100644 --- a/drivers/pipes/pipe_common.c +++ b/drivers/pipes/pipe_common.c @@ -346,6 +346,11 @@ int pipecommon_close(FAR struct file *filep) /* Inform poll writers that other end closed. */ pipecommon_pollnotify(dev, POLLERR); + while (nxsem_get_value(&dev->d_wrsem, &sval) == 0 + && sval < 0) + { + nxsem_post(&dev->d_wrsem); + } } } } @@ -654,6 +659,11 @@ ssize_t pipecommon_write(FAR struct file *filep, FAR const char *buffer, ret = nxsem_wait(&dev->d_wrsem); sched_unlock(); + if (dev->d_nreaders <= 0) + { + ret = -EPIPE; + } + if (ret < 0 || (ret = nxsem_wait(&dev->d_bfsem)) < 0) { /* Either call nxsem_wait may fail because a signal was