Home / Class/ IoUringDomainSocketUnsafe Class — netty Architecture

IoUringDomainSocketUnsafe Class — netty Architecture

Architecture documentation for the IoUringDomainSocketUnsafe class in IoUringDomainSocketChannel.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  dc99258d_71a6_9064_ca08_361c0964e22e["IoUringDomainSocketUnsafe"]
  57b307f7_744f_b12e_e6a9_8b981cc360b3["IoUringDomainSocketChannel.java"]
  dc99258d_71a6_9064_ca08_361c0964e22e -->|defined in| 57b307f7_744f_b12e_e6a9_8b981cc360b3
  717637ae_38a0_fffc_1875_5cb7f8ef6713["scheduleWriteSingle()"]
  dc99258d_71a6_9064_ca08_361c0964e22e -->|method| 717637ae_38a0_fffc_1875_5cb7f8ef6713
  6ff3f324_f12d_4832_612d_719768c2f562["writeComplete0()"]
  dc99258d_71a6_9064_ca08_361c0964e22e -->|method| 6ff3f324_f12d_4832_612d_719768c2f562
  91f0ccfd_b51f_9a8e_8ab5_b27b9355859c["IoUringIoOps()"]
  dc99258d_71a6_9064_ca08_361c0964e22e -->|method| 91f0ccfd_b51f_9a8e_8ab5_b27b9355859c
  9f4cc00d_73a2_67b4_0b9e_3397fce40777["scheduleRead0()"]
  dc99258d_71a6_9064_ca08_361c0964e22e -->|method| 9f4cc00d_73a2_67b4_0b9e_3397fce40777
  f3066102_b27b_d743_8c60_561f9d9cfbcb["scheduleRecvReadFd()"]
  dc99258d_71a6_9064_ca08_361c0964e22e -->|method| f3066102_b27b_d743_8c60_561f9d9cfbcb
  e219aa9f_5053_2a4e_ea19_ccd705287183["readComplete0()"]
  dc99258d_71a6_9064_ca08_361c0964e22e -->|method| e219aa9f_5053_2a4e_ea19_ccd705287183
  169510d1_500a_6706_ea06_8def4e8df8ad["connect()"]
  dc99258d_71a6_9064_ca08_361c0964e22e -->|method| 169510d1_500a_6706_ea06_8def4e8df8ad
  3c1f3526_b7e2_31cb_3701_3a4e4a7e9a86["unregistered()"]
  dc99258d_71a6_9064_ca08_361c0964e22e -->|method| 3c1f3526_b7e2_31cb_3701_3a4e4a7e9a86

Relationship Graph

Source Code

transport-classes-io_uring/src/main/java/io/netty/channel/uring/IoUringDomainSocketChannel.java lines 105–253

    private final class IoUringDomainSocketUnsafe extends IoUringStreamUnsafe {

        private MsgHdrMemory writeMsgHdrMemory;
        private MsgHdrMemory readMsgHdrMemory;

        @Override
        protected int scheduleWriteSingle(Object msg) {
            if (msg instanceof FileDescriptor) {
                // we can reuse the same memory for any fd
                // because we never have more than a single outstanding write.
                if (writeMsgHdrMemory == null) {
                    writeMsgHdrMemory = new MsgHdrMemory();
                }
                IoRegistration registration = registration();
                IoUringIoOps ioUringIoOps = prepSendFdIoOps((FileDescriptor) msg, writeMsgHdrMemory);
                writeId = registration.submit(ioUringIoOps);
                writeOpCode = Native.IORING_OP_SENDMSG;
                if (writeId == 0) {
                    MsgHdrMemory memory = writeMsgHdrMemory;
                    writeMsgHdrMemory = null;
                    memory.release();
                    return 0;
                }
                return 1;
            }
            return super.scheduleWriteSingle(msg);
        }

        @Override
        boolean writeComplete0(byte op, int res, int flags, short data, int outstanding) {
            if (op == Native.IORING_OP_SENDMSG) {
                writeId = 0;
                writeOpCode = 0;
                if (res == Native.ERRNO_ECANCELED_NEGATIVE) {
                    return true;
                }
                try {
                    int nativeCallResult = res >= 0 ? res : Errors.ioResult("io_uring sendmsg", res);
                    if (nativeCallResult >= 0) {
                        ChannelOutboundBuffer channelOutboundBuffer = unsafe().outboundBuffer();
                        channelOutboundBuffer.remove();
                    }
                } catch (Throwable throwable) {
                   handleWriteError(throwable);
                }
                return true;
            }
            return super.writeComplete0(op, res, flags, data, outstanding);
        }

        private IoUringIoOps prepSendFdIoOps(FileDescriptor fileDescriptor, MsgHdrMemory msgHdrMemory) {
            msgHdrMemory.setScmRightsFd(fileDescriptor.intValue());
            return IoUringIoOps.newSendmsg(
                    fd().intValue(), (byte) 0, 0, msgHdrMemory.address(), msgHdrMemory.idx());
        }

        @Override
        protected int scheduleRead0(boolean first, boolean socketIsEmpty) {
            DomainSocketReadMode readMode = config.getReadMode();
            switch (readMode) {
                case FILE_DESCRIPTORS:
                    return scheduleRecvReadFd();
                case BYTES:
                    return super.scheduleRead0(first, socketIsEmpty);
                default:
                    throw new Error("Unexpected read mode: " + readMode);
            }
        }

        private int scheduleRecvReadFd() {
            // we can reuse the same memory for any fd
            // because we only submit one outstanding read
            if (readMsgHdrMemory == null) {
                readMsgHdrMemory = new MsgHdrMemory();
            }
            readMsgHdrMemory.prepRecvReadFd();
            IoRegistration registration = registration();
            IoUringIoOps ioUringIoOps = IoUringIoOps.newRecvmsg(
                    fd().intValue(), (byte) 0, 0, readMsgHdrMemory.address(), readMsgHdrMemory.idx());
            readId = registration.submit(ioUringIoOps);
            readOpCode = Native.IORING_OP_RECVMSG;

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free