pipe: pipe close should notify block writting, and write will return -EPIPE

Signed-off-by: ligd <liguiding1@xiaomi.com>
This commit is contained in:
ligd 2021-10-20 12:25:30 +08:00 committed by Xiang Xiao
parent 2f4662c513
commit dbaf8a92b4

View File

@ -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