aboutsummaryrefslogtreecommitdiff
path: root/chardev
diff options
context:
space:
mode:
authorPeter Xu <peterx@redhat.com>2018-03-06 13:33:17 +0800
committerPaolo Bonzini <pbonzini@redhat.com>2018-03-12 16:12:46 +0100
commit3e7d4d20d3a528b1ed10b1dc3d83119bfb0c5f24 (patch)
tree4ee240d878948dcfa5917ad6d5268f90602e99fe /chardev
parentc7278b43550f501a6d62388eb7a7e68a5b43c044 (diff)
chardev: use chardev's gcontext for async connect
Generalize the function to create the async QIO task connection. Also, fix the context pointer to use the chardev's gcontext. Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Peter Xu <peterx@redhat.com> Message-Id: <20180306053320.15401-7-peterx@redhat.com> Acked-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'chardev')
-rw-r--r--chardev/char-socket.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index 82c7d7a323..09aa345869 100644
--- a/chardev/char-socket.c
+++ b/chardev/char-socket.c
@@ -902,11 +902,22 @@ cleanup:
object_unref(OBJECT(sioc));
}
+static void tcp_chr_connect_async(Chardev *chr)
+{
+ SocketChardev *s = SOCKET_CHARDEV(chr);
+ QIOChannelSocket *sioc;
+
+ sioc = qio_channel_socket_new();
+ tcp_chr_set_client_ioc_name(chr, sioc);
+ qio_channel_socket_connect_async(sioc, s->addr,
+ qemu_chr_socket_connected,
+ chr, NULL, chr->gcontext);
+}
+
static gboolean socket_reconnect_timeout(gpointer opaque)
{
Chardev *chr = CHARDEV(opaque);
SocketChardev *s = SOCKET_CHARDEV(opaque);
- QIOChannelSocket *sioc;
g_source_unref(s->reconnect_timer);
s->reconnect_timer = NULL;
@@ -915,11 +926,7 @@ static gboolean socket_reconnect_timeout(gpointer opaque)
return false;
}
- sioc = qio_channel_socket_new();
- tcp_chr_set_client_ioc_name(chr, sioc);
- qio_channel_socket_connect_async(sioc, s->addr,
- qemu_chr_socket_connected,
- chr, NULL, NULL);
+ tcp_chr_connect_async(chr);
return false;
}
@@ -999,11 +1006,7 @@ static void qmp_chardev_open_socket(Chardev *chr,
}
if (s->reconnect_time) {
- sioc = qio_channel_socket_new();
- tcp_chr_set_client_ioc_name(chr, sioc);
- qio_channel_socket_connect_async(sioc, s->addr,
- qemu_chr_socket_connected,
- chr, NULL, NULL);
+ tcp_chr_connect_async(chr);
} else {
if (s->is_listen) {
char *name;