Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 18 Jan 2008 00:47:32 -0800 (PST)
From:      Michael Allman <msa@allman.ms>
To:        Greg Lewis <glewis@eyesbeyond.com>
Cc:        landonf@macports.org, freebsd-java@freebsd.org
Subject:   Re: bsd implementation of Java_sun_nio_ch_FileChannelImpl_transferTo0 ignores "count" argument
Message-ID:  <20080118002952.M20016@yvyyl.pfbsg.arg>
In-Reply-To: <20080118081554.GA4645@misty.eyesbeyond.com>
References:  <20080117200016.P64623@yvyyl.pfbsg.arg> <20080118081554.GA4645@misty.eyesbeyond.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20080118002952.M20016>