RFR: 8303934: (fc) Use splice in FileChannel::transferFrom when the source is a pipe (Linux)

Brian Burkhalter bpb at openjdk.org
Fri Mar 10 01:26:10 UTC 2023


On Fri, 10 Mar 2023 00:35:38 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

> On Linux, perform `transferFrom()` via the `splice(2)` system call when the source `ReadableByteChannel` is a `Pipe.SourceChannel` (`sun.nio.ch.SourceChannelImpl`).

The Linux system call `copy_file_range(2)` does not work with pipes. In the case of `FileChannel::transferTo` writing to a pipe, the native code path falls back to `sendfile(2)` which does handle a destination pipe so `splice(2)` is not needed there. The `offset` parameter of `sendfile()` however refers to the input so that call is not usable in `FileChannel::transferFrom` which requires the position in the output, i.e., the channel’s file.

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

PR: https://git.openjdk.org/jdk/pull/12965


More information about the nio-dev mailing list