Reputation: 1493
I have read the Linux manpage of pipe2, that states that you can use the O_DIRECT flag to create a pipe that performs I/O in packet mode.
I haven't found anything similar for fifos (named pipes) although I have heard that pipes and fifos share a lot of code in Linux, and it could be useful to me in a project (we already pass messages in fifos, but we have to seek for an especial terminator, reading one byte at a time).
Is there anything equivalent to perform fifo I/O in packet mode?
Upvotes: 0
Views: 1524
Reputation: 21
I'm not able to switch to a socket or message queue, and am stuck with using pipe. But good news, the patch refereed to in user2404501's answer eventually got accepted and is in linux v4.5 and newer. So using fnctl() to set O_DIRECT on a named pipe is valid.
Upvotes: 2
Reputation: 24876
Both pipe
& fifo
are byte stream, it open a file descriptor
, then use read()
and write()
to do communication.
If u want a packet
(I am not sure what u mean, I assume you want to read a block of data without determine the boundary by yourself), POSIX - message queue
might be a good choice. It send / receive data in unit of a message instead of byte by byte.
And you can also set priority
on the messages which change the order of receiving, if all messages have the same priority (e.g 0), then the send & receive order is the same as FIFO.
If that's what u want, then check man mq_overview
for details.
Upvotes: 1
Reputation:
The O_*
flags on a file descriptor can usually be changed by fcntl(fd, F_SETFL, ...)
but in this case I don't think it will work, because of this:
https://lkml.org/lkml/2015/12/15/480
It's a patch that was submitted just 2 weeks ago to support exactly this use case, and the only replies to it have been a couple of build failures from an automated tester.
So you can try fixing that patch and applying it (should be easy - looks like a typo, the f
should be filp
)...
or (this is the option I'd prefer) see if your needs can be met by an AF_UNIX
, SOCK_SEQPACKET
socket instead of a pipe with this new flag. They're more powerful and more portable.
(I assume you already tried passing the O_DIRECT
to open
when you open the named pipe, since that's the most obvious thing.)
Upvotes: 1