Package org.apache.tomcat.util.net
Class NioChannel
java.lang.Object
org.apache.tomcat.util.net.NioChannel
- All Implemented Interfaces:
- Closeable,- AutoCloseable,- ByteChannel,- Channel,- GatheringByteChannel,- ReadableByteChannel,- ScatteringByteChannel,- WritableByteChannel
- Direct Known Subclasses:
- SecureNioChannel
public class NioChannel
extends Object
implements ByteChannel, ScatteringByteChannel, GatheringByteChannel
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 SummaryFieldsModifier and TypeFieldDescriptionprotected final SocketBufferHandlerprotected static final ByteBufferprotected SocketChannelprotected static final StringManagerprotected NioEndpoint.NioSocketWrapper
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected voidThis method should be used to check the interrupt status before attempting a write.voidclose()Closes this channel.voidclose(boolean force) Close the connection.booleanReturn true if the buffer wrote data.voidfree()Free the channel memoryprotected ApplicationBufferHandlerintinthandshake(boolean read, boolean write) Performs SSL handshake hence is a no-op for the non-secure implementation.booleanbooleanbooleanisOpen()Tells whether or not this channel is open.intread(ByteBuffer dst) Reads a sequence of bytes from this channel into the given buffer.longread(ByteBuffer[] dsts) longread(ByteBuffer[] dsts, int offset, int length) voidreset(SocketChannel channel, NioEndpoint.NioSocketWrapper socketWrapper) Reset the channelvoidtoString()intwrite(ByteBuffer src) Writes a sequence of bytes to this channel from the given buffer.longwrite(ByteBuffer[] srcs) longwrite(ByteBuffer[] srcs, int offset, int length) 
- 
Field Details- 
sm
- 
emptyBuf
- 
bufHandler
- 
sc
- 
socketWrapper
 
- 
- 
Constructor Details- 
NioChannel
 
- 
- 
Method Details- 
resetpublic void reset(SocketChannel channel, NioEndpoint.NioSocketWrapper socketWrapper) throws IOException Reset the channel- Parameters:
- channel- the socket channel
- socketWrapper- the socket wrapper
- Throws:
- IOException- If a problem was encountered resetting the channel
 
- 
freepublic void free()Free the channel memory
- 
closeCloses this channel.- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Channel
- Specified by:
- closein interface- Closeable
- Throws:
- IOException- If an I/O error occurs
 
- 
closeClose the connection.- Parameters:
- force- Should the underlying socket be forcibly closed?
- Throws:
- IOException- If closing the secure channel fails.
 
- 
isOpenpublic boolean isOpen()Tells whether or not this channel is open.
- 
writeWrites a sequence of bytes to this channel from the given buffer.- Specified by:
- writein interface- WritableByteChannel
- Parameters:
- src- The buffer from which bytes are to be retrieved
- Returns:
- The number of bytes written, possibly zero
- Throws:
- IOException- If some other I/O error occurs
 
- 
write- Specified by:
- writein interface- GatheringByteChannel
- Throws:
- IOException
 
- 
write- Specified by:
- writein interface- GatheringByteChannel
- Throws:
- IOException
 
- 
readReads a sequence of bytes from this channel into the given buffer.- Specified by:
- readin interface- ReadableByteChannel
- Parameters:
- dst- The buffer into which bytes are to be transferred
- Returns:
- The number of bytes read, possibly zero, or -1if the channel has reached end-of-stream
- Throws:
- IOException- If some other I/O error occurs
 
- 
read- Specified by:
- readin interface- ScatteringByteChannel
- Throws:
- IOException
 
- 
read- Specified by:
- readin interface- ScatteringByteChannel
- Throws:
- IOException
 
- 
getBufHandler
- 
getIOChannel
- 
isClosingpublic boolean isClosing()
- 
isHandshakeCompletepublic boolean isHandshakeComplete()
- 
handshakePerforms SSL handshake hence is a no-op for the non-secure implementation.- Parameters:
- read- Unused in non-secure implementation
- write- Unused in non-secure implementation
- Returns:
- Always returns zero
- Throws:
- IOException- Never for non-secure channel
 
- 
toString
- 
getOutboundRemainingpublic int getOutboundRemaining()
- 
flushOutboundReturn true if the buffer wrote data. NO-OP for non-secure channel.- Returns:
- Always returns falsefor non-secure channel
- Throws:
- IOException- Never for non-secure channel
 
- 
checkInterruptStatusThis method should be used to check the interrupt status before attempting a write. If a thread has been interrupted and the interrupt has not been cleared then an attempt to write to the socket will fail. When this happens the socket is removed from the poller without the socket being selected. This results in a connection limit leak for NIO as the endpoint expects the socket to be selected even in error conditions.- Throws:
- IOException- If the current thread was interrupted
 
- 
setAppReadBufHandler
- 
getAppReadBufHandler
 
-