I think that the socket is invalid, the return should be -1.

For the return value
0:  to tell the caller none connection exist;
the positive number: to tell the caller the connection number
the negative number: to tell the caller some error for the server