I need to communicate with a process (Kamailio SIP server) using named FIFOs in /tmp. The way it works is that I need to set up a response FIFO of my own and then write the request to Kamailio which will write the response back to my FIFO.
So, how I understand it should go..
- mkfifo a new temporary FIFO in /tmp for receiving the response. I use os.getpid() to make a unique name such as /tmp/response_1234_fifo
try to open(fifo, "r") the FIFO and read() it.. but this will block in open() since no-one is yet opening the FIFO for write
write the request to the well known static FIFO (for example /tmp/request_fifo). This request includes the name of my response FIFO
Kamailio will process the request, open my response FIFO for writing and write() the response to it.
At this point my open() should probably unblock and the read() receive the data. But it doesn't seem to do so. It works sometimes but sometimes doesn't.
After writing the response, Kamailio will close my response FIFO which would result in an EOF for the next read()
Now I can rm the temporary response FIFO
My brain has shut down after trying to do this in several different ways including threading, popen:ing a "cat < response_fifo" and even trying to use nonblocking open and polling..
If I look at how the Kamailio shell script for running commands does it, it's so simple it's making me cry :)
cat < $response_fifo &
printf "$CMD" > $request_fifo
wait
rm $response_fifo
Anyone have an elegant solution in Python?