Nio2Endpoint.Nio2SocketWrapper (Apache Tomcat 8.5.12 API Documentation)

org.apache.tomcat.util.net

## Class Nio2Endpoint.Nio2SocketWrapper

- java.lang.Object
- - org.apache.tomcat.util.net.SocketWrapperBase<Nio2Channel>
  - - org.apache.tomcat.util.net.Nio2Endpoint.Nio2SocketWrapper

- Enclosing class:
    Nio2Endpoint

      public static class Nio2Endpoint.Nio2SocketWrapper
      extends SocketWrapperBase<Nio2Channel>

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.apache.tomcat.util.net.SocketWrapperBase

      `SocketWrapperBase.CompletionCheck, SocketWrapperBase.CompletionHandlerCall, SocketWrapperBase.CompletionState`

  - ### Field Summary

    - ### Fields inherited from class org.apache.tomcat.util.net.SocketWrapperBase

      `bufferedWrites, bufferedWriteSize, COMPLETE_WRITE, localAddr, localName, localPort, READ_DATA, remoteAddr, remoteHost, remotePort, sm, socketBufferHandler`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Nio2Endpoint.Nio2SocketWrapper(Nio2Channel channel, Nio2Endpoint endpoint)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `awaitBytes()`
    `boolean` | `awaitReadComplete(long timeout, TimeUnit unit)` If an asynchronous read operation is pending, this method will block until the operation completes, or the specified amount of time has passed.
    `boolean` | `awaitWriteComplete(long timeout, TimeUnit unit)` If an asynchronous write operation is pending, this method will block until the operation completes, or the specified amount of time has passed.
    `void` | `close()`
    `SendfileDataBase` | `createSendfileData(String filename, long pos, long length)`
    `void` | `doClientAuth(SSLSupport sslSupport)` Require the client to perform CLIENT-CERT authentication if it hasn't already done so.
    `protected void` | `doWrite(boolean block, ByteBuffer from)` Write the contents of the ByteBuffer to the socket.
    `protected void` | `flushBlocking()`
    `protected boolean` | `flushNonBlocking()`
    `Nio2Endpoint.SendfileData` | `getSendfileData()`
    `SSLSupport` | `getSslSupport(String clientCertProvider)`
    `boolean` | `hasAsyncIO()` Allows using NIO2 style read/write only for connectors that can efficiently support it.
    `boolean` | `hasDataToWrite()`
    `boolean` | `isClosed()`
    `boolean` | `isReadPending()` Allows checking if an asynchronous read operation is currently pending.
    `boolean` | `isReadyForRead()`
    `boolean` | `isWritePending()` Allows checking if an asynchronous write operation is currently pending.
    `protected void` | `populateLocalAddr()`
    `protected void` | `populateLocalName()`
    `protected void` | `populateLocalPort()`
    `protected void` | `populateRemoteAddr()`
    `protected void` | `populateRemoteHost()`
    `protected void` | `populateRemotePort()`
    `SendfileState` | `processSendfile(SendfileDataBase sendfileData)` Starts the sendfile process.
    `int` | `read(boolean block, byte[] b, int off, int len)`
    `int` | `read(boolean block, ByteBuffer to)`
    `<A> SocketWrapperBase.CompletionState` | `read(ByteBuffer[] dsts, int offset, int length, boolean block, long timeout, TimeUnit unit, A attachment, SocketWrapperBase.CompletionCheck check, CompletionHandler<Long,? super A> handler)` Scatter read.
    `void` | `registerReadInterest()`
    `void` | `registerWriteInterest()`
    `void` | `setAppReadBufHandler(ApplicationBufferHandler handler)`
    `void` | `setSendfileData(Nio2Endpoint.SendfileData sf)`
    `<A> SocketWrapperBase.CompletionState` | `write(ByteBuffer[] srcs, int offset, int length, boolean block, long timeout, TimeUnit unit, A attachment, SocketWrapperBase.CompletionCheck check, CompletionHandler<Long,? super A> handler)` Gather write.
    `protected void` | `writeNonBlocking(byte[] buf, int off, int len)` 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.
    `protected void` | `writeNonBlocking(ByteBuffer from)` Writes the data to the socket (writing that data to the socket 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.

    - ### Methods inherited from class org.apache.tomcat.util.net.SocketWrapperBase

      `addToBuffers, addToBuffers, canWrite, checkError, decrementKeepAlive, doWrite, flush, getBlockingStatus, getBlockingStatusReadLock, getBlockingStatusWriteLock, getEndpoint, getError, getLocalAddr, getLocalName, getLocalPort, getNegotiatedProtocol, getReadTimeout, getRemoteAddr, getRemoteHost, getRemotePort, getSocket, getSocketBufferHandler, getWriteTimeout, isReadyForWrite, isSecure, isUpgraded, populateReadBuffer, populateReadBuffer, processSocket, read, setBlockingStatus, setError, setKeepAliveLeft, setNegotiatedProtocol, setReadTimeout, setSecure, setUpgraded, setWriteTimeout, toString, transfer, transfer, unRead, write, write, write, writeBlocking, writeBlocking, writeByteBufferBlocking, writeByteBufferNonBlocking`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### Nio2Endpoint.Nio2SocketWrapper

          public Nio2Endpoint.Nio2SocketWrapper(Nio2Channel channel,
                                        Nio2Endpoint endpoint)

  - ### Method Detail

    - #### setSendfileData

          public void setSendfileData(Nio2Endpoint.SendfileData sf)

    - #### getSendfileData

          public Nio2Endpoint.SendfileData getSendfileData()

    - #### isReadyForRead

          public boolean isReadyForRead()
                                 throws IOException

      Specified by:
        `isReadyForRead` in class `SocketWrapperBase<Nio2Channel>`
      Throws:
        `IOException`

    - #### read

          public int read(boolean block,
                 byte[] b,
                 int off,
                 int len)
                   throws IOException

      Specified by:
        `read` in class `SocketWrapperBase<Nio2Channel>`
      Throws:
        `IOException`

    - #### read

          public int read(boolean block,
                 ByteBuffer to)
                   throws IOException

      Specified by:
        `read` in class `SocketWrapperBase<Nio2Channel>`
      Throws:
        `IOException`

    - #### close

          public void close()
                     throws IOException

      Specified by:
        `close` in class `SocketWrapperBase<Nio2Channel>`
      Throws:
        `IOException`

    - #### isClosed

          public boolean isClosed()

      Specified by:
        `isClosed` in class `SocketWrapperBase<Nio2Channel>`

    - #### hasAsyncIO

          public boolean hasAsyncIO()

      Description copied from class: `SocketWrapperBase`
      Allows using NIO2 style read/write only for connectors that can efficiently support it.
      Overrides:
        `hasAsyncIO` in class `SocketWrapperBase<Nio2Channel>`
      Returns:
        This default implementation always returns `false`

    - #### read

          public <A> SocketWrapperBase.CompletionState read(ByteBuffer[] dsts,
                                                   int offset,
                                                   int length,
                                                   boolean block,
                                                   long timeout,
                                                   TimeUnit unit,
                                                   A attachment,
                                                   SocketWrapperBase.CompletionCheck check,
                                                   CompletionHandler<Long,? super A> handler)

      Description copied from class: `SocketWrapperBase`
      Scatter read. The completion handler will be called once some data has been read or an error occurred. If a CompletionCheck object has been provided, the completion handler will only be called if the callHandler method returned true. If no CompletionCheck object has been provided, the default NIO2 behavior is used: the completion handler will be called as soon as some data has been read, even if the read has completed inline.
      Overrides:
        `read` in class `SocketWrapperBase<Nio2Channel>`
      Type Parameters:
        `A` - The attachment type
      Parameters:
        `dsts` - buffers
        `offset` - in the buffer array
        `length` - in the buffer array
        `block` - true to block until any pending read is done, if the timeout occurs and a read is still pending, a ReadPendingException will be thrown; false to not block but any pending read operation will cause a ReadPendingException
        `timeout` - timeout duration for the read
        `unit` - units for the timeout duration
        `attachment` - an object to attach to the I/O operation that will be used when calling the completion handler
        `check` - for the IO operation completion
        `handler` - to call when the IO is complete
      Returns:
        the completion state (done, done inline, or still pending)

    - #### 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

    - #### write

          public <A> SocketWrapperBase.CompletionState write(ByteBuffer[] srcs,
                                                    int offset,
                                                    int length,
                                                    boolean block,
                                                    long timeout,
                                                    TimeUnit unit,
                                                    A attachment,
                                                    SocketWrapperBase.CompletionCheck check,
                                                    CompletionHandler<Long,? super A> handler)

      Description copied from class: `SocketWrapperBase`
      Gather write. The completion handler will be called once some data has been written or an error occurred. If a CompletionCheck object has been provided, the completion handler will only be called if the callHandler method returned true. If no CompletionCheck object has been provided, the default NIO2 behavior is used: the completion handler will be called, even if the write is incomplete and data remains in the buffers, or if the write completed inline.
      Overrides:
        `write` in class `SocketWrapperBase<Nio2Channel>`
      Type Parameters:
        `A` - The attachment type
      Parameters:
        `srcs` - buffers
        `offset` - in the buffer array
        `length` - in the buffer array
        `block` - true to block until any pending write is done, if the timeout occurs and a write is still pending, a WritePendingException will be thrown; false to not block but any pending write operation will cause a WritePendingException
        `timeout` - timeout duration for the write
        `unit` - units for the timeout duration
        `attachment` - an object to attach to the I/O operation that will be used when calling the completion handler
        `check` - for the IO operation completion
        `handler` - to call when the IO is complete
      Returns:
        the completion state (done, done inline, or still pending)

    - #### writeNonBlocking

          protected void writeNonBlocking(byte[] buf,
                              int off,
                              int len)
                                   throws 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.

      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:
        `IOException` - If an IO error occurs during the write

    - #### writeNonBlocking

          protected void writeNonBlocking(ByteBuffer from)
                                   throws IOException

      Writes the data to the socket (writing that data to the socket 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. If it is possible use the provided buffer directly and do not transfer to the socket 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:
        `IOException` - If an IO error occurs during the write

    - #### doWrite

          protected void doWrite(boolean block,
                     ByteBuffer from)
                          throws 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:
        `IOException` - If an I/O error such as a timeout occurs during the write

    - #### flushBlocking

          protected void flushBlocking()
                                throws IOException

      Overrides:
        `flushBlocking` in class `SocketWrapperBase<Nio2Channel>`
      Throws:
        `IOException`

    - #### flushNonBlocking

          protected boolean flushNonBlocking()
                                      throws IOException

      Overrides:
        `flushNonBlocking` in class `SocketWrapperBase<Nio2Channel>`
      Throws:
        `IOException`

    - #### hasDataToWrite

          public boolean hasDataToWrite()

      Overrides:
        `hasDataToWrite` in class `SocketWrapperBase<Nio2Channel>`

    - #### 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

    - #### awaitReadComplete

          public boolean awaitReadComplete(long timeout,
                                  TimeUnit unit)

      Description copied from class: `SocketWrapperBase`
      If an asynchronous read operation is pending, this method will block until the operation completes, or the specified amount of time has passed.
      Overrides:
        `awaitReadComplete` in class `SocketWrapperBase<Nio2Channel>`
      Parameters:
        `timeout` - The maximum amount of time to wait
        `unit` - The unit for the timeout
      Returns:
        `true` if the read operation is complete, `false` if the operation is still pending and the specified timeout has passed

    - #### awaitWriteComplete

          public boolean awaitWriteComplete(long timeout,
                                   TimeUnit unit)

      Description copied from class: `SocketWrapperBase`
      If an asynchronous write operation is pending, this method will block until the operation completes, or the specified amount of time has passed.
      Overrides:
        `awaitWriteComplete` in class `SocketWrapperBase<Nio2Channel>`
      Parameters:
        `timeout` - The maximum amount of time to wait
        `unit` - The unit for the timeout
      Returns:
        `true` if the read operation is complete, `false` if the operation is still pending and the specified timeout has passed

    - #### registerReadInterest

          public void registerReadInterest()

      Specified by:
        `registerReadInterest` in class `SocketWrapperBase<Nio2Channel>`

    - #### registerWriteInterest

          public void registerWriteInterest()

      Specified by:
        `registerWriteInterest` in class `SocketWrapperBase<Nio2Channel>`

    - #### awaitBytes

          public void awaitBytes()

    - #### createSendfileData

          public SendfileDataBase createSendfileData(String filename,
                                            long pos,
                                            long length)

      Specified by:
        `createSendfileData` in class `SocketWrapperBase<Nio2Channel>`

    - #### 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 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.

    - #### populateRemoteAddr

          protected void populateRemoteAddr()

      Specified by:
        `populateRemoteAddr` in class `SocketWrapperBase<Nio2Channel>`

    - #### populateRemoteHost

          protected void populateRemoteHost()

      Specified by:
        `populateRemoteHost` in class `SocketWrapperBase<Nio2Channel>`

    - #### populateRemotePort

          protected void populateRemotePort()

      Specified by:
        `populateRemotePort` in class `SocketWrapperBase<Nio2Channel>`

    - #### populateLocalName

          protected void populateLocalName()

      Specified by:
        `populateLocalName` in class `SocketWrapperBase<Nio2Channel>`

    - #### populateLocalAddr

          protected void populateLocalAddr()

      Specified by:
        `populateLocalAddr` in class `SocketWrapperBase<Nio2Channel>`

    - #### populateLocalPort

          protected void populateLocalPort()

      Specified by:
        `populateLocalPort` in class `SocketWrapperBase<Nio2Channel>`

    - #### getSslSupport

          public SSLSupport getSslSupport(String clientCertProvider)

      Specified by:
        `getSslSupport` in class `SocketWrapperBase<Nio2Channel>`
      Parameters:
        `clientCertProvider` - Ignored for this implementation

    - #### doClientAuth

          public void doClientAuth(SSLSupport sslSupport)

      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

    - #### setAppReadBufHandler

          public void setAppReadBufHandler(ApplicationBufferHandler handler)

      Specified by:
        `setAppReadBufHandler` in class `SocketWrapperBase<Nio2Channel>`

Copyright © 2000-2017 Apache Software Foundation. All Rights Reserved.