Saturday, 31 August 2013

Socket send and recv manage proper disconnection

Socket send and recv manage proper disconnection

I have client-client type socket program. One client (first thread)
manages the reception from some servers and the other client (another
thread in the same process) manages to send the data received to others
servers.
When the program starts, this is the thing I do :
Creation of all the connections.
Creation of the receiving thread (poll and recv).
Creation of the sending thread (send).
When I receive data on socket x (thread 1), I have a table that knows that
those data have to be sent to socket x' (thread 2). Identically, I can
receive data from socket x' and send them to socket x.
The main problem for me is to manage the disconnection in order to remove
the unused connection from the pollfd structure :
For the moment, I manage everything in the receiving thread and I use the
return value of the recv function (if 0 then disconnection) to say if a
connection has been closed or not but it doesn't seem to be effective.
Should I use the send function to manage the disconnection as well ?
Are there any advices or better solutions ?

No comments:

Post a Comment