Home / Class/ SocketWritableByteChannel Class — netty Architecture

SocketWritableByteChannel Class — netty Architecture

Architecture documentation for the SocketWritableByteChannel class in SocketWritableByteChannel.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  2e653143_58bc_5790_e74f_93557dafe856["SocketWritableByteChannel"]
  0c608708_ee4b_b9b5_5702_df3320f5bb14["SocketWritableByteChannel.java"]
  2e653143_58bc_5790_e74f_93557dafe856 -->|defined in| 0c608708_ee4b_b9b5_5702_df3320f5bb14
  ca2033ab_fb29_0c3a_7334_da2d09ad521c["SocketWritableByteChannel()"]
  2e653143_58bc_5790_e74f_93557dafe856 -->|method| ca2033ab_fb29_0c3a_7334_da2d09ad521c
  6891e97f_1b2d_eac2_7ce6_8e1768f588a9["write()"]
  2e653143_58bc_5790_e74f_93557dafe856 -->|method| 6891e97f_1b2d_eac2_7ce6_8e1768f588a9
  46bf455a_5632_ccf3_41ec_450d3e4d190a["isOpen()"]
  2e653143_58bc_5790_e74f_93557dafe856 -->|method| 46bf455a_5632_ccf3_41ec_450d3e4d190a
  7f91bf0c_053a_0a82_ed2f_f9f3bf4ca8ef["close()"]
  2e653143_58bc_5790_e74f_93557dafe856 -->|method| 7f91bf0c_053a_0a82_ed2f_f9f3bf4ca8ef
  6d9d44a4_4b7a_7ed0_9d11_3006b987889b["ByteBufAllocator()"]
  2e653143_58bc_5790_e74f_93557dafe856 -->|method| 6d9d44a4_4b7a_7ed0_9d11_3006b987889b

Relationship Graph

Source Code

transport-native-unix-common/src/main/java/io/netty/channel/unix/SocketWritableByteChannel.java lines 25–86

public abstract class SocketWritableByteChannel implements WritableByteChannel {
    protected final FileDescriptor fd;

    protected SocketWritableByteChannel(FileDescriptor fd) {
        this.fd = ObjectUtil.checkNotNull(fd, "fd");
    }

    protected int write(ByteBuffer buf, int pos, int limit) throws IOException {
        return fd.write(buf, pos, limit);
    }

    @Override
    public final int write(java.nio.ByteBuffer src) throws java.io.IOException {
        final int written;
        int position = src.position();
        int limit = src.limit();
        if (src.isDirect()) {
            written = write(src, position, src.limit());
        } else {
            final int readableBytes = limit - position;
            io.netty.buffer.ByteBuf buffer = null;
            try {
                if (readableBytes == 0) {
                    buffer = io.netty.buffer.Unpooled.EMPTY_BUFFER;
                } else {
                    final ByteBufAllocator alloc = alloc();
                    if (alloc.isDirectBufferPooled()) {
                        buffer = alloc.directBuffer(readableBytes);
                    } else {
                        buffer = io.netty.buffer.ByteBufUtil.threadLocalDirectBuffer();
                        if (buffer == null) {
                            buffer = io.netty.buffer.Unpooled.directBuffer(readableBytes);
                        }
                    }
                }
                buffer.writeBytes(src.duplicate());
                java.nio.ByteBuffer nioBuffer = buffer.internalNioBuffer(buffer.readerIndex(), readableBytes);
                written = write(nioBuffer, nioBuffer.position(), nioBuffer.limit());
            } finally {
                if (buffer != null) {
                    buffer.release();
                }
            }
        }
        if (written > 0) {
            src.position(position + written);
        }
        return written;
    }

    @Override
    public final boolean isOpen() {
        return fd.isOpen();
    }

    @Override
    public final void close() throws java.io.IOException {
        fd.close();
    }

    protected abstract ByteBufAllocator alloc();
}

Frequently Asked Questions

What is the SocketWritableByteChannel class?
SocketWritableByteChannel is a class in the netty codebase, defined in transport-native-unix-common/src/main/java/io/netty/channel/unix/SocketWritableByteChannel.java.
Where is SocketWritableByteChannel defined?
SocketWritableByteChannel is defined in transport-native-unix-common/src/main/java/io/netty/channel/unix/SocketWritableByteChannel.java at line 25.

Analyze Your Own Codebase

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

Try Supermodel Free