From owner-freebsd-hackers@FreeBSD.ORG Thu Jan 26 23:56:44 2006 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id F3CE416A420 for ; Thu, 26 Jan 2006 23:56:43 +0000 (GMT) (envelope-from deischen@freebsd.org) Received: from mail.ntplx.net (mail.ntplx.net [204.213.176.10]) by mx1.FreeBSD.org (Postfix) with ESMTP id 922F343D6D for ; Thu, 26 Jan 2006 23:56:43 +0000 (GMT) (envelope-from deischen@freebsd.org) Received: from sea.ntplx.net (sea.ntplx.net [204.213.176.11]) by mail.ntplx.net (8.13.5/8.13.5/NETPLEX) with ESMTP id k0QNugpn022969; Thu, 26 Jan 2006 18:56:42 -0500 (EST) Date: Thu, 26 Jan 2006 18:56:42 -0500 (EST) From: Daniel Eischen X-X-Sender: eischen@sea.ntplx.net To: Kurt Miller In-Reply-To: <200601261803.30503.kurt@intricatesoftware.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by AMaViS and Clam AntiVirus (mail.ntplx.net) Cc: freebsd-hackers@freebsd.org Subject: Re: read hang on datagram socket X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Daniel Eischen List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Jan 2006 23:56:44 -0000 On Thu, 26 Jan 2006, Kurt Miller wrote: > I'm working on 1.5 jdk certification on 5.4 and 6.0. One of the jck > tests hangs on 5.4 but works ok on 6.0. I've reduced the problem > down to the following C program that hangs on 5.4 but works fine > (finishes) on 6.0 and 4.11. > > I could use some assistance with finding a work-around to the > problem or an explanation as to why the program hangs on 5.4. It exit'd in the last connect() in Solaris 9. I modified it to work -- see below. > > Thank you, > -Kurt > > #include > #include > #include > #include > #include > #include > #include [ ... ] > int > main() { > int sock1, sock2; > int optval = 1; > struct sockaddr addr; > struct sockaddr sock1Addr, sock2Addr; > int sock1AddrLen, sock2AddrLen; > short port1, port2; > char sendBuf, readBuf; > int hostAddress; > > if ((hostAddress = getHostAddress()) == 0) > exit(1); > > buildAddr4((struct sockaddr_in *)&addr, 0, 0); > > if ((sock1 = socket(AF_INET, SOCK_DGRAM, 0)) < 0) > exit(1); > if (setsockopt(sock1, SOL_SOCKET, SO_BROADCAST, (char*) &optval, sizeof(optval)) != 0) > exit(1); > if (bind(sock1, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) != 0) > exit(1); + sock1AddrLen = sizeof(sock1Addr); > if (getsockname(sock1, &sock1Addr, &sock1AddrLen) != 0) > exit(1); > setAddress((struct sockaddr_in *)&sock1Addr, hostAddress); > > if ((sock2 = socket(AF_INET, SOCK_DGRAM, 0)) < 0) > exit(1); > if (bind(sock2, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) != 0) > exit(1); + sock2AddrLen = sizeof(sock2Addr); > if (getsockname(sock2, &sock2Addr, &sock2AddrLen) != 0) > exit(1); > setAddress((struct sockaddr_in *)&sock2Addr, hostAddress); > if (connect(sock2, &sock1Addr, sock1AddrLen) != 0) > exit(1); > > sendBuf = 22; > if (sendto(sock1, &sendBuf, 1, 0, &sock2Addr, sock2AddrLen) != 1) > exit(1); > > if (read(sock2, &readBuf, 1) != 1) > exit(1); > > printf("no hang\n"); > } -- DE