From owner-freebsd-java@FreeBSD.ORG Fri Jan 18 08:47:33 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 60A3E16A41A for ; Fri, 18 Jan 2008 08:47:33 +0000 (UTC) (envelope-from msa@allman.ms) Received: from mail102.csoft.net (mail102.csoft.net [205.205.219.4]) by mx1.freebsd.org (Postfix) with ESMTP id 0FFC113C45A for ; Fri, 18 Jan 2008 08:47:32 +0000 (UTC) (envelope-from msa@allman.ms) Received: by mail102.csoft.net (Postfix, from userid 3922) id 9F0751D0CB; Fri, 18 Jan 2008 03:47:32 -0500 (EST) Date: Fri, 18 Jan 2008 00:47:32 -0800 (PST) From: Michael Allman To: Greg Lewis In-Reply-To: <20080118081554.GA4645@misty.eyesbeyond.com> Message-ID: <20080118002952.M20016@yvyyl.pfbsg.arg> References: <20080117200016.P64623@yvyyl.pfbsg.arg> <20080118081554.GA4645@misty.eyesbeyond.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed 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:47:33 -0000 On Fri, 18 Jan 2008, Greg Lewis wrote: > On Thu, Jan 17, 2008 at 08:13:00PM -0800, Michael Allman wrote: >> 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); You're reading my mind. >> 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. I think the calling code can handle a failure gracefully. See FileChannelImpl.java, transferToDirectly(). I am going to have a go at this (sendfile support) in leopard. The freebsd call is a little different, and I don't have ready access to a freebsd machine. Michael