From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51747) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ae1xJ-0004Jc-Kf for qemu-devel@nongnu.org; Thu, 10 Mar 2016 09:52:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ae1xG-0001jb-9h for qemu-devel@nongnu.org; Thu, 10 Mar 2016 09:52:49 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40241) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ae1xG-0001jX-3k for qemu-devel@nongnu.org; Thu, 10 Mar 2016 09:52:46 -0500 Date: Thu, 10 Mar 2016 14:52:42 +0000 From: "Daniel P. Berrange" Message-ID: <20160310145242.GR25607@redhat.com> References: <1457544504-8548-1-git-send-email-berrange@redhat.com> <1457544504-8548-18-git-send-email-berrange@redhat.com> <56E065C5.4010609@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <56E065C5.4010609@redhat.com> Subject: Re: [Qemu-devel] [PATCH v1 17/21] osdep: add wrappers for socket functions Reply-To: "Daniel P. Berrange" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: Stefan Weil , qemu-devel@nongnu.org, Andrew Baumann On Wed, Mar 09, 2016 at 07:04:53PM +0100, Paolo Bonzini wrote: > > > On 09/03/2016 18:28, Daniel P. Berrange wrote: > > +static bool qemu_is_socket(int fd) > > +{ > > + int optval = 0; > > + socklen_t optlen; > > + optlen = sizeof(optval); > > + return getsockopt(fd, SOL_SOCKET, SO_TYPE, > > + (char *)&optval, &optlen) == 0; > > I think it's possible for a socket (which is actually a HANDLE) and a > file descriptor with the same numeric value to exist at the same time. > It's unlikely but it cannot be ruled out. Aieee, nice one realizing that problem ! > gnulib does this getsockopt (or at least could plausibly do it, I didn't > check :)) because it opens a libc file descriptor for every socket. > However, this only breaks ioctl and close and patch 18; neither ioctl > nor close's errors are ever checked in QEMU. > Doing the libc file descriptor in wrapping makes the select and poll > wrappers much more complex. gnulib in fact even makes them work on > files, consoles, etc. besides pipes to provide a fuller POSIX layer. In > my opinion this is beyond QEMU's scope and not really in line with > QEMU's attempts to use Win32 natively whenever applicable (e.g. in > qemu-char.c and block/raw-win32.c). > > However, I'm okay with the other wrapping that you do in this patch. > Being able to drop socket_error() is a big improvement. Yep, so I've removed the wrapping of close/ioctl, and in their place I'm wrapping closesocket/ioctlsocket to address errno/socket_error handling in those. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|