Home / Class/ IoUringFileRegion Class — netty Architecture

IoUringFileRegion Class — netty Architecture

Architecture documentation for the IoUringFileRegion class in IoUringFileRegion.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  c96b81c5_ea33_13b2_52db_63502e2f3044["IoUringFileRegion"]
  66ed4a0c_f239_e361_df2d_3b22aad467ea["IoUringFileRegion.java"]
  c96b81c5_ea33_13b2_52db_63502e2f3044 -->|defined in| 66ed4a0c_f239_e361_df2d_3b22aad467ea
  baeb6659_c48f_fedc_e702_004afcf941b4["IoUringFileRegion()"]
  c96b81c5_ea33_13b2_52db_63502e2f3044 -->|method| baeb6659_c48f_fedc_e702_004afcf941b4
  8b454f2e_72c8_ddb4_4f8e_c8a469a745c4["open()"]
  c96b81c5_ea33_13b2_52db_63502e2f3044 -->|method| 8b454f2e_72c8_ddb4_4f8e_c8a469a745c4
  f3e4a249_43c4_6665_be82_6cb751398764["IoUringIoOps()"]
  c96b81c5_ea33_13b2_52db_63502e2f3044 -->|method| f3e4a249_43c4_6665_be82_6cb751398764
  08686ee3_0989_cbf4_6868_2a6da6c97cdc["handleResult()"]
  c96b81c5_ea33_13b2_52db_63502e2f3044 -->|method| 08686ee3_0989_cbf4_6868_2a6da6c97cdc
  8a91ff5b_285b_42a6_ab61_60e346c849dc["position()"]
  c96b81c5_ea33_13b2_52db_63502e2f3044 -->|method| 8a91ff5b_285b_42a6_ab61_60e346c849dc
  1d4cf248_0174_2957_8029_634afe7f4cca["transfered()"]
  c96b81c5_ea33_13b2_52db_63502e2f3044 -->|method| 1d4cf248_0174_2957_8029_634afe7f4cca
  bc778394_4736_dc59_67b3_30ae07ee14d0["transferred()"]
  c96b81c5_ea33_13b2_52db_63502e2f3044 -->|method| bc778394_4736_dc59_67b3_30ae07ee14d0
  b11e4b38_b4b8_0290_08c2_c03a41d75b16["count()"]
  c96b81c5_ea33_13b2_52db_63502e2f3044 -->|method| b11e4b38_b4b8_0290_08c2_c03a41d75b16
  085a9efe_f134_549a_f7f8_8afe8a16e344["transferTo()"]
  c96b81c5_ea33_13b2_52db_63502e2f3044 -->|method| 085a9efe_f134_549a_f7f8_8afe8a16e344
  bec257c5_6784_17f5_4375_3e92c44d5402["FileRegion()"]
  c96b81c5_ea33_13b2_52db_63502e2f3044 -->|method| bec257c5_6784_17f5_4375_3e92c44d5402
  f8c2c7a2_e1f7_367e_e371_f86b60f0b50f["refCnt()"]
  c96b81c5_ea33_13b2_52db_63502e2f3044 -->|method| f8c2c7a2_e1f7_367e_e371_f86b60f0b50f
  282e0a5e_e964_53e4_faee_e94c8fab3c26["release()"]
  c96b81c5_ea33_13b2_52db_63502e2f3044 -->|method| 282e0a5e_e964_53e4_faee_e94c8fab3c26
  274a1d92_bda7_8539_5c81_ccb728805906["closePipeIfNeeded()"]
  c96b81c5_ea33_13b2_52db_63502e2f3044 -->|method| 274a1d92_bda7_8539_5c81_ccb728805906

Relationship Graph

Source Code

transport-classes-io_uring/src/main/java/io/netty/channel/uring/IoUringFileRegion.java lines 27–190

final class IoUringFileRegion implements FileRegion {
    private static final InternalLogger logger = InternalLoggerFactory.getInstance(IoUringFileRegion.class);

    private static final short SPLICE_TO_PIPE = 1;
    private static final short SPLICE_TO_SOCKET = 2;

    final DefaultFileRegion fileRegion;
    private FileDescriptor[] pipe;
    private int transferred;
    private int pipeLen = -1;

    IoUringFileRegion(DefaultFileRegion fileRegion) {
        this.fileRegion = fileRegion;
    }

    void open() throws IOException {
        fileRegion.open();
        if (pipe == null) {
            pipe = FileDescriptor.pipe();
        }
    }

    IoUringIoOps splice(int fd) {
        if (pipeLen == -1) {
            return spliceToPipe();
        }
        return spliceToSocket(fd, pipeLen);
    }

    IoUringIoOps spliceToPipe() {
        int fileRegionFd = Native.getFd(fileRegion);
        int len = (int) (count() - transferred());
        int offset =  (int) (position() + transferred());
        return IoUringIoOps.newSplice(
                fileRegionFd, offset,
                pipe[1].intValue(), -1L,
                len, Native.SPLICE_F_MOVE, SPLICE_TO_PIPE);
    }

    private IoUringIoOps spliceToSocket(int socket, int len) {
        return IoUringIoOps.newSplice(
                pipe[0].intValue(), -1L,
                socket, -1L,
                len, Native.SPLICE_F_MOVE, SPLICE_TO_SOCKET);
    }

    /**
     * Handle splice result
     *
     * @param result    the result
     * @param data      the data that was submitted as part of the SPLICE.
     * @return          the number of bytes that should be considered to be transferred.
     */
    int handleResult(int result, short data) {
        assert result >= 0;
        if (data == SPLICE_TO_PIPE) {
            // This is the result for spliceToPipe
            transferred += result;
            pipeLen = result;
            return 0;
        }
        if (data == SPLICE_TO_SOCKET) {
            // This is the result for spliceToSocket
            pipeLen -= result;
            assert pipeLen >= 0;
            if (pipeLen == 0) {
                if (transferred() >= count()) {
                    // We transferred the whole file
                    return -1;
                }
                pipeLen = -1;
            }
            return result;
        }
        throw new IllegalArgumentException("Unknown data: " + data);
    }

    @Override
    public long position() {
        return fileRegion.position();
    }

Frequently Asked Questions

What is the IoUringFileRegion class?
IoUringFileRegion is a class in the netty codebase, defined in transport-classes-io_uring/src/main/java/io/netty/channel/uring/IoUringFileRegion.java.
Where is IoUringFileRegion defined?
IoUringFileRegion is defined in transport-classes-io_uring/src/main/java/io/netty/channel/uring/IoUringFileRegion.java at line 27.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free