From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NGCZV-00059O-DU for qemu-devel@nongnu.org; Thu, 03 Dec 2009 09:22:17 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NGCZQ-00055K-CE for qemu-devel@nongnu.org; Thu, 03 Dec 2009 09:22:16 -0500 Received: from [199.232.76.173] (port=39396 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NGCZP-000555-Ik for qemu-devel@nongnu.org; Thu, 03 Dec 2009 09:22:11 -0500 Received: from mail-gx0-f223.google.com ([209.85.217.223]:40414) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NGCZP-0002I4-Em for qemu-devel@nongnu.org; Thu, 03 Dec 2009 09:22:11 -0500 Received: by gxk23 with SMTP id 23so1358125gxk.2 for ; Thu, 03 Dec 2009 06:22:10 -0800 (PST) Message-ID: <4B17C98F.1060208@codemonkey.ws> Date: Thu, 03 Dec 2009 08:22:07 -0600 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [Qemu-devel] Socket reconnection. References: <4B0DCC45.5080308@collabora.co.uk> <4B13FE66.2080401@codemonkey.ws> <4B1503EF.6090806@collabora.co.uk> <58BD0469C48A7443A479A13D101685E30380B88A@ala-mail09.corp.ad.wrs.com> <4B156672.1010008@codemonkey.ws> <4B16442E.3090706@collabora.co.uk> <58BD0469C48A7443A479A13D101685E30380C029@ala-mail09.corp.ad.wrs.com> <4B178D2E.9090608@collabora.co.uk> In-Reply-To: <4B178D2E.9090608@collabora.co.uk> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Ian Molton Cc: "Krumme, Chris" , qemu-devel@nongnu.org Ian Molton wrote: > Fresh patch attached. Anthony, if this is ok, I can rebase this and its > prerequisite. > > From 05581c5badd693b7537fe57f85a2ff5ddcb7972d Mon Sep 17 00:00:00 2001 > From: Ian Molton > Date: Tue, 1 Dec 2009 11:18:41 +0000 > Subject: [PATCH 2/4] socket: Add a reconnect option. > > Add a reconnect option that allows sockets to reconnect (after a > specified delay) to the specified server. This makes the virtio-rng driver > useful in production environments where the EGD server may need to be restarted. > > Signed-off-by: Ian Molton > --- > qemu-char.c | 169 ++++++++++++++++++++++++++++++++++++++++++++------------- > qemu-char.h | 2 + > qemu-config.c | 3 + > vl.c | 4 ++ > 4 files changed, 139 insertions(+), 39 deletions(-) > > diff --git a/qemu-char.c b/qemu-char.c > index e202585..f20d697 100644 > --- a/qemu-char.c > +++ b/qemu-char.c > @@ -1870,8 +1870,12 @@ typedef struct { > int max_size; > int do_telnetopt; > int do_nodelay; > + int reconnect; > int is_unix; > int msgfd; > + QemuOpts *opts; > + CharDriverState *chr; > + int (*setup)(QemuOpts *opts); > } TCPCharDriver; > > static void tcp_chr_accept(void *opaque); > @@ -2011,6 +2015,61 @@ static ssize_t tcp_chr_recv(CharDriverState *chr, char *buf, size_t len) > } > #endif > > +struct reconnect_list { > CODING_STYLE is off (as I mentioned before). > + TCPCharDriver *s; > + uint64_t when; > + struct reconnect_list *next; > +}; > + > +static struct reconnect_list *rc_list; > + > +static void qemu_chr_sched_reconnect(TCPCharDriver *s) > +{ > + struct reconnect_list *new = qemu_malloc(sizeof(*new)); > + struct timeval tv; > + > + gettimeofday(&tv, NULL); > This will break Win32 (use qemu_gettimeofday). > + new->s = s; > + new->when = (s->reconnect + tv.tv_sec) * 1000000 + tv.tv_usec; > + new->next = rc_list; > + rc_list = new; > Don't open code a list, use one of the sys-queue types. > +} > + > +static int qemu_chr_connect_socket(TCPCharDriver *s); > Forward declarations usually imply some form of code motion is required. > +void qemu_chr_reconnect(void) > +{ > + struct reconnect_list *this = rc_list, *prev = NULL; > + struct timeval tv; > + uint64_t now; > + > + if (!this) > + return; > + > + gettimeofday(&tv, NULL); > + now = tv.tv_sec * 1000000 + tv.tv_usec; > + > + while (this) { > + if (this->when <= now) { > + if (qemu_chr_connect_socket(this->s)) { > + if (prev) > + prev->next = this->next; > + else > + rc_list = NULL; > + qemu_chr_event(this->s->chr, CHR_EVENT_RECONNECTED); > + free(this); > + this = prev; > + } > + else { > + this->when += this->s->reconnect * 1000000; > + } > + } > + prev = this; > + if (this) > + this = this->next; > + } > +} > + > Mixing tabs and spaces. Regards, Anthony Liguori