public class SecureNio2Channel extends Nio2Channel
Modifier and Type | Field and Description |
---|---|
protected boolean |
closed |
protected boolean |
closing |
protected Nio2Endpoint |
endpoint |
protected ByteBuffer |
netInBuffer |
protected ByteBuffer |
netOutBuffer |
protected boolean |
sniComplete |
protected SSLEngine |
sslEngine |
bufHandler, emptyBuf, sc, socket
Constructor and Description |
---|
SecureNio2Channel(SocketBufferHandler bufHandler,
Nio2Endpoint endpoint) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Sends a SSL close message, will not physically close the connection here.
|
void |
close(boolean force)
Close the connection.
|
Future<Boolean> |
flush()
Flush the channel.
|
void |
free()
Free the channel memory
|
ByteBuffer |
getEmptyBuf() |
AsynchronousSocketChannel |
getIOChannel() |
SSLEngine |
getSslEngine() |
int |
handshake()
Performs SSL handshake, non blocking, but performs NEED_TASK on the same
thread.
|
protected int |
handshakeInternal(boolean async) |
protected SSLEngineResult |
handshakeUnwrap()
Perform handshake unwrap
|
protected SSLEngineResult |
handshakeWrap()
Performs the WRAP function
|
boolean |
isClosing() |
boolean |
isHandshakeComplete() |
Future<Integer> |
read(ByteBuffer dst)
Reads a sequence of bytes from this channel into the given buffer.
|
<A> void |
read(ByteBuffer[] dsts,
int offset,
int length,
long timeout,
TimeUnit unit,
A attachment,
CompletionHandler<Long,? super A> handler) |
<A> void |
read(ByteBuffer dst,
long timeout,
TimeUnit unit,
A attachment,
CompletionHandler<Integer,? super A> handler) |
void |
rehandshake()
Force a blocking handshake to take place for this key.
|
void |
reset(AsynchronousSocketChannel channel,
SocketWrapperBase<Nio2Channel> socket)
Reset the channel.
|
protected SSLEngineResult.HandshakeStatus |
tasks()
Executes all the tasks needed on the same thread.
|
Future<Integer> |
write(ByteBuffer src)
Writes a sequence of bytes to this channel from the given buffer.
|
<A> void |
write(ByteBuffer[] srcs,
int offset,
int length,
long timeout,
TimeUnit unit,
A attachment,
CompletionHandler<Long,? super A> handler) |
<A> void |
write(ByteBuffer src,
long timeout,
TimeUnit unit,
A attachment,
CompletionHandler<Integer,? super A> handler) |
getBufHandler, getSocket, isOpen, read, toString, write
protected ByteBuffer netInBuffer
protected ByteBuffer netOutBuffer
protected SSLEngine sslEngine
protected final Nio2Endpoint endpoint
protected boolean sniComplete
protected boolean closed
protected boolean closing
public SecureNio2Channel(SocketBufferHandler bufHandler, Nio2Endpoint endpoint)
public void reset(AsynchronousSocketChannel channel, SocketWrapperBase<Nio2Channel> socket) throws IOException
Nio2Channel
reset
in class Nio2Channel
channel
- The new async channel to associate with this NIO2 channelsocket
- The new socket to associate with this NIO2 channelIOException
- If a problem was encountered resetting the channelpublic void free()
Nio2Channel
free
in class Nio2Channel
public Future<Boolean> flush()
flush
in class Nio2Channel
true
if the network buffer has been flushed out and
is empty else false
(as a future)public int handshake() throws IOException
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, the appropriate read/write will already have been called with an appropriate CompletionHandler.
handshake
in class Nio2Channel
IOException
- if an error occurs during the handshakeprotected int handshakeInternal(boolean async) throws IOException
IOException
public void rehandshake() throws IOException
IOException
- - if an IO exception occurs or if application or network buffers contain dataSocketTimeoutException
- - if a socket operation timed outprotected SSLEngineResult.HandshakeStatus tasks()
protected SSLEngineResult handshakeWrap() throws IOException
IOException
- An IO error occurredprotected SSLEngineResult handshakeUnwrap() throws IOException
IOException
- An IO error occurredpublic void close() throws IOException
close();
while (isOpen() && !myTimeoutFunction()) Thread.sleep(25);
if ( isOpen() ) close(true); //forces a close if you timed out
close
in interface Closeable
close
in interface AutoCloseable
close
in interface AsynchronousChannel
close
in interface Channel
close
in class Nio2Channel
IOException
- if an I/O error occursIOException
- if there is data on the outgoing network buffer and we are unable to flush itpublic void close(boolean force) throws IOException
Nio2Channel
close
in class Nio2Channel
force
- Should the underlying socket be forcibly closed?IOException
- If closing the secure channel fails.public Future<Integer> read(ByteBuffer dst)
read
in interface AsynchronousByteChannel
read
in class Nio2Channel
dst
- The buffer into which bytes are to be transferredIllegalStateException
- if the handshake was not completedpublic Future<Integer> write(ByteBuffer src)
write
in interface AsynchronousByteChannel
write
in class Nio2Channel
src
- The buffer from which bytes are to be retrievedpublic <A> void read(ByteBuffer dst, long timeout, TimeUnit unit, A attachment, CompletionHandler<Integer,? super A> handler)
read
in class Nio2Channel
public <A> void read(ByteBuffer[] dsts, int offset, int length, long timeout, TimeUnit unit, A attachment, CompletionHandler<Long,? super A> handler)
read
in class Nio2Channel
public <A> void write(ByteBuffer src, long timeout, TimeUnit unit, A attachment, CompletionHandler<Integer,? super A> handler)
write
in class Nio2Channel
public <A> void write(ByteBuffer[] srcs, int offset, int length, long timeout, TimeUnit unit, A attachment, CompletionHandler<Long,? super A> handler)
write
in class Nio2Channel
public boolean isHandshakeComplete()
isHandshakeComplete
in class Nio2Channel
public boolean isClosing()
isClosing
in class Nio2Channel
public SSLEngine getSslEngine()
public ByteBuffer getEmptyBuf()
public AsynchronousSocketChannel getIOChannel()
getIOChannel
in class Nio2Channel
Copyright © 2000-2016 Apache Software Foundation. All Rights Reserved.