Home / Class/ KQueueRecvByteAllocatorHandle Class — netty Architecture

KQueueRecvByteAllocatorHandle Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  4bd64f5c_3774_04e4_bcf5_527707cf8502["KQueueRecvByteAllocatorHandle"]
  b55ccce9_e4e3_247f_4f38_c4038f0d49e7["KQueueRecvByteAllocatorHandle.java"]
  4bd64f5c_3774_04e4_bcf5_527707cf8502 -->|defined in| b55ccce9_e4e3_247f_4f38_c4038f0d49e7
  05f4a9ba_93c1_2da8_ca4f_bbbedcd1695a["KQueueRecvByteAllocatorHandle()"]
  4bd64f5c_3774_04e4_bcf5_527707cf8502 -->|method| 05f4a9ba_93c1_2da8_ca4f_bbbedcd1695a
  30e975be_8eec_71af_8be9_cb82b5410133["ByteBuf()"]
  4bd64f5c_3774_04e4_bcf5_527707cf8502 -->|method| 30e975be_8eec_71af_8be9_cb82b5410133
  1b238254_66a6_88d0_9147_1069fa8129ed["continueReading()"]
  4bd64f5c_3774_04e4_bcf5_527707cf8502 -->|method| 1b238254_66a6_88d0_9147_1069fa8129ed
  03671952_e8a8_f7b2_56c6_861d6f727532["readEOF()"]
  4bd64f5c_3774_04e4_bcf5_527707cf8502 -->|method| 03671952_e8a8_f7b2_56c6_861d6f727532
  4e230d22_bbd2_db4a_628c_6d8e5e5c1c4e["numberBytesPending()"]
  4bd64f5c_3774_04e4_bcf5_527707cf8502 -->|method| 4e230d22_bbd2_db4a_628c_6d8e5e5c1c4e
  9a63cf2d_dc23_1c65_d113_061f98164a9c["maybeMoreDataToRead()"]
  4bd64f5c_3774_04e4_bcf5_527707cf8502 -->|method| 9a63cf2d_dc23_1c65_d113_061f98164a9c

Relationship Graph

Source Code

transport-classes-kqueue/src/main/java/io/netty/channel/kqueue/KQueueRecvByteAllocatorHandle.java lines 29–85

final class KQueueRecvByteAllocatorHandle extends DelegatingHandle implements ExtendedHandle {
    private final PreferredDirectByteBufAllocator preferredDirectByteBufAllocator =
            new PreferredDirectByteBufAllocator();

    private final UncheckedBooleanSupplier defaultMaybeMoreDataSupplier = new UncheckedBooleanSupplier() {
        @Override
        public boolean get() {
            return maybeMoreDataToRead();
        }
    };
    private boolean readEOF;
    private long numberBytesPending;

    KQueueRecvByteAllocatorHandle(ExtendedHandle handle) {
        super(handle);
    }

    @Override
    public ByteBuf allocate(ByteBufAllocator alloc) {
        // We need to ensure we always allocate a direct ByteBuf as we can only use a direct buffer to read via JNI.
        preferredDirectByteBufAllocator.updateAllocator(alloc);
        return delegate().allocate(preferredDirectByteBufAllocator);
    }

    @Override
    public boolean continueReading(UncheckedBooleanSupplier maybeMoreDataSupplier) {
        return readEOF || ((ExtendedHandle) delegate()).continueReading(maybeMoreDataSupplier);
    }

    @Override
    public boolean continueReading() {
        // We must override the supplier which determines if there maybe more data to read.
        return continueReading(defaultMaybeMoreDataSupplier);
    }

    void readEOF() {
        readEOF = true;
    }

    void numberBytesPending(long numberBytesPending) {
        this.numberBytesPending = numberBytesPending;
    }

    private boolean maybeMoreDataToRead() {
        /**
         * kqueue with EV_CLEAR flag set requires that we read until we consume "data" bytes
         * (see <a href="https://www.freebsd.org/cgi/man.cgi?kqueue">kqueue man</a>). However in order to
         * respect auto read we supporting reading to stop if auto read is off. If auto read is on we force reading to
         * continue to avoid a {@link StackOverflowError} between channelReadComplete and reading from the
         * channel. It is expected that the {@link #KQueueSocketChannel} implementations will track if all data was not
         * read, and will force a EVFILT_READ ready event.
         *
         * It is assumed EOF is handled externally by checking {@link #isReadEOF()}.
         */
        return lastBytesRead() == attemptedBytesRead();
    }
}

Frequently Asked Questions

What is the KQueueRecvByteAllocatorHandle class?
KQueueRecvByteAllocatorHandle is a class in the netty codebase, defined in transport-classes-kqueue/src/main/java/io/netty/channel/kqueue/KQueueRecvByteAllocatorHandle.java.
Where is KQueueRecvByteAllocatorHandle defined?
KQueueRecvByteAllocatorHandle is defined in transport-classes-kqueue/src/main/java/io/netty/channel/kqueue/KQueueRecvByteAllocatorHandle.java at line 29.

Analyze Your Own Codebase

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

Try Supermodel Free