mirror of
https://github.com/apache/nuttx.git
synced 2026-06-04 23:03:27 +08:00
Write to a pipe when there are no readers from the pipe should return -EPIPE.
This commit is contained in:
@@ -531,11 +531,24 @@ ssize_t pipecommon_write(FAR struct file *filep, FAR const char *buffer,
|
|||||||
DEBUGASSERT(dev);
|
DEBUGASSERT(dev);
|
||||||
pipe_dumpbuffer("To PIPE:", (FAR uint8_t *)buffer, len);
|
pipe_dumpbuffer("To PIPE:", (FAR uint8_t *)buffer, len);
|
||||||
|
|
||||||
|
/* Handle zero-length writes */
|
||||||
|
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* REVISIT: "If all file descriptors referring to the read end of a pipe
|
||||||
|
* have been closed, then a write will cause a SIGPIPE signal to be
|
||||||
|
* generated for the calling process. If the calling process is ignoring
|
||||||
|
* this signal, then write(2) fails with the error EPIPE."
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (dev->d_nreaders <= 0)
|
||||||
|
{
|
||||||
|
return -EPIPE;
|
||||||
|
}
|
||||||
|
|
||||||
/* At present, this method cannot be called from interrupt handlers. That
|
/* At present, this method cannot be called from interrupt handlers. That
|
||||||
* is because it calls nxsem_wait (via pipecommon_semtake below) and
|
* is because it calls nxsem_wait (via pipecommon_semtake below) and
|
||||||
* nxsem_wait cannot be called from interrupt level. This actually
|
* nxsem_wait cannot be called from interrupt level. This actually
|
||||||
|
|||||||
Reference in New Issue
Block a user