Top Description Fields Constructors Methods
org.java_websocket

public Class SSLSocketChannel2

extends Object
implements ByteChannel, WrappedByteChannel, ISSLChannel
Class Inheritance
All Implemented Interfaces
org.java_websocket.interfaces.ISSLChannel, org.java_websocket.WrappedByteChannel, java.nio.channels.ByteChannel, java.nio.channels.WritableByteChannel, java.nio.channels.Channel, java.io.Closeable, java.lang.AutoCloseable, java.nio.channels.ReadableByteChannel
Imports
java.io.EOFException, .IOException, java.net.Socket, .SocketAddress, java.nio.ByteBuffer, java.nio.channels.ByteChannel, .SelectableChannel, .SelectionKey, .SocketChannel, java.util.ArrayList, .Iterator, .List, java.util.concurrent.ExecutionException, .ExecutorService, .Future, javax.net.ssl.SSLEngine, .SSLEngineResult, .SSLEngineResult.HandshakeStatus, .SSLEngineResult.Status, .SSLException, .SSLSession, org.java_websocket.interfaces.ISSLChannel, org.slf4j.Logger, .LoggerFactory

Implements the relevant portions of the SocketChannel interface with the SSLEngine wrapper.

Field Summary

Modifier and TypeField and Description
protected int
bufferallocations

Should be used to count the buffer allocations.

protected static ByteBuffer
emptybuffer

This object is used to feed the SSLEngine's wrap and unwrap methods during the handshake phase.

protected ExecutorService
protected ByteBuffer
inCrypt

encrypted data incoming

protected ByteBuffer
inData

raw payload incoming

private final Logger
log

Logger instance

protected ByteBuffer
outCrypt

encrypted data outgoing

protected SSLEngineResult
private byte[]
protected SelectionKey
selectionKey

used to set interestOP SelectionKey.OP_WRITE for the underlying channel

protected SocketChannel
socketChannel

the underlying channel

protected SSLEngine
protected List<Future<?>>
protected SSLEngineResult

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements java.nio.channels.Channel.close.

Closes this channel.

public SelectableChannel
configureBlocking(boolean b)

public boolean
protected void
private void
protected void
public boolean
public SSLEngine
getSSLEngine()

Implements org.java_websocket.interfaces.ISSLChannel.getSSLEngine.

Get the ssl engine used for the de- and encryption of the communication.

public boolean
isBlocking()

Implements org.java_websocket.WrappedByteChannel.isBlocking.

This function returns the blocking state of the channel

public boolean
private boolean
public boolean
public boolean
isNeedRead()

Implements org.java_websocket.WrappedByteChannel.isNeedRead.

returns whether readMore should be called to fetch data which has been decoded but not yet been returned.

public boolean
isNeedWrite()

Implements org.java_websocket.WrappedByteChannel.isNeedWrite.

returns whether writeMore should be called write additional data.

public boolean
isOpen()

Implements java.nio.channels.Channel.isOpen.

Tells whether or not this channel is open.

private synchronized void
processHandshake(boolean isReading)

This method will do whatever necessary to process the sslEngine handshake.

public int

Returns:

the number of bytes read.
read
(ByteBuffer dst)

Implements java.nio.channels.ReadableByteChannel.read.

Blocks when in blocking mode until at least one byte has been decoded.

public int
readMore(ByteBuffer dst)

Implements org.java_websocket.WrappedByteChannel.readMore.

This function does not read data from the underlying channel at all.

private int
readRemaining(ByteBuffer dst)

read(ByteBuffer) may not be to leave all buffers(inData, inCrypt)

private void
public Socket
private int
private void
private synchronized ByteBuffer
unwrap()

performs the unwrap operation by unwrapping from inCrypt to inData

private synchronized ByteBuffer
public int
write(ByteBuffer src)

Implements java.nio.channels.WritableByteChannel.write.

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

public void
writeMore()

Implements org.java_websocket.WrappedByteChannel.writeMore.

Gets called when isNeedWrite() ()} requires a additional rite

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bufferallocationsback to summary
protected int bufferallocations

Should be used to count the buffer allocations. But because of #190 where HandshakeStatus.FINISHED is not properly returned by nio wrap/unwrap this variable is used to check whether createBuffers(SSLSession) needs to be called.

emptybufferback to summary
protected static ByteBuffer emptybuffer

This object is used to feed the SSLEngine's wrap and unwrap methods during the handshake phase.

execback to summary
protected ExecutorService exec
inCryptback to summary
protected ByteBuffer inCrypt

encrypted data incoming

inDataback to summary
protected ByteBuffer inData

raw payload incoming

logback to summary
private final Logger log

Logger instance

Since
1.4.0
outCryptback to summary
protected ByteBuffer outCrypt

encrypted data outgoing

readEngineResultback to summary
protected SSLEngineResult readEngineResult
saveCryptDataback to summary
private byte[] saveCryptData
selectionKeyback to summary
protected SelectionKey selectionKey

used to set interestOP SelectionKey.OP_WRITE for the underlying channel

socketChannelback to summary
protected SocketChannel socketChannel

the underlying channel

sslEngineback to summary
protected SSLEngine sslEngine
tasksback to summary
protected List<Future<?>> tasks
writeEngineResultback to summary
protected SSLEngineResult writeEngineResult

Constructor Detail

SSLSocketChannel2back to summary
public SSLSocketChannel2(SocketChannel channel, SSLEngine sslEngine, ExecutorService exec, SelectionKey key) throws IOException

Method Detail

closeback to summary
public void close() throws IOException

Implements java.nio.channels.Channel.close.

Doc from java.nio.channels.Channel.close.

Closes this channel.

After a channel is closed, any further attempt to invoke I/O operations upon it will cause a ClosedChannelException to be thrown.

If this channel is already closed then invoking this method has no effect.

This method may be invoked at any time. If some other thread has already invoked it, however, then another invocation will block until the first invocation is complete, after which it will return without effect.

Exceptions
IOException:
If an I/O error occurs
configureBlockingback to summary
public SelectableChannel configureBlocking(boolean b) throws IOException
connectback to summary
public boolean connect(SocketAddress remote) throws IOException
consumeDelegatedTasksback to summary
protected void consumeDelegatedTasks()
consumeFutureUninterruptibleback to summary
private void consumeFutureUninterruptible(Future<?> f)
createBuffersback to summary
protected void createBuffers(SSLSession session)
finishConnectback to summary
public boolean finishConnect() throws IOException
getSSLEngineback to summary
public SSLEngine getSSLEngine()

Implements org.java_websocket.interfaces.ISSLChannel.getSSLEngine.

Doc from org.java_websocket.interfaces.ISSLChannel.getSSLEngine.

Get the ssl engine used for the de- and encryption of the communication.

Annotations
@Override
isBlockingback to summary
public boolean isBlocking()

Implements org.java_websocket.WrappedByteChannel.isBlocking.

Doc from org.java_websocket.WrappedByteChannel.isBlocking.

This function returns the blocking state of the channel

Annotations
@Override
isConnectedback to summary
public boolean isConnected()
isHandShakeCompleteback to summary
private boolean isHandShakeComplete()
isInboundDoneback to summary
public boolean isInboundDone()
isNeedReadback to summary
public boolean isNeedRead()

Implements org.java_websocket.WrappedByteChannel.isNeedRead.

Doc from org.java_websocket.WrappedByteChannel.isNeedRead.

returns whether readMore should be called to fetch data which has been decoded but not yet been returned.

Annotations
@Override
isNeedWriteback to summary
public boolean isNeedWrite()

Implements org.java_websocket.WrappedByteChannel.isNeedWrite.

Doc from org.java_websocket.WrappedByteChannel.isNeedWrite.

returns whether writeMore should be called write additional data.

Annotations
@Override
isOpenback to summary
public boolean isOpen()

Implements java.nio.channels.Channel.isOpen.

Doc from java.nio.channels.Channel.isOpen.

Tells whether or not this channel is open.

Annotations
@Override
processHandshakeback to summary
private synchronized void processHandshake(boolean isReading) throws IOException

This method will do whatever necessary to process the sslEngine handshake. Thats why it's called both from the read(ByteBuffer) and write(ByteBuffer)

readback to summary
public int read(ByteBuffer dst) throws IOException

Implements java.nio.channels.ReadableByteChannel.read.

Blocks when in blocking mode until at least one byte has been decoded.
When not in blocking mode 0 may be returned.

Returns:int

the number of bytes read.

Exceptions
IOException:

Doc from java.nio.channels.ReadableByteChannel.read.

If some other I/O error occurs

readMoreback to summary
public int readMore(ByteBuffer dst) throws SSLException

Implements org.java_websocket.WrappedByteChannel.readMore.

Doc from org.java_websocket.WrappedByteChannel.readMore.

This function does not read data from the underlying channel at all. It is just a way to fetch data which has already be received or decoded but was but was not yet returned to the user. This could be the case when the decoded data did not fit into the buffer the user passed to read(ByteBuffer).

Annotations
@Override
readRemainingback to summary
private int readRemaining(ByteBuffer dst) throws SSLException

read(ByteBuffer) may not be to leave all buffers(inData, inCrypt)

saveCryptedDataback to summary
private void saveCryptedData()
socketback to summary
public Socket socket()
transfereToback to summary
private int transfereTo(ByteBuffer from, ByteBuffer to)
tryRestoreCryptedDataback to summary
private void tryRestoreCryptedData()
unwrapback to summary
private synchronized ByteBuffer unwrap() throws SSLException

performs the unwrap operation by unwrapping from inCrypt to inData

wrapback to summary
private synchronized ByteBuffer wrap(ByteBuffer b) throws SSLException
writeback to summary
public int write(ByteBuffer src) throws IOException

Implements java.nio.channels.WritableByteChannel.write.

Doc from java.nio.channels.WritableByteChannel.write.

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

An attempt is made to write up to r bytes to the channel, where r is the number of bytes remaining in the buffer, that is, src.remaining(), at the moment this method is invoked.

Suppose that a byte sequence of length n is written, where 0 <= n <= r. This byte sequence will be transferred from the buffer starting at index p, where p is the buffer's position at the moment this method is invoked; the index of the last byte written will be p + n - 1. Upon return the buffer's position will be equal to p + n; its limit will not have changed.

Unless otherwise specified, a write operation will return only after writing all of the r requested bytes. Some types of channels, depending upon their state, may write only some of the bytes or possibly none at all. A socket channel in non-blocking mode, for example, cannot write any more bytes than are free in the socket's output buffer.

This method may be invoked at any time. If another thread has already initiated a write operation upon this channel, however, then an invocation of this method will block until the first operation is complete.

Exceptions
IOException:
If some other I/O error occurs
writeMoreback to summary
public void writeMore() throws IOException

Implements org.java_websocket.WrappedByteChannel.writeMore.

Doc from org.java_websocket.WrappedByteChannel.writeMore.

Gets called when isNeedWrite() ()} requires a additional rite

Annotations
@Override
Exceptions
IOException:
may be thrown due to an error while writing