From owner-freebsd-java@FreeBSD.ORG Mon Dec 11 15:48:19 2006 Return-Path: X-Original-To: freebsd-java@freebsd.org Delivered-To: freebsd-java@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 8E99F16A47B for ; Mon, 11 Dec 2006 15:48:19 +0000 (UTC) (envelope-from achill@matrix.gatewaynet.com) Received: from matrix.gatewaynet.com (host2.dynacom.ondsl.gr [62.103.35.210]) by mx1.FreeBSD.org (Postfix) with ESMTP id 043BC43DFC for ; Mon, 11 Dec 2006 15:44:28 +0000 (GMT) (envelope-from achill@matrix.gatewaynet.com) Received: from host3.dynacom.ondsl.gr ([62.103.35.211] helo=ip216.internal.net) by matrix.gatewaynet.com with esmtp (Exim 4.62) (envelope-from ) id 1GtnLT-0006B7-Ke for freebsd-java@freebsd.org; Mon, 11 Dec 2006 17:45:35 +0200 From: Achilleas Mantzios Organization: Dynacom Tankers Mgmt To: freebsd-java@freebsd.org Date: Mon, 11 Dec 2006 17:45:34 +0200 User-Agent: KMail/1.9.3 References: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-7" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200612111745.35227.achill@matrix.gatewaynet.com> Subject: Re: close() of active socket does not work on FreeBSD 6 X-BeenThere: freebsd-java@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting Java to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Dec 2006 15:48:19 -0000 =D3=F4=E9=F2 =C4=E5=F5=F4=DD=F1=E1 11 =C4=E5=EA=DD=EC=E2=F1=E9=EF=F2 2006 1= 7:07, =EF/=E7 Arne H. Juul =DD=E3=F1=E1=F8=E5: > On Mon, 11 Dec 2006, Arne H. Juul wrote: > > I've had problems with some tests hanging on FreeBSD 6/amd64. This > > happens both with diablo-1.5.0_07-b01 and the java/jdk15 compiled from > > ports. > > > > After much digging we've determined that the root cause is that > > the guarantee in the socket.close() API, see the documentation at > > http://java.sun.com/j2se/1.5.0/docs/api/java/net/Socket.html#close() > > isn't fulfulled - the thread blocked in I/O on the socket doesn't wake > > up. > > Looking at the Java VM source code it does some tricks with dup2() to > reopen the close()'d filedescriptor, making it point to a filedescriptor > that's pre-connected to a closed socket. > > A small C program that duplicates this (using pipes to make it a bit > simpler) follows. I'm not sure if any standards demand that this > works like it used to on FreeBSD 4 / libc_r, but since Java uses it it > would be really nice if this could be made to work in FreeBSD 6 (libthr > and libpthread). Or maybe somebody has another suggestions on how to > implement the Java close() semantics? > I forgot to mention that all my tests were on 386. (So most probably it's n= ot=20 amd64 related). And indeed in FreeBSD 6, by mapping libpthread.so.2 to libc_r.so.6 =46ooConn seems to work correctly. Only with libthr.so.2 / libpthread.so.2 the problem exists. > Anyway, the following C program works as intended on FreeBSD 4, > hangs on FreeBSD 6 (amd64), compiled with: > cc -Wall -pthread read_dup2.c -o read_dup2 > > > #include > #include > #include > #include > #include > > int p[2]; > > void *run(void *arg) { > ssize_t res; > char tmp[128]; > fprintf(stderr, "reading...\n"); > res =3D read(p[0], tmp, sizeof(tmp)); > fprintf(stderr, "read result: %d\n", (int)res); > if (res < 0) { > perror("read"); > } > return arg; > } > > int main(int argc, char **argv) { > pthread_t t; > int d =3D open("/dev/null", O_RDONLY); > if (pipe(p) !=3D 0) { > perror("pipe"); > return 1; > } > if (pthread_create(&t, NULL, run, NULL) !=3D 0) { > perror("thread create"); > return 1; > } > sleep(1); > d =3D open("/dev/null", O_RDONLY); > if (d < 0) { > perror("open dev null"); > exit(1); > } > if (dup2(d, p[0]) < 0) { > perror("dup2"); > exit(1); > } > if (pthread_join(t, NULL) !=3D 0) { > perror("thread join"); > exit(1); > } > return 0; > } > _______________________________________________ > freebsd-java@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-java > To unsubscribe, send any mail to "freebsd-java-unsubscribe@freebsd.org" =2D-=20 Achilleas Mantzios