/* Called with chr_write_lock held. */ static void pty_chr_state(Chardev *chr, int connected) { PtyChardev *s = PTY_CHARDEV(chr); if (!connected) { if (s->open_source) { g_source_destroy(s->open_source); g_source_unref(s->open_source); s->open_source = NULL; } remove_fd_in_watch(chr); s->connected = 0; /* (re-)connect poll interval for idle guests: once per second. * We check more frequently in case the guests sends data to * the virtual device linked to our pty. */ pty_chr_rearm_timer(chr, 1000); } else { pty_chr_timer_cancel(s); if (!s->connected) { g_assert(s->open_source == NULL); s->open_source = g_idle_source_new(); s->connected = 1; g_source_set_callback(s->open_source, qemu_chr_be_generic_open_func, chr, NULL); g_source_attach(s->open_source, chr->gcontext); } if (!chr->gsource) { chr->gsource = io_add_watch_poll(chr, s->ioc, pty_chr_read_poll, pty_chr_read, chr, chr->gcontext); } } }
static void pty_chr_state(Chardev *chr, int connected) { PtyChardev *s = PTY_CHARDEV(chr); if (!connected) { remove_fd_in_watch(chr); s->connected = 0; /* (re-)connect poll interval for idle guests: once per second. * We check more frequently in case the guests sends data to * the virtual device linked to our pty. */ pty_chr_rearm_timer(chr, 1000); } else { pty_chr_timer_cancel(s); if (!s->connected) { s->connected = 1; qemu_chr_be_event(chr, CHR_EVENT_OPENED); } if (!chr->gsource) { chr->gsource = io_add_watch_poll(chr, s->ioc, pty_chr_read_poll, pty_chr_read, chr, chr->gcontext); } } }
static void char_pty_finalize(Object *obj) { Chardev *chr = CHARDEV(obj); PtyChardev *s = PTY_CHARDEV(obj); pty_chr_state(chr, 0); object_unref(OBJECT(s->ioc)); pty_chr_timer_cancel(s); qemu_chr_be_event(chr, CHR_EVENT_CLOSED); }
/* Called with chr_write_lock held. */ static void pty_chr_rearm_timer(Chardev *chr, int ms) { PtyChardev *s = PTY_CHARDEV(chr); char *name; pty_chr_timer_cancel(s); name = g_strdup_printf("pty-timer-%s", chr->label); s->timer_src = qemu_chr_timeout_add_ms(chr, ms, pty_chr_timer, chr); g_source_set_name(s->timer_src, name); g_free(name); }
static gboolean pty_chr_timer(gpointer opaque) { struct Chardev *chr = CHARDEV(opaque); PtyChardev *s = PTY_CHARDEV(opaque); pty_chr_timer_cancel(s); if (!s->connected) { /* Next poll ... */ qemu_chr_be_update_read_handlers(chr, chr->gcontext); } return FALSE; }