Class SocketWrapperBase<E>
- Direct Known Subclasses:
AprEndpoint.AprSocketWrapper
,Nio2Endpoint.Nio2SocketWrapper
,NioEndpoint.NioSocketWrapper
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
static interface
static enum
static enum
protected class
Internal state tracker for vectored operations.protected class
Completion handler for vectored operations. -
Field Summary
Modifier and TypeFieldDescriptionprotected int
The max size of the individual buffered write buffersprotected final AtomicBoolean
static final SocketWrapperBase.CompletionCheck
This utility CompletionCheck will cause the completion handler to be called once the given buffers are full.static final SocketWrapperBase.CompletionCheck
This utility CompletionCheck will cause the completion handler to be called once the given buffers are full.static final SocketWrapperBase.CompletionCheck
This utility CompletionCheck will cause the write to fully write all remaining data.static final SocketWrapperBase.CompletionCheck
This utility CompletionCheck will cause the write to fully write all remaining data.protected String
protected String
protected int
protected final WriteBuffer
Additional buffer used for non-blocking writes.protected IOException
static final SocketWrapperBase.CompletionCheck
This utility CompletionCheck will cause the completion handler to be called once some data has been read.protected SocketWrapperBase<E>.OperationState<?>
protected final Semaphore
protected String
protected String
protected int
protected static final StringManager
protected SocketBufferHandler
The buffers used for communicating with the socket.protected SocketWrapperBase<E>.OperationState<?>
protected final Semaphore
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
awaitReadComplete
(long timeout, TimeUnit unit) Deprecated.boolean
awaitWriteComplete
(long timeout, TimeUnit unit) Deprecated.protected static boolean
buffersArrayHasRemaining
(ByteBuffer[] buffers, int offset, int length) boolean
canWrite()
void
void
close()
Close the socket wrapper.abstract SendfileDataBase
createSendfileData
(String filename, long pos, long length) int
abstract void
doClientAuth
(SSLSupport sslSupport) Require the client to perform CLIENT-CERT authentication if it hasn't already done so.protected abstract void
doClose()
Perform the actual close.protected void
doWrite
(boolean block) Write the contents of the socketWriteBuffer to the socket.protected abstract void
doWrite
(boolean block, ByteBuffer from) Write the contents of the ByteBuffer to the socket.void
Transfers processing to a container thread.boolean
flush
(boolean block) Writes as much data as possible from any that remains in the buffers.protected void
Writes all remaining data from the buffers and blocks until the write is complete.protected abstract boolean
Writes as much data as possible from any that remains in the buffers.protected AbstractEndpoint<E,
?> getError()
int
getLock()
long
int
abstract SSLSupport
Obtain an SSLSupport instance for this socket.getSslSupport
(String clientCertProvider) Deprecated.Will be removed in Tomcat 10.1.x onwardslong
boolean
Allows using NIO2 style read/write.boolean
boolean
boolean
Allows indicating if the connector supports per operation timeout.boolean
isClosed()
boolean
Allows checking if an asynchronous read operation is currently pending.abstract boolean
boolean
Checks to see if there are any writes pending and if there are callsregisterWriteInterest()
to trigger a callback once the pending writes have completed.boolean
isSecure()
Deprecated.Unused.boolean
Deprecated.Unused.boolean
Allows checking if an asynchronous write operation is currently pending.boolean
Allows indicating if the connector needs semaphores.protected abstract <A> SocketWrapperBase<E>.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<E>.VectoredIOCompletionHandler<A> completion) protected abstract void
protected abstract void
protected abstract void
protected int
populateReadBuffer
(byte[] b, int off, int len) protected int
protected abstract void
protected abstract void
protected abstract void
abstract SendfileState
processSendfile
(SendfileDataBase sendfileData) Starts the sendfile process.void
processSocket
(SocketEvent socketStatus, boolean dispatch) abstract int
read
(boolean block, byte[] b, int off, int len) abstract int
read
(boolean block, ByteBuffer to) final <A> SocketWrapperBase.CompletionState
read
(long timeout, TimeUnit unit, A attachment, CompletionHandler<Long, ? super A> handler, ByteBuffer... dsts) Scatter read.final <A> SocketWrapperBase.CompletionState
read
(ByteBuffer[] dsts, int offset, int length, SocketWrapperBase.BlockingMode block, long timeout, TimeUnit unit, A attachment, SocketWrapperBase.CompletionCheck check, CompletionHandler<Long, ? super A> handler) Scatter read.final <A> SocketWrapperBase.CompletionState
read
(SocketWrapperBase.BlockingMode block, long timeout, TimeUnit unit, A attachment, SocketWrapperBase.CompletionCheck check, CompletionHandler<Long, ? super A> handler, ByteBuffer... dsts) Scatter read.abstract void
abstract void
protected void
abstract void
void
setCurrentProcessor
(Object currentProcessor) void
setError
(IOException error) void
setKeepAliveLeft
(int keepAliveLeft) void
setNegotiatedProtocol
(String negotiatedProtocol) void
setReadTimeout
(long readTimeout) Set the timeout for reading.void
setSecure
(boolean secure) Deprecated.Unused.void
setUpgraded
(boolean upgraded) Deprecated.Unused.void
setWriteTimeout
(long writeTimeout) Set the timeout for writing.toString()
Overridden for debug purposes.protected static int
transfer
(byte[] from, int offset, int length, ByteBuffer to) protected static int
transfer
(ByteBuffer from, ByteBuffer to) void
unRead
(ByteBuffer returnedInput) Return input that has been read to the input buffer for re-reading by the correct component.protected final <A> SocketWrapperBase.CompletionState
vectoredOperation
(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) Vectored operation.final void
write
(boolean block, byte[] buf, int off, int len) Writes the provided data to the socket write buffer.final void
write
(boolean block, ByteBuffer from) Writes the provided data to the socket write buffer.final <A> SocketWrapperBase.CompletionState
write
(long timeout, TimeUnit unit, A attachment, CompletionHandler<Long, ? super A> handler, ByteBuffer... srcs) Gather write.final <A> SocketWrapperBase.CompletionState
write
(ByteBuffer[] srcs, int offset, int length, SocketWrapperBase.BlockingMode block, long timeout, TimeUnit unit, A attachment, SocketWrapperBase.CompletionCheck check, CompletionHandler<Long, ? super A> handler) Gather write.final <A> SocketWrapperBase.CompletionState
write
(SocketWrapperBase.BlockingMode block, long timeout, TimeUnit unit, A attachment, SocketWrapperBase.CompletionCheck check, CompletionHandler<Long, ? super A> handler, ByteBuffer... srcs) Gather write.protected void
writeBlocking
(byte[] buf, int off, int len) Writes the provided data to the socket write buffer.protected void
writeBlocking
(ByteBuffer from) Writes the provided data to the socket write buffer.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) 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
Separate method so it can be re-used by the socket write buffer to write data to the network
-
Field Details
-
sm
-
closed
-
previousIOException
-
localAddr
-
localName
-
localPort
protected int localPort -
remoteAddr
-
remoteHost
-
remotePort
protected int remotePort -
socketBufferHandler
The buffers used for communicating with the socket. -
bufferedWriteSize
protected int bufferedWriteSizeThe max size of the individual buffered write buffers -
nonBlockingWriteBuffer
Additional buffer used for non-blocking writes. Non-blocking writes need to return immediately even if the data cannot be written immediately but the socket buffer may not be big enough to hold all of the unwritten data. This structure provides an additional buffer to hold the data until it can be written. Not that while the Servlet API only allows one non-blocking write at a time, due to buffering and the possible need to write HTTP headers, this layer may see multiple writes. -
readPending
-
readOperation
-
writePending
-
writeOperation
-
COMPLETE_WRITE
This utility CompletionCheck will cause the write to fully write all remaining data. If the operation completes inline, the completion handler will not be called. -
COMPLETE_WRITE_WITH_COMPLETION
This utility CompletionCheck will cause the write to fully write all remaining data. The completion handler will then be called. -
READ_DATA
This utility CompletionCheck will cause the completion handler to be called once some data has been read. If the operation completes inline, the completion handler will not be called. -
COMPLETE_READ_WITH_COMPLETION
This utility CompletionCheck will cause the completion handler to be called once the given buffers are full. The completion handler will then be called. -
COMPLETE_READ
This utility CompletionCheck will cause the completion handler to be called once the given buffers are full. If the operation completes inline, the completion handler will not be called.
-
-
Constructor Details
-
SocketWrapperBase
-
-
Method Details
-
getSocket
-
reset
-
getEndpoint
-
getLock
-
getCurrentProcessor
-
setCurrentProcessor
-
takeCurrentProcessor
-
execute
Transfers processing to a container thread.- Parameters:
runnable
- The actions to process on a container thread- Throws:
RejectedExecutionException
- If the runnable cannot be executed
-
getError
-
setError
-
checkError
- Throws:
IOException
-
isUpgraded
Deprecated.Unused. Will be removed in Tomcat 10.- Returns:
true
if the connection has been upgraded.
-
setUpgraded
Deprecated.Unused. Will be removed in Tomcat 10.- Parameters:
upgraded
-true
if the connection has been upgraded.
-
isSecure
Deprecated.Unused. Will be removed in Tomcat 10.- Returns:
true
if the connection uses TLS
-
setSecure
Deprecated.Unused. Will be removed in Tomcat 10.- Parameters:
secure
-true
if the connection uses TLS
-
getNegotiatedProtocol
-
setNegotiatedProtocol
-
setReadTimeout
public void setReadTimeout(long readTimeout) Set the timeout for reading. Values of zero or less will be changed to -1.- Parameters:
readTimeout
- The timeout in milliseconds. A value of -1 indicates an infinite timeout.
-
getReadTimeout
public long getReadTimeout() -
setWriteTimeout
public void setWriteTimeout(long writeTimeout) Set the timeout for writing. Values of zero or less will be changed to -1.- Parameters:
writeTimeout
- The timeout in milliseconds. A value of zero or less indicates an infinite timeout.
-
getWriteTimeout
public long getWriteTimeout() -
setKeepAliveLeft
public void setKeepAliveLeft(int keepAliveLeft) -
decrementKeepAlive
public int decrementKeepAlive() -
getRemoteHost
-
populateRemoteHost
protected abstract void populateRemoteHost() -
getRemoteAddr
-
populateRemoteAddr
protected abstract void populateRemoteAddr() -
getRemotePort
public int getRemotePort() -
populateRemotePort
protected abstract void populateRemotePort() -
getLocalName
-
populateLocalName
protected abstract void populateLocalName() -
getLocalAddr
-
populateLocalAddr
protected abstract void populateLocalAddr() -
getLocalPort
public int getLocalPort() -
populateLocalPort
protected abstract void populateLocalPort() -
getSocketBufferHandler
-
hasDataToRead
public boolean hasDataToRead() -
hasDataToWrite
public boolean hasDataToWrite() -
isReadyForWrite
public boolean isReadyForWrite()Checks to see if there are any writes pending and if there are callsregisterWriteInterest()
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: ModifyregisterWriteInterest()
so the above restriction is enforced there rather than relying on the caller.- Returns:
true
if no writes are pending and data can be written otherwisefalse
-
canWrite
public boolean canWrite() -
toString
Overridden for debug purposes. No guarantees are made about the format of this message which may vary significantly between point releases. -
read
- Throws:
IOException
-
read
- Throws:
IOException
-
isReadyForRead
- Throws:
IOException
-
setAppReadBufHandler
-
populateReadBuffer
protected int populateReadBuffer(byte[] b, int off, int len) -
populateReadBuffer
-
unRead
Return input that has been read to the input buffer for re-reading by the correct component. There are times when a component may read more data than it needs before it passes control to another component. One example of this is during HTTP upgrade. If an (arguably misbehaving client) sends data associated with the upgraded protocol before the HTTP upgrade completes, the HTTP handler may read it. This method provides a way for that data to be returned so it can be processed by the correct component.- Parameters:
returnedInput
- The input to return to the input buffer.
-
close
public void close()Close the socket wrapper. -
doClose
protected abstract void doClose()Perform the actual close. The closed atomic boolean guarantees this will be called only once per wrapper. -
isClosed
public boolean isClosed()- Returns:
- true if the wrapper has been closed
-
write
Writes the provided data to the socket write buffer. If the socket write buffer fills during the write, the content of the socket write buffer is written to the network and this method starts to fill the socket write buffer again. Depending on the size of the data to write, there may be multiple writes to the network.Non-blocking writes must return immediately and the byte array holding the data to be written must be immediately available for re-use. It may not be possible to write sufficient data to the network to allow this to happen. In this case data that cannot be written to the network and cannot be held by the socket buffer is stored in the non-blocking write buffer.
Note: There is an implementation assumption that, before switching from non-blocking writes to blocking writes, any data remaining in the non-blocking write buffer will have been written to the network.
- Parameters:
block
-true
if a blocking write should be used, otherwise a non-blocking write will be usedbuf
- 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
-
write
Writes the provided data to the socket write buffer. If the socket write buffer fills during the write, the content of the socket write buffer is written to the network and this method starts to fill the socket write buffer again. Depending on the size of the data to write, there may be multiple writes to the network.Non-blocking writes must return immediately and the ByteBuffer holding the data to be written must be immediately available for re-use. It may not be possible to write sufficient data to the network to allow this to happen. In this case data that cannot be written to the network and cannot be held by the socket buffer is stored in the non-blocking write buffer.
Note: There is an implementation assumption that, before switching from non-blocking writes to blocking writes, any data remaining in the non-blocking write buffer will have been written to the network.
- Parameters:
block
-true
if a blocking write should be used, otherwise a non-blocking write will be usedfrom
- The ByteBuffer containing the data to be written- Throws:
IOException
- If an IO error occurs during the write
-
writeBlocking
Writes the provided data to the socket write buffer. If the socket write buffer fills during the write, the content of the socket write buffer is written to the network using a blocking write. Once that blocking write is complete, this method starts to fill the socket write buffer again. Depending on the size of the data to write, there may be multiple writes to the network. On completion of this method there will always be space remaining in the socket write buffer.- 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
-
writeBlocking
Writes the provided data to the socket write buffer. If the socket write buffer fills during the write, the content of the socket write buffer is written to the network using a blocking write. Once that blocking write is complete, this method starts to fill the socket write buffer again. Depending on the size of the data to write, there may be multiple writes to the network. On completion of this method there will always be space remaining in the socket write buffer.- Parameters:
from
- The ByteBuffer containing 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.- 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.- 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 network- Parameters:
from
- The ByteBuffer containing the data to be written- Throws:
IOException
- If an IO error occurs during the write
-
flush
Writes as much data as possible from any that remains in the buffers.- Parameters:
block
-true
if a blocking write should be used, otherwise a non-blocking write will be used- Returns:
true
if data remains to be flushed after this method completes, otherwisefalse
. In blocking mode therefore, the return value should always befalse
- Throws:
IOException
- If an IO error occurs during the write
-
flushBlocking
Writes all remaining data from the buffers and blocks until the write is complete.- Throws:
IOException
- If an IO error occurs during the write
-
flushNonBlocking
Writes as much data as possible from any that remains in the buffers.- Returns:
true
if data remains to be flushed after this method completes, otherwisefalse
.- Throws:
IOException
- If an IO error occurs during the write
-
doWrite
Write the contents of the socketWriteBuffer 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.- Parameters:
block
- Should the write be blocking or not?- Throws:
IOException
- If an I/O error such as a timeout occurs during the write
-
doWrite
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.- Parameters:
block
- Should the write be blocking or not?from
- the ByteBuffer containing the data to be written- Throws:
IOException
- If an I/O error such as a timeout occurs during the write
-
processSocket
-
registerReadInterest
public abstract void registerReadInterest() -
registerWriteInterest
public abstract void registerWriteInterest() -
createSendfileData
-
processSendfile
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.- Parameters:
sendfileData
- Data representing the file to send- Returns:
- The state of the sendfile process after the first write.
-
doClientAuth
Require the client to perform CLIENT-CERT authentication if it hasn't already done so.- 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
-
getSslSupport
Deprecated.Will be removed in Tomcat 10.1.x onwardsObtain an SSLSupport instance for this socket.- Parameters:
clientCertProvider
- The name of the client certificate provider to use. Only used by APR/native.- Returns:
- An SSLSupport instance for this socket.
-
getSslSupport
Obtain an SSLSupport instance for this socket.- Returns:
- An SSLSupport instance for this socket.
-
hasAsyncIO
public boolean hasAsyncIO()Allows using NIO2 style read/write.- Returns:
true
if the connector has the capability enabled
-
needSemaphores
public boolean needSemaphores()Allows indicating if the connector needs semaphores.- Returns:
- This default implementation always returns
false
-
hasPerOperationTimeout
public boolean hasPerOperationTimeout()Allows indicating if the connector supports per operation timeout.- Returns:
- This default implementation always returns
false
-
isReadPending
public boolean isReadPending()Allows checking if an asynchronous read operation is currently pending.- Returns:
true
if the endpoint supports asynchronous IO and a read operation is being processed asynchronously
-
isWritePending
public boolean isWritePending()Allows checking if an asynchronous write operation is currently pending.- Returns:
true
if the endpoint supports asynchronous IO and a write operation is being processed asynchronously
-
awaitReadComplete
Deprecated.If an asynchronous read operation is pending, this method will block until the operation completes, or the specified amount of time has passed.- Parameters:
timeout
- The maximum amount of time to waitunit
- 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
Deprecated.If an asynchronous write operation is pending, this method will block until the operation completes, or the specified amount of time has passed.- Parameters:
timeout
- The maximum amount of time to waitunit
- 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
-
read
public final <A> SocketWrapperBase.CompletionState read(long timeout, TimeUnit unit, A attachment, CompletionHandler<Long, ? super A> handler, ByteBuffer... dsts) Scatter read. The completion handler will be called once some data has been read or an error occurred. 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.- Type Parameters:
A
- The attachment type- Parameters:
timeout
- timeout duration for the readunit
- units for the timeout durationattachment
- an object to attach to the I/O operation that will be used when calling the completion handlerhandler
- to call when the IO is completedsts
- buffers- Returns:
- the completion state (done, done inline, or still pending)
-
read
public final <A> SocketWrapperBase.CompletionState read(SocketWrapperBase.BlockingMode block, long timeout, TimeUnit unit, A attachment, SocketWrapperBase.CompletionCheck check, CompletionHandler<Long, ? super A> handler, ByteBuffer... dsts) 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.- Type Parameters:
A
- The attachment type- Parameters:
block
- is the blocking mode that will be used for this operationtimeout
- timeout duration for the readunit
- units for the timeout durationattachment
- an object to attach to the I/O operation that will be used when calling the completion handlercheck
- for the IO operation completionhandler
- to call when the IO is completedsts
- buffers- Returns:
- the completion state (done, done inline, or still pending)
-
read
public final <A> SocketWrapperBase.CompletionState read(ByteBuffer[] dsts, int offset, int length, SocketWrapperBase.BlockingMode block, long timeout, TimeUnit unit, A attachment, SocketWrapperBase.CompletionCheck check, CompletionHandler<Long, ? super A> handler) 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.- Type Parameters:
A
- The attachment type- Parameters:
dsts
- buffersoffset
- in the buffer arraylength
- in the buffer arrayblock
- is the blocking mode that will be used for this operationtimeout
- timeout duration for the readunit
- units for the timeout durationattachment
- an object to attach to the I/O operation that will be used when calling the completion handlercheck
- for the IO operation completionhandler
- to call when the IO is complete- Returns:
- the completion state (done, done inline, or still pending)
-
write
public final <A> SocketWrapperBase.CompletionState write(long timeout, TimeUnit unit, A attachment, CompletionHandler<Long, ? super A> handler, ByteBuffer... srcs) Gather write. The completion handler will be called once some data has been written or an error occurred. 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.- Type Parameters:
A
- The attachment type- Parameters:
timeout
- timeout duration for the writeunit
- units for the timeout durationattachment
- an object to attach to the I/O operation that will be used when calling the completion handlerhandler
- to call when the IO is completesrcs
- buffers- Returns:
- the completion state (done, done inline, or still pending)
-
write
public final <A> SocketWrapperBase.CompletionState write(SocketWrapperBase.BlockingMode block, long timeout, TimeUnit unit, A attachment, SocketWrapperBase.CompletionCheck check, CompletionHandler<Long, ? super A> handler, ByteBuffer... srcs) 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.- Type Parameters:
A
- The attachment type- Parameters:
block
- is the blocking mode that will be used for this operationtimeout
- timeout duration for the writeunit
- units for the timeout durationattachment
- an object to attach to the I/O operation that will be used when calling the completion handlercheck
- for the IO operation completionhandler
- to call when the IO is completesrcs
- buffers- Returns:
- the completion state (done, done inline, or still pending)
-
write
public final <A> SocketWrapperBase.CompletionState write(ByteBuffer[] srcs, int offset, int length, SocketWrapperBase.BlockingMode block, long timeout, TimeUnit unit, A attachment, SocketWrapperBase.CompletionCheck check, CompletionHandler<Long, ? super A> handler) 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.- Type Parameters:
A
- The attachment type- Parameters:
srcs
- buffersoffset
- in the buffer arraylength
- in the buffer arrayblock
- is the blocking mode that will be used for this operationtimeout
- timeout duration for the writeunit
- units for the timeout durationattachment
- an object to attach to the I/O operation that will be used when calling the completion handlercheck
- for the IO operation completionhandler
- to call when the IO is complete- Returns:
- the completion state (done, done inline, or still pending)
-
vectoredOperation
protected final <A> SocketWrapperBase.CompletionState vectoredOperation(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) Vectored operation. The completion handler will be called once the operation is complete 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 operation is incomplete, or if the operation completed inline.- Type Parameters:
A
- The attachment type- Parameters:
read
- true if the operation is a read, false if it is a writebuffers
- buffersoffset
- in the buffer arraylength
- in the buffer arrayblock
- is the blocking mode that will be used for this operationtimeout
- timeout duration for the writeunit
- units for the timeout durationattachment
- an object to attach to the I/O operation that will be used when calling the completion handlercheck
- for the IO operation completionhandler
- to call when the IO is complete- Returns:
- the completion state (done, done inline, or still pending)
-
newOperationState
protected abstract <A> SocketWrapperBase<E>.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<E>.VectoredIOCompletionHandler<A> completion) -
transfer
-
transfer
-
buffersArrayHasRemaining
-