I have a problem where I am looking for something very similar.
My project talks to multiple sockets, and most of them anticipate send/receive. Thus, I can see an error/disconnect on the receive task for those sockets.
I have one socket that only anticipates sending, thus I have no practical need for a receive task for that socket. What I find is this:
- First connect works exactly as expected.
- Remote endpoint disconnects (intentionally). Because there is no receive, there's no task that detects that the disconnect occurred, and I keep my send task alive.
- The remote endpoint reconnects. My code never left the 1st connection, and thus until I attempt a send, acts as though a disconnect/reconnect never occurred. The remote endpoint can disconnect/reconnect all day, and until I send, nothing happens recognizing a disconnect or error in this socket task's coding.
- I attempt sending to the endpoint. I assume because the connection IS a different connection, send(...) is to equal to RTCS_ERROR, which in turn disconnects my end of the connection, which the remote endpoint doesn't seem to recognize.
- My code waits for a proper connection to occur again. If the remote endpoint disconnects and reconnects once more, we go back to step 1, and the cycle continues.
If I had a receive task, I'd likely have no issues, as my other sockets are working fairly well. The problem might be a superficial one, but it is that this socket should never anticipate receiving on my end, and if I did receive, all I would do is throw it out and waste resources.
Is there a better way to detect a disconnect/error than to effectively have a task to do recv(...) for this socket?
If not, do I have to put the data from recv somewhere, thus allocating a "worthless" message struct, or could I simply do something like recv([socket], NULL, 0, 0)?