2

Having looked at code for sometime now, I see most coders have used sockets for IPC over Pipes (Or FIFO to be specific).

Considering that there's only one client and one server, isn't it better to use FIFO over sockets? Please educate me in this matter.

1
  • FIFOs are more limited, they don't work well with multiple simultaneous clients. Commented Sep 5, 2017 at 10:42

2 Answers 2

2

FIFO has following benefits:

  • they are atomic for writing if data len is less than PIPE_BUF
  • splice is almost garanted working with SPLICE_F_MOVE (no user space data copy kernel will move data between pipes)
  • they are more easy to set up in comparison with sockets

But on the other hand it is unidirectional i.e. you most likely need 2 separate fifo:

  • for writing data from client to server
  • for writing data from server to client

Or use one fifo but reopen it as need i.e. get data on server - reopen fifo WR_ONLY on server, reopen fifo RD_ONLY on client, get data on client and do vice versa after reading data from server.

http://man7.org/linux/man-pages/man7/pipe.7.html

2
  • Socket is bi-directional, pipe/fifo is uni-directional.
  • Socket can be stream or datagram, pipe/fifo are always streams.
  • Socket and fifo do not require related processes, whereas unnamed pipes do.
  • Socket can handle more than one peer.
2
  • "Socket buffer size can be changed." And FIFO and pipes buffer size cannot be changed i suppose :) ?
    – Maquefel
    Commented Sep 5, 2017 at 11:25
  • @Maquefel Since kernel 2.6.11 pipe buffer size can be changed. Commented Sep 5, 2017 at 11:30

Not the answer you're looking for? Browse other questions tagged or ask your own question.