From owner-freebsd-java@FreeBSD.ORG Tue Jun 21 18:33:13 2005 Return-Path: X-Original-To: freebsd-java@freebsd.org Delivered-To: freebsd-java@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D80F716A41C for ; Tue, 21 Jun 2005 18:33:13 +0000 (GMT) (envelope-from landonf@threerings.net) Received: from mail.earth.threerings.net (mail.earth.threerings.net [64.81.51.57]) by mx1.FreeBSD.org (Postfix) with ESMTP id A589743D58 for ; Tue, 21 Jun 2005 18:33:13 +0000 (GMT) (envelope-from landonf@threerings.net) Received: from [192.168.50.11] (timor.sea.earth.threerings.net [192.168.50.11]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by mail.earth.threerings.net (Postfix) with ESMTP id 931686121 for ; Tue, 21 Jun 2005 11:34:03 -0700 (PDT) Mime-Version: 1.0 (Apple Message framework v622) To: freebsd-java@freebsd.org Message-Id: Content-Type: multipart/signed; protocol="application/pgp-signature"; micalg=pgp-sha1; boundary="Apple-Mail-4--662330866" From: Landon Fuller Date: Tue, 21 Jun 2005 11:33:09 -0700 Content-Transfer-Encoding: 7bit X-Pgp-Agent: GPGMail 1.0.2 X-Mailer: Apple Mail (2.622) Subject: [PATCH] jdk1.4.2, getsockname(), and ECONNRESET 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: Tue, 21 Jun 2005 18:33:14 -0000 --Apple-Mail-4--662330866 Content-Type: multipart/mixed; boundary=Apple-Mail-3--662330884 --Apple-Mail-3--662330884 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=ISO-8859-1; format=flowed In j2se/src/solaris/native/sun/nio/ch/Net.c, getsockname() is called to=20= determine the local address and port of a socket. Under both Linux and Solaris, getsockname() will only fail if invalid=20 arguments are provided. If getsockname() returns an error, Java throws=20= a java.lang.Error. On FreeBSD, getsockname() will also return an error with errno set to=20 ECONNRESET if the connection has been reset by the peer. Consequently,=20= Java throws a java.lang.Error. The only way to handle this without an API change is to check for=20 ECONNRESET; In the attached patch, if errno is set to=A0ECONNRESET we=20 fill in the sockaddr structure with a port of 0, an IP of INADDR_ANY,=20 and clear out the error. Also, any comments on the thread-safe resolver patch? Thanks, -landonf --Apple-Mail-3--662330884 Content-Transfer-Encoding: 7bit Content-Type: application/octet-stream; x-unix-mode=0644; name="getsockname-1.diff" Content-Disposition: attachment; filename=getsockname-1.diff Only in getsockname: cscope.out diff -ru bsdjdk/j2se/src/solaris/native/sun/nio/ch/Net.c getsockname/j2se/src/solaris/native/sun/nio/ch/Net.c --- bsdjdk/j2se/src/solaris/native/sun/nio/ch/Net.c Fri May 13 18:04:33 2005 +++ getsockname/j2se/src/solaris/native/sun/nio/ch/Net.c Sun May 29 01:32:32 2005 @@ -118,8 +118,30 @@ SOCKADDR sa; int sa_len = SOCKADDR_LEN; if (getsockname(fdval(env, fdo), (struct sockaddr *)&sa, &sa_len) < 0) { +#ifdef _BSD_SOURCE + /* + * XXXBSD: + * ECONNRESET is specific to the BSDs. We can not return an error, + * as the calling Java code with raise a java.lang.Error given the expectation + * that getsockname() will never fail. According to the Single UNIX Specification, + * it shouldn't fail. As such, we just fill in generic values. + */ + if (errno == ECONNRESET) { + struct sockaddr_in *sin; + sin = (struct sockaddr_in *) &sa; + bzero(sin, sizeof(*sin)); + sin->sin_len = sizeof(struct sockaddr_in); + sin->sin_family = AF_INET; + sin->sin_port = htonl(0); + sin->sin_addr.s_addr = INADDR_ANY; + } else { + handleSocketError(env, errno); + return -1; + } +#else /* _BSD_SOURCE */ handleSocketError(env, errno); return -1; +#endif /* _BSD_SOURCE */ } return NET_GetPortFromSockaddr((struct sockaddr *)&sa); } @@ -131,8 +153,30 @@ int sa_len = SOCKADDR_LEN; int port; if (getsockname(fdval(env, fdo), (struct sockaddr *)&sa, &sa_len) < 0) { +#ifdef _BSD_SOURCE + /* + * XXXBSD: + * ECONNRESET is specific to the BSDs. We can not return an error, + * as the calling Java code with raise a java.lang.Error with the expectation + * that getsockname() will never fail. According to the Single UNIX Specification, + * it shouldn't fail. As such, we just fill in generic values. + */ + if (errno == ECONNRESET) { + struct sockaddr_in *sin; + sin = (struct sockaddr_in *) &sa; + bzero(sin, sizeof(*sin)); + sin->sin_len = sizeof(struct sockaddr_in); + sin->sin_family = AF_INET; + sin->sin_port = htonl(0); + sin->sin_addr.s_addr = INADDR_ANY; + } else { + handleSocketError(env, errno); + return NULL; + } +#else /* _BSD_SOURCE */ handleSocketError(env, errno); return NULL; +#endif /* _BSD_SOURCE */ } return NET_SockaddrToInetAddress(env, (struct sockaddr *)&sa, &port); } --Apple-Mail-3--662330884-- --Apple-Mail-4--662330866 content-type: application/pgp-signature; x-mac-type=70674453; name=PGP.sig content-description: This is a digitally signed message part content-disposition: inline; filename=PGP.sig content-transfer-encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.6 (Darwin) iD8DBQFCuF1nlplZCE/15mMRAlrDAJ9rqNEWNaX6iAmWW4AQEZUVz4lX1gCfVig7 +Kz1+xJm32a/fQVBsibMm2Y= =tLoZ -----END PGP SIGNATURE----- --Apple-Mail-4--662330866--