public class SecureNioChannel extends NioChannel
Modifier and Type | Class and Description |
---|---|
static interface |
SecureNioChannel.ApplicationBufferHandler
Callback interface to be able to expand buffers
when buffer overflow exceptions happen
|
Modifier and Type | Field and Description |
---|---|
protected boolean |
closed |
protected boolean |
closing |
protected boolean |
handshakeComplete |
protected javax.net.ssl.SSLEngineResult.HandshakeStatus |
handshakeStatus |
protected static Log |
log |
protected java.nio.ByteBuffer |
netInBuffer |
protected java.nio.ByteBuffer |
netOutBuffer |
protected NioSelectorPool |
pool |
protected javax.net.ssl.SSLEngine |
sslEngine |
bufHandler, emptyBuf, poller, sc, sm
Constructor and Description |
---|
SecureNioChannel(java.nio.channels.SocketChannel channel,
javax.net.ssl.SSLEngine engine,
SecureNioChannel.ApplicationBufferHandler bufHandler,
NioSelectorPool pool) |
Modifier and Type | Method and Description |
---|---|
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)
Flush the channel.
|
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()
getBufHandler
|
java.nio.ByteBuffer |
getEmptyBuf() |
java.nio.channels.SocketChannel |
getIOChannel()
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()
isClosing
|
boolean |
isHandshakeComplete()
isInitHandshakeComplete
|
int |
read(java.nio.ByteBuffer dst)
Reads a sequence of bytes from this channel into the given buffer.
|
void |
rehandshake(long timeout)
Force a blocking handshake to take place for this key.
|
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.
|
checkInterruptStatus, getAttachment, getPoller, isOpen, setIOChannel, setPoller, toString
protected static final Log log
protected java.nio.ByteBuffer netInBuffer
protected java.nio.ByteBuffer netOutBuffer
protected javax.net.ssl.SSLEngine sslEngine
protected boolean handshakeComplete
protected javax.net.ssl.SSLEngineResult.HandshakeStatus handshakeStatus
protected boolean closed
protected boolean closing
protected NioSelectorPool pool
public SecureNioChannel(java.nio.channels.SocketChannel channel, javax.net.ssl.SSLEngine engine, SecureNioChannel.ApplicationBufferHandler bufHandler, NioSelectorPool pool) throws java.io.IOException
java.io.IOException
public void reset(javax.net.ssl.SSLEngine engine) throws java.io.IOException
java.io.IOException
public void reset() throws java.io.IOException
reset
in class NioChannel
java.io.IOException
public int getBufferSize()
getBufferSize
in class NioChannel
public boolean flush(boolean block, java.nio.channels.Selector s, long timeout) throws java.io.IOException
flush
in class NioChannel
block
- Should a blocking write be used?s
- timeout
- true
if the network buffer has been flushed out and
is empty else false
java.io.IOException
protected boolean flush(java.nio.ByteBuffer buf) throws java.io.IOException
buf
- ByteBufferjava.io.IOException
public int handshake(boolean read, boolean write) throws java.io.IOException
handshake
in class NioChannel
read
- boolean - true if the underlying channel is readablewrite
- boolean - true if the underlying channel is writablejava.io.IOException
public void rehandshake(long timeout) throws java.io.IOException
timeout
- - timeout in milliseconds for each socket operationjava.io.IOException
- - if an IO exception occurs or if application or network buffers contain datajava.net.SocketTimeoutException
- - if a socket operation timed outprotected javax.net.ssl.SSLEngineResult.HandshakeStatus tasks()
protected javax.net.ssl.SSLEngineResult handshakeWrap(boolean doWrite) throws java.io.IOException
doWrite
- booleanjava.io.IOException
protected javax.net.ssl.SSLEngineResult handshakeUnwrap(boolean doread) throws java.io.IOException
doread
- booleanjava.io.IOException
public void close() throws java.io.IOException
close();
while (isOpen() && !myTimeoutFunction()) Thread.sleep(25);
if ( isOpen() ) close(true); //forces a close if you timed out
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in interface java.nio.channels.Channel
close
in class NioChannel
java.io.IOException
- if an I/O error occursjava.io.IOException
- if there is data on the outgoing network buffer and we are unable to flush it
TODO Implement this java.io.Closeable methodpublic void close(boolean force) throws java.io.IOException
close
in class NioChannel
force
- booleanjava.io.IOException
public int read(java.nio.ByteBuffer dst) throws java.io.IOException
read
in interface java.nio.channels.ReadableByteChannel
read
in class NioChannel
dst
- The buffer into which bytes are to be transferredjava.io.IOException
- If some other I/O error occursjava.lang.IllegalArgumentException
- if the destination buffer is different than bufHandler.getReadBuffer()
TODO Implement this java.nio.channels.ReadableByteChannel methodpublic int write(java.nio.ByteBuffer src) throws java.io.IOException
write
in interface java.nio.channels.WritableByteChannel
write
in class NioChannel
src
- The buffer from which bytes are to be retrievedjava.io.IOException
- If some other I/O error occurs
TODO Implement this java.nio.channels.WritableByteChannel methodpublic int getOutboundRemaining()
getOutboundRemaining
in class NioChannel
public boolean flushOutbound() throws java.io.IOException
NioChannel
flushOutbound
in class NioChannel
java.io.IOException
public SecureNioChannel.ApplicationBufferHandler getBufHandler()
NioChannel
getBufHandler
in class NioChannel
public boolean isHandshakeComplete()
NioChannel
isHandshakeComplete
in class NioChannel
public boolean isClosing()
NioChannel
isClosing
in class NioChannel
public javax.net.ssl.SSLEngine getSslEngine()
public java.nio.ByteBuffer getEmptyBuf()
public void setBufHandler(SecureNioChannel.ApplicationBufferHandler bufHandler)
public java.nio.channels.SocketChannel getIOChannel()
NioChannel
getIOChannel
in class NioChannel
Copyright © 2000-2015 Apache Software Foundation. All Rights Reserved.