Fix check for validity of socket file descriptor