I have a thread A that calls poll()
in a loop. This thread is responsible for IO on incoming and outgoing connections. However, when thread B has opened an outgoing connection, it has to give it to A somehow. Do you think it'd be a good idea to have a pipe between threads A (reading side) and B (writing side) that B writes to after opening the socket?
Asked
Active
Viewed 87 times
2
2 Answers
4
That sounds reasonable. poll
should be happy watching a pipe alongside your socket(s).

James M
- 18,506
- 3
- 48
- 56
-
Ok, thanks - if there's no better way, I guess I'll have to do it this way. – thejh Apr 23 '12 at 19:07
1
Rather than an actual pipe, you could look at using a socket pair. You could create a unix-domain socket pair and send messages to the blocked thread using send()
or sendmsg()
. This approach might be more convenient for you. Unix-domain sockets also support passing file descriptors between processes, although that's overkill for your application.
The other approach is to interrupt the call to poll()
with a signal. See this question.