int inet_connect_opts(QemuOpts *opts, Error **errp,

                      NonBlockingConnectHandler *callback, void *opaque)

{

    struct addrinfo *res, *e;

    int sock = -1;

    bool in_progress;

    ConnectState *connect_state = NULL;



    res = inet_parse_connect_opts(opts, errp);

    if (!res) {

        return -1;

    }



    if (callback != NULL) {

        connect_state = g_malloc0(sizeof(*connect_state));

        connect_state->addr_list = res;

        connect_state->callback = callback;

        connect_state->opaque = opaque;

    }



    for (e = res; e != NULL; e = e->ai_next) {

        if (error_is_set(errp)) {

            error_free(*errp);

            *errp = NULL;

        }

        if (connect_state != NULL) {

            connect_state->current_addr = e;

        }

        sock = inet_connect_addr(e, &in_progress, connect_state, errp);

        if (in_progress) {

            return sock;

        } else if (sock >= 0) {

            /* non blocking socket immediate success, call callback */

            if (callback != NULL) {

                callback(sock, opaque);

            }

            break;

        }

    }

    g_free(connect_state);

    freeaddrinfo(res);

    return sock;

}

int inet_connect_opts(QemuOpts *opts, Error **errp,

                      NonBlockingConnectHandler *callback, void *opaque)

{

    struct addrinfo *res, *e;

    int sock = -1;

    bool in_progress;

    ConnectState *connect_state = NULL;



    res = inet_parse_connect_opts(opts, errp);

    if (!res) {

        return -1;

    }



    if (callback != NULL) {

        connect_state = g_malloc0(sizeof(*connect_state));

        connect_state->addr_list = res;

        connect_state->callback = callback;

        connect_state->opaque = opaque;

    }



    for (e = res; e != NULL; e = e->ai_next) {

        if (error_is_set(errp)) {

            error_free(*errp);

            *errp = NULL;

        }

        if (connect_state != NULL) {

            connect_state->current_addr = e;

        }

        sock = inet_connect_addr(e, &in_progress, connect_state, errp);

        if (in_progress) {

            return sock;

        } else if (sock >= 0) {

            

            if (callback != NULL) {

                callback(sock, opaque);

            }

            break;

        }

    }

    g_free(connect_state);

    freeaddrinfo(res);

    return sock;

}

int FUNC_0(QemuOpts *VAR_0, Error **VAR_1,

                      NonBlockingConnectHandler *VAR_2, void *VAR_3)

{

    struct addrinfo *VAR_4, *VAR_5;

    int VAR_6 = -1;

    bool in_progress;

    ConnectState *connect_state = NULL;



    VAR_4 = inet_parse_connect_opts(VAR_0, VAR_1);

    if (!VAR_4) {

        return -1;

    }



    if (VAR_2 != NULL) {

        connect_state = g_malloc0(sizeof(*connect_state));

        connect_state->addr_list = VAR_4;

        connect_state->VAR_2 = VAR_2;

        connect_state->VAR_3 = VAR_3;

    }



    for (VAR_5 = VAR_4; VAR_5 != NULL; VAR_5 = VAR_5->ai_next) {

        if (error_is_set(VAR_1)) {

            error_free(*VAR_1);

            *VAR_1 = NULL;

        }

        if (connect_state != NULL) {

            connect_state->current_addr = VAR_5;

        }

        VAR_6 = inet_connect_addr(VAR_5, &in_progress, connect_state, VAR_1);

        if (in_progress) {

            return VAR_6;

        } else if (VAR_6 >= 0) {

            

            if (VAR_2 != NULL) {

                VAR_2(VAR_6, VAR_3);

            }

            break;

        }

    }

    g_free(connect_state);

    freeaddrinfo(VAR_4);

    return VAR_6;

}

int FUNC_0(QemuOpts *VAR_0, Error **VAR_1,
NonBlockingConnectHandler *VAR_2, void *VAR_3)
{ struct addrinfo *VAR_4, *VAR_5; int VAR_6 = -1; bool in_progress; ConnectState *connect_state = NULL; VAR_4 = inet_parse_connect_opts(VAR_0, VAR_1); if (!VAR_4) { return -1; } if (VAR_2 != NULL) { connect_state = g_malloc0(sizeof(*connect_state)); connect_state->addr_list = VAR_4; connect_state->VAR_2 = VAR_2; connect_state->VAR_3 = VAR_3; } for (VAR_5 = VAR_4; VAR_5 != NULL; VAR_5 = VAR_5->ai_next) { if (error_is_set(VAR_1)) { error_free(*VAR_1); *VAR_1 = NULL; } if (connect_state != NULL) { connect_state->current_addr = VAR_5; } VAR_6 = inet_connect_addr(VAR_5, &in_progress, connect_state, VAR_1); if (in_progress) { return VAR_6; } else if (VAR_6 >= 0) { if (VAR_2 != NULL) { VAR_2(VAR_6, VAR_3); } break; } } g_free(connect_state); freeaddrinfo(VAR_4); return VAR_6; }