Home / Class/ Socket Class — netty Architecture

Socket Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  c1db2c0c_ff79_5334_3102_02a56efa545c["Socket"]
  168a4629_be82_d960_455d_22212da17114["Socket.java"]
  c1db2c0c_ff79_5334_3102_02a56efa545c -->|defined in| 168a4629_be82_d960_455d_22212da17114
  e74eaf71_6af3_e7fb_1697_ec27c6e1ba6e["Socket()"]
  c1db2c0c_ff79_5334_3102_02a56efa545c -->|method| e74eaf71_6af3_e7fb_1697_ec27c6e1ba6e
  12e44c1a_7b43_2eff_41e9_0e1fbbb204fc["useIpv6()"]
  c1db2c0c_ff79_5334_3102_02a56efa545c -->|method| 12e44c1a_7b43_2eff_41e9_0e1fbbb204fc
  0318ab46_0607_9eba_b942_9234c54fef93["shutdown()"]
  c1db2c0c_ff79_5334_3102_02a56efa545c -->|method| 0318ab46_0607_9eba_b942_9234c54fef93
  7559c5e1_1680_8579_7ab1_2e0442eef682["isShutdown()"]
  c1db2c0c_ff79_5334_3102_02a56efa545c -->|method| 7559c5e1_1680_8579_7ab1_2e0442eef682
  0c46b448_3102_da0b_d492_a8e591d60c1b["isInputShutdown()"]
  c1db2c0c_ff79_5334_3102_02a56efa545c -->|method| 0c46b448_3102_da0b_d492_a8e591d60c1b
  b8111b9b_3cbc_f278_637a_b9e78f9d3df0["isOutputShutdown()"]
  c1db2c0c_ff79_5334_3102_02a56efa545c -->|method| b8111b9b_3cbc_f278_637a_b9e78f9d3df0
  35c2483d_a778_f44a_d78c_d2eef3460def["sendTo()"]
  c1db2c0c_ff79_5334_3102_02a56efa545c -->|method| 35c2483d_a778_f44a_d78c_d2eef3460def
  c6f705d8_a073_c032_f6e4_3b609cf383c1["sendToDomainSocket()"]
  c1db2c0c_ff79_5334_3102_02a56efa545c -->|method| c6f705d8_a073_c032_f6e4_3b609cf383c1
  e8f7ee3b_3307_2b56_0615_27a77f744de6["sendToAddress()"]
  c1db2c0c_ff79_5334_3102_02a56efa545c -->|method| e8f7ee3b_3307_2b56_0615_27a77f744de6
  4474bbcb_1525_e6e6_d352_32b40d1edbab["sendToAddressDomainSocket()"]
  c1db2c0c_ff79_5334_3102_02a56efa545c -->|method| 4474bbcb_1525_e6e6_d352_32b40d1edbab
  f6219bc7_a2c1_cb4d_2b99_06f53c87d092["sendToAddresses()"]
  c1db2c0c_ff79_5334_3102_02a56efa545c -->|method| f6219bc7_a2c1_cb4d_2b99_06f53c87d092
  b0562efb_7970_229c_0b05_d79c965941c7["sendToAddressesDomainSocket()"]
  c1db2c0c_ff79_5334_3102_02a56efa545c -->|method| b0562efb_7970_229c_0b05_d79c965941c7
  195f6673_7a65_85fb_16fd_8f64d61e6b4a["DatagramSocketAddress()"]
  c1db2c0c_ff79_5334_3102_02a56efa545c -->|method| 195f6673_7a65_85fb_16fd_8f64d61e6b4a

Relationship Graph

Source Code

transport-native-unix-common/src/main/java/io/netty/channel/unix/Socket.java lines 48–752

public class Socket extends FileDescriptor {

    private static volatile boolean isIpv6Preferred;

    @Deprecated
    public static final int UDS_SUN_PATH_SIZE = 100;

    protected final boolean ipv6;

    public Socket(int fd) {
        super(fd);
        ipv6 = isIPv6(fd);
    }
    /**
     * Returns {@code true} if we should use IPv6 internally, {@code false} otherwise.
     */
    private boolean useIpv6(InetAddress address) {
        return useIpv6(this, address);
    }

    /**
     * Returns {@code true} if the given socket and address combination should use IPv6 internally,
     * {@code false} otherwise.
     */
    protected static boolean useIpv6(Socket socket, InetAddress address) {
        return socket.ipv6 || address instanceof Inet6Address;
    }

    public final void shutdown() throws IOException {
        shutdown(true, true);
    }

    public final void shutdown(boolean read, boolean write) throws IOException {
        for (;;) {
            // We need to only shutdown what has not been shutdown yet, and if there is no change we should not
            // shutdown anything. This is because if the underlying FD is reused and we still have an object which
            // represents the previous incarnation of the FD we need to be sure we don't inadvertently shutdown the
            // "new" FD without explicitly having a change.
            final int oldState = state;
            if (isClosed(oldState)) {
                throw new ClosedChannelException();
            }
            int newState = oldState;
            if (read && !isInputShutdown(newState)) {
                newState = inputShutdown(newState);
            }
            if (write && !isOutputShutdown(newState)) {
                newState = outputShutdown(newState);
            }

            // If there is no change in state, then we should not take any action.
            if (newState == oldState) {
                return;
            }
            if (casState(oldState, newState)) {
                break;
            }
        }
        int res = shutdown(fd, read, write);
        if (res < 0) {
            ioResult("shutdown", res);
        }
    }

    public final boolean isShutdown() {
        int state = this.state;
        return isInputShutdown(state) && isOutputShutdown(state);
    }

    public final boolean isInputShutdown() {
        return isInputShutdown(state);
    }

    public final boolean isOutputShutdown() {
        return isOutputShutdown(state);
    }

    public final int sendTo(ByteBuffer buf, int pos, int limit, InetAddress addr, int port) throws IOException {
        return sendTo(buf, pos, limit, addr, port, false);
    }

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free