Explicitly handle a closed socket

If there is no data *yet* on the socket, but it is still open, it will time
out. If the socket is closed, recv() will return 0.