Class AprSocket

  • All Implemented Interfaces:
    Runnable

    public class AprSocket
    extends Object
    implements 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()
      • isPolling

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

        public int write​(byte[] data,
                         int off,
                         int len,
                         long to)
                  throws 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:
        IOException
      • read

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

        public void close()
      • 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()
      • isBlocking

        public boolean isBlocking()
      • isError

        public boolean isError()
      • run

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

        public void blockingStartTLS()
                              throws 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:
        IOException