RFR: 8271308: (fc) FileChannel.transferTo() transfers no more than Integer.MAX_VALUE bytes in one call [v2]

Brian Burkhalter bpb at openjdk.java.net
Mon Aug 2 21:58:19 UTC 2021


On Sun, 1 Aug 2021 07:57:15 GMT, Alan Bateman <alanb at openjdk.org> wrote:

>> Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   8271308: Make direct transfer map to only one syscall
>
> src/java.base/share/classes/sun/nio/ch/FileChannelImpl.java line 705:
> 
>> 703:                 break;
>> 704:             position += n;
>> 705:             bytesTransferred += n;
> 
> I think this patch is problematic for the cases where the second (or subsequent) call to transferTo fails. transferToArbitraryChannel has to deal with this by returning the number of bytes transferred before the error.
> 
> I think it might be better to just continue with having transferTo map to one syscall where possible. In this case I'd prefer not introduce a loop but instead just use the OS "max transfer size" to cap the number of bytes transferred in one call to this method.

In the updated code, the direct transfer case no longer loops and just maps to one syscall. The previously introduced private `transferTo()` method is removed. `transferToArbitraryChannel()` is modified to have a `long`-valued count. `transferToTrustedChannel()` works out of the box as-is and is not changed.

-------------

PR: https://git.openjdk.java.net/jdk/pull/4940


More information about the nio-dev mailing list