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:
- Closeable,- AutoCloseable,- ByteChannel,- Channel,- GatheringByteChannel,- ReadableByteChannel,- ScatteringByteChannel,- WritableByteChannel
Implementation of a secure socket channel
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected booleanprotected booleanprotected booleanprotected SSLEngineResult.HandshakeStatusprotected ByteBufferprotected ByteBufferprotected booleanprotected SSLEngineFields inherited from class org.apache.tomcat.util.net.NioChannelbufHandler, emptyBuf, sc, socketWrapper
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidclose()Sends an SSL close message, will not physically close the connection here.voidclose(boolean force) Close the connection.protected booleanflush(ByteBuffer buf) Flushes the buffer to the network, non blockingbooleanReturn true if the buffer wrote data.voidfree()Free the channel memoryintinthandshake(boolean read, boolean write) Performs SSL handshake, non blocking, but performs NEED_TASK on the same thread.protected SSLEngineResulthandshakeUnwrap(boolean doread) Perform handshake unwrapprotected SSLEngineResulthandshakeWrap(boolean doWrite) Performs the WRAP functionbooleanbooleanintread(ByteBuffer dst) Reads a sequence of bytes from this channel into the given buffer.longread(ByteBuffer[] dsts, int offset, int length) voidrehandshake(long timeout) Force a blocking handshake to take place for this key.voidreset(SocketChannel channel, NioEndpoint.NioSocketWrapper socketWrapper) Reset the channelprotected SSLEngineResult.HandshakeStatustasks()Executes all the tasks needed on the same thread.intwrite(ByteBuffer src) Writes a sequence of bytes to this channel from the given buffer.longwrite(ByteBuffer[] srcs, int offset, int length) Methods inherited from class org.apache.tomcat.util.net.NioChannelcheckInterruptStatus, getAppReadBufHandler, getBufHandler, getIOChannel, isOpen, read, setAppReadBufHandler, toString, write
- 
Field Details- 
netInBuffer
- 
netOutBuffer
- 
sslEngine
- 
sniCompleteprotected boolean sniComplete
- 
handshakeCompleteprotected boolean handshakeComplete
- 
handshakeStatus
- 
closedprotected boolean closed
- 
closingprotected boolean closing
 
- 
- 
Constructor Details- 
SecureNioChannel
 
- 
- 
Method Details- 
resetpublic void reset(SocketChannel channel, NioEndpoint.NioSocketWrapper socketWrapper) throws IOException Description copied from class:NioChannelReset the channel- Overrides:
- resetin class- NioChannel
- Parameters:
- channel- the socket channel
- socketWrapper- the socket wrapper
- Throws:
- IOException- If a problem was encountered resetting the channel
 
- 
freepublic void free()Description copied from class:NioChannelFree the channel memory- Overrides:
- freein class- NioChannel
 
- 
flushFlushes the buffer to the network, non blocking- Parameters:
- buf- ByteBuffer
- Returns:
- boolean true if the buffer has been emptied out, false otherwise
- Throws:
- IOException- An IO error occurred writing data
 
- 
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. 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:
- IOException- If an I/O error occurs during the handshake or if the handshake fails during wrapping or unwrapping
 
- 
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.- Parameters:
- timeout- - timeout in milliseconds for each socket operation
- 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- Parameters:
- doWrite- boolean
- Returns:
- the result
- Throws:
- IOException- An IO error occurred
 
- 
handshakeUnwrapPerform handshake unwrap- Parameters:
- doread- boolean
- 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- AutoCloseable
- Specified by:
- closein interface- Channel
- Specified by:
- closein interface- Closeable
- Overrides:
- closein class- NioChannel
- 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:NioChannelClose the connection.- Overrides:
- closein class- NioChannel
- 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- 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:
- IOException- If some other I/O error occurs
- IllegalArgumentException- if the destination buffer is different than getBufHandler().getReadBuffer()
 
- 
read- Specified by:
- readin interface- ScatteringByteChannel
- Overrides:
- readin class- NioChannel
- Throws:
- IOException
 
- 
writeWrites a sequence of bytes to this channel from the given buffer.- Specified by:
- writein interface- 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:
- IOException- If some other I/O error occurs
 
- 
write- Specified by:
- writein interface- GatheringByteChannel
- Overrides:
- writein class- NioChannel
- Throws:
- IOException
 
- 
getOutboundRemainingpublic int getOutboundRemaining()- Overrides:
- getOutboundRemainingin class- NioChannel
 
- 
flushOutboundDescription 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:
- IOException- Never for non-secure channel
 
- 
isHandshakeCompletepublic boolean isHandshakeComplete()- Overrides:
- isHandshakeCompletein class- NioChannel
 
- 
isClosingpublic boolean isClosing()- Overrides:
- isClosingin class- NioChannel
 
- 
getSslEngine
- 
getEmptyBuf
 
-