Home / Function/ drainEventFd() — netty Function Reference

drainEventFd() — netty Function Reference

Architecture documentation for the drainEventFd() function in IoUringIoHandler.java from the netty codebase.

Function java Buffer Search calls 4 called by 1

Entity Profile

Dependency Diagram

graph TD
  ba804e78_369a_b616_6db6_06516ef2b298["drainEventFd()"]
  54b1e24c_acd2_7686_4313_2695f1b73de1["IoUringIoHandler"]
  ba804e78_369a_b616_6db6_06516ef2b298 -->|defined in| 54b1e24c_acd2_7686_4313_2695f1b73de1
  093f8eee_4384_b7ac_3228_6a911c17e627["destroy()"]
  093f8eee_4384_b7ac_3228_6a911c17e627 -->|calls| ba804e78_369a_b616_6db6_06516ef2b298
  3dd4563f_fb58_41cc_3ce1_aa727be6023e["handle()"]
  ba804e78_369a_b616_6db6_06516ef2b298 -->|calls| 3dd4563f_fb58_41cc_3ce1_aa727be6023e
  5de35c14_38b4_da68_9364_e35d6355eda9["submitEventFdRead()"]
  ba804e78_369a_b616_6db6_06516ef2b298 -->|calls| 5de35c14_38b4_da68_9364_e35d6355eda9
  513438f0_b49b_4a1e_b61f_b88845bcbbfb["submit()"]
  ba804e78_369a_b616_6db6_06516ef2b298 -->|calls| 513438f0_b49b_4a1e_b61f_b88845bcbbfb
  00f4b33f_14c8_6a03_69e4_20eca4fce924["processCompletionsAndHandleOverflow()"]
  ba804e78_369a_b616_6db6_06516ef2b298 -->|calls| 00f4b33f_14c8_6a03_69e4_20eca4fce924
  style ba804e78_369a_b616_6db6_06516ef2b298 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

transport-classes-io_uring/src/main/java/io/netty/channel/uring/IoUringIoHandler.java lines 405–446

    private void drainEventFd() {
        CompletionQueue completionQueue = ringBuffer.ioUringCompletionQueue();
        SubmissionQueue submissionQueue = ringBuffer.ioUringSubmissionQueue();
        assert !eventFdClosing;
        eventFdClosing = true;
        boolean eventPending = eventfdAsyncNotify.getAndSet(true);
        if (eventPending) {
            // There is an event that has been or will be written by another thread, so we must wait for the event.
            // Make sure we're actually listening for writes to the event fd.
            while (eventfdReadSubmitted == 0) {
                submitEventFdRead();
                submissionQueue.submit();
            }
            // Drain the eventfd of the pending wakup.
            class DrainFdEventCallback implements CompletionCallback {
                boolean eventFdDrained;

                @Override
                public void handle(int res, int flags, long udata, ByteBuffer extraCqeData) {
                    if (UserData.decodeId(udata) == EVENTFD_ID) {
                        eventFdDrained = true;
                    }
                    IoUringIoHandler.this.handle(res, flags, udata, extraCqeData);
                }
            }
            final DrainFdEventCallback handler = new DrainFdEventCallback();
            completionQueue.process(handler);
            while (!handler.eventFdDrained) {
                submissionQueue.submitAndGet();
                processCompletionsAndHandleOverflow(submissionQueue, completionQueue, handler);
            }
        }
        // We've consumed any pending eventfd read and `eventfdAsyncNotify` should never
        // transition back to false, thus we should never have any more events written.
        // So, if we have a read event pending, we can cancel it.
        if (eventfdReadSubmitted != 0) {
            long udata = UserData.encode(EVENTFD_ID, Native.IORING_OP_ASYNC_CANCEL, (short) 0);
            submissionQueue.addCancel(eventfdReadSubmitted, udata);
            eventfdReadSubmitted = 0;
            submissionQueue.submit();
        }
    }

Domain

Subdomains

Called By

Frequently Asked Questions

What does drainEventFd() do?
drainEventFd() is a function in the netty codebase, defined in transport-classes-io_uring/src/main/java/io/netty/channel/uring/IoUringIoHandler.java.
Where is drainEventFd() defined?
drainEventFd() is defined in transport-classes-io_uring/src/main/java/io/netty/channel/uring/IoUringIoHandler.java at line 405.
What does drainEventFd() call?
drainEventFd() calls 4 function(s): handle, processCompletionsAndHandleOverflow, submit, submitEventFdRead.
What calls drainEventFd()?
drainEventFd() is called by 1 function(s): destroy.

Analyze Your Own Codebase

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

Try Supermodel Free