Class SecureNio2Channel

    • Field Detail

      • sniComplete

        protected volatile boolean sniComplete
      • closed

        protected boolean closed
      • closing

        protected boolean closing
    • Method Detail

      • free

        public void free()
        Description copied from class: Nio2Channel
        Free the channel memory
        Overrides:
        free in class Nio2Channel
      • flush

        public Future<Boolean> flush()
        Flush the channel.
        Overrides:
        flush in class Nio2Channel
        Returns:
        true if the network buffer has been flushed out and is empty else false (as a future)
      • handshake

        public int handshake()
                      throws IOException
        Performs SSL handshake, non blocking, but performs NEED_TASK on the same thread. Hence, you should never call this method using your Acceptor thread, as you would slow down your system significantly.

        The return for this operation is 0 if the handshake is complete and a positive value if it is not complete. In the event of a positive value coming back, the appropriate read/write will already have been called with an appropriate CompletionHandler.

        Overrides:
        handshake in class Nio2Channel
        Returns:
        0 if hand shake is complete, negative if the socket needs to close and positive if the handshake is incomplete
        Throws:
        IOException - if an error occurs during the handshake
      • handshakeInternal

        protected int handshakeInternal​(boolean async)
                                 throws IOException
        Throws:
        IOException
      • rehandshake

        public void rehandshake()
                         throws IOException
        Force a blocking handshake to take place for this key. This requires that both network and application buffers have been emptied out prior to this call taking place, or a IOException will be thrown.
        Throws:
        IOException - - if an IO exception occurs or if application or network buffers contain data
        SocketTimeoutException - - if a socket operation timed out
      • getSSLSupport

        public SSLSupport getSSLSupport()
      • close

        public void close()
                   throws IOException
        Sends an SSL close message, will not physically close the connection here.
        To close the connection, you could do something like
        
           close();
           while (isOpen() && !myTimeoutFunction()) Thread.sleep(25);
           if ( isOpen() ) close(true); //forces a close if you timed out
         
        Specified by:
        close in interface AsynchronousChannel
        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface Channel
        Specified by:
        close in interface Closeable
        Overrides:
        close in class Nio2Channel
        Throws:
        IOException - if an I/O error occurs
        IOException - if there is data on the outgoing network buffer and we are unable to flush it
      • close

        public void close​(boolean force)
                   throws IOException
        Description copied from class: Nio2Channel
        Close the connection.
        Overrides:
        close in class Nio2Channel
        Parameters:
        force - Should the underlying socket be forcibly closed?
        Throws:
        IOException - If closing the secure channel fails.
      • read

        public Future<Integer> read​(ByteBuffer dst)
        Reads a sequence of bytes from this channel into the given buffer.
        Specified by:
        read in interface AsynchronousByteChannel
        Overrides:
        read in class Nio2Channel
        Parameters:
        dst - The buffer into which bytes are to be transferred
        Returns:
        The number of bytes read, possibly zero, or -1 if the channel has reached end-of-stream
        Throws:
        IllegalStateException - if the handshake was not completed
      • write

        public Future<Integer> write​(ByteBuffer src)
        Writes a sequence of bytes to this channel from the given buffer.
        Specified by:
        write in interface AsynchronousByteChannel
        Overrides:
        write in class Nio2Channel
        Parameters:
        src - The buffer from which bytes are to be retrieved
        Returns:
        The number of bytes written, possibly zero
      • getSslEngine

        public SSLEngine getSslEngine()