Class Nio2Endpoint.Nio2SocketWrapper

    • Method Detail

      • read

        public int read​(boolean block,
                        byte[] b,
                        int off,
                        int len)
                 throws java.io.IOException
        Specified by:
        read in class SocketWrapperBase<Nio2Channel>
        Throws:
        java.io.IOException
      • read

        public int read​(boolean block,
                        java.nio.ByteBuffer to)
                 throws java.io.IOException
        Specified by:
        read in class SocketWrapperBase<Nio2Channel>
        Throws:
        java.io.IOException
      • writeNonBlocking

        protected void writeNonBlocking​(byte[] buf,
                                        int off,
                                        int len)
                                 throws java.io.IOException
        Transfers the data to the socket write buffer (writing that data to the socket if the buffer fills up using a non-blocking write) until either all the data has been transferred and space remains in the socket write buffer or a non-blocking write leaves data in the socket write buffer. After an incomplete write, any data remaining to be transferred to the socket write buffer will be copied to the socket write buffer. If the remaining data is too big for the socket write buffer, the socket write buffer will be filled and the additional data written to the non-blocking write buffer.

        Overridden for NIO2 to enable a gathering write to be used to write all of the remaining data in a single additional write should a non-blocking write leave data in the buffer.

        Overrides:
        writeNonBlocking in class SocketWrapperBase<Nio2Channel>
        Parameters:
        buf - The byte array containing the data to be written
        off - The offset within the byte array of the data to be written
        len - The length of the data to be written
        Throws:
        java.io.IOException - If an IO error occurs during the write
      • writeNonBlocking

        protected void writeNonBlocking​(java.nio.ByteBuffer from)
                                 throws java.io.IOException
        Transfers the data to the socket write buffer (writing that data to the socket if the buffer fills up using a non-blocking write) until either all the data has been transferred and space remains in the socket write buffer or a non-blocking write leaves data in the socket write buffer. After an incomplete write, any data remaining to be transferred to the socket write buffer will be copied to the socket write buffer. If the remaining data is too big for the socket write buffer, the socket write buffer will be filled and the additional data written to the non-blocking write buffer.

        Overridden for NIO2 to enable a gathering write to be used to write all of the remaining data in a single additional write should a non-blocking write leave data in the buffer.

        Overrides:
        writeNonBlocking in class SocketWrapperBase<Nio2Channel>
        Parameters:
        from - The ByteBuffer containing the data to be written
        Throws:
        java.io.IOException - If an IO error occurs during the write
      • writeNonBlockingInternal

        protected void writeNonBlockingInternal​(java.nio.ByteBuffer from)
                                         throws java.io.IOException
        Separate method so it can be re-used by the socket write buffer to write data to the network

        Overridden for NIO2 to enable a gathering write to be used to write all of the remaining data in a single additional write should a non-blocking write leave data in the buffer.

        Overrides:
        writeNonBlockingInternal in class SocketWrapperBase<Nio2Channel>
        Parameters:
        from - The ByteBuffer containing the data to be written
        Throws:
        java.io.IOException - If an IO error occurs during the write
      • doWrite

        protected void doWrite​(boolean block,
                               java.nio.ByteBuffer from)
                        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<Nio2Channel>
        Parameters:
        block - Ignored since this method is only called in the blocking case
        from - 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
      • flushBlocking

        protected void flushBlocking()
                              throws java.io.IOException
        Description copied from class: SocketWrapperBase
        Writes all remaining data from the buffers and blocks until the write is complete.
        Overrides:
        flushBlocking in class SocketWrapperBase<Nio2Channel>
        Throws:
        java.io.IOException - If an IO error occurs during the write
      • flushNonBlocking

        protected boolean flushNonBlocking()
                                    throws java.io.IOException
        Description copied from class: SocketWrapperBase
        Writes as much data as possible from any that remains in the buffers.
        Specified by:
        flushNonBlocking in class SocketWrapperBase<Nio2Channel>
        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
      • isReadPending

        public boolean isReadPending()
        Description copied from class: SocketWrapperBase
        Allows checking if an asynchronous read operation is currently pending.
        Overrides:
        isReadPending in class SocketWrapperBase<Nio2Channel>
        Returns:
        true if the endpoint supports asynchronous IO and a read operation is being processed asynchronously
      • isWritePending

        public boolean isWritePending()
        Description copied from class: SocketWrapperBase
        Allows checking if an asynchronous write operation is currently pending.
        Overrides:
        isWritePending in class SocketWrapperBase<Nio2Channel>
        Returns:
        true if the endpoint supports asynchronous IO and a write operation is being processed asynchronously
      • 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<Nio2Channel>
        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<Nio2Channel>
        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