From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41854) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XbRZB-000510-PM for qemu-devel@nongnu.org; Tue, 07 Oct 2014 06:00:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XbRZ5-0006Tn-J6 for qemu-devel@nongnu.org; Tue, 07 Oct 2014 06:00:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36813) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XbRZ5-0006TV-BV for qemu-devel@nongnu.org; Tue, 07 Oct 2014 06:00:19 -0400 Date: Tue, 7 Oct 2014 11:00:04 +0100 From: "Dr. David Alan Gilbert" Message-ID: <20141007100003.GD2404@work-vm> References: <1412358473-31398-1-git-send-email-dgilbert@redhat.com> <1412358473-31398-9-git-send-email-dgilbert@redhat.com> <543037D8.6000009@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <543037D8.6000009@redhat.com> Subject: Re: [Qemu-devel] [PATCH v4 08/47] socket shutdown List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: aarcange@redhat.com, yamahata@private.email.ne.jp, lilei@linux.vnet.ibm.com, quintela@redhat.com, cristian.klein@cs.umu.se, qemu-devel@nongnu.org, amit.shah@redhat.com, yanghy@cn.fujitsu.com * Paolo Bonzini (pbonzini@redhat.com) wrote: > Il 03/10/2014 19:47, Dr. David Alan Gilbert (git) ha scritto: > > +#ifndef WIN32 > > + if (rd) { > > + how = SHUT_RD; > > + } > > + > > + if (wr) { > > + how = rd ? SHUT_RDWR : SHUT_WR; > > + } > > + > > +#else > > + /* Untested */ > > + if (rd) { > > + how = SD_RECEIVE; > > + } > > + > > + if (wr) { > > + how = rd ? SD_BOTH : SD_SEND; > > + } > > + > > +#endif > > + > > > These are the same on Windows and non-Windows actually. Just #define > SHUT_* to 0/1/2 and avoid the wrapper. OK, something like this? (the qemu-file.c abstraction is still needed to cover QEMUFile's that aren't simple sockets, but I've removed the second layer in util/qemu-sockets.c). --- a/include/qemu/sockets.h +++ b/include/qemu/sockets.h @@ -44,6 +44,13 @@ int socket_set_fast_reuse(int fd); int send_all(int fd, const void *buf, int len1); int recv_all(int fd, void *buf, int len1, bool single_read); +#ifdef WIN32 +/* Windows has different names for the same constants with the same values */ +#define SHUT_RD 0 +#define SHUT_WR 1 +#define SHUT_RDWR 2 +#endif + /* callback function for nonblocking connect * valid fd on success, negative error code on failure */ --- a/qemu-file.c +++ b/qemu-file.c @@ -90,6 +90,13 @@ static int socket_close(void *opaque) return 0; } +static int socket_shutdown(void *opaque, bool rd, bool wr) +{ + QEMUFileSocket *s = opaque; + + return shutdown(s->fd, rd ? (wr ? SHUT_RDWR : SHUT_RD) : SHUT_WR); +} + static int stdio_get_fd(void *opaque) { QEMUFileStdio *s = opaque; -- Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK