Package org.apache.tomcat.util.net
Class SecureNioChannel
- java.lang.Object
- 
- org.apache.tomcat.util.net.NioChannel
- 
- org.apache.tomcat.util.net.SecureNioChannel
 
 
- 
- All Implemented Interfaces:
- java.io.Closeable,- java.lang.AutoCloseable,- java.nio.channels.ByteChannel,- java.nio.channels.Channel,- java.nio.channels.GatheringByteChannel,- java.nio.channels.ReadableByteChannel,- java.nio.channels.ScatteringByteChannel,- java.nio.channels.WritableByteChannel
 
 public class SecureNioChannel extends NioChannel Implementation of a secure socket channel
- 
- 
Field SummaryFields Modifier and Type Field Description protected booleanclosedprotected booleanclosingprotected booleanhandshakeCompleteprotected javax.net.ssl.SSLEngineResult.HandshakeStatushandshakeStatusprotected java.nio.ByteBuffernetInBufferprotected java.nio.ByteBuffernetOutBufferprotected booleansniCompleteprotected javax.net.ssl.SSLEnginesslEngine- 
Fields inherited from class org.apache.tomcat.util.net.NioChannelbufHandler, emptyBuf, sc, socketWrapper
 
- 
 - 
Constructor SummaryConstructors Constructor Description SecureNioChannel(SocketBufferHandler bufHandler, NioEndpoint 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.voidclose(boolean force)Close the connection.protected booleanflush(java.nio.ByteBuffer buf)Flushes the buffer to the network, non blockingbooleanflushOutbound()Return true if the buffer wrote data.voidfree()Free the channel memoryjava.nio.ByteBuffergetEmptyBuf()intgetOutboundRemaining()javax.net.ssl.SSLEnginegetSslEngine()SSLSupportgetSSLSupport()inthandshake(boolean read, boolean write)Performs SSL handshake, non blocking, but performs NEED_TASK on the same thread.protected javax.net.ssl.SSLEngineResulthandshakeUnwrap(boolean doread)Perform handshake unwrapprotected javax.net.ssl.SSLEngineResulthandshakeWrap(boolean doWrite)Performs the WRAP functionbooleanisClosing()booleanisHandshakeComplete()intread(java.nio.ByteBuffer dst)Reads a sequence of bytes from this channel into the given buffer.longread(java.nio.ByteBuffer[] dsts, int offset, int length)voidrehandshake(long timeout)Force a blocking handshake to take place for this key.voidreset(java.nio.channels.SocketChannel channel, NioEndpoint.NioSocketWrapper socketWrapper)Reset the channelprotected javax.net.ssl.SSLEngineResult.HandshakeStatustasks()Executes all the tasks needed on the same thread.intwrite(java.nio.ByteBuffer src)Writes a sequence of bytes to this channel from the given buffer.longwrite(java.nio.ByteBuffer[] srcs, int offset, int length)- 
Methods inherited from class org.apache.tomcat.util.net.NioChannelcheckInterruptStatus, flush, getAppReadBufHandler, getBufHandler, getIOChannel, isOpen, read, setAppReadBufHandler, toString, write
 
- 
 
- 
- 
- 
Field Detail- 
netInBufferprotected java.nio.ByteBuffer netInBuffer 
 - 
netOutBufferprotected java.nio.ByteBuffer netOutBuffer 
 - 
sslEngineprotected javax.net.ssl.SSLEngine sslEngine 
 - 
sniCompleteprotected boolean sniComplete 
 - 
handshakeCompleteprotected boolean handshakeComplete 
 - 
handshakeStatusprotected javax.net.ssl.SSLEngineResult.HandshakeStatus handshakeStatus 
 - 
closedprotected boolean closed 
 - 
closingprotected boolean closing 
 
- 
 - 
Constructor Detail- 
SecureNioChannelpublic SecureNioChannel(SocketBufferHandler bufHandler, NioEndpoint endpoint) 
 
- 
 - 
Method Detail- 
resetpublic void reset(java.nio.channels.SocketChannel channel, NioEndpoint.NioSocketWrapper socketWrapper) throws java.io.IOExceptionDescription copied from class:NioChannelReset the channel- Overrides:
- resetin class- NioChannel
- Parameters:
- channel- the socket channel
- socketWrapper- the socket wrapper
- Throws:
- java.io.IOException- If a problem was encountered resetting the channel
 
 - 
freepublic void free() Description copied from class:NioChannelFree the channel memory- Overrides:
- freein class- NioChannel
 
 - 
flushprotected boolean flush(java.nio.ByteBuffer buf) throws java.io.IOExceptionFlushes the buffer to the network, non blocking- Parameters:
- buf- ByteBuffer
- Returns:
- boolean true if the buffer has been emptied out, false otherwise
- Throws:
- java.io.IOException- An IO error occurred writing data
 
 - 
handshakepublic int handshake(boolean read, boolean write) 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. If the return value from this method is positive, the selection key should be registered interestOps given by the return value.- Overrides:
- handshakein class- NioChannel
- Parameters:
- read- boolean - true if the underlying channel is readable
- write- boolean - true if the underlying channel is writable
- Returns:
- 0 if hand shake is complete, -1 if an error (other than an IOException) occurred, otherwise it returns a SelectionKey interestOps value
- Throws:
- java.io.IOException- If an I/O error occurs during the handshake or if the handshake fails during wrapping or unwrapping
 
 - 
rehandshakepublic void rehandshake(long timeout) 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.- Parameters:
- timeout- - timeout in milliseconds for each socket operation
- 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(boolean doWrite) throws java.io.IOExceptionPerforms the WRAP function- Parameters:
- doWrite- boolean
- Returns:
- the result
- Throws:
- java.io.IOException- An IO error occurred
 
 - 
handshakeUnwrapprotected javax.net.ssl.SSLEngineResult handshakeUnwrap(boolean doread) throws java.io.IOExceptionPerform handshake unwrap- Parameters:
- doread- boolean
- 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.lang.AutoCloseable
- Specified by:
- closein interface- java.nio.channels.Channel
- Specified by:
- closein interface- java.io.Closeable
- Overrides:
- closein class- NioChannel
- 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:NioChannelClose the connection.- Overrides:
- closein class- NioChannel
- Parameters:
- force- Should the underlying socket be forcibly closed?
- Throws:
- java.io.IOException- If closing the secure channel fails.
 
 - 
readpublic int read(java.nio.ByteBuffer dst) throws java.io.IOExceptionReads a sequence of bytes from this channel into the given buffer.- Specified by:
- readin interface- java.nio.channels.ReadableByteChannel
- Overrides:
- readin class- NioChannel
- 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.io.IOException- If some other I/O error occurs
- java.lang.IllegalArgumentException- if the destination buffer is different than getBufHandler().getReadBuffer()
 
 - 
readpublic long read(java.nio.ByteBuffer[] dsts, int offset, int length) throws java.io.IOException- Specified by:
- readin interface- java.nio.channels.ScatteringByteChannel
- Overrides:
- readin class- NioChannel
- Throws:
- java.io.IOException
 
 - 
writepublic int write(java.nio.ByteBuffer src) throws java.io.IOExceptionWrites a sequence of bytes to this channel from the given buffer.- Specified by:
- writein interface- java.nio.channels.WritableByteChannel
- Overrides:
- writein class- NioChannel
- Parameters:
- src- The buffer from which bytes are to be retrieved
- Returns:
- The number of bytes written, possibly zero
- Throws:
- java.io.IOException- If some other I/O error occurs
 
 - 
writepublic long write(java.nio.ByteBuffer[] srcs, int offset, int length) throws java.io.IOException- Specified by:
- writein interface- java.nio.channels.GatheringByteChannel
- Overrides:
- writein class- NioChannel
- Throws:
- java.io.IOException
 
 - 
getOutboundRemainingpublic int getOutboundRemaining() - Overrides:
- getOutboundRemainingin class- NioChannel
 
 - 
flushOutboundpublic boolean flushOutbound() throws java.io.IOExceptionDescription copied from class:NioChannelReturn true if the buffer wrote data. NO-OP for non-secure channel.- Overrides:
- flushOutboundin class- NioChannel
- Returns:
- Always returns falsefor non-secure channel
- Throws:
- java.io.IOException- Never for non-secure channel
 
 - 
isHandshakeCompletepublic boolean isHandshakeComplete() - Overrides:
- isHandshakeCompletein class- NioChannel
 
 - 
isClosingpublic boolean isClosing() - Overrides:
- isClosingin class- NioChannel
 
 - 
getSslEnginepublic javax.net.ssl.SSLEngine getSslEngine() 
 - 
getEmptyBufpublic java.nio.ByteBuffer getEmptyBuf() 
 
- 
 
-