Search code examples
c++tcpsdlsdl-net

SDLnet check if TCPsocket has closed connection


How can I check if a SDLnet TCPsocket has closed the connection? I tried checking if the socket is NULL but it doesn't work, this is what I tried:

    for(int i = 0; i < clientConnections.size(); i++) {
        if(!clientConnections[i]) {
            clientConnections.erase(clientConnections.begin() + i);
            i--;
        }
    }

Also I haven't found anything in the documentation.


Solution

  • There's no single utility function in SDLNet to check for a disconnection status, as it's really nothing more than a thin platform-independent wrapping around the underlying platforms network functionality which almost universally doesn't have such direct functionality.

    With the SDLNet API it could be implemented using socket sets, which (as is the nature of SDLNet) wraps similar functionality of the most common OS network facilities.