Overview | Package | Class | Tree | Deprecated | Index | Help
| Apache Tomcat 6.0.53
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## 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.nio.channels.ByteChannel, java.nio.channels.Channel, java.nio.channels.ReadableByteChannel, java.nio.channels.WritableByteChannel

    public class SecureNioChannel

extends NioChannel

Implementation of a secure socket channel

Version:
  1.0
Author:
  Filip Hanik

Nested Class Summary
`static interface` | `SecureNioChannel.ApplicationBufferHandler` Callback interface to be able to expand buffers when buffer overflow exceptions happen

Field Summary
`protected boolean` | `closed`
`protected boolean` | `closing`
`protected boolean` | `initHandshakeComplete`
`protected javax.net.ssl.SSLEngineResult.HandshakeStatus` | `initHandshakeStatus`
`protected java.nio.ByteBuffer` | `netInBuffer`
`protected java.nio.ByteBuffer` | `netOutBuffer`
`protected NioSelectorPool` | `pool`
`protected javax.net.ssl.SSLEngine` | `sslEngine`

Fields inherited from class org.apache.tomcat.util.net.NioChannel
`bufHandler, emptyBuf, poller, sc`

Constructor Summary
`SecureNioChannel(java.nio.channels.SocketChannel channel, javax.net.ssl.SSLEngine engine, SecureNioChannel.ApplicationBufferHandler bufHandler, NioSelectorPool pool)`

Method Summary
`void` | `close()` Sends a SSL close message, will not physically close the connection here.
`void` | `close(boolean force)` Force a close, can throw an IOException
`boolean` | `flush(boolean block, java.nio.channels.Selector s, long timeout, MutableInteger lastWrite)` returns true if the network buffer has been flushed out and is empty
`protected boolean` | `flush(java.nio.ByteBuffer buf)` Flushes the buffer to the network, non blocking
`boolean` | `flushOutbound()` Return true if the buffer wrote data.
`int` | `getBufferSize()`
`SecureNioChannel.ApplicationBufferHandler` | `getBufHandler()`
`java.nio.ByteBuffer` | `getEmptyBuf()`
`java.nio.channels.SocketChannel` | `getIOChannel()`
`int` | `getOutboundRemaining()`
`javax.net.ssl.SSLEngine` | `getSslEngine()`
`int` | `handshake(boolean read, boolean write)` Performs SSL handshake, non blocking, but performs NEED_TASK on the same thread.
`protected javax.net.ssl.SSLEngineResult` | `handshakeUnwrap(boolean doread)` Perform handshake unwrap
`protected javax.net.ssl.SSLEngineResult` | `handshakeWrap(boolean doWrite)` Performs the WRAP function
`boolean` | `isClosing()`
`boolean` | `isInitHandshakeComplete()`
`int` | `read(java.nio.ByteBuffer dst)` Reads a sequence of bytes from this channel into the given buffer.
`void` | `reset()`
`void` | `reset(javax.net.ssl.SSLEngine engine)`
`void` | `setBufHandler(SecureNioChannel.ApplicationBufferHandler bufHandler)`
`protected javax.net.ssl.SSLEngineResult.HandshakeStatus` | `tasks()` Executes all the tasks needed on the same thread.
`int` | `write(java.nio.ByteBuffer src)` Writes a sequence of bytes to this channel from the given buffer.

Methods inherited from class org.apache.tomcat.util.net.NioChannel
`getAttachment, getPoller, isOpen, setIOChannel, setPoller, toString`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### netInBuffer

    protected java.nio.ByteBuffer netInBuffer

### netOutBuffer

    protected java.nio.ByteBuffer netOutBuffer

### sslEngine

    protected javax.net.ssl.SSLEngine sslEngine

### initHandshakeComplete

    protected boolean initHandshakeComplete

### initHandshakeStatus

    protected javax.net.ssl.SSLEngineResult.HandshakeStatus initHandshakeStatus

### closed

    protected boolean closed

### closing

    protected boolean closing

### pool

    protected NioSelectorPool pool

Constructor Detail

### SecureNioChannel

    public SecureNioChannel(java.nio.channels.SocketChannel channel,
                            javax.net.ssl.SSLEngine engine,
                            SecureNioChannel.ApplicationBufferHandler bufHandler,
                            NioSelectorPool pool)
                     throws java.io.IOException

Throws:
  `java.io.IOException`

Method Detail

### reset

    public void reset(javax.net.ssl.SSLEngine engine)
               throws java.io.IOException

  Throws:
    `java.io.IOException`

### reset

    public void reset()
               throws java.io.IOException

  Overrides:
    `reset` in class `NioChannel`
  Throws:
    `java.io.IOException`

### getBufferSize

    public int getBufferSize()

  Overrides:
    `getBufferSize` in class `NioChannel`

### flush

    public boolean flush(boolean block,
                         java.nio.channels.Selector s,
                         long timeout,
                         MutableInteger lastWrite)
                  throws java.io.IOException

  returns true if the network buffer has been flushed out and is empty

  Overrides:
    `flush` in class `NioChannel`
  Returns:
    boolean
  Throws:
    `java.io.IOException`

### flush

    protected boolean flush(java.nio.ByteBuffer buf)
                     throws java.io.IOException

  Flushes 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`

### handshake

    public int handshake(boolean read,
                         boolean write)
                  throws java.io.IOException

  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.

  Overrides:
    `handshake` in class `NioChannel`
  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:
    `java.io.IOException`

### tasks

    protected javax.net.ssl.SSLEngineResult.HandshakeStatus tasks()

  Executes all the tasks needed on the same thread.

  Returns:
    HandshakeStatus

### handshakeWrap

    protected javax.net.ssl.SSLEngineResult handshakeWrap(boolean doWrite)
                                                   throws java.io.IOException

  Performs the WRAP function

  Parameters:
    `doWrite` - boolean
  Returns:
    SSLEngineResult
  Throws:
    `java.io.IOException`

### handshakeUnwrap

    protected javax.net.ssl.SSLEngineResult handshakeUnwrap(boolean doread)
                                                     throws java.io.IOException

  Perform handshake unwrap

  Parameters:
    `doread` - boolean
  Returns:
    SSLEngineResult
  Throws:
    `java.io.IOException`

### close

    public void close()
               throws java.io.IOException

  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

  Specified by:
    `close` in interface `java.io.Closeable`
  Specified by:
    `close` in interface `java.nio.channels.Channel`
  Overrides:
    `close` in 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

### close

    public void close(boolean force)
               throws java.io.IOException

  Force a close, can throw an IOException

  Overrides:
    `close` in class `NioChannel`
  Parameters:
    `force` - boolean
  Throws:
    `java.io.IOException`

### read

    public int read(java.nio.ByteBuffer dst)
             throws java.io.IOException

  Reads a sequence of bytes from this channel into the given buffer.

  Specified by:
    `read` in interface `java.nio.channels.ReadableByteChannel`
  Overrides:
    `read` in class `NioChannel`
  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:
    `java.io.IOException` - If some other I/O error occurs
    `java.lang.IllegalArgumentException` - if the destination buffer is different than bufHandler.getReadBuffer()

### write

    public int write(java.nio.ByteBuffer src)
              throws java.io.IOException

  Writes a sequence of bytes to this channel from the given buffer.

  Specified by:
    `write` in interface `java.nio.channels.WritableByteChannel`
  Overrides:
    `write` in 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

### getOutboundRemaining

    public int getOutboundRemaining()

  Overrides:
    `getOutboundRemaining` in class `NioChannel`

### flushOutbound

    public boolean flushOutbound()
                          throws java.io.IOException

  Description copied from class: `NioChannel`
  Return true if the buffer wrote data.

  Overrides:
    `flushOutbound` in class `NioChannel`
  Throws:
    `java.io.IOException`

### getBufHandler

    public SecureNioChannel.ApplicationBufferHandler getBufHandler()

  Overrides:
    `getBufHandler` in class `NioChannel`

### isInitHandshakeComplete

    public boolean isInitHandshakeComplete()

  Overrides:
    `isInitHandshakeComplete` in class `NioChannel`

### isClosing

    public boolean isClosing()

  Overrides:
    `isClosing` in class `NioChannel`

### getSslEngine

    public javax.net.ssl.SSLEngine getSslEngine()

### getEmptyBuf

    public java.nio.ByteBuffer getEmptyBuf()

### setBufHandler

    public void setBufHandler(SecureNioChannel.ApplicationBufferHandler bufHandler)

### getIOChannel

    public java.nio.channels.SocketChannel getIOChannel()

  Overrides:
    `getIOChannel` in class `NioChannel`

Overview | Package | Class | Tree | Deprecated | Index | Help
| Apache Tomcat 6.0.53
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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