Man, things haven't been going smooth over here lately. :/
Here's my latest snag.
My server loops through all active sockets and calls ReadAvail() which returns the # of bytes the socket can receive. It returns 0 if there is no activity.
If it is greater than 0, I call Recv() on the socket and get the data. When a client socket closes Recv returns 0, and you normally would use a simple if to detect this and then handle closing the socket server side. The problem here is that ReadAvail() returns 0 also when the socket sends its close message. This means Recv() is never called and I can't detect if the socket is closed.
Getting rid of my ReadAvail() call fixes that problem, but then Recv() is going to get called on every connection and whenever it hits a connection with no data it'll return 0 and then close the connection.
As far as I understand, I need to call ReadAvail() to see if I should call Recv(), but ReadAvail() is masking the notification of a socket closing.
Any ideas?
Here's my latest snag.
My server loops through all active sockets and calls ReadAvail() which returns the # of bytes the socket can receive. It returns 0 if there is no activity.
If it is greater than 0, I call Recv() on the socket and get the data. When a client socket closes Recv returns 0, and you normally would use a simple if to detect this and then handle closing the socket server side. The problem here is that ReadAvail() returns 0 also when the socket sends its close message. This means Recv() is never called and I can't detect if the socket is closed.
Getting rid of my ReadAvail() call fixes that problem, but then Recv() is going to get called on every connection and whenever it hits a connection with no data it'll return 0 and then close the connection.
As far as I understand, I need to call ReadAvail() to see if I should call Recv(), but ReadAvail() is masking the notification of a socket closing.
Any ideas?