• O_RDWR On Named Pipes

    From Lawrence D'Oliveiro@21:1/5 to All on Tue Mar 11 01:48:01 2025
    Typically when you open a file descriptor on a pipe, it’s either for
    reading or writing, but not both.

    However, when you open a named pipe, it is possible to specify the mode
    O_RDWR; but does this work, or return an error? And if it doesn’t return
    an error, what exactly does it do?

    I checked some relevant man pages <https://manpages.debian.org/fifo(7)> <https://manpages.debian.org/pipe(7)>, but they completely avoid any
    mention of O_RDWR mode.

    So I tried it. And it works without error. You get back a single file descriptor, that you can use for both writing to the pipe and reading from
    it. So if no other processes open the same named pipe, you can write
    something to it (I suppose until the kernel buffer fills up), and read the
    same thing back again.

    Not very useful, on the face of it. But I guess it means you can (with appropriate coordination from both ends) switch the direction of data flow
    at any point, without having to close and reopen the named pipe. Basically O_RDWR gives you a half-duplex communication channel, where O_RDONLY and O_WRONLY will give you the ends of a simplex (unidirectional) channel.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)