Home / Class/ IoUringDatagramChannelUnsafe Class — netty Architecture

IoUringDatagramChannelUnsafe Class — netty Architecture

Architecture documentation for the IoUringDatagramChannelUnsafe class in IoUringDatagramChannel.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  84fa1210_78f7_d596_04d2_ce3b690b2252["IoUringDatagramChannelUnsafe"]
  84d8ef59_34c3_a366_2f8b_b5fcde9ce2c0["IoUringDatagramChannel.java"]
  84fa1210_78f7_d596_04d2_ce3b690b2252 -->|defined in| 84d8ef59_34c3_a366_2f8b_b5fcde9ce2c0
  d3789b6f_ecb7_8b61_ce80_a4927993c3f5["readComplete0()"]
  84fa1210_78f7_d596_04d2_ce3b690b2252 -->|method| d3789b6f_ecb7_8b61_ce80_a4927993c3f5
  c5570cd2_0dd7_0431_e465_f4f118304cf7["recvmsgComplete()"]
  84fa1210_78f7_d596_04d2_ce3b690b2252 -->|method| c5570cd2_0dd7_0431_e465_f4f118304cf7
  f0afd207_cffb_c246_72a5_ffe39ea4cfc9["scheduleRead0()"]
  84fa1210_78f7_d596_04d2_ce3b690b2252 -->|method| f0afd207_cffb_c246_72a5_ffe39ea4cfc9
  002f14bf_467b_81db_b4c4_3c6c831693f3["scheduleRecvmsg()"]
  84fa1210_78f7_d596_04d2_ce3b690b2252 -->|method| 002f14bf_467b_81db_b4c4_3c6c831693f3
  e300f4b4_c3de_e00d_8d51_49f63f0c8d92["scheduleRecvmsg0()"]
  84fa1210_78f7_d596_04d2_ce3b690b2252 -->|method| e300f4b4_c3de_e00d_8d51_49f63f0c8d92
  24996de9_a29f_2a63_cae2_9ba4865b783d["writeComplete0()"]
  84fa1210_78f7_d596_04d2_ce3b690b2252 -->|method| 24996de9_a29f_2a63_cae2_9ba4865b783d
  c415803e_78d1_412c_b6ce_0985275eb244["removeFromOutboundBuffer()"]
  84fa1210_78f7_d596_04d2_ce3b690b2252 -->|method| c415803e_78d1_412c_b6ce_0985275eb244
  cf7f8334_b62d_b8a7_1f8f_3dd910ecf5ef["connectComplete()"]
  84fa1210_78f7_d596_04d2_ce3b690b2252 -->|method| cf7f8334_b62d_b8a7_1f8f_3dd910ecf5ef
  11fa58d9_4c07_a0d3_f25b_643126b299d2["scheduleWriteMultiple()"]
  84fa1210_78f7_d596_04d2_ce3b690b2252 -->|method| 11fa58d9_4c07_a0d3_f25b_643126b299d2
  7d8ae120_49f5_dabd_df9a_d786454ac122["scheduleWriteSingle()"]
  84fa1210_78f7_d596_04d2_ce3b690b2252 -->|method| 7d8ae120_49f5_dabd_df9a_d786454ac122
  2a343a6c_561d_38ec_1375_a3d1f1002378["scheduleWrite()"]
  84fa1210_78f7_d596_04d2_ce3b690b2252 -->|method| 2a343a6c_561d_38ec_1375_a3d1f1002378
  b8a7824c_8cd1_0faf_9968_e5da48b83ee6["scheduleSendmsg()"]
  84fa1210_78f7_d596_04d2_ce3b690b2252 -->|method| b8a7824c_8cd1_0faf_9968_e5da48b83ee6
  bea4dc91_4c22_bd38_0d24_6c492086d55c["unregistered()"]
  84fa1210_78f7_d596_04d2_ce3b690b2252 -->|method| bea4dc91_4c22_bd38_0d24_6c492086d55c

Relationship Graph

Source Code

transport-classes-io_uring/src/main/java/io/netty/channel/uring/IoUringDatagramChannel.java lines 377–649

    private final class IoUringDatagramChannelUnsafe extends AbstractUringUnsafe {
        private final WriteProcessor writeProcessor = new WriteProcessor();

        private ByteBuf readBuffer;

        private final class WriteProcessor implements ChannelOutboundBuffer.MessageProcessor {
            private int written;
            @Override
            public boolean processMessage(Object msg) {
                if (scheduleWrite(msg, written == 0)) {
                    written++;
                    return true;
                }
                return false;
            }

            int write(ChannelOutboundBuffer in) {
                written = 0;
                try {
                    in.forEachFlushedMessage(this);
                } catch (Exception e) {
                    // This should never happen as our processMessage(...) never throws.
                    throw new IllegalStateException(e);
                }
                return written;
            }
        }

        @Override
        protected void readComplete0(byte op, int res, int flags, short data, int outstanding) {
            assert outstanding != -1 : "multi-shot not implemented yet";

            final IoUringRecvByteAllocatorHandle allocHandle = recvBufAllocHandle();
            final ChannelPipeline pipeline = pipeline();
            ByteBuf byteBuf = this.readBuffer;
            assert byteBuf != null;
            try {
                recvmsgComplete(pipeline, allocHandle, byteBuf, res, flags, data, outstanding);
            } catch (Throwable t) {
                Throwable e = (connected && t instanceof NativeIoException) ?
                  translateForConnected((NativeIoException) t) : t;
                pipeline.fireExceptionCaught(e);
            }
        }

        private void recvmsgComplete(ChannelPipeline pipeline, IoUringRecvByteAllocatorHandle allocHandle,
                                      ByteBuf byteBuf, int res, int flags, int idx, int outstanding)
                throws IOException {
            MsgHdrMemory hdr = recvmsgHdrs.hdr(idx);
            if (res < 0) {
                if (res != Native.ERRNO_ECANCELED_NEGATIVE) {
                    // If res is negative we should pass it to ioResult(...) which will either throw
                    // or convert it to 0 if we could not read because the socket was not readable.
                    allocHandle.lastBytesRead(ioResult("io_uring recvmsg", res));
                }
            } else {
                allocHandle.lastBytesRead(res);
                if (hdr.hasPort(IoUringDatagramChannel.this)) {
                    allocHandle.incMessagesRead(1);
                    DatagramPacket packet = hdr.get(
                            IoUringDatagramChannel.this, registration().attachment(), byteBuf, res);
                    pipeline.fireChannelRead(packet);
                }
            }

            // Reset the id as this read was completed and so don't need to be cancelled later.
            recvmsgHdrs.setId(idx, MsgHdrMemoryArray.NO_ID);
            if (outstanding == 0) {
                // There are no outstanding completion events, release the readBuffer and see if we need to schedule
                // another one or if the user will do it.
                this.readBuffer.release();
                this.readBuffer = null;
                recvmsgHdrs.clear();

                if (res != Native.ERRNO_ECANCELED_NEGATIVE) {
                    if (allocHandle.lastBytesRead() > 0 &&
                            allocHandle.continueReading(UncheckedBooleanSupplier.TRUE_SUPPLIER) &&
                            // If IORING_CQE_F_SOCK_NONEMPTY is supported we should check for it first before
                            // trying to schedule a read. If it's supported and not part of the flags we know for sure
                            // that the next read (which would be using Native.MSG_DONTWAIT) will complete without
                            // be able to read any data. This is useless work and we can skip it.

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free