Class BsdSocket


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

      • FREEBSD_SND_LOW_AT_MAX

        private static final int FREEBSD_SND_LOW_AT_MAX
        See Also:
        Constant Field Values
      • 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:
        Constant Field Values
    • Constructor Detail

      • BsdSocket

        BsdSocket​(int fd)
    • Method Detail

      • setAcceptFilter

        void setAcceptFilter​(AcceptFilter acceptFilter)
                      throws java.io.IOException
        Throws:
        java.io.IOException
      • setTcpNoPush

        void setTcpNoPush​(boolean tcpNoPush)
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • setSndLowAt

        void setSndLowAt​(int lowAt)
                  throws java.io.IOException
        Throws:
        java.io.IOException
      • setTcpFastOpen

        public void setTcpFastOpen​(boolean enableTcpFastOpen)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • isTcpNoPush

        boolean isTcpNoPush()
                     throws java.io.IOException
        Throws:
        java.io.IOException
      • getSndLowAt

        int getSndLowAt()
                 throws java.io.IOException
        Throws:
        java.io.IOException
      • getAcceptFilter

        AcceptFilter getAcceptFilter()
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • isTcpFastOpen

        public boolean isTcpFastOpen()
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • getPeerCredentials

        PeerCredentials getPeerCredentials()
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • sendFile

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

        int connectx​(java.net.InetSocketAddress source,
                     java.net.InetSocketAddress destination,
                     IovArray data,
                     boolean tcpFastOpen)
              throws java.io.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:
        java.io.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()
      • newSocketDgram

        public static BsdSocket newSocketDgram()
      • 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 java.io.IOException
        Throws:
        java.io.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 java.lang.String[] getAcceptFilter​(int fd)
                                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • getTcpNoPush

        private static int getTcpNoPush​(int fd)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • getSndLowAt

        private static int getSndLowAt​(int fd)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • isTcpFastOpen

        private static int isTcpFastOpen​(int fd)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • getPeerCredentials

        private static PeerCredentials getPeerCredentials​(int fd)
                                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • setAcceptFilter

        private static void setAcceptFilter​(int fd,
                                            java.lang.String filterName,
                                            java.lang.String filterArgs)
                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • setTcpNoPush

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

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

        private static void setTcpFastOpen​(int fd,
                                           int enableFastOpen)
                                    throws java.io.IOException
        Throws:
        java.io.IOException