Class NioEndpoint.NioSocketWrapper
java.lang.Object
org.apache.tomcat.util.net.SocketWrapperBase<NioChannel>
org.apache.tomcat.util.net.NioEndpoint.NioSocketWrapper
- Enclosing class:
NioEndpoint
NIO socket wrapper that wraps an NioChannel.
-
Nested Class Summary
Nested classes/interfaces inherited from class SocketWrapperBase
SocketWrapperBase.BlockingMode, SocketWrapperBase.CompletionCheck, SocketWrapperBase.CompletionHandlerCall, SocketWrapperBase.CompletionState, SocketWrapperBase.OperationState<A>, SocketWrapperBase.VectoredIOCompletionHandler<A> -
Field Summary
Fields inherited from class 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, servletConnection, sm, sniHostName, socketBufferHandler, writeOperation, writePending -
Constructor Summary
ConstructorsConstructorDescriptionNioSocketWrapper(NioChannel channel, NioEndpoint endpoint) Creates a new NIO socket wrapper. -
Method Summary
Modifier and TypeMethodDescriptionbooleancanWrite()Checks if the socket write buffer is writable and there is no pending non-blocking write data.createSendfileData(String filename, long pos, long length) Creates a sendfile data object for the specified file.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, ByteBuffer buffer) Write the contents of the ByteBuffer to the socket.protected booleanFlushes remaining buffered data using a non-blocking write.longReturns the last read timestamp.longReturns the last write timestamp.Returns the poller.Returns the sendfile data.Obtain an SSLSupport instance for this socket.booleanChecks if there is data waiting to be written to the socket.intReturns the current interest operations.intinterestOps(int ops) Sets the interest operations.booleaninterestOpsHas(int targetOp) Checks if a specific interest operation is set.booleanChecks if the socket is ready for reading.protected <A> SocketWrapperBase<NioChannel>.OperationState<A> newOperationState(boolean read, ByteBuffer[] buffers, int offset, int length, SocketWrapperBase.BlockingMode block, long timeout, TimeUnit unit, A attachment, SocketWrapperBase.CompletionCheck check, CompletionHandler<Long, ? super A> handler, Semaphore semaphore, SocketWrapperBase<NioChannel>.VectoredIOCompletionHandler<A> completion) Creates a new operation state for vectored I/O operations.protected voidPopulates the cached local IP address from the underlying socket.protected voidPopulates the cached local host name from the underlying socket.protected voidPopulates the cached local port number from the underlying socket.protected voidPopulates the cached remote IP address from the underlying socket.protected voidPopulates the cached remote host name from the underlying socket.protected voidPopulates the cached remote port number from the underlying socket.processSendfile(SendfileDataBase sendfileData) Starts the sendfile process.intread(boolean block, byte[] b, int off, int len) Reads data from the socket into a byte array.intread(boolean block, ByteBuffer to) Reads data from the socket into a ByteBuffer.voidRegisters interest in read events.voidRegisters interest in write events.voidSets the application-level read buffer handler.voidSets the sendfile data.voidUpdates the last read timestamp.voidUpdates the last write timestamp.Methods inherited from class SocketWrapperBase
buffersArrayHasRemaining, checkError, close, decrementKeepAlive, doWrite, execute, flush, flushBlocking, getCurrentProcessor, getEndpoint, getError, getLocalAddr, getLocalName, getLocalPort, getLock, getNegotiatedProtocol, getReadTimeout, getRemoteAddr, getRemoteHost, getRemotePort, getServletConnection, getSniHostName, getSocket, getSocketBufferHandler, getWriteTimeout, hasAsyncIO, hasDataToRead, hasPerOperationTimeout, isClosed, isReadPending, isReadyForWrite, isWritePending, needSemaphores, populateReadBuffer, populateReadBuffer, processSocket, read, read, read, reset, setCurrentProcessor, setError, setKeepAliveLeft, setNegotiatedProtocol, setReadTimeout, setSniHostName, setWriteTimeout, takeCurrentProcessor, toString, transfer, transfer, unRead, vectoredOperation, write, write, write, write, write, writeBlocking, writeBlocking, writeNonBlocking, writeNonBlocking, writeNonBlockingInternal
-
Constructor Details
-
NioSocketWrapper
Creates a new NIO socket wrapper.- Parameters:
channel- The NIO channelendpoint- The NIO endpoint
-
-
Method Details
-
getPoller
-
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:
trueif the target operation is set
-
setSendfileData
Sets the sendfile data.- Parameters:
sf- the sendfile data
-
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
Description copied from class:SocketWrapperBaseChecks if the socket is ready for reading.- Specified by:
isReadyForReadin classSocketWrapperBase<NioChannel>- Returns:
trueif data is available to read- Throws:
IOException- If an I/O error occurs
-
read
Description copied from class:SocketWrapperBaseReads data from the socket into a byte array.- Specified by:
readin classSocketWrapperBase<NioChannel>- Parameters:
block- Whether to blockb- The byte array to read intooff- The offset in the arraylen- The number of bytes to read- Returns:
- the number of bytes read
- Throws:
IOException- If an I/O error occurs
-
read
Description copied from class:SocketWrapperBaseReads data from the socket into a ByteBuffer.- Specified by:
readin classSocketWrapperBase<NioChannel>- Parameters:
block- Whether to blockto- The ByteBuffer to read into- Returns:
- the number of bytes read
- Throws:
IOException- If an I/O error occurs
-
doClose
protected 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 classSocketWrapperBase<NioChannel>
-
flushNonBlocking
Description copied from class:SocketWrapperBaseFlushes remaining buffered data using a non-blocking write.- Specified by:
flushNonBlockingin classSocketWrapperBase<NioChannel>- Returns:
trueif data remains to be flushed after this method completes, otherwisefalse- Throws:
IOException- If an IO error occurs during the write
-
hasDataToWrite
public boolean hasDataToWrite()Description copied from class:SocketWrapperBaseChecks if there is data waiting to be written to the socket.- Overrides:
hasDataToWritein classSocketWrapperBase<NioChannel>- Returns:
trueif there is pending write data
-
canWrite
public boolean canWrite()Description copied from class:SocketWrapperBaseChecks if the socket write buffer is writable and there is no pending non-blocking write data.- Overrides:
canWritein classSocketWrapperBase<NioChannel>- Returns:
trueif the socket is ready for writing
-
doWrite
Description 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 classSocketWrapperBase<NioChannel>- Parameters:
block- Should the write be blocking or not?buffer- the ByteBuffer containing the data to be written- Throws:
IOException- If an I/O error such as a timeout occurs during the write
-
registerReadInterest
public void registerReadInterest()Description copied from class:SocketWrapperBaseRegisters interest in read events.- Specified by:
registerReadInterestin classSocketWrapperBase<NioChannel>
-
registerWriteInterest
public void registerWriteInterest()Description copied from class:SocketWrapperBaseRegisters interest in write events.- Specified by:
registerWriteInterestin classSocketWrapperBase<NioChannel>
-
createSendfileData
Description copied from class:SocketWrapperBaseCreates a sendfile data object for the specified file.- Specified by:
createSendfileDatain classSocketWrapperBase<NioChannel>- Parameters:
filename- The file to sendpos- The starting position in the filelength- The number of bytes to send- Returns:
- a new sendfile data object
-
processSendfile
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 classSocketWrapperBase<NioChannel>- Parameters:
sendfileData- Data representing the file to send- Returns:
- The state of the sendfile process after the first write.
-
populateRemoteAddr
protected void populateRemoteAddr()Description copied from class:SocketWrapperBasePopulates the cached remote IP address from the underlying socket.- Specified by:
populateRemoteAddrin classSocketWrapperBase<NioChannel>
-
populateRemoteHost
protected void populateRemoteHost()Description copied from class:SocketWrapperBasePopulates the cached remote host name from the underlying socket.- Specified by:
populateRemoteHostin classSocketWrapperBase<NioChannel>
-
populateRemotePort
protected void populateRemotePort()Description copied from class:SocketWrapperBasePopulates the cached remote port number from the underlying socket.- Specified by:
populateRemotePortin classSocketWrapperBase<NioChannel>
-
populateLocalName
protected void populateLocalName()Description copied from class:SocketWrapperBasePopulates the cached local host name from the underlying socket.- Specified by:
populateLocalNamein classSocketWrapperBase<NioChannel>
-
populateLocalAddr
protected void populateLocalAddr()Description copied from class:SocketWrapperBasePopulates the cached local IP address from the underlying socket.- Specified by:
populateLocalAddrin classSocketWrapperBase<NioChannel>
-
populateLocalPort
protected void populateLocalPort()Description copied from class:SocketWrapperBasePopulates the cached local port number from the underlying socket.- Specified by:
populateLocalPortin classSocketWrapperBase<NioChannel>
-
getSslSupport
Description copied from class:SocketWrapperBaseObtain an SSLSupport instance for this socket.- Specified by:
getSslSupportin classSocketWrapperBase<NioChannel>- Returns:
- An SSLSupport instance for this socket.
-
doClientAuth
Description copied from class:SocketWrapperBaseRequire the client to perform CLIENT-CERT authentication if it hasn't already done so.- Specified by:
doClientAuthin classSocketWrapperBase<NioChannel>- Parameters:
sslSupport- The SSL/TLS support instance currently being used by the connection that may need updating after the client authentication- Throws:
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
Description copied from class:SocketWrapperBaseSets the application-level read buffer handler.- Specified by:
setAppReadBufHandlerin classSocketWrapperBase<NioChannel>- Parameters:
handler- The application buffer handler
-
newOperationState
protected <A> SocketWrapperBase<NioChannel>.OperationState<A> newOperationState(boolean read, ByteBuffer[] buffers, int offset, int length, SocketWrapperBase.BlockingMode block, long timeout, TimeUnit unit, A attachment, SocketWrapperBase.CompletionCheck check, CompletionHandler<Long, ? super A> handler, Semaphore semaphore, SocketWrapperBase<NioChannel>.VectoredIOCompletionHandler<A> completion) Description copied from class:SocketWrapperBaseCreates a new operation state for vectored I/O operations.- Specified by:
newOperationStatein classSocketWrapperBase<NioChannel>- Type Parameters:
A- The attachment type- Parameters:
read- Whether this is a read operationbuffers- The buffers for the operationoffset- The offset in the buffer arraylength- The number of buffersblock- The blocking modetimeout- The timeout durationunit- The timeout time unitattachment- An attachment objectcheck- The completion checkhandler- The completion handlersemaphore- The semaphore for synchronizationcompletion- The vectored I/O completion handler- Returns:
- a new operation state instance
-