[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 73/74] char-socket: update all ioc handlers when chan
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 73/74] char-socket: update all ioc handlers when changing context |
Date: |
Tue, 21 Aug 2018 19:02:45 +0200 |
From: Marc-André Lureau <address@hidden>
So far, tcp_chr_update_read_handler() only updated the read
handler. Let's also update the hup handler.
Factorize the code while at it. (note that s->ioc != NULL when
s->connected)
Signed-off-by: Marc-André Lureau <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
Signed-off-by: Marc-André Lureau <address@hidden>
---
chardev/char-socket.c | 59 ++++++++++++++++++++++++++++-----------------------
1 file changed, 33 insertions(+), 26 deletions(-)
diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index 14f6567..7cd0ae2 100644
--- a/chardev/char-socket.c
+++ b/chardev/char-socket.c
@@ -353,6 +353,15 @@ static GSource *tcp_chr_add_watch(Chardev *chr,
GIOCondition cond)
return qio_channel_create_watch(s->ioc, cond);
}
+static void remove_hup_source(SocketChardev *s)
+{
+ if (s->hup_source != NULL) {
+ g_source_destroy(s->hup_source);
+ g_source_unref(s->hup_source);
+ s->hup_source = NULL;
+ }
+}
+
static void tcp_chr_free_connection(Chardev *chr)
{
SocketChardev *s = SOCKET_CHARDEV(chr);
@@ -367,11 +376,7 @@ static void tcp_chr_free_connection(Chardev *chr)
s->read_msgfds_num = 0;
}
- if (s->hup_source != NULL) {
- g_source_destroy(s->hup_source);
- g_source_unref(s->hup_source);
- s->hup_source = NULL;
- }
+ remove_hup_source(s);
tcp_set_msgfds(chr, NULL, 0);
remove_fd_in_watch(chr);
@@ -540,6 +545,27 @@ static char *sockaddr_to_str(struct sockaddr_storage *ss,
socklen_t ss_len,
}
}
+static void update_ioc_handlers(SocketChardev *s)
+{
+ Chardev *chr = CHARDEV(s);
+
+ if (!s->connected) {
+ return;
+ }
+
+ remove_fd_in_watch(chr);
+ chr->gsource = io_add_watch_poll(chr, s->ioc,
+ tcp_chr_read_poll,
+ tcp_chr_read, chr,
+ chr->gcontext);
+
+ remove_hup_source(s);
+ s->hup_source = qio_channel_create_watch(s->ioc, G_IO_HUP);
+ g_source_set_callback(s->hup_source, (GSourceFunc)tcp_chr_hup,
+ chr, NULL);
+ g_source_attach(s->hup_source, chr->gcontext);
+}
+
static void tcp_chr_connect(void *opaque)
{
Chardev *chr = CHARDEV(opaque);
@@ -552,16 +578,7 @@ static void tcp_chr_connect(void *opaque)
s->is_listen, s->is_telnet);
s->connected = 1;
- chr->gsource = io_add_watch_poll(chr, s->ioc,
- tcp_chr_read_poll,
- tcp_chr_read,
- chr, chr->gcontext);
-
- s->hup_source = qio_channel_create_watch(s->ioc, G_IO_HUP);
- g_source_set_callback(s->hup_source, (GSourceFunc)tcp_chr_hup,
- chr, NULL);
- g_source_attach(s->hup_source, chr->gcontext);
-
+ update_ioc_handlers(s);
qemu_chr_be_event(chr, CHR_EVENT_OPENED);
}
@@ -592,17 +609,7 @@ static void tcp_chr_update_read_handler(Chardev *chr)
tcp_chr_telnet_init(CHARDEV(s));
}
- if (!s->connected) {
- return;
- }
-
- remove_fd_in_watch(chr);
- if (s->ioc) {
- chr->gsource = io_add_watch_poll(chr, s->ioc,
- tcp_chr_read_poll,
- tcp_chr_read, chr,
- chr->gcontext);
- }
+ update_ioc_handlers(s);
}
static gboolean tcp_chr_telnet_init_io(QIOChannel *ioc,
--
1.8.3.1
- [Qemu-devel] [PULL 53/74] cpus: allow cpu_get_ticks out of BQL, (continued)
- [Qemu-devel] [PULL 53/74] cpus: allow cpu_get_ticks out of BQL, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 50/74] cpus: protect all icount computation with seqlock, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 26/74] hmp-commands-info: add sync-profile, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 56/74] vhost-scsi: expose 't10_pi' property for VIRTIO_SCSI_F_T10_PI, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 54/74] vhost-user-scsi: move host_features into VHostSCSICommon, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 29/74] fw_cfg: import & use linux/qemu_fw_cfg.h, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 35/74] target-i386: fix segment limit check in ljmp, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 69/74] target/i386: update MPX flags when CPL changes, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 61/74] pc-dimm: assign and verify the "addr" property during pre_plug, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 70/74] KVM: cleanup unnecessary #ifdef KVM_CAP_..., Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 73/74] char-socket: update all ioc handlers when changing context,
Paolo Bonzini <=
- [Qemu-devel] [PULL 60/74] pc: drop memory region alignment check for 0, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 71/74] Revert "chardev: tcp: postpone TLS work until machine done", Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 59/74] util/oslib-win32: indicate alignment for qemu_anon_ram_alloc(), Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 58/74] pc-dimm: assign and verify the "slot" property during pre_plug, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 72/74] Revert "chardev: tcp: postpone async connection setup", Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 74/74] test-char: add socket reconnect test, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 57/74] ipmi: Use proper struct reference for BT vmstate, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 67/74] i2c: pm_smbus: Don't delay host status register busy bit when interrupts are enabled, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 68/74] i2c: pm_smbus: Add the ability to force block transfer enable, Paolo Bonzini, 2018/08/21
- [Qemu-devel] [PULL 64/74] i2c: pm_smbus: Make the I2C block read command read-only, Paolo Bonzini, 2018/08/21