Write requests to a pipe or FIFO shall be handled in the same way as a regular file with the following excep-
tions:
* There is no file offset associated with a pipe, hence each write request shall append to the end of the pipe.
* Write requests of {PIPE_BUF} bytes or less shall not be interleaved with data from other processes doing
writes on the same pipe. Writes of greater than {PIPE_BUF} bytes may have data interleaved, on arbitrary
boundaries, with writes by other processes, whether or not the O_NONBLOCK flag of the file status flags is
set.
* If the O_NONBLOCK flag is clear, a write request may cause the thread to block, but on normal completion it
shall return nbyte.
* If the O_NONBLOCK flag is set, write() requests shall be handled differently, in the following ways:
* The write() function shall not block the thread.
* A write request for {PIPE_BUF} or fewer bytes shall have the following effect: if there is sufficient space
available in the pipe, write() shall transfer all the data and return the number of bytes requested. Other-
wise, write() shall transfer no data and return -1 with errno set to [EAGAIN].
* A write request for more than {PIPE_BUF} bytes shall cause one of the following:
* When at least one byte can be written, transfer what it can and return the number of bytes written. When
all data previously written to the pipe is read, it shall transfer at least {PIPE_BUF} bytes.
* When no data can be written, transfer no data, and return -1 with errno set to [EAGAIN].
我觉得这段说的比较清晰, 唯一特别的就是非阻塞情况下写大于PIPE_BUF的数据在管道空的情况下会保证至少写入PIPE_BUF, 其他的我认为只要你根据返回值和errno都可以通用化的解决写入量问题, 不用考虑那么复杂, 这种问题我很早就研究过了, 最后发现我基本不会多个进程/线程写PIPE/FIFO, 就算写, 通常都是<PIPE_BUF的通知1字节.
tions:
* There is no file offset associated with a pipe, hence each write request shall append to the end of the pipe.
* Write requests of {PIPE_BUF} bytes or less shall not be interleaved with data from other processes doing
writes on the same pipe. Writes of greater than {PIPE_BUF} bytes may have data interleaved, on arbitrary
boundaries, with writes by other processes, whether or not the O_NONBLOCK flag of the file status flags is
set.
* If the O_NONBLOCK flag is clear, a write request may cause the thread to block, but on normal completion it
shall return nbyte.
* If the O_NONBLOCK flag is set, write() requests shall be handled differently, in the following ways:
* The write() function shall not block the thread.
* A write request for {PIPE_BUF} or fewer bytes shall have the following effect: if there is sufficient space
available in the pipe, write() shall transfer all the data and return the number of bytes requested. Other-
wise, write() shall transfer no data and return -1 with errno set to [EAGAIN].
* A write request for more than {PIPE_BUF} bytes shall cause one of the following:
* When at least one byte can be written, transfer what it can and return the number of bytes written. When
all data previously written to the pipe is read, it shall transfer at least {PIPE_BUF} bytes.
* When no data can be written, transfer no data, and return -1 with errno set to [EAGAIN].
我觉得这段说的比较清晰, 唯一特别的就是非阻塞情况下写大于PIPE_BUF的数据在管道空的情况下会保证至少写入PIPE_BUF, 其他的我认为只要你根据返回值和errno都可以通用化的解决写入量问题, 不用考虑那么复杂, 这种问题我很早就研究过了, 最后发现我基本不会多个进程/线程写PIPE/FIFO, 就算写, 通常都是<PIPE_BUF的通知1字节.