Home / Class/ KQueueDatagramChannelUnsafe Class — netty Architecture

KQueueDatagramChannelUnsafe Class — netty Architecture

Architecture documentation for the KQueueDatagramChannelUnsafe class in KQueueDatagramChannel.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  9313a9ce_3971_e082_2088_9dd72ef133fe["KQueueDatagramChannelUnsafe"]
  9772fc6c_7786_606d_0861_764516b3bf93["KQueueDatagramChannel.java"]
  9313a9ce_3971_e082_2088_9dd72ef133fe -->|defined in| 9772fc6c_7786_606d_0861_764516b3bf93
  7d73a1ce_8dab_4b77_c0bb_3c2a989b5b4e["readReady()"]
  9313a9ce_3971_e082_2088_9dd72ef133fe -->|method| 7d73a1ce_8dab_4b77_c0bb_3c2a989b5b4e

Relationship Graph

Source Code

transport-classes-kqueue/src/main/java/io/netty/channel/kqueue/KQueueDatagramChannel.java lines 391–492

    final class KQueueDatagramChannelUnsafe extends AbstractKQueueUnsafe {

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

            Throwable exception = null;
            try {
                ByteBuf byteBuf = null;
                try {
                    boolean connected = isConnected();
                    do {
                        byteBuf = allocHandle.allocate(allocator);
                        allocHandle.attemptedBytesRead(byteBuf.writableBytes());

                        final DatagramPacket packet;
                        if (connected) {
                            try {
                                allocHandle.lastBytesRead(doReadBytes(byteBuf));
                            } catch (Errors.NativeIoException e) {
                                // We need to correctly translate connect errors to match NIO behaviour.
                                if (e.expectedErr() == Errors.ERROR_ECONNREFUSED_NEGATIVE) {
                                    PortUnreachableException error = new PortUnreachableException(e.getMessage());
                                    error.initCause(e);
                                    throw error;
                                }
                                throw e;
                            }
                            if (allocHandle.lastBytesRead() <= 0) {
                                // nothing was read, release the buffer.
                                byteBuf.release();
                                byteBuf = null;
                                break;
                            }
                            packet = new DatagramPacket(byteBuf,
                                    (InetSocketAddress) localAddress(), (InetSocketAddress) remoteAddress());
                        } else {
                            final DatagramSocketAddress remoteAddress;
                            if (byteBuf.hasMemoryAddress()) {
                                // has a memory address so use optimized call
                                remoteAddress = socket.recvFromAddress(byteBuf.memoryAddress(), byteBuf.writerIndex(),
                                        byteBuf.capacity());
                            } else {
                                ByteBuffer nioData = byteBuf.internalNioBuffer(
                                        byteBuf.writerIndex(), byteBuf.writableBytes());
                                remoteAddress = socket.recvFrom(nioData, nioData.position(), nioData.limit());
                            }

                            if (remoteAddress == null) {
                                allocHandle.lastBytesRead(-1);
                                byteBuf.release();
                                byteBuf = null;
                                break;
                            }
                            InetSocketAddress localAddress = remoteAddress.localAddress();
                            if (localAddress == null) {
                                localAddress = (InetSocketAddress) localAddress();
                            }
                            allocHandle.lastBytesRead(remoteAddress.receivedAmount());
                            byteBuf.writerIndex(byteBuf.writerIndex() + allocHandle.lastBytesRead());

                            packet = new DatagramPacket(byteBuf, localAddress, remoteAddress);
                        }

                        allocHandle.incMessagesRead(1);

                        readPending = false;
                        pipeline.fireChannelRead(packet);

                        byteBuf = null;

                    // We use the TRUE_SUPPLIER as it is also ok to read less then what we did try to read (as long
                    // as we read anything).

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free