Home / Function/ scheduleRead0() — netty Function Reference

scheduleRead0() — netty Function Reference

Architecture documentation for the scheduleRead0() function in AbstractIoUringServerChannel.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  18480b94_3706_e128_938e_ec849da3eb51["scheduleRead0()"]
  92c310a1_fd2c_26a6_1171_7ed00ce40178["UringServerChannelUnsafe"]
  18480b94_3706_e128_938e_ec849da3eb51 -->|defined in| 92c310a1_fd2c_26a6_1171_7ed00ce40178
  style 18480b94_3706_e128_938e_ec849da3eb51 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

transport-classes-io_uring/src/main/java/io/netty/channel/uring/AbstractIoUringServerChannel.java lines 149–208

        @Override
        protected int scheduleRead0(boolean first, boolean socketIsEmpty) {
            assert acceptId == 0;
            final IoUringRecvByteAllocatorHandle allocHandle = recvBufAllocHandle();
            allocHandle.attemptedBytesRead(1);

            int fd = fd().intValue();
            IoRegistration registration = registration();

            final short ioPrio;

            final long acceptedAddressMemoryAddress;
            final long acceptedAddressLengthMemoryAddress;
            if (IoUring.isAcceptMultishotEnabled()) {
                // Let's use multi-shot accept to reduce overhead.
                ioPrio = Native.IORING_ACCEPT_MULTISHOT;
                acceptedAddressMemoryAddress = 0;
                acceptedAddressLengthMemoryAddress = 0;
            } else {
                // Depending on if socketIsEmpty is true we will arm the poll upfront and skip the initial transfer
                // attempt.
                // See https://github.com/axboe/liburing/wiki/io_uring-and-networking-in-2023#socket-state
                //
                // Depending on if this is the first read or not we will use Native.IORING_ACCEPT_DONT_WAIT.
                // The idea is that if the socket is blocking we can do the first read in a blocking fashion
                // and so not need to also register POLLIN. As we can not 100 % sure if reads after the first will
                // be possible directly we schedule these with Native.IORING_ACCEPT_DONT_WAIT. This allows us to still
                // be able to signal the fireChannelReadComplete() in a timely manner and be consistent with other
                // transports.
                //
                // IORING_ACCEPT_POLL_FIRST and IORING_ACCEPT_DONTWAIT were added in the same release.
                // We need to check if its supported as otherwise providing these would result in an -EINVAL.
                if (IoUring.isAcceptNoWaitSupported()) {
                    if (first) {
                        ioPrio = socketIsEmpty ? Native.IORING_ACCEPT_POLL_FIRST : 0;
                    } else {
                        ioPrio = Native.IORING_ACCEPT_DONTWAIT;
                    }
                } else {
                    ioPrio = 0;
                }

                assert acceptedAddressMemory != null;
                acceptedAddressMemoryAddress = acceptedAddressMemory.acceptedAddressMemoryAddress;
                acceptedAddressLengthMemoryAddress = acceptedAddressMemory.acceptedAddressLengthMemoryAddress;
            }

            // See https://github.com/axboe/liburing/wiki/What's-new-with-io_uring-in-6.10#improvements-for-accept
            IoUringIoOps ops = IoUringIoOps.newAccept(fd, (byte) 0, 0, ioPrio,
                    acceptedAddressMemoryAddress, acceptedAddressLengthMemoryAddress, nextOpsId());
            acceptId = registration.submit(ops);
            if (acceptId == 0) {
                return 0;
            }
            if ((ioPrio & Native.IORING_ACCEPT_MULTISHOT) != 0) {
                // Let's return -1 to signal that we used multi-shot.
                return -1;
            }
            return 1;
        }

Domain

Subdomains

Frequently Asked Questions

What does scheduleRead0() do?
scheduleRead0() is a function in the netty codebase, defined in transport-classes-io_uring/src/main/java/io/netty/channel/uring/AbstractIoUringServerChannel.java.
Where is scheduleRead0() defined?
scheduleRead0() is defined in transport-classes-io_uring/src/main/java/io/netty/channel/uring/AbstractIoUringServerChannel.java at line 149.

Analyze Your Own Codebase

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

Try Supermodel Free