Package org.apache.tomcat.util.net
Class Nio2Channel
java.lang.Object
org.apache.tomcat.util.net.Nio2Channel
- All Implemented Interfaces:
Closeable
,AutoCloseable
,AsynchronousByteChannel
,AsynchronousChannel
,Channel
- Direct Known Subclasses:
SecureNio2Channel
Base class for a SocketChannel wrapper used by the endpoint.
This way, logic for an SSL socket channel remains the same as for
a non SSL, making sure we don't need to code for any exception cases.
-
Field Summary
Modifier and TypeFieldDescriptionprotected final SocketBufferHandler
protected static final ByteBuffer
protected AsynchronousSocketChannel
protected SocketWrapperBase<Nio2Channel>
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes this channel.void
close
(boolean force) Close the connection.flush()
void
free()
Free the channel memoryprotected ApplicationBufferHandler
int
Performs SSL handshake hence is a no-op for the non-secure implementation.boolean
boolean
boolean
isOpen()
Tells whether or not this channel is open.read
(ByteBuffer dst) <A> void
read
(ByteBuffer[] dsts, int offset, int length, long timeout, TimeUnit unit, A attachment, CompletionHandler<Long, ? super A> handler) <A> void
read
(ByteBuffer dst, long timeout, TimeUnit unit, A attachment, CompletionHandler<Integer, ? super A> handler) <A> void
read
(ByteBuffer dst, A attachment, CompletionHandler<Integer, ? super A> handler) void
reset
(AsynchronousSocketChannel channel, SocketWrapperBase<Nio2Channel> socketWrapper) Reset the channel.void
toString()
write
(ByteBuffer src) <A> void
write
(ByteBuffer[] srcs, int offset, int length, long timeout, TimeUnit unit, A attachment, CompletionHandler<Long, ? super A> handler) <A> void
write
(ByteBuffer src, long timeout, TimeUnit unit, A attachment, CompletionHandler<Integer, ? super A> handler) <A> void
write
(ByteBuffer src, A attachment, CompletionHandler<Integer, ? super A> handler)
-
Field Details
-
emptyBuf
-
bufHandler
-
sc
-
socketWrapper
-
-
Constructor Details
-
Nio2Channel
-
-
Method Details
-
reset
public void reset(AsynchronousSocketChannel channel, SocketWrapperBase<Nio2Channel> socketWrapper) throws IOException Reset the channel.- Parameters:
channel
- The new async channel to associate with this NIO2 channelsocketWrapper
- The new socket to associate with this NIO2 channel- Throws:
IOException
- If a problem was encountered resetting the channel
-
free
public void free()Free the channel memory -
close
Closes this channel.- Specified by:
close
in interfaceAsynchronousChannel
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceChannel
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
- If an I/O error occurs
-
close
Close the connection.- Parameters:
force
- Should the underlying socket be forcibly closed?- Throws:
IOException
- If closing the secure channel fails.
-
isOpen
public boolean isOpen()Tells whether or not this channel is open. -
getBufHandler
-
getIOChannel
-
isClosing
public boolean isClosing() -
isHandshakeComplete
public boolean isHandshakeComplete() -
handshake
Performs SSL handshake hence is a no-op for the non-secure implementation.- Returns:
- Always returns zero
- Throws:
IOException
- Never for non-secure channel
-
toString
-
read
- Specified by:
read
in interfaceAsynchronousByteChannel
-
read
- Specified by:
read
in interfaceAsynchronousByteChannel
-
read
public <A> void read(ByteBuffer dst, long timeout, TimeUnit unit, A attachment, CompletionHandler<Integer, ? super A> handler) -
read
public <A> void read(ByteBuffer[] dsts, int offset, int length, long timeout, TimeUnit unit, A attachment, CompletionHandler<Long, ? super A> handler) -
write
- Specified by:
write
in interfaceAsynchronousByteChannel
-
write
- Specified by:
write
in interfaceAsynchronousByteChannel
-
write
public <A> void write(ByteBuffer src, long timeout, TimeUnit unit, A attachment, CompletionHandler<Integer, ? super A> handler) -
write
public <A> void write(ByteBuffer[] srcs, int offset, int length, long timeout, TimeUnit unit, A attachment, CompletionHandler<Long, ? super A> handler) -
flush
-
setAppReadBufHandler
-
getAppReadBufHandler
-