handling EWOULDBLOCK and restoring errno before calling handle_socket_errno