I have an implementation of a bi-directional message channel which, to reduce overhead, I implemented as a couple of circular buffers of messages. To write from one end to the other you add the pointer to the message to one circular buffer and tweak the read and write indices for it. To write in the other direction you do the same for the other buffer and so on. The code is small and simple and it avoids the overheads of using a pipe or fifo, although possibly that might have been a better solution in some ways.
I implemented a poll on this by simply checking if there was a message waiting to be read, and if not doing a timed wait on a condition variable that gets signalled when a message is added to the relevant array.
Now I have an application that needs to wait on a socket (more or less) and on the message channel at the same time. I now wish I had used a fifo or pipe, but due to overhead in getting the code changed (long story), it's not really feasible to rewrite it to use a fifo or pipe.
Is there any way to get a file descriptor associated with a conditional variable? If so it is easier to implement a poll on two file descriptors at once, one for the conditional variable and one for the socket.
Out of curiosity, and making this question more useful to others with a similar problem, is it possible to get a file descriptor associated with a semaphore so you could poll on the semaphore and a regular file descriptor at the same time?