Class AprSocket

  • All Implemented Interfaces:
    java.lang.Runnable

    public class AprSocket
    extends java.lang.Object
    implements java.lang.Runnable
    Native socket, using JNI + APR + openssl. The socket is non-blocking - you can register either a blocking or non blocking callback. There is no explicit method to register/unregister poll interest - it is done automatically, when read/write methods return 0. To keep the socket polling you must read all the available data, until read() returns 0. If you want to pause - don't read all input. To resume - read again until it returns 0. Same for write - when write() returns 0 the socket is registered for write interest. You can also use the blocking read/write methods.
    • Method Detail

      • recycle

        public void recycle()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • setNonBlocking

        private void setNonBlocking()
      • isPolling

        public boolean isPolling()
        Check if the socket is currently registered with a poller.
      • connect

        public void connect()
                     throws java.io.IOException
        Throws:
        java.io.IOException
      • afterConnect

        void afterConnect()
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • write

        public int write​(byte[] data,
                         int off,
                         int len,
                         long to)
                  throws java.io.IOException
        Write as much data as possible to the socket.
        Parameters:
        data -
        off -
        len -
        Returns:
        For both blocking and non-blocking, returns the number of bytes written. If no data can be written (e.g. if the buffers are full) 0 will be returned.
        Throws:
        java.io.IOException
      • write

        public int write​(byte[] data,
                         int off,
                         int len)
                  throws java.io.IOException
        Throws:
        java.io.IOException
      • writeInternal

        private int writeInternal​(byte[] data,
                                  int off,
                                  int len)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] data,
                        int off,
                        int len,
                        long to)
                 throws java.io.IOException
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] data,
                        int off,
                        int len)
                 throws java.io.IOException
        Throws:
        java.io.IOException
      • processReadResult

        private int processReadResult​(byte[] data,
                                      int off,
                                      int len,
                                      int read)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • readNB

        public int readNB​(byte[] data,
                          int off,
                          int len)
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • close

        public void close()
      • maybeDestroy

        void maybeDestroy()
      • reset

        public void reset()
        Close input and output, potentially sending RST, than close the socket. The proper way to close when gracefully done is by calling writeEnd() and reading all remaining input until -1 (EOF) is received. If EOF is received, the proper way to close is send whatever is remaining and call writeEnd();
      • isClosed

        public boolean isClosed()
      • getIOTimeout

        public long getIOTimeout()
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • getPeerCert

        public byte[][] getPeerCert​(boolean check)
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • getPeerX509Cert

        public java.security.cert.X509Certificate[] getPeerX509Cert()
                                                             throws java.io.IOException
        Throws:
        java.io.IOException
      • getCipherSuite

        public java.lang.String getCipherSuite()
                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • getKeySize

        public int getKeySize()
                       throws java.io.IOException
        Throws:
        java.io.IOException
      • getRemotePort

        public int getRemotePort()
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • getRemoteAddress

        public java.lang.String getRemoteAddress()
                                          throws java.io.IOException
        Throws:
        java.io.IOException
      • getRemoteHostname

        public java.lang.String getRemoteHostname()
                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • getLocalPort

        public int getLocalPort()
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • getLocalAddress

        public java.lang.String getLocalAddress()
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • getLocalHostname

        public java.lang.String getLocalHostname()
                                          throws java.io.IOException
        Throws:
        java.io.IOException
      • isBlocking

        public boolean isBlocking()
      • isError

        public boolean isError()
      • notifyError

        void notifyError​(java.lang.Throwable err,
                         boolean needsThread)
      • notifyIO

        void notifyIO()
               throws java.io.IOException
        Throws:
        java.io.IOException
      • notifyConnected

        private void notifyConnected​(boolean server)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • updatePolling

        private void updatePolling()
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • run

        public void run()
        Specified by:
        run in interface java.lang.Runnable
      • blockingStartTLS

        public void blockingStartTLS()
                              throws java.io.IOException
        This is a blocking call ! ( can be made non-blocking, but too complex ) Will be called automatically after connect() or accept if 'secure' is true. Can be called manually to upgrade the channel
        Throws:
        java.io.IOException
      • handshakeDone

        private void handshakeDone()
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • requestedPolling

        int requestedPolling()
      • checkBitAndSocket

        boolean checkBitAndSocket​(int bit)
      • checkPreConnect

        boolean checkPreConnect​(int bit)
      • clearStatus

        void clearStatus​(int bit)
      • setStatus

        boolean setStatus​(int bit)