Class NioEndpoint.NioSocketWrapper

    • Constructor Detail

      • NioSocketWrapper

        public NioSocketWrapper​(NioChannel channel,
                                NioEndpoint endpoint)
        Creates a new NIO socket wrapper.
        Parameters:
        channel - The NIO channel
        endpoint - The NIO endpoint
    • Method Detail

      • getPoller

        public NioEndpoint.Poller getPoller()
        Returns the poller.
        Returns:
        the poller
      • interestOps

        public int interestOps()
        Returns the current interest operations.
        Returns:
        the interest operations
      • interestOps

        public int interestOps​(int ops)
        Sets the interest operations.
        Parameters:
        ops - the interest operations
        Returns:
        the interest operations
      • interestOpsHas

        public boolean interestOpsHas​(int targetOp)
        Checks if a specific interest operation is set.
        Parameters:
        targetOp - the operation to check
        Returns:
        true if the target operation is set
      • setSendfileData

        public void setSendfileData​(NioEndpoint.SendfileData sf)
        Sets the sendfile data.
        Parameters:
        sf - the sendfile data
      • getSendfileData

        public NioEndpoint.SendfileData getSendfileData()
        Returns the sendfile data.
        Returns:
        the sendfile data
      • updateLastWrite

        public void updateLastWrite()
        Updates the last write timestamp.
      • getLastWrite

        public long getLastWrite()
        Returns the last write timestamp.
        Returns:
        the last write time in milliseconds
      • updateLastRead

        public void updateLastRead()
        Updates the last read timestamp.
      • getLastRead

        public long getLastRead()
        Returns the last read timestamp.
        Returns:
        the last read time in milliseconds
      • isReadyForRead

        public boolean isReadyForRead()
                               throws java.io.IOException
        Description copied from class: SocketWrapperBase
        Checks if the socket is ready for reading.
        Specified by:
        isReadyForRead in class SocketWrapperBase<NioChannel>
        Returns:
        true if data is available to read
        Throws:
        java.io.IOException - If an I/O error occurs
      • read

        public int read​(boolean block,
                        byte[] b,
                        int off,
                        int len)
                 throws java.io.IOException
        Description copied from class: SocketWrapperBase
        Reads data from the socket into a byte array.
        Specified by:
        read in class SocketWrapperBase<NioChannel>
        Parameters:
        block - Whether to block
        b - The byte array to read into
        off - The offset in the array
        len - The number of bytes to read
        Returns:
        the number of bytes read
        Throws:
        java.io.IOException - If an I/O error occurs
      • read

        public int read​(boolean block,
                        java.nio.ByteBuffer to)
                 throws java.io.IOException
        Description copied from class: SocketWrapperBase
        Reads data from the socket into a ByteBuffer.
        Specified by:
        read in class SocketWrapperBase<NioChannel>
        Parameters:
        block - Whether to block
        to - The ByteBuffer to read into
        Returns:
        the number of bytes read
        Throws:
        java.io.IOException - If an I/O error occurs
      • doClose

        protected void doClose()
        Description copied from class: SocketWrapperBase
        Perform the actual close. The closed atomic boolean guarantees this will be called only once per wrapper.
        Specified by:
        doClose in class SocketWrapperBase<NioChannel>
      • flushNonBlocking

        protected boolean flushNonBlocking()
                                    throws java.io.IOException
        Description copied from class: SocketWrapperBase
        Flushes remaining buffered data using a non-blocking write.
        Specified by:
        flushNonBlocking in class SocketWrapperBase<NioChannel>
        Returns:
        true if data remains to be flushed after this method completes, otherwise false
        Throws:
        java.io.IOException - If an IO error occurs during the write
      • canWrite

        public boolean canWrite()
        Description copied from class: SocketWrapperBase
        Checks if the socket write buffer is writable and there is no pending non-blocking write data.
        Overrides:
        canWrite in class SocketWrapperBase<NioChannel>
        Returns:
        true if the socket is ready for writing
      • doWrite

        protected void doWrite​(boolean block,
                               java.nio.ByteBuffer buffer)
                        throws java.io.IOException
        Description copied from class: SocketWrapperBase
        Write the contents of the ByteBuffer to the socket. For blocking writes either then entire contents of the buffer will be written or an IOException will be thrown. Partial blocking writes will not occur.
        Specified by:
        doWrite in class SocketWrapperBase<NioChannel>
        Parameters:
        block - Should the write be blocking or not?
        buffer - the ByteBuffer containing the data to be written
        Throws:
        java.io.IOException - If an I/O error such as a timeout occurs during the write
      • createSendfileData

        public SendfileDataBase createSendfileData​(java.lang.String filename,
                                                   long pos,
                                                   long length)
        Description copied from class: SocketWrapperBase
        Creates a sendfile data object for the specified file.
        Specified by:
        createSendfileData in class SocketWrapperBase<NioChannel>
        Parameters:
        filename - The file to send
        pos - The starting position in the file
        length - The number of bytes to send
        Returns:
        a new sendfile data object
      • processSendfile

        public SendfileState processSendfile​(SendfileDataBase sendfileData)
        Description copied from class: SocketWrapperBase
        Starts the sendfile process. It is expected that if the sendfile process does not complete during this call and does not report an error, that the caller will not add the socket to the poller (or equivalent). That is the responsibility of this method.
        Specified by:
        processSendfile in class SocketWrapperBase<NioChannel>
        Parameters:
        sendfileData - Data representing the file to send
        Returns:
        The state of the sendfile process after the first write.
      • doClientAuth

        public void doClientAuth​(SSLSupport sslSupport)
                          throws java.io.IOException
        Description copied from class: SocketWrapperBase
        Require the client to perform CLIENT-CERT authentication if it hasn't already done so.
        Specified by:
        doClientAuth in class SocketWrapperBase<NioChannel>
        Parameters:
        sslSupport - The SSL/TLS support instance currently being used by the connection that may need updating after the client authentication
        Throws:
        java.io.IOException - If authentication is required then there will be I/O with the client and this exception will be thrown if that goes wrong
      • newOperationState

        protected <A> SocketWrapperBase.OperationState<A> newOperationState​(boolean read,
                                                                            java.nio.ByteBuffer[] buffers,
                                                                            int offset,
                                                                            int length,
                                                                            SocketWrapperBase.BlockingMode block,
                                                                            long timeout,
                                                                            java.util.concurrent.TimeUnit unit,
                                                                            A attachment,
                                                                            SocketWrapperBase.CompletionCheck check,
                                                                            java.nio.channels.CompletionHandler<java.lang.Long,​? super A> handler,
                                                                            java.util.concurrent.Semaphore semaphore,
                                                                            SocketWrapperBase.VectoredIOCompletionHandler<A> completion)
        Description copied from class: SocketWrapperBase
        Creates a new operation state for vectored I/O operations.
        Specified by:
        newOperationState in class SocketWrapperBase<NioChannel>
        Type Parameters:
        A - The attachment type
        Parameters:
        read - Whether this is a read operation
        buffers - The buffers for the operation
        offset - The offset in the buffer array
        length - The number of buffers
        block - The blocking mode
        timeout - The timeout duration
        unit - The timeout time unit
        attachment - An attachment object
        check - The completion check
        handler - The completion handler
        semaphore - The semaphore for synchronization
        completion - The vectored I/O completion handler
        Returns:
        a new operation state instance