3

I'm working on a library to create IPC based on UNIX socket on Linux. The goal is to hide the IPC logic in a library and I use a thread which handles the socket for external communication.

Since I want to mux/demux data coming from outside to multiple reader/writer internal threads, I'm using pipes to communicate between this management thread and the others.

Now, I would like to manage kind of QoS as well and thus, would like to block some user threads in write direction when I know there is no space left of the other side (the other IPC process reading data from me too slowly for example).

To notify a internal user thread there is no place left for sending data (in its "virtual channel"), I would like to mark its sending pipe as non writable then this thread can use for example select on this sending pipe file descriptor.

My question is then: is there a way to mark a pipe write file descriptor as non writable even if there is still free place in its internal buffer and mark it as writable again when my management thread decides it ? Keeping in mind the write status event should be able to be managed by functions like select, poll, etc.

P.S.: I know there is a lot of libraries which could help me doing the same job more easily like ZeroMQ or nanomsg but they are far too heavy for what I would like to achieve.

hilt0n
  • 376
  • 1
  • 10
  • 2
    I don't think there is. – Petr Skocik May 11 '19 at 16:04
  • 1
    I'm assuming your goal is to avoid the normal flow control of filling up the pipe buffer. How about making it pull instead of push. Your consumer can send a "go ahead" signal, and your producer can select/poll for reads. – that other guy May 11 '19 at 17:02
  • 1
    thanks guys! Following inspiration from nng (next gen nanomsg), I add a pipe for "ready to write" status. When the management thread accept again data to write, it writes a byte to this notif pipe and the user thread can then do a select/poll on the read side of the notif pipe. The management thread write a byte to this pipe only if this pipe if empty (need some race protection here). Thks! – hilt0n May 11 '19 at 17:12

0 Answers0