Package one.nio.net

Class NativeSocket

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, java.nio.channels.ByteChannel, java.nio.channels.Channel, java.nio.channels.ReadableByteChannel, java.nio.channels.WritableByteChannel
    Direct Known Subclasses:
    NativeSslSocket

    class NativeSocket
    extends Socket
    • Field Detail

      • INET_FAMILY

        private static final int INET_FAMILY
      • ARRAY_FIELD

        private static final long ARRAY_FIELD
      • OFFSET_FIELD

        private static final long OFFSET_FIELD
      • fd

        int fd
    • Constructor Detail

      • NativeSocket

        NativeSocket​(int domain,
                     int type)
              throws java.io.IOException
        Throws:
        java.io.IOException
      • NativeSocket

        NativeSocket​(int fd)
    • Method Detail

      • isOpen

        public final boolean isOpen()
        Specified by:
        isOpen in interface java.nio.channels.Channel
        Specified by:
        isOpen in class Socket
      • accept

        public NativeSocket accept()
                            throws java.io.IOException
        Specified by:
        accept in class Socket
        Throws:
        java.io.IOException
      • getLocalAddress

        public final java.net.InetSocketAddress getLocalAddress()
        Specified by:
        getLocalAddress in class Socket
      • getRemoteAddress

        public final java.net.InetSocketAddress getRemoteAddress()
        Specified by:
        getRemoteAddress in class Socket
      • sslWrap

        public Socket sslWrap​(SslContext context)
                       throws java.io.IOException
        Specified by:
        sslWrap in class Socket
        Throws:
        java.io.IOException
      • connect

        public void connect​(java.net.InetAddress address,
                            int port)
                     throws java.io.IOException
        Specified by:
        connect in class Socket
        Throws:
        java.io.IOException
      • connect

        public void connect​(java.lang.String host,
                            int port)
                     throws java.io.IOException
        Overrides:
        connect in class Socket
        Throws:
        java.io.IOException
      • bind

        public void bind​(java.net.InetAddress address,
                         int port,
                         int backlog)
                  throws java.io.IOException
        Specified by:
        bind in class Socket
        Throws:
        java.io.IOException
      • bind

        public void bind​(java.lang.String host,
                         int port,
                         int backlog)
                  throws java.io.IOException
        Overrides:
        bind in class Socket
        Throws:
        java.io.IOException
      • listen

        public void listen​(int backlog)
                    throws java.io.IOException
        Specified by:
        listen in class Socket
        Throws:
        java.io.IOException
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.nio.channels.Channel
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in class Socket
      • writeRaw

        public int writeRaw​(long buf,
                            int count,
                            int flags)
                     throws java.io.IOException
        Specified by:
        writeRaw in class Socket
        Throws:
        java.io.IOException
      • send

        public int send​(java.nio.ByteBuffer src,
                        int flags,
                        java.net.InetAddress address,
                        int port)
                 throws java.io.IOException
        Specified by:
        send in class Socket
        Throws:
        java.io.IOException
      • send

        public int send​(java.nio.ByteBuffer data,
                        int flags,
                        java.lang.String host,
                        int port)
                 throws java.io.IOException
        Overrides:
        send in class Socket
        Throws:
        java.io.IOException
      • sendTo

        private int sendTo​(java.nio.ByteBuffer src,
                           int flags,
                           java.lang.Object address,
                           int port)
                    throws java.io.IOException
        Throws:
        java.io.IOException
      • getArray

        private byte[] getArray​(java.nio.ByteBuffer src)
                         throws java.lang.IllegalAccessException
        Throws:
        java.lang.IllegalAccessException
      • getOffset

        private int getOffset​(java.nio.ByteBuffer src)
                       throws java.lang.IllegalAccessException
        Throws:
        java.lang.IllegalAccessException
      • write

        public int write​(byte[] data,
                         int offset,
                         int count,
                         int flags)
                  throws java.io.IOException
        Specified by:
        write in class Socket
        Throws:
        java.io.IOException
      • writeFully

        public void writeFully​(byte[] data,
                               int offset,
                               int count)
                        throws java.io.IOException
        Specified by:
        writeFully in class Socket
        Throws:
        java.io.IOException
      • readRaw

        public int readRaw​(long buf,
                           int count,
                           int flags)
                    throws java.io.IOException
        Specified by:
        readRaw in class Socket
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] data,
                        int offset,
                        int count,
                        int flags)
                 throws java.io.IOException
        Specified by:
        read in class Socket
        Throws:
        java.io.IOException
      • recv

        public java.net.InetSocketAddress recv​(java.nio.ByteBuffer dst,
                                               int flags)
                                        throws java.io.IOException
        Specified by:
        recv in class Socket
        Throws:
        java.io.IOException
      • readFully

        public void readFully​(byte[] data,
                              int offset,
                              int count)
                       throws java.io.IOException
        Specified by:
        readFully in class Socket
        Throws:
        java.io.IOException
      • sendFile

        public long sendFile​(java.io.RandomAccessFile file,
                             long offset,
                             long count)
                      throws java.io.IOException
        Specified by:
        sendFile in class Socket
        Throws:
        java.io.IOException
      • read

        public int read​(java.nio.ByteBuffer dst)
                 throws java.io.IOException
        Throws:
        java.io.IOException
      • write

        public int write​(java.nio.ByteBuffer src)
                  throws java.io.IOException
        Throws:
        java.io.IOException
      • sendMsg

        public int sendMsg​(Msg msg,
                           int flags)
                    throws java.io.IOException
        Specified by:
        sendMsg in class Socket
        Throws:
        java.io.IOException
      • recvMsg

        public int recvMsg​(Msg msg,
                           int flags)
                    throws java.io.IOException
        Specified by:
        recvMsg in class Socket
        Throws:
        java.io.IOException
      • setBlocking

        public final void setBlocking​(boolean blocking)
        Specified by:
        setBlocking in class Socket
      • isBlocking

        public final boolean isBlocking()
        Specified by:
        isBlocking in class Socket
      • setTimeout

        public final void setTimeout​(int timeout)
        Specified by:
        setTimeout in class Socket
      • getTimeout

        public final int getTimeout()
        Specified by:
        getTimeout in class Socket
      • setKeepAlive

        public final void setKeepAlive​(boolean keepAlive)
        Specified by:
        setKeepAlive in class Socket
      • getKeepAlive

        public final boolean getKeepAlive()
        Specified by:
        getKeepAlive in class Socket
      • setNoDelay

        public final void setNoDelay​(boolean noDelay)
        Specified by:
        setNoDelay in class Socket
      • getNoDelay

        public final boolean getNoDelay()
        Specified by:
        getNoDelay in class Socket
      • setTcpFastOpen

        public final void setTcpFastOpen​(boolean tcpFastOpen)
        Specified by:
        setTcpFastOpen in class Socket
      • getTcpFastOpen

        public final boolean getTcpFastOpen()
        Specified by:
        getTcpFastOpen in class Socket
      • setDeferAccept

        public final void setDeferAccept​(boolean deferAccept)
        Specified by:
        setDeferAccept in class Socket
      • getDeferAccept

        public final boolean getDeferAccept()
        Specified by:
        getDeferAccept in class Socket
      • setReuseAddr

        public final void setReuseAddr​(boolean reuseAddr,
                                       boolean reusePort)
        Specified by:
        setReuseAddr in class Socket
      • getReuseAddr

        public final boolean getReuseAddr()
        Specified by:
        getReuseAddr in class Socket
      • getReusePort

        public final boolean getReusePort()
        Specified by:
        getReusePort in class Socket
      • setRecvBuffer

        public final void setRecvBuffer​(int recvBuf)
        Specified by:
        setRecvBuffer in class Socket
      • getRecvBuffer

        public final int getRecvBuffer()
        Specified by:
        getRecvBuffer in class Socket
      • setSendBuffer

        public final void setSendBuffer​(int sendBuf)
        Specified by:
        setSendBuffer in class Socket
      • getSendBuffer

        public final int getSendBuffer()
        Specified by:
        getSendBuffer in class Socket
      • setTos

        public final void setTos​(int tos)
        Specified by:
        setTos in class Socket
      • getTos

        public final int getTos()
        Specified by:
        getTos in class Socket
      • setNotsentLowat

        public final void setNotsentLowat​(int lowat)
        Overrides:
        setNotsentLowat in class Socket
      • setThinLinearTimeouts

        public final void setThinLinearTimeouts​(boolean thinLto)
        Overrides:
        setThinLinearTimeouts in class Socket
      • getOption

        public byte[] getOption​(int level,
                                int option)
        Specified by:
        getOption in class Socket
      • setOption

        public boolean setOption​(int level,
                                 int option,
                                 byte[] value)
        Specified by:
        setOption in class Socket
      • toNativeAddr

        static java.lang.Object toNativeAddr​(java.lang.String host,
                                             int port)
                                      throws java.net.UnknownHostException
        Throws:
        java.net.UnknownHostException
      • initNatives

        private static int initNatives​(boolean preferIPv4)
      • socket0

        private static int socket0​(int domain,
                                   int type)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • connect0

        final void connect0​(java.lang.Object address,
                            int port)
                     throws java.io.IOException
        Throws:
        java.io.IOException
      • bind0

        final void bind0​(java.lang.Object address,
                         int port)
                  throws java.io.IOException
        Throws:
        java.io.IOException
      • accept0

        final int accept0​(boolean nonblock)
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • sendFile0

        long sendFile0​(int sourceFD,
                       long offset,
                       long count)
                throws java.io.IOException
        Throws:
        java.io.IOException
      • sendTo0

        final int sendTo0​(byte[] data,
                          int offset,
                          int size,
                          int flags,
                          java.lang.Object address,
                          int port)
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • sendTo1

        final int sendTo1​(long buf,
                          int size,
                          int flags,
                          java.lang.Object address,
                          int port)
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • recvFrom0

        final int recvFrom0​(byte[] data,
                            int offset,
                            int maxSize,
                            int flags,
                            AddressHolder holder)
                     throws java.io.IOException
        Throws:
        java.io.IOException
      • recvFrom1

        final int recvFrom1​(long buf,
                            int maxSize,
                            int flags,
                            AddressHolder holder)
                     throws java.io.IOException
        Throws:
        java.io.IOException
      • sendMsg0

        final int sendMsg0​(byte[] data,
                           int cmsgType,
                           int[] cmsgData,
                           int flags)
                    throws java.io.IOException
        Throws:
        java.io.IOException
      • recvMsg0

        final int recvMsg0​(byte[] data,
                           Msg msg,
                           int flags)
                    throws java.io.IOException
        Throws:
        java.io.IOException