From d8939d9af7bcc9601cbb553ac540f6dd77e503b3 Mon Sep 17 00:00:00 2001 Message-Id: In-Reply-To: <94968b7fa9b14e71f004474d7ce77e189e6a2bf3.1349175436.git.minovotn@redhat.com> References: <94968b7fa9b14e71f004474d7ce77e189e6a2bf3.1349175436.git.minovotn@redhat.com> From: Amos Kong Date: Mon, 1 Oct 2012 14:12:41 +0200 Subject: [PATCH 28/34] net: inet_connect(), inet_connect_opts(): add in_progress argument RH-Author: Amos Kong Message-id: <1349100767-9066-9-git-send-email-akong@redhat.com> Patchwork-id: 42567 O-Subject: [RHEL-6.4 qemu-kvm PATCH v7 08/14] net: inet_connect(), inet_connect_opts(): add in_progress argument Bugzilla: 680356 RH-Acked-by: Paolo Bonzini RH-Acked-by: Markus Armbruster RH-Acked-by: Orit Wasserman From: Luiz Capitulino It's used to indicate the special case where a valid file-descriptor is returned (ie. success) but the connection can't be completed w/o blocking. This is needed because QERR_SOCKET_CONNECT_IN_PROGRESS is not treated like an error and a future commit will drop it. (Cherry-picked from commit 02a08fef079469c005d48fe2d181f0e0eb5752ae) Conflicts: nbd.c ui/vnc.c Signed-off-by: Luiz Capitulino Reviewed-by: Markus Armbruster Signed-off-by: Amos Kong --- migration-tcp.c | 2 +- qemu-char.c | 2 +- qemu-sockets.c | 14 +++++++++++--- qemu_socket.h | 4 ++-- vnc.c | 2 +- 5 files changed, 16 insertions(+), 8 deletions(-) Signed-off-by: Michal Novotny --- migration-tcp.c | 2 +- qemu-char.c | 2 +- qemu-sockets.c | 14 +++++++++++--- qemu_socket.h | 4 ++-- vnc.c | 2 +- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/migration-tcp.c b/migration-tcp.c index 3be5c53..b327223 100644 --- a/migration-tcp.c +++ b/migration-tcp.c @@ -106,7 +106,7 @@ MigrationState *tcp_start_outgoing_migration(Monitor *mon, migrate_fd_monitor_suspend(s, mon); } - s->fd = inet_connect(host_port, false, errp); + s->fd = inet_connect(host_port, false, NULL, errp); if (!error_is_set(errp)) { migrate_fd_connect(s); diff --git a/qemu-char.c b/qemu-char.c index e4ad0ea..5622eb2 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -2350,7 +2350,7 @@ static CharDriverState *qemu_chr_open_socket(QemuOpts *opts) if (is_listen) { fd = inet_listen_opts(opts, 0, NULL); } else { - fd = inet_connect_opts(opts, NULL); + fd = inet_connect_opts(opts, NULL, NULL); } } if (fd < 0) diff --git a/qemu-sockets.c b/qemu-sockets.c index 91554e2..9693be2 100644 --- a/qemu-sockets.c +++ b/qemu-sockets.c @@ -206,7 +206,7 @@ listen: return slisten; } -int inet_connect_opts(QemuOpts *opts, Error **errp) +int inet_connect_opts(QemuOpts *opts, bool *in_progress, Error **errp) { struct addrinfo ai,*res,*e; const char *addr; @@ -221,6 +221,10 @@ int inet_connect_opts(QemuOpts *opts, Error **errp) ai.ai_family = PF_UNSPEC; ai.ai_socktype = SOCK_STREAM; + if (in_progress) { + *in_progress = false; + } + addr = qemu_opt_get(opts, "host"); port = qemu_opt_get(opts, "port"); block = qemu_opt_get_bool(opts, "block", 0); @@ -274,6 +278,10 @@ int inet_connect_opts(QemuOpts *opts, Error **errp) #else if (!block && (rc == -EINPROGRESS)) { #endif + if (in_progress) { + *in_progress = true; + } + error_set(errp, QERR_SOCKET_CONNECT_IN_PROGRESS); } else if (rc < 0) { if (NULL == e->ai_next) @@ -484,7 +492,7 @@ int inet_listen(const char *str, char *ostr, int olen, return sock; } -int inet_connect(const char *str, bool block, Error **errp) +int inet_connect(const char *str, bool block, bool *in_progress, Error **errp) { QemuOpts *opts; int sock = -1; @@ -494,7 +502,7 @@ int inet_connect(const char *str, bool block, Error **errp) if (block) { qemu_opt_set(opts, "block", "on"); } - sock = inet_connect_opts(opts, errp); + sock = inet_connect_opts(opts, in_progress, errp); } else { error_set(errp, QERR_SOCKET_CREATE_FAILED); } diff --git a/qemu_socket.h b/qemu_socket.h index 927f02f..d3076cd 100644 --- a/qemu_socket.h +++ b/qemu_socket.h @@ -43,8 +43,8 @@ int send_all(CharDriverState *chr, int fd, const void *buf, int len1); int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp); int inet_listen(const char *str, char *ostr, int olen, int socktype, int port_offset, Error **errp); -int inet_connect_opts(QemuOpts *opts, Error **errp); -int inet_connect(const char *str, bool block, Error **errp); +int inet_connect_opts(QemuOpts *opts, bool *in_progress, Error **errp); +int inet_connect(const char *str, bool block, bool *in_progress, Error **errp); int inet_dgram_opts(QemuOpts *opts); const char *inet_strfamily(int family); diff --git a/vnc.c b/vnc.c index 6375c41..a38fa33 100644 --- a/vnc.c +++ b/vnc.c @@ -2844,7 +2844,7 @@ int vnc_display_open(DisplayState *ds, const char *display) if (strncmp(display, "unix:", 5) == 0) vs->lsock = unix_connect(display+5); else - vs->lsock = inet_connect(display, true, NULL); + vs->lsock = inet_connect(display, true, NULL, NULL); if (-1 == vs->lsock) { free(vs->display); vs->display = NULL; -- 1.7.11.4