def _try_options(options, exceptions,
                 jid, metadata, negotiation_timeout, loop, logger):
    """
    Helper function for :func:`connect_xmlstream`.
    """
    for host, port, conn in options:
        logger.debug(
            "domain %s: trying to connect to %r:%s using %r",
            jid.domain, host, port, conn
        )
        try:
            transport, xmlstream, features = yield from conn.connect(
                loop,
                metadata,
                jid.domain,
                host,
                port,
                negotiation_timeout,
                base_logger=logger,
            )
        except OSError as exc:
            logger.warning(
                "connection failed: %s", exc
            )
            exceptions.append(exc)
            continue

        logger.debug(
            "domain %s: connection succeeded using %r",
            jid.domain,
            conn,
        )

        if not metadata.sasl_providers:
            return transport, xmlstream, features

        try:
            features = yield from security_layer.negotiate_sasl(
                transport,
                xmlstream,
                metadata.sasl_providers,
                negotiation_timeout=None,
                jid=jid,
                features=features,
            )
        except errors.SASLUnavailable as exc:
            protocol.send_stream_error_and_close(
                xmlstream,
                condition=errors.StreamErrorCondition.POLICY_VIOLATION,
                text=str(exc),
            )
            exceptions.append(exc)
            continue
        except Exception as exc:
            protocol.send_stream_error_and_close(
                xmlstream,
                condition=errors.StreamErrorCondition.UNDEFINED_CONDITION,
                text=str(exc),
            )
            raise

        return transport, xmlstream, features

    return None
Helper function for :func:`connect_xmlstream`.