socket: check for failure before setting errno.