Home / Function/ doWrite() — netty Function Reference

doWrite() — netty Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  c8293004_868c_58d4_b6db_89847c10f0c1["doWrite()"]
  81a44f54_ab3c_5f8b_4522_05c91e5f8eb8["LocalChannel"]
  c8293004_868c_58d4_b6db_89847c10f0c1 -->|defined in| 81a44f54_ab3c_5f8b_4522_05c91e5f8eb8
  19db0fc8_1524_a49b_2c8e_8b165b94bc06["close()"]
  c8293004_868c_58d4_b6db_89847c10f0c1 -->|calls| 19db0fc8_1524_a49b_2c8e_8b165b94bc06
  2c83511c_fc90_29cc_5eaa_7b360efc3314["finishPeerRead()"]
  c8293004_868c_58d4_b6db_89847c10f0c1 -->|calls| 2c83511c_fc90_29cc_5eaa_7b360efc3314
  style c8293004_868c_58d4_b6db_89847c10f0c1 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

transport/src/main/java/io/netty/channel/local/LocalChannel.java lines 370–418

    @Override
    protected void doWrite(ChannelOutboundBuffer in) throws Exception {
        switch (state) {
        case OPEN:
        case BOUND:
            throw new NotYetConnectedException();
        case CLOSED:
            throw new ClosedChannelException();
        case CONNECTED:
            break;
        }

        final LocalChannel peer = this.peer;

        writeInProgress = true;
        try {
            ClosedChannelException exception = null;
            for (;;) {
                Object msg = in.current();
                if (msg == null) {
                    break;
                }
                try {
                    // It is possible the peer could have closed while we are writing, and in this case we should
                    // simulate real socket behavior and ensure the write operation is failed.
                    if (peer.state == State.CONNECTED) {
                        peer.inboundBuffer.add(ReferenceCountUtil.retain(msg));
                        in.remove();
                    } else {
                        if (exception == null) {
                            exception = new ClosedChannelException();
                        }
                        in.remove(exception);
                    }
                } catch (Throwable cause) {
                    in.remove(cause);
                }
            }
        } finally {
            // The following situation may cause trouble:
            // 1. Write (with promise X)
            // 2. promise X is completed when in.remove() is called, and a listener on this promise calls close()
            // 3. Then the close event will be executed for the peer before the write events, when the write events
            // actually happened before the close event.
            writeInProgress = false;
        }

        finishPeerRead(peer);
    }

Domain

Subdomains

Frequently Asked Questions

What does doWrite() do?
doWrite() is a function in the netty codebase, defined in transport/src/main/java/io/netty/channel/local/LocalChannel.java.
Where is doWrite() defined?
doWrite() is defined in transport/src/main/java/io/netty/channel/local/LocalChannel.java at line 370.
What does doWrite() call?
doWrite() calls 2 function(s): close, finishPeerRead.

Analyze Your Own Codebase

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

Try Supermodel Free