Question

I'm trying to do some inter program data exchange and I decided to play a bit with named pipes. I have a very basic reader and a very basic writer, taken from the example answer here.

  • My first problem is that I cannot use two time write(...) unless I let the program sleep. Is there a way around that? Having it call sleep(1) after every entry will explode the process time.

  • I would also like to have more than one process write into the same fifo. Is that possible? My attempts returned quite a few issues...

  • Finally is there a way to have a fifo carry an object instead of a string?

Was it helpful?

Solution

1) Writing - check the result of the write. If the other end of the pipe is not open, the number of bytes written will be 0.

2) Not possible but you can have one server fifo for receiving requests. It then generates a pipe name for each client process to connect to and sends it to the client. The client reads the server pipe, closes the server pipe and opens a pipe with the new name given by the server. The server will have to poll all the pipes in separate threads.

3) It is just a write - it can take anything. Just dump the whole object in binary. Note that there should not be any pointers in the object as the pointers will not be pointing to the same address space.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top