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.SocketWrapperBaseSocketWrapperBase.BlockingMode, SocketWrapperBase.CompletionCheck, SocketWrapperBase.CompletionHandlerCall, SocketWrapperBase.CompletionState, SocketWrapperBase.OperationState<A>, SocketWrapperBase.VectoredIOCompletionHandler<A>
 
- 
 - 
Field Summary- 
Fields inherited from class org.apache.tomcat.util.net.SocketWrapperBasebufferedWriteSize, closed, COMPLETE_READ, COMPLETE_READ_WITH_COMPLETION, COMPLETE_WRITE, COMPLETE_WRITE_WITH_COMPLETION, localAddr, localName, localPort, nonBlockingWriteBuffer, previousIOException, READ_DATA, readOperation, readPending, remoteAddr, remoteHost, remotePort, sm, socketBufferHandler, writeOperation, writePending
 
- 
 - 
Constructor SummaryConstructors Constructor Description Nio2SocketWrapper(Nio2Channel channel, Nio2Endpoint endpoint)
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanawaitReadComplete(long timeout, java.util.concurrent.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.booleanawaitWriteComplete(long timeout, java.util.concurrent.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.SendfileDataBasecreateSendfileData(java.lang.String filename, long pos, long length)voiddoClientAuth(SSLSupport sslSupport)Require the client to perform CLIENT-CERT authentication if it hasn't already done so.protected voiddoClose()Perform the actual close.protected voiddoWrite(boolean block, java.nio.ByteBuffer from)Write the contents of the ByteBuffer to the socket.protected voidflushBlocking()Writes all remaining data from the buffers and blocks until the write is complete.protected booleanflushNonBlocking()Writes as much data as possible from any that remains in the buffers.Nio2Endpoint.SendfileDatagetSendfileData()SSLSupportgetSslSupport(java.lang.String clientCertProvider)booleanhasAsyncIO()Allows using NIO2 style read/write.booleanhasDataToRead()booleanhasDataToWrite()booleanhasPerOperationTimeout()Allows indicating if the connector supports per operation timeout.booleanisReadPending()Allows checking if an asynchronous read operation is currently pending.booleanisReadyForRead()booleanisReadyForWrite()Checks to see if there are any writes pending and if there are callsSocketWrapperBase.registerWriteInterest()to trigger a callback once the pending writes have completed.booleanisWritePending()Allows checking if an asynchronous write operation is currently pending.booleanneedSemaphores()Allows indicating if the connector needs semaphores.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)protected voidpopulateLocalAddr()protected voidpopulateLocalName()protected voidpopulateLocalPort()protected voidpopulateRemoteAddr()protected voidpopulateRemoteHost()protected voidpopulateRemotePort()SendfileStateprocessSendfile(SendfileDataBase sendfileData)Starts the sendfile process.intread(boolean block, byte[] b, int off, int len)intread(boolean block, java.nio.ByteBuffer to)voidregisterReadInterest()voidregisterWriteInterest()voidsetAppReadBufHandler(ApplicationBufferHandler handler)voidsetSendfileData(Nio2Endpoint.SendfileData sf)protected voidwriteNonBlocking(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 voidwriteNonBlocking(java.nio.ByteBuffer from)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 voidwriteNonBlockingInternal(java.nio.ByteBuffer from)Separate method so it can be re-used by the socket write buffer to write data to the network- 
Methods inherited from class org.apache.tomcat.util.net.SocketWrapperBasebuffersArrayHasRemaining, canWrite, checkError, close, decrementKeepAlive, doWrite, execute, flush, getCurrentProcessor, getEndpoint, getError, getLocalAddr, getLocalName, getLocalPort, getNegotiatedProtocol, getReadTimeout, getRemoteAddr, getRemoteHost, getRemotePort, getSocket, getSocketBufferHandler, getWriteTimeout, isClosed, isSecure, isUpgraded, populateReadBuffer, populateReadBuffer, processSocket, read, read, read, reset, setCurrentProcessor, setError, setKeepAliveLeft, setNegotiatedProtocol, setReadTimeout, setSecure, setUpgraded, setWriteTimeout, takeCurrentProcessor, toString, transfer, transfer, unRead, vectoredOperation, write, write, write, write, write, writeBlocking, writeBlocking
 
- 
 
- 
- 
- 
Constructor Detail- 
Nio2SocketWrapperpublic Nio2SocketWrapper(Nio2Channel channel, Nio2Endpoint endpoint) 
 
- 
 - 
Method Detail- 
setSendfileDatapublic void setSendfileData(Nio2Endpoint.SendfileData sf) 
 - 
getSendfileDatapublic Nio2Endpoint.SendfileData getSendfileData() 
 - 
isReadyForReadpublic boolean isReadyForRead() throws java.io.IOException- Specified by:
- isReadyForReadin class- SocketWrapperBase<Nio2Channel>
- Throws:
- java.io.IOException
 
 - 
isReadyForWritepublic boolean isReadyForWrite() Description copied from class:SocketWrapperBaseChecks to see if there are any writes pending and if there are callsSocketWrapperBase.registerWriteInterest()to trigger a callback once the pending writes have completed.Note: Once this method has returned falseit MUST NOT be called again until the pending write has completed and the callback has been fired. TODO: ModifySocketWrapperBase.registerWriteInterest()so the above restriction is enforced there rather than relying on the caller.- Overrides:
- isReadyForWritein class- SocketWrapperBase<Nio2Channel>
- Returns:
- trueif no writes are pending and data can be written otherwise- false
 
 - 
readpublic int read(boolean block, byte[] b, int off, int len) throws java.io.IOException- Specified by:
- readin class- SocketWrapperBase<Nio2Channel>
- Throws:
- java.io.IOException
 
 - 
readpublic int read(boolean block, java.nio.ByteBuffer to) throws java.io.IOException- Specified by:
- readin class- SocketWrapperBase<Nio2Channel>
- Throws:
- java.io.IOException
 
 - 
doCloseprotected void doClose() Description copied from class:SocketWrapperBasePerform the actual close. The closed atomic boolean guarantees this will be called only once per wrapper.- Specified by:
- doClosein class- SocketWrapperBase<Nio2Channel>
 
 - 
hasAsyncIOpublic boolean hasAsyncIO() Description copied from class:SocketWrapperBaseAllows using NIO2 style read/write.- Overrides:
- hasAsyncIOin class- SocketWrapperBase<Nio2Channel>
- Returns:
- trueif the connector has the capability enabled
 
 - 
needSemaphorespublic boolean needSemaphores() Description copied from class:SocketWrapperBaseAllows indicating if the connector needs semaphores.- Overrides:
- needSemaphoresin class- SocketWrapperBase<Nio2Channel>
- Returns:
- This default implementation always returns false
 
 - 
hasPerOperationTimeoutpublic boolean hasPerOperationTimeout() Description copied from class:SocketWrapperBaseAllows indicating if the connector supports per operation timeout.- Overrides:
- hasPerOperationTimeoutin class- SocketWrapperBase<Nio2Channel>
- Returns:
- This default implementation always returns false
 
 - 
newOperationStateprotected <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) - Specified by:
- newOperationStatein class- SocketWrapperBase<Nio2Channel>
 
 - 
writeNonBlockingprotected void writeNonBlocking(byte[] buf, int off, int len) throws java.io.IOExceptionTransfers 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:
- writeNonBlockingin 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
 
 - 
writeNonBlockingprotected void writeNonBlocking(java.nio.ByteBuffer from) throws java.io.IOExceptionTransfers 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:
- writeNonBlockingin 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
 
 - 
writeNonBlockingInternalprotected void writeNonBlockingInternal(java.nio.ByteBuffer from) throws java.io.IOExceptionSeparate method so it can be re-used by the socket write buffer to write data to the networkOverridden 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:
- writeNonBlockingInternalin 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
 
 - 
doWriteprotected void doWrite(boolean block, java.nio.ByteBuffer from) throws java.io.IOExceptionDescription copied from class:SocketWrapperBaseWrite 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:
- doWritein 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
 
 - 
flushBlockingprotected void flushBlocking() throws java.io.IOExceptionDescription copied from class:SocketWrapperBaseWrites all remaining data from the buffers and blocks until the write is complete.- Overrides:
- flushBlockingin class- SocketWrapperBase<Nio2Channel>
- Throws:
- java.io.IOException- If an IO error occurs during the write
 
 - 
flushNonBlockingprotected boolean flushNonBlocking() throws java.io.IOExceptionDescription copied from class:SocketWrapperBaseWrites as much data as possible from any that remains in the buffers.- Specified by:
- flushNonBlockingin class- SocketWrapperBase<Nio2Channel>
- Returns:
- trueif data remains to be flushed after this method completes, otherwise- false.
- Throws:
- java.io.IOException- If an IO error occurs during the write
 
 - 
hasDataToReadpublic boolean hasDataToRead() - Overrides:
- hasDataToReadin class- SocketWrapperBase<Nio2Channel>
 
 - 
hasDataToWritepublic boolean hasDataToWrite() - Overrides:
- hasDataToWritein class- SocketWrapperBase<Nio2Channel>
 
 - 
isReadPendingpublic boolean isReadPending() Description copied from class:SocketWrapperBaseAllows checking if an asynchronous read operation is currently pending.- Overrides:
- isReadPendingin class- SocketWrapperBase<Nio2Channel>
- Returns:
- trueif the endpoint supports asynchronous IO and a read operation is being processed asynchronously
 
 - 
isWritePendingpublic boolean isWritePending() Description copied from class:SocketWrapperBaseAllows checking if an asynchronous write operation is currently pending.- Overrides:
- isWritePendingin class- SocketWrapperBase<Nio2Channel>
- Returns:
- trueif the endpoint supports asynchronous IO and a write operation is being processed asynchronously
 
 - 
awaitReadCompletepublic boolean awaitReadComplete(long timeout, java.util.concurrent.TimeUnit unit)Description copied from class:SocketWrapperBaseIf an asynchronous read operation is pending, this method will block until the operation completes, or the specified amount of time has passed.- Overrides:
- awaitReadCompletein class- SocketWrapperBase<Nio2Channel>
- Parameters:
- timeout- The maximum amount of time to wait
- unit- The unit for the timeout
- Returns:
- trueif the read operation is complete,- falseif the operation is still pending and the specified timeout has passed
 
 - 
awaitWriteCompletepublic boolean awaitWriteComplete(long timeout, java.util.concurrent.TimeUnit unit)Description copied from class:SocketWrapperBaseIf an asynchronous write operation is pending, this method will block until the operation completes, or the specified amount of time has passed.- Overrides:
- awaitWriteCompletein class- SocketWrapperBase<Nio2Channel>
- Parameters:
- timeout- The maximum amount of time to wait
- unit- The unit for the timeout
- Returns:
- trueif the read operation is complete,- falseif the operation is still pending and the specified timeout has passed
 
 - 
registerReadInterestpublic void registerReadInterest() - Specified by:
- registerReadInterestin class- SocketWrapperBase<Nio2Channel>
 
 - 
registerWriteInterestpublic void registerWriteInterest() - Specified by:
- registerWriteInterestin class- SocketWrapperBase<Nio2Channel>
 
 - 
createSendfileDatapublic SendfileDataBase createSendfileData(java.lang.String filename, long pos, long length) - Specified by:
- createSendfileDatain class- SocketWrapperBase<Nio2Channel>
 
 - 
processSendfilepublic SendfileState processSendfile(SendfileDataBase sendfileData) Description copied from class:SocketWrapperBaseStarts 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:
- processSendfilein class- SocketWrapperBase<Nio2Channel>
- Parameters:
- sendfileData- Data representing the file to send
- Returns:
- The state of the sendfile process after the first write.
 
 - 
populateRemoteAddrprotected void populateRemoteAddr() - Specified by:
- populateRemoteAddrin class- SocketWrapperBase<Nio2Channel>
 
 - 
populateRemoteHostprotected void populateRemoteHost() - Specified by:
- populateRemoteHostin class- SocketWrapperBase<Nio2Channel>
 
 - 
populateRemotePortprotected void populateRemotePort() - Specified by:
- populateRemotePortin class- SocketWrapperBase<Nio2Channel>
 
 - 
populateLocalNameprotected void populateLocalName() - Specified by:
- populateLocalNamein class- SocketWrapperBase<Nio2Channel>
 
 - 
populateLocalAddrprotected void populateLocalAddr() - Specified by:
- populateLocalAddrin class- SocketWrapperBase<Nio2Channel>
 
 - 
populateLocalPortprotected void populateLocalPort() - Specified by:
- populateLocalPortin class- SocketWrapperBase<Nio2Channel>
 
 - 
getSslSupportpublic SSLSupport getSslSupport(java.lang.String clientCertProvider) - Specified by:
- getSslSupportin class- SocketWrapperBase<Nio2Channel>
- Parameters:
- clientCertProvider- Ignored for this implementation
 
 - 
doClientAuthpublic void doClientAuth(SSLSupport sslSupport) throws java.io.IOException Description copied from class:SocketWrapperBaseRequire the client to perform CLIENT-CERT authentication if it hasn't already done so.- Specified by:
- doClientAuthin 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
 
 - 
setAppReadBufHandlerpublic void setAppReadBufHandler(ApplicationBufferHandler handler) - Specified by:
- setAppReadBufHandlerin class- SocketWrapperBase<Nio2Channel>
 
 
- 
 
-