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
public class Nio2Channel extends Object implements AsynchronousByteChannel
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
Fields Modifier and Type Field Description protected SocketBufferHandler
bufHandler
protected static ByteBuffer
emptyBuf
protected AsynchronousSocketChannel
sc
protected SocketWrapperBase<Nio2Channel>
socketWrapper
-
Constructor Summary
Constructors Constructor Description Nio2Channel(SocketBufferHandler bufHandler)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes this channel.void
close(boolean force)
Close the connection.Future<Boolean>
flush()
void
free()
Free the channel memoryprotected ApplicationBufferHandler
getAppReadBufHandler()
SocketBufferHandler
getBufHandler()
AsynchronousSocketChannel
getIOChannel()
int
handshake()
Performs SSL handshake hence is a no-op for the non-secure implementation.boolean
isClosing()
boolean
isHandshakeComplete()
boolean
isOpen()
Tells whether or not this channel is open.Future<Integer>
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
setAppReadBufHandler(ApplicationBufferHandler handler)
String
toString()
Future<Integer>
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 Detail
-
emptyBuf
protected static final ByteBuffer emptyBuf
-
bufHandler
protected final SocketBufferHandler bufHandler
-
sc
protected AsynchronousSocketChannel sc
-
socketWrapper
protected SocketWrapperBase<Nio2Channel> socketWrapper
-
-
Constructor Detail
-
Nio2Channel
public Nio2Channel(SocketBufferHandler bufHandler)
-
-
Method Detail
-
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
public void close() throws IOException
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
public void close(boolean force) throws IOException
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
public SocketBufferHandler getBufHandler()
-
getIOChannel
public AsynchronousSocketChannel getIOChannel()
-
isClosing
public boolean isClosing()
-
isHandshakeComplete
public boolean isHandshakeComplete()
-
handshake
public int handshake() throws IOException
Performs SSL handshake hence is a no-op for the non-secure implementation.- Returns:
- Always returns zero
- Throws:
IOException
- Never for non-secure channel
-
read
public Future<Integer> read(ByteBuffer dst)
- Specified by:
read
in interfaceAsynchronousByteChannel
-
read
public <A> void read(ByteBuffer dst, A attachment, CompletionHandler<Integer,? super A> handler)
- 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
public Future<Integer> write(ByteBuffer src)
- Specified by:
write
in interfaceAsynchronousByteChannel
-
write
public <A> void write(ByteBuffer src, A attachment, CompletionHandler<Integer,? super A> handler)
- 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)
-
setAppReadBufHandler
public void setAppReadBufHandler(ApplicationBufferHandler handler)
-
getAppReadBufHandler
protected ApplicationBufferHandler getAppReadBufHandler()
-
-