Print the value stored in sockfd (that is, print it in the error message)
Is it a garbage value, or good?

Check elsewhere to see if the socket has been closed.

Have you tried running the code...