Home / Class/ KQueueStreamUnsafe Class — netty Architecture

KQueueStreamUnsafe Class — netty Architecture

Architecture documentation for the KQueueStreamUnsafe class in AbstractKQueueStreamChannel.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  9d9cd790_d6e0_6f39_011d_e69a35e7c41f["KQueueStreamUnsafe"]
  dec001f2_dbaa_7715_de1b_ddd2dc9c85f8["AbstractKQueueStreamChannel.java"]
  9d9cd790_d6e0_6f39_011d_e69a35e7c41f -->|defined in| dec001f2_dbaa_7715_de1b_ddd2dc9c85f8
  6d88f03c_d085_4d3f_377d_9b355305a2cd["Executor()"]
  9d9cd790_d6e0_6f39_011d_e69a35e7c41f -->|method| 6d88f03c_d085_4d3f_377d_9b355305a2cd
  fdaf9f05_9ac5_91fc_0d36_89416c50ee16["readReady()"]
  9d9cd790_d6e0_6f39_011d_e69a35e7c41f -->|method| fdaf9f05_9ac5_91fc_0d36_89416c50ee16
  992cf68c_d981_2e34_b60d_f19218c38fe8["handleReadException()"]
  9d9cd790_d6e0_6f39_011d_e69a35e7c41f -->|method| 992cf68c_d981_2e34_b60d_f19218c38fe8

Relationship Graph

Source Code

transport-classes-kqueue/src/main/java/io/netty/channel/kqueue/AbstractKQueueStreamChannel.java lines 505–603

    class KQueueStreamUnsafe extends AbstractKQueueUnsafe {
        // Overridden here just to be able to access this method from AbstractKQueueStreamChannel
        @Override
        protected Executor prepareToClose() {
            return super.prepareToClose();
        }

        @Override
        void readReady(final KQueueRecvByteAllocatorHandle allocHandle) {
            final ChannelConfig config = config();
            if (shouldBreakReadReady(config)) {
                clearReadFilter0();
                return;
            }
            final ChannelPipeline pipeline = pipeline();
            final ByteBufAllocator allocator = config.getAllocator();
            allocHandle.reset(config);

            ByteBuf byteBuf = null;
            boolean close = false;
            try {
                do {
                    // we use a direct buffer here as the native implementations only be able
                    // to handle direct buffers.
                    byteBuf = allocHandle.allocate(allocator);
                    allocHandle.lastBytesRead(doReadBytes(byteBuf));
                    if (allocHandle.lastBytesRead() <= 0) {
                        // nothing was read, release the buffer.
                        byteBuf.release();
                        byteBuf = null;
                        close = allocHandle.lastBytesRead() < 0;
                        if (close) {
                            // There is nothing left to read as we received an EOF.
                            readPending = false;
                        }
                        break;
                    }
                    allocHandle.incMessagesRead(1);
                    readPending = false;
                    pipeline.fireChannelRead(byteBuf);
                    byteBuf = null;

                    if (shouldBreakReadReady(config)) {
                        // We need to do this for two reasons:
                        //
                        // - If the input was shutdown in between (which may be the case when the user did it in the
                        //   fireChannelRead(...) method we should not try to read again to not produce any
                        //   miss-leading exceptions.
                        //
                        // - If the user closes the channel we need to ensure we not try to read from it again as
                        //   the filedescriptor may be re-used already by the OS if the system is handling a lot of
                        //   concurrent connections and so needs a lot of filedescriptors. If not do this we risk
                        //   reading data from a filedescriptor that belongs to another socket then the socket that
                        //   was "wrapped" by this Channel implementation.
                        break;
                    }
                } while (allocHandle.continueReading());

                allocHandle.readComplete();
                pipeline.fireChannelReadComplete();

                if (close) {
                    shutdownInput(false);
                }
            } catch (Throwable t) {
                handleReadException(pipeline, byteBuf, t, close, allocHandle);
            } finally {
                if (shouldStopReading(config)) {
                    clearReadFilter0();
                }
            }
        }

        private void handleReadException(ChannelPipeline pipeline, ByteBuf byteBuf, Throwable cause, boolean close,
                                         KQueueRecvByteAllocatorHandle allocHandle) {
            if (byteBuf != null) {
                if (byteBuf.isReadable()) {
                    readPending = false;
                    pipeline.fireChannelRead(byteBuf);
                } else {
                    byteBuf.release();

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free