Class Nio2Endpoint.Nio2SocketWrapper
- Enclosing class:
Nio2Endpoint
-
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
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateSendfileData(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 from) Write the contents of the ByteBuffer to the socket.protected voidWrites all remaining data from the buffers and blocks until the write is complete.protected booleanFlushes remaining buffered data using a non-blocking write.Obtain an SSLSupport instance for this socket.booleanAllows using NIO2 style read/write.booleanChecks if there is data available to read from the socket.booleanChecks if there is data waiting to be written to the socket.booleanAllows indicating if the connector supports per operation timeout.booleanAllows checking if an asynchronous read operation is currently pending.booleanChecks if the socket is ready for reading.booleanChecks to see if there are any writes pending and if there are callsSocketWrapperBase.registerWriteInterest()to trigger a callback once the pending writes have completed.booleanAllows checking if an asynchronous write operation is currently pending.booleanAllows indicating if the connector needs semaphores.protected <A> SocketWrapperBase<Nio2Channel>.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<Nio2Channel>.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.voidprotected 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(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 voidSeparate method so it can be re-used by the socket write buffer to write data to the networkMethods inherited from class SocketWrapperBase
buffersArrayHasRemaining, canWrite, checkError, close, decrementKeepAlive, doWrite, execute, flush, getCurrentProcessor, getEndpoint, getError, getLocalAddr, getLocalName, getLocalPort, getLock, getNegotiatedProtocol, getReadTimeout, getRemoteAddr, getRemoteHost, getRemotePort, getServletConnection, getSniHostName, getSocket, getSocketBufferHandler, getWriteTimeout, isClosed, 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
-
Constructor Details
-
Nio2SocketWrapper
-
-
Method Details
-
setSendfileData
-
getSendfileData
-
isReadyForRead
Description copied from class:SocketWrapperBaseChecks if the socket is ready for reading.- Specified by:
isReadyForReadin classSocketWrapperBase<Nio2Channel>- Returns:
trueif data is available to read- Throws:
IOException- If an I/O error occurs
-
isReadyForWrite
public 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 classSocketWrapperBase<Nio2Channel>- Returns:
trueif no writes are pending and data can be written otherwisefalse
-
read
Description copied from class:SocketWrapperBaseReads data from the socket into a byte array.- Specified by:
readin classSocketWrapperBase<Nio2Channel>- 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<Nio2Channel>- 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<Nio2Channel>
-
hasAsyncIO
public boolean hasAsyncIO()Description copied from class:SocketWrapperBaseAllows using NIO2 style read/write.- Overrides:
hasAsyncIOin classSocketWrapperBase<Nio2Channel>- Returns:
trueif the connector has the capability enabled
-
needSemaphores
public boolean needSemaphores()Description copied from class:SocketWrapperBaseAllows indicating if the connector needs semaphores.- Overrides:
needSemaphoresin classSocketWrapperBase<Nio2Channel>- Returns:
- This default implementation always returns
false
-
hasPerOperationTimeout
public boolean hasPerOperationTimeout()Description copied from class:SocketWrapperBaseAllows indicating if the connector supports per operation timeout.- Overrides:
hasPerOperationTimeoutin classSocketWrapperBase<Nio2Channel>- Returns:
- This default implementation always returns
false
-
newOperationState
protected <A> SocketWrapperBase<Nio2Channel>.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<Nio2Channel>.VectoredIOCompletionHandler<A> completion) Description copied from class:SocketWrapperBaseCreates a new operation state for vectored I/O operations.- Specified by:
newOperationStatein classSocketWrapperBase<Nio2Channel>- 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
-
writeNonBlocking
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:
writeNonBlockingin 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:
IOException- If an IO error occurs during the write
-
writeNonBlocking
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:
writeNonBlockingin classSocketWrapperBase<Nio2Channel>- Parameters:
from- The ByteBuffer containing the data to be written- Throws:
IOException- If an IO error occurs during the write
-
writeNonBlockingInternal
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:
writeNonBlockingInternalin classSocketWrapperBase<Nio2Channel>- Parameters:
from- The ByteBuffer containing the data to be written- Throws:
IOException- If an IO error occurs during the write
-
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<Nio2Channel>- Parameters:
block- Ignored since this method is only called in the blocking casefrom- the ByteBuffer containing the data to be written- Throws:
IOException- If an I/O error such as a timeout occurs during the write
-
flushBlocking
Description copied from class:SocketWrapperBaseWrites all remaining data from the buffers and blocks until the write is complete.- Overrides:
flushBlockingin classSocketWrapperBase<Nio2Channel>- Throws:
IOException- If an IO error occurs during the write
-
flushNonBlocking
Description copied from class:SocketWrapperBaseFlushes remaining buffered data using a non-blocking write.- Specified by:
flushNonBlockingin classSocketWrapperBase<Nio2Channel>- Returns:
trueif data remains to be flushed after this method completes, otherwisefalse- Throws:
IOException- If an IO error occurs during the write
-
hasDataToRead
public boolean hasDataToRead()Description copied from class:SocketWrapperBaseChecks if there is data available to read from the socket.- Overrides:
hasDataToReadin classSocketWrapperBase<Nio2Channel>- Returns:
truesince it is always safe to attempt a read
-
hasDataToWrite
public boolean hasDataToWrite()Description copied from class:SocketWrapperBaseChecks if there is data waiting to be written to the socket.- Overrides:
hasDataToWritein classSocketWrapperBase<Nio2Channel>- Returns:
trueif there is pending write data
-
isReadPending
public boolean isReadPending()Description copied from class:SocketWrapperBaseAllows checking if an asynchronous read operation is currently pending.- Overrides:
isReadPendingin classSocketWrapperBase<Nio2Channel>- Returns:
trueif the endpoint supports asynchronous IO and a read operation is being processed asynchronously
-
isWritePending
public boolean isWritePending()Description copied from class:SocketWrapperBaseAllows checking if an asynchronous write operation is currently pending.- Overrides:
isWritePendingin classSocketWrapperBase<Nio2Channel>- Returns:
trueif the endpoint supports asynchronous IO and a write operation is being processed asynchronously
-
registerReadInterest
public void registerReadInterest()Description copied from class:SocketWrapperBaseRegisters interest in read events.- Specified by:
registerReadInterestin classSocketWrapperBase<Nio2Channel>
-
registerWriteInterest
public void registerWriteInterest()Description copied from class:SocketWrapperBaseRegisters interest in write events.- Specified by:
registerWriteInterestin classSocketWrapperBase<Nio2Channel>
-
createSendfileData
Description copied from class:SocketWrapperBaseCreates a sendfile data object for the specified file.- Specified by:
createSendfileDatain classSocketWrapperBase<Nio2Channel>- 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<Nio2Channel>- 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<Nio2Channel>
-
populateRemoteHost
protected void populateRemoteHost()Description copied from class:SocketWrapperBasePopulates the cached remote host name from the underlying socket.- Specified by:
populateRemoteHostin classSocketWrapperBase<Nio2Channel>
-
populateRemotePort
protected void populateRemotePort()Description copied from class:SocketWrapperBasePopulates the cached remote port number from the underlying socket.- Specified by:
populateRemotePortin classSocketWrapperBase<Nio2Channel>
-
populateLocalName
protected void populateLocalName()Description copied from class:SocketWrapperBasePopulates the cached local host name from the underlying socket.- Specified by:
populateLocalNamein classSocketWrapperBase<Nio2Channel>
-
populateLocalAddr
protected void populateLocalAddr()Description copied from class:SocketWrapperBasePopulates the cached local IP address from the underlying socket.- Specified by:
populateLocalAddrin classSocketWrapperBase<Nio2Channel>
-
populateLocalPort
protected void populateLocalPort()Description copied from class:SocketWrapperBasePopulates the cached local port number from the underlying socket.- Specified by:
populateLocalPortin classSocketWrapperBase<Nio2Channel>
-
getSslSupport
Description copied from class:SocketWrapperBaseObtain an SSLSupport instance for this socket.- Specified by:
getSslSupportin classSocketWrapperBase<Nio2Channel>- 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<Nio2Channel>- 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<Nio2Channel>- Parameters:
handler- The application buffer handler
-