From owner-freebsd-java@FreeBSD.ORG Fri Jan 18 08:15:59 2008 Return-Path: Delivered-To: freebsd-java@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3DD4D16A46B for ; Fri, 18 Jan 2008 08:15:59 +0000 (UTC) (envelope-from glewis@eyesbeyond.com) Received: from misty.eyesbeyond.com (gerbercreations.com [71.39.140.16]) by mx1.freebsd.org (Postfix) with ESMTP id B2F9913C4EB for ; Fri, 18 Jan 2008 08:15:58 +0000 (UTC) (envelope-from glewis@eyesbeyond.com) Received: from misty.eyesbeyond.com (localhost.eyesbeyond.com [127.0.0.1]) by misty.eyesbeyond.com (8.13.1/8.13.3) with ESMTP id m0I8FtJi004799; Fri, 18 Jan 2008 00:15:55 -0800 (PST) (envelope-from glewis@eyesbeyond.com) Received: (from glewis@localhost) by misty.eyesbeyond.com (8.13.1/8.13.3/Submit) id m0I8Ftq9004798; Fri, 18 Jan 2008 00:15:55 -0800 (PST) (envelope-from glewis@eyesbeyond.com) X-Authentication-Warning: misty.eyesbeyond.com: glewis set sender to glewis@eyesbeyond.com using -f Date: Fri, 18 Jan 2008 00:15:54 -0800 From: Greg Lewis To: Michael Allman Message-ID: <20080118081554.GA4645@misty.eyesbeyond.com> References: <20080117200016.P64623@yvyyl.pfbsg.arg> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20080117200016.P64623@yvyyl.pfbsg.arg> User-Agent: Mutt/1.4.2.2i Cc: landonf@macports.org, freebsd-java@freebsd.org Subject: Re: bsd implementation of Java_sun_nio_ch_FileChannelImpl_transferTo0 ignores "count" argument 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: Fri, 18 Jan 2008 08:15:59 -0000 On Thu, Jan 17, 2008 at 08:13:00PM -0800, Michael Allman wrote: > There's a bug in the bsd patch to FileChannelImpl.c, as described in the > subject of this message. FYI, I have verified this using the "current" > jdk16 freebsd patchset found here: > > http://www.eyesbeyond.com/freebsddom/java/JDK16JRLConfirm.html D'oh...there certainly is. > I haven't fully analyzed the impact of this defect. I can say that in my > case, if I call FileChannel.transferTo(0, 100, socketChannel), where 100 > is less than the length of the file in question, it transfers the entire > file to the destination. According to the docs for this method, it should > only transfer a maximum of 100 bytes. This is key to my particular usage > of this method. The problem is that it ignores the count entirely and just transfers the whole thing. > I can attempt to provide a patch, but C is not my thing, and I could not > make a reliable claim as to the correctness of my patch. Also, there's > the whole license issue. Fixing this seems simple enough, though. I > would like to help insofar as I can. Something like this maybe? (Untested) --- ../../j2se/src/solaris/native/sun/nio/ch/FileChannelImpl.c 6 Mar 2007 17:45:05 -0000 1.11 +++ ../../j2se/src/solaris/native/sun/nio/ch/FileChannelImpl.c 18 Jan 2008 08:11:36 -0000 @@ -264,11 +264,12 @@ return IOS_THROWN; } - while ((r = pread(srcFD, buf, 4096, offset)) > 0) { + while (count > 0 && (r = pread(srcFD, buf, (count < 4096) ? count : 4096, offset)) > 0) { w = write(dstFD, buf, r); if (w == -1) break; offset += w; + count -= w; } free(buf); > Also, I know this is getting pushy, but it seems like fixing this issue > would be a great time to replace the current implementation of this method > with a true bsd sendfile() call. I could give that a try, too. As noted in the comments, you can't since the BSD implementation of sendfile(2) expects to be sending the file to a socket, not just any old file descriptor. Solaris and Linux are both ok with any old fd. -- Greg Lewis Email : glewis@eyesbeyond.com Eyes Beyond Web : http://www.eyesbeyond.com Information Technology FreeBSD : glewis@FreeBSD.org