org.apache.tomcat.util.net

Class SecureNioChannel

public class SecureNioChannel extends NioChannel

Implementation of a secure socket channel

Version: 1.0

Author: Filip Hanik

Nested Class Summary
static interfaceSecureNioChannel.ApplicationBufferHandler
Callback interface to be able to expand buffers when buffer overflow exceptions happen
Field Summary
protected booleanclosed
protected booleanclosing
protected booleaninitHandshakeComplete
protected HandshakeStatusinitHandshakeStatus
protected ByteBuffernetInBuffer
protected ByteBuffernetOutBuffer
protected NioSelectorPoolpool
protected SSLEnginesslEngine
Constructor Summary
SecureNioChannel(SocketChannel channel, SSLEngine engine, SecureNioChannel.ApplicationBufferHandler bufHandler, NioSelectorPool pool)
Method Summary
voidclose()
Sends a SSL close message, will not physically close the connection here.
To close the connection, you could do something like

   close();
   while (isOpen() && !
voidclose(boolean force)
Force a close, can throw an IOException
booleanflush(boolean block, Selector s, long timeout, MutableInteger lastWrite)
returns true if the network buffer has been flushed out and is empty
protected booleanflush(ByteBuffer buf)
Flushes the buffer to the network, non blocking
intgetBufferSize()
SecureNioChannel.ApplicationBufferHandlergetBufHandler()
ByteBuffergetEmptyBuf()
SocketChannelgetIOChannel()
SSLEnginegetSslEngine()
inthandshake(boolean read, boolean write)
Performs 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.
protected SSLEngineResulthandshakeUnwrap(boolean doread)
Perform handshake unwrap
protected SSLEngineResulthandshakeWrap(boolean doWrite)
Performs the WRAP function
booleanisClosing()
booleanisInitHandshakeComplete()
intread(ByteBuffer dst)
Reads a sequence of bytes from this channel into the given buffer.
voidreset(SSLEngine engine)
voidreset()
voidsetBufHandler(SecureNioChannel.ApplicationBufferHandler bufHandler)
protected 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.

Field Detail

closed

protected boolean closed

closing

protected boolean closing

initHandshakeComplete

protected boolean initHandshakeComplete

initHandshakeStatus

protected HandshakeStatus initHandshakeStatus

netInBuffer

protected ByteBuffer netInBuffer

netOutBuffer

protected ByteBuffer netOutBuffer

pool

protected NioSelectorPool pool

sslEngine

protected SSLEngine sslEngine

Constructor Detail

SecureNioChannel

public SecureNioChannel(SocketChannel channel, SSLEngine engine, SecureNioChannel.ApplicationBufferHandler bufHandler, NioSelectorPool pool)

Method Detail

close

public void close()
Sends a SSL close message, will not physically close the connection here.
To close the connection, you could do something like

   close();
   while (isOpen() && !myTimeoutFunction()) Thread.sleep(25);
   if ( isOpen() ) close(true); //forces a close if you timed out
 

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

UNKNOWN: Implement this java.io.Closeable method

close

public void close(boolean force)
Force a close, can throw an IOException

Parameters: force boolean

Throws: IOException

flush

public boolean flush(boolean block, Selector s, long timeout, MutableInteger lastWrite)
returns true if the network buffer has been flushed out and is empty

Returns: boolean

flush

protected boolean flush(ByteBuffer buf)
Flushes the buffer to the network, non blocking

Parameters: buf ByteBuffer

Returns: boolean true if the buffer has been emptied out, false otherwise

Throws: IOException

getBufferSize

public int getBufferSize()

getBufHandler

public SecureNioChannel.ApplicationBufferHandler getBufHandler()

getEmptyBuf

public ByteBuffer getEmptyBuf()

getIOChannel

public SocketChannel getIOChannel()

getSslEngine

public SSLEngine getSslEngine()

handshake

public int handshake(boolean read, boolean write)
Performs 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, reregister the selection key for the return values interestOps.

Parameters: read boolean - true if the underlying channel is readable write boolean - true if the underlying channel is writable

Returns: int - 0 if hand shake is complete, otherwise it returns a SelectionKey interestOps value

Throws: IOException

handshakeUnwrap

protected SSLEngineResult handshakeUnwrap(boolean doread)
Perform handshake unwrap

Parameters: doread boolean

Returns: SSLEngineResult

Throws: IOException

handshakeWrap

protected SSLEngineResult handshakeWrap(boolean doWrite)
Performs the WRAP function

Parameters: doWrite boolean

Returns: SSLEngineResult

Throws: IOException

isClosing

public boolean isClosing()

isInitHandshakeComplete

public boolean isInitHandshakeComplete()

read

public int read(ByteBuffer dst)
Reads a sequence of bytes from this channel into the given buffer.

Parameters: dst The buffer into which bytes are to be transferred

Returns: The number of bytes read, possibly zero, or -1 if the channel has reached end-of-stream

Throws: IOException If some other I/O error occurs IllegalArgumentException if the destination buffer is different than bufHandler.getReadBuffer()

UNKNOWN: Implement this java.nio.channels.ReadableByteChannel method

reset

public void reset(SSLEngine engine)

reset

public void reset()

setBufHandler

public void setBufHandler(SecureNioChannel.ApplicationBufferHandler bufHandler)

tasks

protected HandshakeStatus tasks()
Executes all the tasks needed on the same thread.

Returns: HandshakeStatus

write

public int write(ByteBuffer src)
Writes a sequence of bytes to this channel from the given buffer.

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

UNKNOWN: Implement this java.nio.channels.WritableByteChannel method

Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.