Class Socket

Direct Known Subclasses:
BsdSocket, LinuxSocket

public class Socket extends FileDescriptor
Provides a JNI bridge to native socket operations. Internal usage only!
  • Field Details

    • isIpv6Preferred

      private static volatile boolean isIpv6Preferred
    • UDS_SUN_PATH_SIZE

      @Deprecated public static final int UDS_SUN_PATH_SIZE
      Deprecated.
      See Also:
    • ipv6

      protected final boolean ipv6
  • Constructor Details

    • Socket

      public Socket(int fd)
  • Method Details

    • useIpv6

      private boolean useIpv6(InetAddress address)
      Returns true if we should use IPv6 internally, false otherwise.
    • useIpv6

      protected static boolean useIpv6(Socket socket, InetAddress address)
      Returns true if the given socket and address combination should use IPv6 internally, false otherwise.
    • shutdown

      public final void shutdown() throws IOException
      Throws:
      IOException
    • shutdown

      public final void shutdown(boolean read, boolean write) throws IOException
      Throws:
      IOException
    • isShutdown

      public final boolean isShutdown()
    • isInputShutdown

      public final boolean isInputShutdown()
    • isOutputShutdown

      public final boolean isOutputShutdown()
    • sendTo

      public final int sendTo(ByteBuffer buf, int pos, int limit, InetAddress addr, int port) throws IOException
      Throws:
      IOException
    • sendTo

      public final int sendTo(ByteBuffer buf, int pos, int limit, InetAddress addr, int port, boolean fastOpen) throws IOException
      Throws:
      IOException
    • sendToDomainSocket

      public final int sendToDomainSocket(ByteBuffer buf, int pos, int limit, byte[] path) throws IOException
      Throws:
      IOException
    • sendToAddress

      public final int sendToAddress(long memoryAddress, int pos, int limit, InetAddress addr, int port) throws IOException
      Throws:
      IOException
    • sendToAddress

      public final int sendToAddress(long memoryAddress, int pos, int limit, InetAddress addr, int port, boolean fastOpen) throws IOException
      Throws:
      IOException
    • sendToAddressDomainSocket

      public final int sendToAddressDomainSocket(long memoryAddress, int pos, int limit, byte[] path) throws IOException
      Throws:
      IOException
    • sendToAddresses

      public final int sendToAddresses(long memoryAddress, int length, InetAddress addr, int port) throws IOException
      Throws:
      IOException
    • sendToAddresses

      public final int sendToAddresses(long memoryAddress, int length, InetAddress addr, int port, boolean fastOpen) throws IOException
      Throws:
      IOException
    • sendToAddressesDomainSocket

      public final int sendToAddressesDomainSocket(long memoryAddress, int length, byte[] path) throws IOException
      Throws:
      IOException
    • recvFrom

      public final DatagramSocketAddress recvFrom(ByteBuffer buf, int pos, int limit) throws IOException
      Throws:
      IOException
    • recvFromAddress

      public final DatagramSocketAddress recvFromAddress(long memoryAddress, int pos, int limit) throws IOException
      Throws:
      IOException
    • recvFromDomainSocket

      public final DomainDatagramSocketAddress recvFromDomainSocket(ByteBuffer buf, int pos, int limit) throws IOException
      Throws:
      IOException
    • recvFromAddressDomainSocket

      public final DomainDatagramSocketAddress recvFromAddressDomainSocket(long memoryAddress, int pos, int limit) throws IOException
      Throws:
      IOException
    • recv

      public int recv(ByteBuffer buf, int pos, int limit) throws IOException
      Throws:
      IOException
    • recvAddress

      public int recvAddress(long address, int pos, int limit) throws IOException
      Throws:
      IOException
    • send

      public int send(ByteBuffer buf, int pos, int limit) throws IOException
      Throws:
      IOException
    • sendAddress

      public int sendAddress(long address, int pos, int limit) throws IOException
      Throws:
      IOException
    • recvFd

      public final int recvFd() throws IOException
      Throws:
      IOException
    • sendFd

      public final int sendFd(int fdToSend) throws IOException
      Throws:
      IOException
    • connect

      public final boolean connect(SocketAddress socketAddress) throws IOException
      Throws:
      IOException
    • finishConnect

      public final boolean finishConnect() throws IOException
      Throws:
      IOException
    • disconnect

      public final void disconnect() throws IOException
      Throws:
      IOException
    • bind

      public final void bind(SocketAddress socketAddress) throws IOException
      Throws:
      IOException
    • listen

      public final void listen(int backlog) throws IOException
      Throws:
      IOException
    • accept

      public final int accept(byte[] addr) throws IOException
      Throws:
      IOException
    • remoteAddress

      public final InetSocketAddress remoteAddress()
    • remoteDomainSocketAddress

      public final DomainSocketAddress remoteDomainSocketAddress()
    • localAddress

      public final InetSocketAddress localAddress()
    • localDomainSocketAddress

      public final DomainSocketAddress localDomainSocketAddress()
    • getReceiveBufferSize

      public final int getReceiveBufferSize() throws IOException
      Throws:
      IOException
    • getSendBufferSize

      public final int getSendBufferSize() throws IOException
      Throws:
      IOException
    • isKeepAlive

      public final boolean isKeepAlive() throws IOException
      Throws:
      IOException
    • isTcpNoDelay

      public final boolean isTcpNoDelay() throws IOException
      Throws:
      IOException
    • isReuseAddress

      public final boolean isReuseAddress() throws IOException
      Throws:
      IOException
    • isReusePort

      public final boolean isReusePort() throws IOException
      Throws:
      IOException
    • isBroadcast

      public final boolean isBroadcast() throws IOException
      Throws:
      IOException
    • getSoLinger

      public final int getSoLinger() throws IOException
      Throws:
      IOException
    • getSoError

      public final int getSoError() throws IOException
      Throws:
      IOException
    • getTrafficClass

      public final int getTrafficClass() throws IOException
      Throws:
      IOException
    • setKeepAlive

      public final void setKeepAlive(boolean keepAlive) throws IOException
      Throws:
      IOException
    • setReceiveBufferSize

      public final void setReceiveBufferSize(int receiveBufferSize) throws IOException
      Throws:
      IOException
    • setSendBufferSize

      public final void setSendBufferSize(int sendBufferSize) throws IOException
      Throws:
      IOException
    • setTcpNoDelay

      public final void setTcpNoDelay(boolean tcpNoDelay) throws IOException
      Throws:
      IOException
    • setSoLinger

      public final void setSoLinger(int soLinger) throws IOException
      Throws:
      IOException
    • setReuseAddress

      public final void setReuseAddress(boolean reuseAddress) throws IOException
      Throws:
      IOException
    • setReusePort

      public final void setReusePort(boolean reusePort) throws IOException
      Throws:
      IOException
    • setBroadcast

      public final void setBroadcast(boolean broadcast) throws IOException
      Throws:
      IOException
    • setTrafficClass

      public final void setTrafficClass(int trafficClass) throws IOException
      Throws:
      IOException
    • setIntOpt

      public void setIntOpt(int level, int optname, int optvalue) throws IOException
      Throws:
      IOException
    • setRawOpt

      public void setRawOpt(int level, int optname, ByteBuffer optvalue) throws IOException
      Throws:
      IOException
    • getIntOpt

      public int getIntOpt(int level, int optname) throws IOException
      Throws:
      IOException
    • getRawOpt

      public void getRawOpt(int level, int optname, ByteBuffer out) throws IOException
      Throws:
      IOException
    • isIPv6Preferred

      public static boolean isIPv6Preferred()
    • shouldUseIpv6

      public static boolean shouldUseIpv6(InternetProtocolFamily family)
    • isIPv6Preferred0

      private static boolean isIPv6Preferred0(boolean ipv4Preferred)
    • isIPv6

      private static boolean isIPv6(int fd)
    • toString

      public String toString()
      Overrides:
      toString in class FileDescriptor
    • newSocketStream

      public static Socket newSocketStream()
    • newSocketDgram

      public static Socket newSocketDgram()
    • newSocketDomain

      public static Socket newSocketDomain()
    • newSocketDomainDgram

      public static Socket newSocketDomainDgram()
    • initialize

      public static void initialize()
    • newSocketStream0

      protected static int newSocketStream0()
    • newSocketStream0

      protected static int newSocketStream0(InternetProtocolFamily protocol)
    • newSocketStream0

      protected static int newSocketStream0(boolean ipv6)
    • newSocketDgram0

      protected static int newSocketDgram0()
    • newSocketDgram0

      protected static int newSocketDgram0(InternetProtocolFamily family)
    • newSocketDgram0

      protected static int newSocketDgram0(boolean ipv6)
    • newSocketDomain0

      protected static int newSocketDomain0()
    • newSocketDomainDgram0

      protected static int newSocketDomainDgram0()
    • shutdown

      private static int shutdown(int fd, boolean read, boolean write)
    • connect

      private static int connect(int fd, boolean ipv6, byte[] address, int scopeId, int port)
    • connectDomainSocket

      private static int connectDomainSocket(int fd, byte[] path)
    • finishConnect

      private static int finishConnect(int fd)
    • disconnect

      private static int disconnect(int fd, boolean ipv6)
    • bind

      private static int bind(int fd, boolean ipv6, byte[] address, int scopeId, int port)
    • bindDomainSocket

      private static int bindDomainSocket(int fd, byte[] path)
    • listen

      private static int listen(int fd, int backlog)
    • accept

      private static int accept(int fd, byte[] addr)
    • remoteAddress

      private static byte[] remoteAddress(int fd)
    • remoteDomainSocketAddress

      private static byte[] remoteDomainSocketAddress(int fd)
    • localAddress

      private static byte[] localAddress(int fd)
    • localDomainSocketAddress

      private static byte[] localDomainSocketAddress(int fd)
    • send

      private static int send(int fd, ByteBuffer buf, int pos, int limit)
    • sendAddress

      private static int sendAddress(int fd, long address, int pos, int limit)
    • recv

      private static int recv(int fd, ByteBuffer buf, int pos, int limit)
    • recvAddress

      private static int recvAddress(int fd, long address, int pos, int limit)
    • sendTo

      private static int sendTo(int fd, boolean ipv6, ByteBuffer buf, int pos, int limit, byte[] address, int scopeId, int port, int flags)
    • sendToAddress

      private static int sendToAddress(int fd, boolean ipv6, long memoryAddress, int pos, int limit, byte[] address, int scopeId, int port, int flags)
    • sendToAddresses

      private static int sendToAddresses(int fd, boolean ipv6, long memoryAddress, int length, byte[] address, int scopeId, int port, int flags)
    • sendToDomainSocket

      private static int sendToDomainSocket(int fd, ByteBuffer buf, int pos, int limit, byte[] path)
    • sendToAddressDomainSocket

      private static int sendToAddressDomainSocket(int fd, long memoryAddress, int pos, int limit, byte[] path)
    • sendToAddressesDomainSocket

      private static int sendToAddressesDomainSocket(int fd, long memoryAddress, int length, byte[] path)
    • recvFrom

      private static DatagramSocketAddress recvFrom(int fd, ByteBuffer buf, int pos, int limit) throws IOException
      Throws:
      IOException
    • recvFromAddress

      private static DatagramSocketAddress recvFromAddress(int fd, long memoryAddress, int pos, int limit) throws IOException
      Throws:
      IOException
    • recvFromDomainSocket

      private static DomainDatagramSocketAddress recvFromDomainSocket(int fd, ByteBuffer buf, int pos, int limit) throws IOException
      Throws:
      IOException
    • recvFromAddressDomainSocket

      private static DomainDatagramSocketAddress recvFromAddressDomainSocket(int fd, long memoryAddress, int pos, int limit) throws IOException
      Throws:
      IOException
    • recvFd

      private static int recvFd(int fd)
    • sendFd

      private static int sendFd(int socketFd, int fd)
    • msgFastopen

      private static int msgFastopen()
    • newSocketStreamFd

      private static int newSocketStreamFd(boolean ipv6)
    • newSocketDgramFd

      private static int newSocketDgramFd(boolean ipv6)
    • newSocketDomainFd

      private static int newSocketDomainFd()
    • newSocketDomainDgramFd

      private static int newSocketDomainDgramFd()
    • isReuseAddress

      private static int isReuseAddress(int fd) throws IOException
      Throws:
      IOException
    • isReusePort

      private static int isReusePort(int fd) throws IOException
      Throws:
      IOException
    • getReceiveBufferSize

      private static int getReceiveBufferSize(int fd) throws IOException
      Throws:
      IOException
    • getSendBufferSize

      private static int getSendBufferSize(int fd) throws IOException
      Throws:
      IOException
    • isKeepAlive

      private static int isKeepAlive(int fd) throws IOException
      Throws:
      IOException
    • isTcpNoDelay

      private static int isTcpNoDelay(int fd) throws IOException
      Throws:
      IOException
    • isBroadcast

      private static int isBroadcast(int fd) throws IOException
      Throws:
      IOException
    • getSoLinger

      private static int getSoLinger(int fd) throws IOException
      Throws:
      IOException
    • getSoError

      private static int getSoError(int fd) throws IOException
      Throws:
      IOException
    • getTrafficClass

      private static int getTrafficClass(int fd, boolean ipv6) throws IOException
      Throws:
      IOException
    • setReuseAddress

      private static void setReuseAddress(int fd, int reuseAddress) throws IOException
      Throws:
      IOException
    • setReusePort

      private static void setReusePort(int fd, int reuseAddress) throws IOException
      Throws:
      IOException
    • setKeepAlive

      private static void setKeepAlive(int fd, int keepAlive) throws IOException
      Throws:
      IOException
    • setReceiveBufferSize

      private static void setReceiveBufferSize(int fd, int receiveBufferSize) throws IOException
      Throws:
      IOException
    • setSendBufferSize

      private static void setSendBufferSize(int fd, int sendBufferSize) throws IOException
      Throws:
      IOException
    • setTcpNoDelay

      private static void setTcpNoDelay(int fd, int tcpNoDelay) throws IOException
      Throws:
      IOException
    • setSoLinger

      private static void setSoLinger(int fd, int soLinger) throws IOException
      Throws:
      IOException
    • setBroadcast

      private static void setBroadcast(int fd, int broadcast) throws IOException
      Throws:
      IOException
    • setTrafficClass

      private static void setTrafficClass(int fd, boolean ipv6, int trafficClass) throws IOException
      Throws:
      IOException
    • setIntOpt

      private static void setIntOpt(int fd, int level, int optname, int optvalue) throws IOException
      Throws:
      IOException
    • setRawOptArray

      private static void setRawOptArray(int fd, int level, int optname, byte[] optvalue, int offset, int length) throws IOException
      Throws:
      IOException
    • setRawOptAddress

      private static void setRawOptAddress(int fd, int level, int optname, long optvalueMemoryAddress, int length) throws IOException
      Throws:
      IOException
    • getIntOpt

      private static int getIntOpt(int fd, int level, int optname) throws IOException
      Throws:
      IOException
    • getRawOptArray

      private static void getRawOptArray(int fd, int level, int optname, byte[] out, int offset, int length) throws IOException
      Throws:
      IOException
    • getRawOptAddress

      private static void getRawOptAddress(int fd, int level, int optname, long outMemoryAddress, int length) throws IOException
      Throws:
      IOException