Home / Function/ doWrite() — netty Function Reference

doWrite() — netty Function Reference

Architecture documentation for the doWrite() function in EpollDatagramChannel.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  5d8b824f_1d60_b1ed_e124_4f2179ce144c["doWrite()"]
  dab3c3bb_b3e2_f3b8_e8e0_37c99496afe9["EpollDatagramChannel"]
  5d8b824f_1d60_b1ed_e124_4f2179ce144c -->|defined in| dab3c3bb_b3e2_f3b8_e8e0_37c99496afe9
  daa0830e_c1a5_555e_b994_3e9c10904a12["isConnected()"]
  5d8b824f_1d60_b1ed_e124_4f2179ce144c -->|calls| daa0830e_c1a5_555e_b994_3e9c10904a12
  b105a0f5_23fa_a7fb_ac82_23b3039c4e43["doWriteMessage()"]
  5d8b824f_1d60_b1ed_e124_4f2179ce144c -->|calls| b105a0f5_23fa_a7fb_ac82_23b3039c4e43
  style 5d8b824f_1d60_b1ed_e124_4f2179ce144c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

transport-classes-epoll/src/main/java/io/netty/channel/epoll/EpollDatagramChannel.java lines 364–430

    @Override
    protected void doWrite(ChannelOutboundBuffer in) throws Exception {
        int maxMessagesPerWrite = maxMessagesPerWrite();
        while (maxMessagesPerWrite > 0) {
            Object msg = in.current();
            if (msg == null) {
                // Wrote all messages.
                break;
            }

            try {
                // Check if sendmmsg(...) is supported which is only the case for GLIBC 2.14+
                if (Native.IS_SUPPORTING_SENDMMSG && in.size() > 1 ||
                        // We only handle UDP_SEGMENT in sendmmsg.
                        in.current() instanceof io.netty.channel.unix.SegmentedDatagramPacket) {
                    NativeDatagramPacketArray array = cleanDatagramPacketArray();
                    array.add(in, isConnected(), maxMessagesPerWrite);
                    int cnt = array.count();

                    if (cnt >= 1) {
                        // Try to use gathering writes via sendmmsg(...) syscall.
                        int offset = 0;
                        NativeDatagramPacketArray.NativeDatagramPacket[] packets = array.packets();

                        int send = socket.sendmmsg(packets, offset, cnt);
                        if (send == 0) {
                            // Did not write all messages.
                            break;
                        }
                        for (int i = 0; i < send; i++) {
                            in.remove();
                        }
                        maxMessagesPerWrite -= send;
                        continue;
                    }
                }
                boolean done = false;
                for (int i = config().getWriteSpinCount(); i > 0; --i) {
                    if (doWriteMessage(msg)) {
                        done = true;
                        break;
                    }
                }

                if (done) {
                    in.remove();
                    maxMessagesPerWrite --;
                } else {
                    break;
                }
            } catch (IOException e) {
                maxMessagesPerWrite --;
                // Continue on write error as a DatagramChannel can write to multiple remote peers
                //
                // See https://github.com/netty/netty/issues/2665
                in.remove(e);
            }
        }

        if (in.isEmpty()) {
            // Did write all messages.
            clearFlag(Native.EPOLLOUT);
        } else {
            // Did not write all messages.
            setFlag(Native.EPOLLOUT);
        }
    }

Domain

Subdomains

Frequently Asked Questions

What does doWrite() do?
doWrite() is a function in the netty codebase, defined in transport-classes-epoll/src/main/java/io/netty/channel/epoll/EpollDatagramChannel.java.
Where is doWrite() defined?
doWrite() is defined in transport-classes-epoll/src/main/java/io/netty/channel/epoll/EpollDatagramChannel.java at line 364.
What does doWrite() call?
doWrite() calls 2 function(s): doWriteMessage, isConnected.

Analyze Your Own Codebase

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

Try Supermodel Free