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:
- java.io.Closeable,- java.lang.AutoCloseable,- java.nio.channels.AsynchronousByteChannel,- java.nio.channels.AsynchronousChannel,- java.nio.channels.Channel
 
 public class SecureNio2Channel extends Nio2Channel Implementation of a secure socket channel for NIO2.
- 
- 
Field SummaryFields Modifier and Type Field Description protected booleanclosedprotected booleanclosingprotected Nio2Endpointendpointprotected java.nio.ByteBuffernetInBufferprotected java.nio.ByteBuffernetOutBufferprotected booleansniCompleteprotected javax.net.ssl.SSLEnginesslEngine- 
Fields inherited from class org.apache.tomcat.util.net.Nio2ChannelbufHandler, emptyBuf, sc, socketWrapper
 
- 
 - 
Constructor SummaryConstructors Constructor Description SecureNio2Channel(SocketBufferHandler bufHandler, Nio2Endpoint endpoint)
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()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.java.util.concurrent.Future<java.lang.Boolean>flush()Flush the channel.voidfree()Free the channel memoryjava.nio.ByteBuffergetEmptyBuf()javax.net.ssl.SSLEnginegetSslEngine()SSLSupportgetSSLSupport()inthandshake()Performs SSL handshake, non blocking, but performs NEED_TASK on the same thread.protected inthandshakeInternal(boolean async)protected javax.net.ssl.SSLEngineResulthandshakeUnwrap()Perform handshake unwrapprotected javax.net.ssl.SSLEngineResulthandshakeWrap()Performs the WRAP functionbooleanisClosing()booleanisHandshakeComplete()java.util.concurrent.Future<java.lang.Integer>read(java.nio.ByteBuffer dst)Reads a sequence of bytes from this channel into the given buffer.<A> voidread(java.nio.ByteBuffer[] dsts, int offset, int length, long timeout, java.util.concurrent.TimeUnit unit, A attachment, java.nio.channels.CompletionHandler<java.lang.Long,? super A> handler)<A> voidread(java.nio.ByteBuffer dst, long timeout, java.util.concurrent.TimeUnit unit, A attachment, java.nio.channels.CompletionHandler<java.lang.Integer,? super A> handler)voidrehandshake()Force a blocking handshake to take place for this key.voidreset(java.nio.channels.AsynchronousSocketChannel channel, SocketWrapperBase<Nio2Channel> socket)Reset the channel.protected javax.net.ssl.SSLEngineResult.HandshakeStatustasks()Executes all the tasks needed on the same thread.java.util.concurrent.Future<java.lang.Integer>write(java.nio.ByteBuffer src)Writes a sequence of bytes to this channel from the given buffer.<A> voidwrite(java.nio.ByteBuffer[] srcs, int offset, int length, long timeout, java.util.concurrent.TimeUnit unit, A attachment, java.nio.channels.CompletionHandler<java.lang.Long,? super A> handler)<A> voidwrite(java.nio.ByteBuffer src, long timeout, java.util.concurrent.TimeUnit unit, A attachment, java.nio.channels.CompletionHandler<java.lang.Integer,? super A> handler)- 
Methods inherited from class org.apache.tomcat.util.net.Nio2ChannelgetAppReadBufHandler, getBufHandler, getIOChannel, isOpen, read, setAppReadBufHandler, toString, write
 
- 
 
- 
- 
- 
Field Detail- 
endpointprotected final Nio2Endpoint endpoint 
 - 
netInBufferprotected java.nio.ByteBuffer netInBuffer 
 - 
netOutBufferprotected java.nio.ByteBuffer netOutBuffer 
 - 
sslEngineprotected javax.net.ssl.SSLEngine sslEngine 
 - 
sniCompleteprotected volatile boolean sniComplete 
 - 
closedprotected boolean closed 
 - 
closingprotected boolean closing 
 
- 
 - 
Constructor Detail- 
SecureNio2Channelpublic SecureNio2Channel(SocketBufferHandler bufHandler, Nio2Endpoint endpoint) 
 
- 
 - 
Method Detail- 
resetpublic void reset(java.nio.channels.AsynchronousSocketChannel channel, SocketWrapperBase<Nio2Channel> socket) throws java.io.IOExceptionDescription 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:
- java.io.IOException- If a problem was encountered resetting the channel
 
 - 
freepublic void free() Description copied from class:Nio2ChannelFree the channel memory- Overrides:
- freein class- Nio2Channel
 
 - 
flushpublic java.util.concurrent.Future<java.lang.Boolean> flush() Flush the channel.- Overrides:
- flushin class- Nio2Channel
- Returns:
- trueif the network buffer has been flushed out and is empty else- false(as a future)
 
 - 
handshakepublic int handshake() throws java.io.IOExceptionPerforms 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:
- java.io.IOException- if an error occurs during the handshake
 
 - 
handshakeInternalprotected int handshakeInternal(boolean async) throws java.io.IOException- Throws:
- java.io.IOException
 
 - 
rehandshakepublic void rehandshake() throws java.io.IOExceptionForce 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:
- java.io.IOException- - if an IO exception occurs or if application or network buffers contain data
- java.net.SocketTimeoutException- - if a socket operation timed out
 
 - 
tasksprotected javax.net.ssl.SSLEngineResult.HandshakeStatus tasks() Executes all the tasks needed on the same thread.- Returns:
- the status
 
 - 
handshakeWrapprotected javax.net.ssl.SSLEngineResult handshakeWrap() throws java.io.IOExceptionPerforms the WRAP function- Returns:
- the result
- Throws:
- java.io.IOException- An IO error occurred
 
 - 
handshakeUnwrapprotected javax.net.ssl.SSLEngineResult handshakeUnwrap() throws java.io.IOExceptionPerform handshake unwrap- Returns:
- the result
- Throws:
- java.io.IOException- An IO error occurred
 
 - 
getSSLSupportpublic SSLSupport getSSLSupport() 
 - 
closepublic void close() throws java.io.IOExceptionSends 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- java.nio.channels.AsynchronousChannel
- Specified by:
- closein interface- java.lang.AutoCloseable
- Specified by:
- closein interface- java.nio.channels.Channel
- Specified by:
- closein interface- java.io.Closeable
- Overrides:
- closein class- Nio2Channel
- Throws:
- java.io.IOException- if an I/O error occurs
- java.io.IOException- if there is data on the outgoing network buffer and we are unable to flush it
 
 - 
closepublic void close(boolean force) throws java.io.IOExceptionDescription copied from class:Nio2ChannelClose the connection.- Overrides:
- closein class- Nio2Channel
- Parameters:
- force- Should the underlying socket be forcibly closed?
- Throws:
- java.io.IOException- If closing the secure channel fails.
 
 - 
readpublic java.util.concurrent.Future<java.lang.Integer> read(java.nio.ByteBuffer dst) Reads a sequence of bytes from this channel into the given buffer.- Specified by:
- readin interface- java.nio.channels.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:
- java.lang.IllegalStateException- if the handshake was not completed
 
 - 
writepublic java.util.concurrent.Future<java.lang.Integer> write(java.nio.ByteBuffer src) Writes a sequence of bytes to this channel from the given buffer.- Specified by:
- writein interface- java.nio.channels.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(java.nio.ByteBuffer dst, long timeout, java.util.concurrent.TimeUnit unit, A attachment, java.nio.channels.CompletionHandler<java.lang.Integer,? super A> handler)- Overrides:
- readin class- Nio2Channel
 
 - 
readpublic <A> void read(java.nio.ByteBuffer[] dsts, int offset, int length, long timeout, java.util.concurrent.TimeUnit unit, A attachment, java.nio.channels.CompletionHandler<java.lang.Long,? super A> handler)- Overrides:
- readin class- Nio2Channel
 
 - 
writepublic <A> void write(java.nio.ByteBuffer src, long timeout, java.util.concurrent.TimeUnit unit, A attachment, java.nio.channels.CompletionHandler<java.lang.Integer,? super A> handler)- Overrides:
- writein class- Nio2Channel
 
 - 
writepublic <A> void write(java.nio.ByteBuffer[] srcs, int offset, int length, long timeout, java.util.concurrent.TimeUnit unit, A attachment, java.nio.channels.CompletionHandler<java.lang.Long,? super A> handler)- Overrides:
- writein class- Nio2Channel
 
 - 
isHandshakeCompletepublic boolean isHandshakeComplete() - Overrides:
- isHandshakeCompletein class- Nio2Channel
 
 - 
isClosingpublic boolean isClosing() - Overrides:
- isClosingin class- Nio2Channel
 
 - 
getSslEnginepublic javax.net.ssl.SSLEngine getSslEngine() 
 - 
getEmptyBufpublic java.nio.ByteBuffer getEmptyBuf() 
 
- 
 
-