Linux:有没有办法在非阻塞模式下在编写器端使用命名的fifos?

时间:2013-10-25 14:50:40

标签: linux pipe nonblocking mkfifo

我在Linux上发现了许多关于管道的问题和答案,但几乎所有人都在讨论读者方面。

对于一旦准备好将数据传递到命名管道的进程,只要数据可用就连接了一个读取过程,有没有办法在非-blocking 时尚:

  1. 等待(poll(2))让读者打开管道,
  2. 在循环中等待(再次轮询(2)),表示写入管道的信号不会阻塞,
  3. 收到此类信号时,请检查可以在不阻塞的情况下将多少字节写入管道
  4. 我理解如何做(2.),但我无法找到(1.)和(3。)的一致答案。

    编辑:我正在为管道寻找(类似的)FIONWRITE,但Linux没有FIONWRITE(用于管道)(?)

    EDIT2:编写器的预期主循环(伪代码的种类,目标语言是C / C ++):

    forever
        poll(can_read_command, can_write_to_the_fifo)
        if (can_read_command) {
            read and parse command
            update internal status
            continue
        }
        if (can_write_to_the_fifo) {
            length = min(data_available, space_for_nonblocking_write)
            write(output_fifo, buffer, length)
            update internal status
            continue
        }
    

0 个答案:

没有答案