Unix domain socket blocking problem
I am writing an application split into two parts for Mac OS X - a daemon and an agent. I am using standard unix socket for communication between daemon and agents. That is, the socket is created using PF_UNIX
and SOCK_STREAM
.
When agents are created (whenever a user logs in) one of the first things they do is connect to a socket. This seems to work great for the first agent. However, when the second agent connects, the daemon has the following problem:
I am using select()
readable data validation. The call select()
succeeds and indicates that there is data to read. However, when I call recv()
it returns with -1
and is errno
set to 35
or"Resource temporarily unavailable".
Now I would expect this for a non-blocking socket, but I have a triple checkbox - I have never set the socket to be non-blocking.
As far as I can tell, this only happens when the second agent connects to the same unix socket. If I limit myself to one daemon and one agent, then everything seems to work fine. What could be causing this strange behavior?
a source to share
Sounds a bit like you are trying to read from the wrong fd client. It's hard to tell without seeing your code, but it also sounds the same as from your description.
So just in case, this is how it works. Your server ends up with three file descriptors, the socket it starts listening on first, and then one file descriptor for each connected client. When there is something in the original juice that means a new customer; it looks like you have this part of the right. Each connected client then gives you its own independent read / write fd. The select () call will return if any of them are ready to be read; you need to check each fd in the readfds variable from select with FD_ISSET () to see if it actually has data to read.
You can see a basic example of this type of code here .
a source to share