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.BlockingMode, SocketWrapperBase.CompletionCheck, SocketWrapperBase.CompletionHandlerCall, SocketWrapperBase.CompletionState, SocketWrapperBase.OperationState<A>, SocketWrapperBase.VectoredIOCompletionHandler<A>
-
-
Field Summary
-
Fields inherited from class org.apache.tomcat.util.net.SocketWrapperBase
bufferedWriteSize, 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 Summary
Constructors Constructor Description Nio2SocketWrapper(Nio2Channel channel, Nio2Endpoint endpoint)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SendfileDataBase
createSendfileData(java.lang.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
doClose()
Perform the actual close.protected void
doWrite(boolean block, java.nio.ByteBuffer from)
Write the contents of the ByteBuffer to the socket.protected void
flushBlocking()
Writes all remaining data from the buffers and blocks until the write is complete.protected boolean
flushNonBlocking()
Writes as much data as possible from any that remains in the buffers.Nio2Endpoint.SendfileData
getSendfileData()
SSLSupport
getSslSupport()
Obtain an SSLSupport instance for this socket.boolean
hasAsyncIO()
Allows using NIO2 style read/write.boolean
hasDataToRead()
boolean
hasDataToWrite()
boolean
hasPerOperationTimeout()
Allows indicating if the connector supports per operation timeout.boolean
isReadPending()
Allows checking if an asynchronous read operation is currently pending.boolean
isReadyForRead()
boolean
isReadyForWrite()
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.boolean
isWritePending()
Allows checking if an asynchronous write operation is currently pending.boolean
needSemaphores()
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 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, java.nio.ByteBuffer to)
void
registerReadInterest()
void
registerWriteInterest()
void
setAppReadBufHandler(ApplicationBufferHandler handler)
void
setSendfileData(Nio2Endpoint.SendfileData sf)
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(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 void
writeNonBlockingInternal(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.SocketWrapperBase
buffersArrayHasRemaining, canWrite, checkError, close, decrementKeepAlive, doWrite, execute, flush, getCurrentProcessor, getEndpoint, getError, getLocalAddr, getLocalName, getLocalPort, getNegotiatedProtocol, getReadTimeout, getRemoteAddr, getRemoteHost, getRemotePort, getSocket, getSocketBufferHandler, getSslSupport, getWriteTimeout, isClosed, populateReadBuffer, populateReadBuffer, processSocket, read, read, read, reset, setCurrentProcessor, setError, setKeepAliveLeft, setNegotiatedProtocol, setReadTimeout, setWriteTimeout, takeCurrentProcessor, toString, transfer, transfer, unRead, vectoredOperation, write, write, write, write, write, writeBlocking, writeBlocking
-
-
-
-
Constructor Detail
-
Nio2SocketWrapper
public Nio2SocketWrapper(Nio2Channel channel, Nio2Endpoint endpoint)
-
-
Method Detail
-
setSendfileData
public void setSendfileData(Nio2Endpoint.SendfileData sf)
-
getSendfileData
public Nio2Endpoint.SendfileData getSendfileData()
-
isReadyForRead
public boolean isReadyForRead() throws java.io.IOException
- Specified by:
isReadyForRead
in classSocketWrapperBase<Nio2Channel>
- Throws:
java.io.IOException
-
isReadyForWrite
public boolean isReadyForWrite()
Description copied from class:SocketWrapperBase
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.Note: Once this method has returned
false
it 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:
isReadyForWrite
in classSocketWrapperBase<Nio2Channel>
- Returns:
true
if no writes are pending and data can be written otherwisefalse
-
read
public int read(boolean block, byte[] b, int off, int len) throws java.io.IOException
- Specified by:
read
in classSocketWrapperBase<Nio2Channel>
- Throws:
java.io.IOException
-
read
public int read(boolean block, java.nio.ByteBuffer to) throws java.io.IOException
- Specified by:
read
in classSocketWrapperBase<Nio2Channel>
- Throws:
java.io.IOException
-
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 classSocketWrapperBase<Nio2Channel>
-
hasAsyncIO
public boolean hasAsyncIO()
Description copied from class:SocketWrapperBase
Allows using NIO2 style read/write.- Overrides:
hasAsyncIO
in classSocketWrapperBase<Nio2Channel>
- Returns:
true
if the connector has the capability enabled
-
needSemaphores
public boolean needSemaphores()
Description copied from class:SocketWrapperBase
Allows indicating if the connector needs semaphores.- Overrides:
needSemaphores
in classSocketWrapperBase<Nio2Channel>
- Returns:
- This default implementation always returns
false
-
hasPerOperationTimeout
public boolean hasPerOperationTimeout()
Description copied from class:SocketWrapperBase
Allows indicating if the connector supports per operation timeout.- Overrides:
hasPerOperationTimeout
in classSocketWrapperBase<Nio2Channel>
- Returns:
- This default implementation always returns
false
-
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)
- Specified by:
newOperationState
in classSocketWrapperBase<Nio2Channel>
-
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 classSocketWrapperBase<Nio2Channel>
- Parameters:
buf
- The byte array containing the data to be writtenoff
- The offset within the byte array of the data to be writtenlen
- 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 classSocketWrapperBase<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 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:
writeNonBlockingInternal
in classSocketWrapperBase<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 classSocketWrapperBase<Nio2Channel>
- Parameters:
block
- Ignored since this method is only called in the blocking casefrom
- 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 classSocketWrapperBase<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 classSocketWrapperBase<Nio2Channel>
- Returns:
true
if data remains to be flushed after this method completes, otherwisefalse
.- Throws:
java.io.IOException
- If an IO error occurs during the write
-
hasDataToRead
public boolean hasDataToRead()
- Overrides:
hasDataToRead
in classSocketWrapperBase<Nio2Channel>
-
hasDataToWrite
public boolean hasDataToWrite()
- Overrides:
hasDataToWrite
in classSocketWrapperBase<Nio2Channel>
-
isReadPending
public boolean isReadPending()
Description copied from class:SocketWrapperBase
Allows checking if an asynchronous read operation is currently pending.- Overrides:
isReadPending
in classSocketWrapperBase<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 classSocketWrapperBase<Nio2Channel>
- Returns:
true
if the endpoint supports asynchronous IO and a write operation is being processed asynchronously
-
registerReadInterest
public void registerReadInterest()
- Specified by:
registerReadInterest
in classSocketWrapperBase<Nio2Channel>
-
registerWriteInterest
public void registerWriteInterest()
- Specified by:
registerWriteInterest
in classSocketWrapperBase<Nio2Channel>
-
createSendfileData
public SendfileDataBase createSendfileData(java.lang.String filename, long pos, long length)
- Specified by:
createSendfileData
in classSocketWrapperBase<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 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 classSocketWrapperBase<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 classSocketWrapperBase<Nio2Channel>
-
populateRemoteHost
protected void populateRemoteHost()
- Specified by:
populateRemoteHost
in classSocketWrapperBase<Nio2Channel>
-
populateRemotePort
protected void populateRemotePort()
- Specified by:
populateRemotePort
in classSocketWrapperBase<Nio2Channel>
-
populateLocalName
protected void populateLocalName()
- Specified by:
populateLocalName
in classSocketWrapperBase<Nio2Channel>
-
populateLocalAddr
protected void populateLocalAddr()
- Specified by:
populateLocalAddr
in classSocketWrapperBase<Nio2Channel>
-
populateLocalPort
protected void populateLocalPort()
- Specified by:
populateLocalPort
in classSocketWrapperBase<Nio2Channel>
-
getSslSupport
public SSLSupport getSslSupport()
Description copied from class:SocketWrapperBase
Obtain an SSLSupport instance for this socket.- Specified by:
getSslSupport
in classSocketWrapperBase<Nio2Channel>
- Returns:
- An SSLSupport instance for this socket.
-
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 classSocketWrapperBase<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
-
setAppReadBufHandler
public void setAppReadBufHandler(ApplicationBufferHandler handler)
- Specified by:
setAppReadBufHandler
in classSocketWrapperBase<Nio2Channel>
-
-