From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=45513 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pzyr5-0000H8-6q for qemu-devel@nongnu.org; Wed, 16 Mar 2011 18:06:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Pzyr0-0002AS-E1 for qemu-devel@nongnu.org; Wed, 16 Mar 2011 18:06:07 -0400 Received: from mail-vx0-f173.google.com ([209.85.220.173]:35910) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Pzyr0-0002AO-9H for qemu-devel@nongnu.org; Wed, 16 Mar 2011 18:06:06 -0400 Received: by vxb41 with SMTP id 41so2273564vxb.4 for ; Wed, 16 Mar 2011 15:06:05 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <414060358dedfe8455354ef2fc1a90e6254abe16.1300297944.git.quintela@redhat.com> References: <414060358dedfe8455354ef2fc1a90e6254abe16.1300297944.git.quintela@redhat.com> Date: Wed, 16 Mar 2011 22:06:05 +0000 Message-ID: Subject: Re: [Qemu-devel] [PATCH 1/2] Use getaddrinfo for migration From: Peter Maydell Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Juan Quintela Cc: qemu-devel@nongnu.org On 16 March 2011 21:01, Juan Quintela wrote: > +static int tcp_server_bind(int fd, struct addrinfo *rp) > +{ > + =C2=A0 =C2=A0int val =3D 1; > + =C2=A0 =C2=A0int ret; > + > + =C2=A0 =C2=A0/* allow fast reuse */ > + =C2=A0 =C2=A0setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const char *)&va= l, > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 sizeof(val)); > + > + =C2=A0 =C2=A0ret =3D bind(fd, rp->ai_addr, rp->ai_addrlen); > + > + =C2=A0 =C2=A0if (ret =3D=3D -1) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0ret =3D -socket_error(); > + =C2=A0 =C2=A0} > + =C2=A0 =C2=A0return ret; > + > +} I know this is just moved code, but does this do the right thing on Windows? Windows semantics for SO_REUSEADDR are completely different from the Unix ones: http://blogs.msdn.com/b/wndp/archive/2005/08/03/anthony-jones.aspx http://msdn.microsoft.com/en-us/library/ms740618%28VS.85%29.aspx Roughly, Unix default behaviour is like Windows SO_EXCLUSIVEADDRUSE; Unix SO_REUSEADDR is like Windows default behaviour; and Windows SO_REUSEADDR behaviour is really weird and you don't want it. (I think Cygwin has a workaround for this to give unix semantics, but Windows qemu builds as a mingw app, so we get the MS semantics, right?) > +static int tcp_start_common(const char *str, int *fd, bool server) > +{ [...] > + =C2=A0 =C2=A0s =3D getaddrinfo(name, service, &hints, &result); > + =C2=A0 =C2=A0if (s !=3D 0) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0fprintf(stderr, "qemu: getaddrinfo: %s\n", g= ai_strerror(s)); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0return -EINVAL; > + =C2=A0 =C2=A0} It seems a bit odd to have a low level utility routine printing diagnostics to stderr rather than just returning the error details to its caller somehow. Ditto the other fprintf later. -- PMM