Received: from [140.186.70.92] (port=53098 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pzz6W-0002bO-Nv for qemu-devel@nongnu.org; Wed, 16 Mar 2011 18:22:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Pzz6U-0004wj-JU for qemu-devel@nongnu.org; Wed, 16 Mar 2011 18:22:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35156) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Pzz6U-0004wV-9q for qemu-devel@nongnu.org; Wed, 16 Mar 2011 18:22:06 -0400 From: Juan Quintela In-Reply-To: (Peter Maydell's message of "Wed, 16 Mar 2011 22:06:05 +0000") References: <414060358dedfe8455354ef2fc1a90e6254abe16.1300297944.git.quintela@redhat.com> Date: Wed, 16 Mar 2011 23:20:21 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] Re: [PATCH 1/2] Use getaddrinfo for migration Reply-To: quintela@redhat.com List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: qemu-devel@nongnu.org Peter Maydell wrote: > 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 *)&v= al, >> + =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?) No clue really, but again, this is the code that existed there, we can fix on top of it. >> +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", = gai_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. Previous code did it. I am not clear what to do here. The way to get an error for getaddrinfo is to return one string with gai_strerror(). Suggestions appreciated. Later, Jaun.