static void wait_for_connect(void *opaque) { ConnectState *s = opaque; int val = 0, rc = 0; socklen_t valsize = sizeof(val); bool in_progress; Error *err = NULL; qemu_set_fd_handler(s->fd, NULL, NULL, NULL); do { rc = qemu_getsockopt(s->fd, SOL_SOCKET, SO_ERROR, &val, &valsize); } while (rc == -1 && errno == EINTR); /* update rc to contain error */ if (!rc && val) { rc = -1; errno = val; } /* connect error */ if (rc < 0) { error_setg_errno(&err, errno, "Error connecting to socket"); closesocket(s->fd); s->fd = rc; } /* try to connect to the next address on the list */ if (s->current_addr) { while (s->current_addr->ai_next != NULL && s->fd < 0) { s->current_addr = s->current_addr->ai_next; s->fd = inet_connect_addr(s->current_addr, &in_progress, s, NULL); if (s->fd < 0) { error_free(err); err = NULL; error_setg_errno(&err, errno, "Unable to start socket connect"); } /* connect in progress */ if (in_progress) { goto out; } } freeaddrinfo(s->addr_list); } if (s->callback) { s->callback(s->fd, err, s->opaque); } g_free(s); out: error_free(err); }
static void wait_for_connect(void *opaque) { ConnectState *s = opaque; int val = 0, rc = 0; socklen_t valsize = sizeof(val); bool in_progress; qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL); do { rc = qemu_getsockopt(s->fd, SOL_SOCKET, SO_ERROR, &val, &valsize); } while (rc == -1 && socket_error() == EINTR); /* update rc to contain error */ if (!rc && val) { rc = -1; } /* connect error */ if (rc < 0) { closesocket(s->fd); s->fd = rc; } /* try to connect to the next address on the list */ if (s->current_addr) { while (s->current_addr->ai_next != NULL && s->fd < 0) { s->current_addr = s->current_addr->ai_next; s->fd = inet_connect_addr(s->current_addr, &in_progress, s, NULL); /* connect in progress */ if (in_progress) { return; } } freeaddrinfo(s->addr_list); } if (s->callback) { s->callback(s->fd, s->opaque); } g_free(s); }