I believe you should be checking for SOCKET_ERROR if you're on Windows and -1 if you're on *nix to signify errors. Zero is an indication of a closed connection, so that part you have correct.
...