Class BsdSocket


final class BsdSocket extends Socket
A socket which provides access BSD native methods.
  • Field Details

    • APPLE_SND_LOW_AT_MAX

      private static final int APPLE_SND_LOW_AT_MAX
      See Also:
    • FREEBSD_SND_LOW_AT_MAX

      private static final int FREEBSD_SND_LOW_AT_MAX
      See Also:
    • BSD_SND_LOW_AT_MAX

      static final int BSD_SND_LOW_AT_MAX
    • UNSPECIFIED_SOURCE_INTERFACE

      private static final int UNSPECIFIED_SOURCE_INTERFACE
      The `endpoints` structure passed to `connectx(2)` has an optional "source interface" field, which is the index of the network interface to use. According to `if_nametoindex(3)`, the value 0 is used when no interface is specified.
      See Also:
  • Constructor Details

    • BsdSocket

      BsdSocket(int fd)
  • Method Details

    • setAcceptFilter

      void setAcceptFilter(AcceptFilter acceptFilter) throws IOException
      Throws:
      IOException
    • setTcpNoPush

      void setTcpNoPush(boolean tcpNoPush) throws IOException
      Throws:
      IOException
    • setSndLowAt

      void setSndLowAt(int lowAt) throws IOException
      Throws:
      IOException
    • setTcpFastOpen

      public void setTcpFastOpen(boolean enableTcpFastOpen) throws IOException
      Throws:
      IOException
    • isTcpNoPush

      boolean isTcpNoPush() throws IOException
      Throws:
      IOException
    • getSndLowAt

      int getSndLowAt() throws IOException
      Throws:
      IOException
    • getAcceptFilter

      AcceptFilter getAcceptFilter() throws IOException
      Throws:
      IOException
    • isTcpFastOpen

      public boolean isTcpFastOpen() throws IOException
      Throws:
      IOException
    • getPeerCredentials

      PeerCredentials getPeerCredentials() throws IOException
      Throws:
      IOException
    • sendFile

      long sendFile(DefaultFileRegion src, long baseOffset, long offset, long length) throws IOException
      Throws:
      IOException
    • connectx

      int connectx(InetSocketAddress source, InetSocketAddress destination, IovArray data, boolean tcpFastOpen) throws IOException
      Establish a connection to the given destination address, and send the given data to it. Note: This method relies on the connectx(2) system call, which is MacOS specific.
      Parameters:
      source - the source address we are connecting from.
      destination - the destination address we are connecting to.
      data - the data to copy to the kernel-side socket buffer.
      tcpFastOpen - if true, set the flags needed to enable TCP FastOpen connecting.
      Returns:
      The number of bytes copied to the kernel-side socket buffer, or the number of bytes sent to the destination. This number is negative if connecting is left in an in-progress state, or positive if the connection was immediately established.
      Throws:
      IOException - if an IO error occurs, if the data is too big to send in one go, or if the system call is not supported on your platform.
    • newSocketStream

      public static BsdSocket newSocketStream()
    • newSocketStream

      public static BsdSocket newSocketStream(InternetProtocolFamily protocol)
    • newSocketDgram

      public static BsdSocket newSocketDgram()
    • newSocketDgram

      public static BsdSocket newSocketDgram(InternetProtocolFamily protocol)
    • newSocketDomain

      public static BsdSocket newSocketDomain()
    • newSocketDomainDgram

      public static BsdSocket newSocketDomainDgram()
    • sendFile

      private static long sendFile(int socketFd, DefaultFileRegion src, long baseOffset, long offset, long length) throws IOException
      Throws:
      IOException
    • connectx

      private static int connectx(int socketFd, int sourceInterface, boolean sourceIPv6, byte[] sourceAddress, int sourceScopeId, int sourcePort, boolean destinationIPv6, byte[] destinationAddress, int destinationScopeId, int destinationPort, int flags, long iovAddress, int iovCount, int iovDataLength)
      Returns:
      If successful, zero or positive number of bytes transfered, otherwise negative errno.
    • getAcceptFilter

      private static String[] getAcceptFilter(int fd) throws IOException
      Throws:
      IOException
    • getTcpNoPush

      private static int getTcpNoPush(int fd) throws IOException
      Throws:
      IOException
    • getSndLowAt

      private static int getSndLowAt(int fd) throws IOException
      Throws:
      IOException
    • isTcpFastOpen

      private static int isTcpFastOpen(int fd) throws IOException
      Throws:
      IOException
    • getPeerCredentials

      private static PeerCredentials getPeerCredentials(int fd) throws IOException
      Throws:
      IOException
    • setAcceptFilter

      private static void setAcceptFilter(int fd, String filterName, String filterArgs) throws IOException
      Throws:
      IOException
    • setTcpNoPush

      private static void setTcpNoPush(int fd, int tcpNoPush) throws IOException
      Throws:
      IOException
    • setSndLowAt

      private static void setSndLowAt(int fd, int lowAt) throws IOException
      Throws:
      IOException
    • setTcpFastOpen

      private static void setTcpFastOpen(int fd, int enableFastOpen) throws IOException
      Throws:
      IOException