public static class Nio2Endpoint.Nio2SocketWrapper extends SocketWrapperBase<Nio2Channel>
SocketWrapperBase.BlockingMode, SocketWrapperBase.CompletionCheck, SocketWrapperBase.CompletionHandlerCall, SocketWrapperBase.CompletionState, SocketWrapperBase.OperationState<A>, SocketWrapperBase.VectoredIOCompletionHandler<A>
bufferedWriteSize, closed, COMPLETE_READ, COMPLETE_READ_WITH_COMPLETION, COMPLETE_WRITE, COMPLETE_WRITE_WITH_COMPLETION, currentProcessor, localAddr, localName, localPort, nonBlockingWriteBuffer, previousIOException, READ_DATA, readOperation, readPending, remoteAddr, remoteHost, remotePort, sm, socketBufferHandler, writeOperation, writePending
Constructor and Description |
---|
Nio2SocketWrapper(Nio2Channel channel,
Nio2Endpoint endpoint) |
Modifier and Type | Method and Description |
---|---|
SendfileDataBase |
createSendfileData(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,
ByteBuffer from)
Write the contents of the ByteBuffer to the socket.
|
protected void |
flushBlocking() |
protected boolean |
flushNonBlocking() |
Nio2Endpoint.SendfileData |
getSendfileData() |
SSLSupport |
getSslSupport(String clientCertProvider) |
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 calls
SocketWrapperBase.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,
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.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,
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(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(ByteBuffer from)
Separate method so it can be re-used by the socket write buffer to write
data to the network
|
buffersArrayHasRemaining, canWrite, checkError, close, decrementKeepAlive, doWrite, execute, flush, getCurrentProcessor, getEndpoint, getError, getLocalAddr, getLocalName, getLocalPort, getNegotiatedProtocol, getReadTimeout, getRemoteAddr, getRemoteHost, getRemotePort, getSocket, getSocketBufferHandler, getWriteTimeout, isClosed, populateReadBuffer, populateReadBuffer, processSocket, read, read, read, reset, setCurrentProcessor, setError, setKeepAliveLeft, setNegotiatedProtocol, setReadTimeout, setWriteTimeout, toString, transfer, transfer, unRead, vectoredOperation, write, write, write, write, write, writeBlocking, writeBlocking
public Nio2SocketWrapper(Nio2Channel channel, Nio2Endpoint endpoint)
public void setSendfileData(Nio2Endpoint.SendfileData sf)
public Nio2Endpoint.SendfileData getSendfileData()
public boolean isReadyForRead() throws IOException
isReadyForRead
in class SocketWrapperBase<Nio2Channel>
IOException
public boolean isReadyForWrite()
SocketWrapperBase
SocketWrapperBase.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: Modify SocketWrapperBase.registerWriteInterest()
so the above
restriction is enforced there rather than relying on the caller.
isReadyForWrite
in class SocketWrapperBase<Nio2Channel>
true
if no writes are pending and data can be
written otherwise false
public int read(boolean block, byte[] b, int off, int len) throws IOException
read
in class SocketWrapperBase<Nio2Channel>
IOException
public int read(boolean block, ByteBuffer to) throws IOException
read
in class SocketWrapperBase<Nio2Channel>
IOException
protected void doClose()
SocketWrapperBase
doClose
in class SocketWrapperBase<Nio2Channel>
public boolean hasAsyncIO()
SocketWrapperBase
hasAsyncIO
in class SocketWrapperBase<Nio2Channel>
true
if the connector has the capability enabledpublic boolean needSemaphores()
SocketWrapperBase
needSemaphores
in class SocketWrapperBase<Nio2Channel>
false
public boolean hasPerOperationTimeout()
SocketWrapperBase
hasPerOperationTimeout
in class SocketWrapperBase<Nio2Channel>
false
protected <A> SocketWrapperBase.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.VectoredIOCompletionHandler<A> completion)
newOperationState
in class SocketWrapperBase<Nio2Channel>
protected void writeNonBlocking(byte[] buf, int off, int len) throws IOException
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.
writeNonBlocking
in class SocketWrapperBase<Nio2Channel>
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 writtenIOException
- If an IO error occurs during the writeprotected void writeNonBlocking(ByteBuffer from) throws IOException
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.
writeNonBlocking
in class SocketWrapperBase<Nio2Channel>
from
- The ByteBuffer containing the data to be writtenIOException
- If an IO error occurs during the writeprotected void writeNonBlockingInternal(ByteBuffer from) throws IOException
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.
writeNonBlockingInternal
in class SocketWrapperBase<Nio2Channel>
from
- The ByteBuffer containing the data to be writtenIOException
- If an IO error occurs during the writeprotected void doWrite(boolean block, ByteBuffer from) throws IOException
SocketWrapperBase
doWrite
in class SocketWrapperBase<Nio2Channel>
block
- Ignored since this method is only called in the
blocking casefrom
- the ByteBuffer containing the data to be writtenIOException
- If an I/O error such as a timeout occurs during the
writeprotected void flushBlocking() throws IOException
flushBlocking
in class SocketWrapperBase<Nio2Channel>
IOException
protected boolean flushNonBlocking() throws IOException
flushNonBlocking
in class SocketWrapperBase<Nio2Channel>
IOException
public boolean hasDataToRead()
hasDataToRead
in class SocketWrapperBase<Nio2Channel>
public boolean hasDataToWrite()
hasDataToWrite
in class SocketWrapperBase<Nio2Channel>
public boolean isReadPending()
SocketWrapperBase
isReadPending
in class SocketWrapperBase<Nio2Channel>
true
if the endpoint supports asynchronous IO and
a read operation is being processed asynchronouslypublic boolean isWritePending()
SocketWrapperBase
isWritePending
in class SocketWrapperBase<Nio2Channel>
true
if the endpoint supports asynchronous IO and
a write operation is being processed asynchronouslypublic void registerReadInterest()
registerReadInterest
in class SocketWrapperBase<Nio2Channel>
public void registerWriteInterest()
registerWriteInterest
in class SocketWrapperBase<Nio2Channel>
public SendfileDataBase createSendfileData(String filename, long pos, long length)
createSendfileData
in class SocketWrapperBase<Nio2Channel>
public SendfileState processSendfile(SendfileDataBase sendfileData)
SocketWrapperBase
processSendfile
in class SocketWrapperBase<Nio2Channel>
sendfileData
- Data representing the file to sendprotected void populateRemoteAddr()
populateRemoteAddr
in class SocketWrapperBase<Nio2Channel>
protected void populateRemoteHost()
populateRemoteHost
in class SocketWrapperBase<Nio2Channel>
protected void populateRemotePort()
populateRemotePort
in class SocketWrapperBase<Nio2Channel>
protected void populateLocalName()
populateLocalName
in class SocketWrapperBase<Nio2Channel>
protected void populateLocalAddr()
populateLocalAddr
in class SocketWrapperBase<Nio2Channel>
protected void populateLocalPort()
populateLocalPort
in class SocketWrapperBase<Nio2Channel>
public SSLSupport getSslSupport(String clientCertProvider)
getSslSupport
in class SocketWrapperBase<Nio2Channel>
clientCertProvider
- Ignored for this implementationpublic void doClientAuth(SSLSupport sslSupport) throws IOException
SocketWrapperBase
doClientAuth
in class SocketWrapperBase<Nio2Channel>
sslSupport
- The SSL/TLS support instance currently being used by
the connection that may need updating after the client
authenticationIOException
- If authentication is required then there will be I/O
with the client and this exception will be thrown if
that goes wrongpublic void setAppReadBufHandler(ApplicationBufferHandler handler)
setAppReadBufHandler
in class SocketWrapperBase<Nio2Channel>
Copyright © 2000-2021 Apache Software Foundation. All Rights Reserved.