O_RDWR On Named Pipes

Liste des GroupesRevenir à cu programmer 
Sujet : O_RDWR On Named Pipes
De : ldo (at) *nospam* nz.invalid (Lawrence D'Oliveiro)
Groupes : comp.unix.programmer
Date : 15. Mar 2025, 22:52:16
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vr4sqg$cbcb$4@dont-email.me>
User-Agent : Pan/0.162 (Pokrosvk)
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.

Date Sujet#  Auteur
15 Mar 25 * O_RDWR On Named Pipes2Lawrence D'Oliveiro
17 Mar 25 `- Re: O_RDWR On Named Pipes1Janis Papanagnou

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal