static int unix_connect_saddr(UnixSocketAddress *saddr,

                              NonBlockingConnectHandler *callback, void *opaque,

                              Error **errp)

{

    struct sockaddr_un un;

    ConnectState *connect_state = NULL;

    int sock, rc;



    if (saddr->path == NULL) {

        error_setg(errp, "unix connect: no path specified");

        return -1;

    }



    sock = qemu_socket(PF_UNIX, SOCK_STREAM, 0);

    if (sock < 0) {

        error_setg_errno(errp, errno, "Failed to create socket");

        return -1;

    }

    if (callback != NULL) {

        connect_state = g_malloc0(sizeof(*connect_state));

        connect_state->callback = callback;

        connect_state->opaque = opaque;

        qemu_set_nonblock(sock);

    }



    memset(&un, 0, sizeof(un));

    un.sun_family = AF_UNIX;

    snprintf(un.sun_path, sizeof(un.sun_path), "%s", saddr->path);



    /* connect to peer */

    do {

        rc = 0;

        if (connect(sock, (struct sockaddr *) &un, sizeof(un)) < 0) {

            rc = -errno;

        }

    } while (rc == -EINTR);



    if (connect_state != NULL && QEMU_SOCKET_RC_INPROGRESS(rc)) {

        connect_state->fd = sock;

        qemu_set_fd_handler(sock, NULL, wait_for_connect, connect_state);

        return sock;

    } else if (rc >= 0) {

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

        if (callback != NULL) {

            callback(sock, NULL, opaque);

        }

    }



    if (rc < 0) {

        error_setg_errno(errp, -rc, "Failed to connect socket");

        close(sock);

        sock = -1;

    }



    g_free(connect_state);

    return sock;

}

static int unix_connect_saddr(UnixSocketAddress *saddr,

                              NonBlockingConnectHandler *callback, void *opaque,

                              Error **errp)

{

    struct sockaddr_un un;

    ConnectState *connect_state = NULL;

    int sock, rc;



    if (saddr->path == NULL) {

        error_setg(errp, "unix connect: no path specified");

        return -1;

    }



    sock = qemu_socket(PF_UNIX, SOCK_STREAM, 0);

    if (sock < 0) {

        error_setg_errno(errp, errno, "Failed to create socket");

        return -1;

    }

    if (callback != NULL) {

        connect_state = g_malloc0(sizeof(*connect_state));

        connect_state->callback = callback;

        connect_state->opaque = opaque;

        qemu_set_nonblock(sock);

    }



    memset(&un, 0, sizeof(un));

    un.sun_family = AF_UNIX;

    snprintf(un.sun_path, sizeof(un.sun_path), "%s", saddr->path);



    

    do {

        rc = 0;

        if (connect(sock, (struct sockaddr *) &un, sizeof(un)) < 0) {

            rc = -errno;

        }

    } while (rc == -EINTR);



    if (connect_state != NULL && QEMU_SOCKET_RC_INPROGRESS(rc)) {

        connect_state->fd = sock;

        qemu_set_fd_handler(sock, NULL, wait_for_connect, connect_state);

        return sock;

    } else if (rc >= 0) {

        

        if (callback != NULL) {

            callback(sock, NULL, opaque);

        }

    }



    if (rc < 0) {

        error_setg_errno(errp, -rc, "Failed to connect socket");

        close(sock);

        sock = -1;

    }



    g_free(connect_state);

    return sock;

}

static int FUNC_0(UnixSocketAddress *VAR_0,

                              NonBlockingConnectHandler *VAR_1, void *VAR_2,

                              Error **VAR_3)

{

    struct sockaddr_un VAR_4;

    ConnectState *connect_state = NULL;

    int VAR_5, VAR_6;



    if (VAR_0->path == NULL) {

        error_setg(VAR_3, "unix connect: no path specified");

        return -1;

    }



    VAR_5 = qemu_socket(PF_UNIX, SOCK_STREAM, 0);

    if (VAR_5 < 0) {

        error_setg_errno(VAR_3, errno, "Failed to create socket");

        return -1;

    }

    if (VAR_1 != NULL) {

        connect_state = g_malloc0(sizeof(*connect_state));

        connect_state->VAR_1 = VAR_1;

        connect_state->VAR_2 = VAR_2;

        qemu_set_nonblock(VAR_5);

    }



    memset(&VAR_4, 0, sizeof(VAR_4));

    VAR_4.sun_family = AF_UNIX;

    snprintf(VAR_4.sun_path, sizeof(VAR_4.sun_path), "%s", VAR_0->path);



    

    do {

        VAR_6 = 0;

        if (connect(VAR_5, (struct sockaddr *) &VAR_4, sizeof(VAR_4)) < 0) {

            VAR_6 = -errno;

        }

    } while (VAR_6 == -EINTR);



    if (connect_state != NULL && QEMU_SOCKET_RC_INPROGRESS(VAR_6)) {

        connect_state->fd = VAR_5;

        qemu_set_fd_handler(VAR_5, NULL, wait_for_connect, connect_state);

        return VAR_5;

    } else if (VAR_6 >= 0) {

        

        if (VAR_1 != NULL) {

            VAR_1(VAR_5, NULL, VAR_2);

        }

    }



    if (VAR_6 < 0) {

        error_setg_errno(VAR_3, -VAR_6, "Failed to connect socket");

        close(VAR_5);

        VAR_5 = -1;

    }



    g_free(connect_state);

    return VAR_5;

}

static int FUNC_0(UnixSocketAddress *VAR_0,
NonBlockingConnectHandler *VAR_1, void *VAR_2,
Error **VAR_3)
{ struct sockaddr_un VAR_4; ConnectState *connect_state = NULL; int VAR_5, VAR_6; if (VAR_0->path == NULL) { error_setg(VAR_3, "unix connect: no path specified"); return -1; } VAR_5 = qemu_socket(PF_UNIX, SOCK_STREAM, 0); if (VAR_5 < 0) { error_setg_errno(VAR_3, errno, "Failed to create socket"); return -1; } if (VAR_1 != NULL) { connect_state = g_malloc0(sizeof(*connect_state)); connect_state->VAR_1 = VAR_1; connect_state->VAR_2 = VAR_2; qemu_set_nonblock(VAR_5); } memset(&VAR_4, 0, sizeof(VAR_4)); VAR_4.sun_family = AF_UNIX; snprintf(VAR_4.sun_path, sizeof(VAR_4.sun_path), "%s", VAR_0->path); do { VAR_6 = 0; if (connect(VAR_5, (struct sockaddr *) &VAR_4, sizeof(VAR_4)) < 0) { VAR_6 = -errno; } } while (VAR_6 == -EINTR); if (connect_state != NULL && QEMU_SOCKET_RC_INPROGRESS(VAR_6)) { connect_state->fd = VAR_5; qemu_set_fd_handler(VAR_5, NULL, wait_for_connect, connect_state); return VAR_5; } else if (VAR_6 >= 0) { if (VAR_1 != NULL) { VAR_1(VAR_5, NULL, VAR_2); } } if (VAR_6 < 0) { error_setg_errno(VAR_3, -VAR_6, "Failed to connect socket"); close(VAR_5); VAR_5 = -1; } g_free(connect_state); return VAR_5; }