Package org.apache.tomcat.util.net
Class SecureNio2Channel
java.lang.Object
org.apache.tomcat.util.net.Nio2Channel
org.apache.tomcat.util.net.SecureNio2Channel
- All Implemented Interfaces:
- Closeable,- AutoCloseable,- AsynchronousByteChannel,- AsynchronousChannel,- Channel
Implementation of a secure socket channel for NIO2.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected booleanprotected booleanprotected final Nio2Endpointprotected ByteBufferprotected ByteBufferprotected booleanprotected SSLEngineFields inherited from class org.apache.tomcat.util.net.Nio2ChannelbufHandler, emptyBuf, sc, socketWrapper
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidclose()Sends an SSL close message, will not physically close the connection here.
 To close the connection, you could do something likevoidclose(boolean force) Close the connection.flush()Flush the channel.voidfree()Free the channel memoryintPerforms SSL handshake, non blocking, but performs NEED_TASK on the same thread.protected inthandshakeInternal(boolean async) protected SSLEngineResultPerform handshake unwrapprotected SSLEngineResultPerforms the WRAP functionbooleanbooleanread(ByteBuffer dst) Reads a sequence of bytes from this channel into the given buffer.<A> voidread(ByteBuffer[] dsts, int offset, int length, long timeout, TimeUnit unit, A attachment, CompletionHandler<Long, ? super A> handler) <A> voidread(ByteBuffer dst, long timeout, TimeUnit unit, A attachment, CompletionHandler<Integer, ? super A> handler) voidForce a blocking handshake to take place for this key.voidreset(AsynchronousSocketChannel channel, SocketWrapperBase<Nio2Channel> socket) Reset the channel.protected SSLEngineResult.HandshakeStatustasks()Executes all the tasks needed on the same thread.write(ByteBuffer src) Writes a sequence of bytes to this channel from the given buffer.<A> voidwrite(ByteBuffer[] srcs, int offset, int length, long timeout, TimeUnit unit, A attachment, CompletionHandler<Long, ? super A> handler) <A> voidwrite(ByteBuffer src, long timeout, TimeUnit unit, A attachment, CompletionHandler<Integer, ? super A> handler) Methods inherited from class org.apache.tomcat.util.net.Nio2ChannelgetAppReadBufHandler, getBufHandler, getIOChannel, isOpen, read, setAppReadBufHandler, toString, write
- 
Field Details- 
endpoint
- 
netInBuffer
- 
netOutBuffer
- 
sslEngine
- 
sniCompleteprotected volatile boolean sniComplete
- 
closedprotected boolean closed
- 
closingprotected boolean closing
 
- 
- 
Constructor Details- 
SecureNio2Channel
 
- 
- 
Method Details- 
resetpublic void reset(AsynchronousSocketChannel channel, SocketWrapperBase<Nio2Channel> socket) throws IOException Description copied from class:Nio2ChannelReset the channel.- Overrides:
- resetin class- Nio2Channel
- Parameters:
- channel- The new async channel to associate with this NIO2 channel
- socket- The new socket to associate with this NIO2 channel
- Throws:
- IOException- If a problem was encountered resetting the channel
 
- 
freepublic void free()Description copied from class:Nio2ChannelFree the channel memory- Overrides:
- freein class- Nio2Channel
 
- 
flushFlush the channel.- Overrides:
- flushin class- Nio2Channel
- Returns:
- trueif the network buffer has been flushed out and is empty else- false(as a future)
 
- 
handshakePerforms SSL handshake, non blocking, but performs NEED_TASK on the same thread. Hence, you should never call this method using your Acceptor thread, as you would slow down your system significantly.The return for this operation is 0 if the handshake is complete and a positive value if it is not complete. In the event of a positive value coming back, the appropriate read/write will already have been called with an appropriate CompletionHandler. - Overrides:
- handshakein class- Nio2Channel
- Returns:
- 0 if hand shake is complete, negative if the socket needs to close and positive if the handshake is incomplete
- Throws:
- IOException- if an error occurs during the handshake
 
- 
handshakeInternal- Throws:
- IOException
 
- 
rehandshakeForce a blocking handshake to take place for this key. This requires that both network and application buffers have been emptied out prior to this call taking place, or a IOException will be thrown.- Throws:
- IOException- - if an IO exception occurs or if application or network buffers contain data
- SocketTimeoutException- - if a socket operation timed out
 
- 
tasksExecutes all the tasks needed on the same thread.- Returns:
- the status
 
- 
handshakeWrapPerforms the WRAP function- Returns:
- the result
- Throws:
- IOException- An IO error occurred
 
- 
handshakeUnwrapPerform handshake unwrap- Returns:
- the result
- Throws:
- IOException- An IO error occurred
 
- 
getSSLSupport
- 
closeSends an SSL close message, will not physically close the connection here.
 To close the connection, you could do something likeclose(); while (isOpen() && !myTimeoutFunction()) Thread.sleep(25); if ( isOpen() ) close(true); //forces a close if you timed out- Specified by:
- closein interface- AsynchronousChannel
- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Channel
- Specified by:
- closein interface- Closeable
- Overrides:
- closein class- Nio2Channel
- Throws:
- IOException- if an I/O error occurs
- IOException- if there is data on the outgoing network buffer and we are unable to flush it
 
- 
closeDescription copied from class:Nio2ChannelClose the connection.- Overrides:
- closein class- Nio2Channel
- Parameters:
- force- Should the underlying socket be forcibly closed?
- Throws:
- IOException- If closing the secure channel fails.
 
- 
readReads a sequence of bytes from this channel into the given buffer.- Specified by:
- readin interface- AsynchronousByteChannel
- Overrides:
- readin class- Nio2Channel
- 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:
- IllegalStateException- if the handshake was not completed
 
- 
writeWrites a sequence of bytes to this channel from the given buffer.- Specified by:
- writein interface- AsynchronousByteChannel
- Overrides:
- writein class- Nio2Channel
- Parameters:
- src- The buffer from which bytes are to be retrieved
- Returns:
- The number of bytes written, possibly zero
 
- 
readpublic <A> void read(ByteBuffer dst, long timeout, TimeUnit unit, A attachment, CompletionHandler<Integer, ? super A> handler) - Overrides:
- readin class- Nio2Channel
 
- 
readpublic <A> void read(ByteBuffer[] dsts, int offset, int length, long timeout, TimeUnit unit, A attachment, CompletionHandler<Long, ? super A> handler) - Overrides:
- readin class- Nio2Channel
 
- 
writepublic <A> void write(ByteBuffer src, long timeout, TimeUnit unit, A attachment, CompletionHandler<Integer, ? super A> handler) - Overrides:
- writein class- Nio2Channel
 
- 
writepublic <A> void write(ByteBuffer[] srcs, int offset, int length, long timeout, TimeUnit unit, A attachment, CompletionHandler<Long, ? super A> handler) - Overrides:
- writein class- Nio2Channel
 
- 
isHandshakeCompletepublic boolean isHandshakeComplete()- Overrides:
- isHandshakeCompletein class- Nio2Channel
 
- 
isClosingpublic boolean isClosing()- Overrides:
- isClosingin class- Nio2Channel
 
- 
getSslEngine
- 
getEmptyBuf
 
-