Package org.java_websocket
Class SSLSocketChannel2
- java.lang.Object
-
- org.java_websocket.SSLSocketChannel2
-
- All Implemented Interfaces:
Closeable,AutoCloseable,ByteChannel,Channel,ReadableByteChannel,WritableByteChannel,WrappedByteChannel
public class SSLSocketChannel2 extends Object implements ByteChannel, WrappedByteChannel
Implements the relevant portions of the SocketChannel interface with the SSLEngine wrapper.
-
-
Field Summary
Fields Modifier and Type Field Description protected intbufferallocationsShould be used to count the buffer allocations.protected static ByteBufferemptybufferThis object is used to feed theSSLEngine's wrap and unwrap methods during the handshake phase.protected ExecutorServiceexecprotected ByteBufferinCryptencrypted data incomingprotected ByteBufferinDataraw payload incommingprotected ByteBufferoutCryptencrypted data outgoingprotected SSLEngineResultreadEngineResultprotected SelectionKeyselectionKeyused to set interestOP SelectionKey.OP_WRITE for the underlying channelprotected SocketChannelsocketChannelthe underlying channelprotected SSLEnginesslEngineprotected List<Future<?>>tasksprotected SSLEngineResultwriteEngineResult
-
Constructor Summary
Constructors Constructor Description SSLSocketChannel2(SocketChannel channel, SSLEngine sslEngine, ExecutorService exec, SelectionKey key)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()SelectableChannelconfigureBlocking(boolean b)booleanconnect(SocketAddress remote)protected voidconsumeDelegatedTasks()protected voidcreateBuffers(SSLSession session)booleanfinishConnect()booleanisBlocking()This function returns the blocking state of the channelbooleanisConnected()booleanisInboundDone()booleanisNeedRead()returns whether readMore should be called to fetch data which has been decoded but not yet been returned.booleanisNeedWrite()returns whether writeMore should be called write additional data.booleanisOpen()intread(ByteBuffer dst)Blocks when in blocking mode until at least one byte has been decoded.
When not in blocking mode 0 may be returned.intreadMore(ByteBuffer dst)This function does not read data from the underlying channel at all.Socketsocket()intwrite(ByteBuffer src)voidwriteMore()Gets called whenWrappedByteChannel.isNeedWrite()()} requires a additional rite
-
-
-
Field Detail
-
emptybuffer
protected static ByteBuffer emptybuffer
This object is used to feed theSSLEngine's wrap and unwrap methods during the handshake phase.
-
exec
protected ExecutorService exec
-
inData
protected ByteBuffer inData
raw payload incomming
-
outCrypt
protected ByteBuffer outCrypt
encrypted data outgoing
-
inCrypt
protected ByteBuffer inCrypt
encrypted data incoming
-
socketChannel
protected SocketChannel socketChannel
the underlying channel
-
selectionKey
protected SelectionKey selectionKey
used to set interestOP SelectionKey.OP_WRITE for the underlying channel
-
sslEngine
protected SSLEngine sslEngine
-
readEngineResult
protected SSLEngineResult readEngineResult
-
writeEngineResult
protected SSLEngineResult writeEngineResult
-
bufferallocations
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 whethercreateBuffers(SSLSession)needs to be called.
-
-
Constructor Detail
-
SSLSocketChannel2
public SSLSocketChannel2(SocketChannel channel, SSLEngine sslEngine, ExecutorService exec, SelectionKey key) throws IOException
- Throws:
IOException
-
-
Method Detail
-
consumeDelegatedTasks
protected void consumeDelegatedTasks()
-
createBuffers
protected void createBuffers(SSLSession session)
-
write
public int write(ByteBuffer src) throws IOException
- Specified by:
writein interfaceWritableByteChannel- Throws:
IOException
-
read
public int read(ByteBuffer dst) throws IOException
Blocks when in blocking mode until at least one byte has been decoded.
When not in blocking mode 0 may be returned.- Specified by:
readin interfaceReadableByteChannel- Returns:
- the number of bytes read.
- Throws:
IOException
-
isConnected
public boolean isConnected()
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceChannel- Specified by:
closein interfaceCloseable- Throws:
IOException
-
configureBlocking
public SelectableChannel configureBlocking(boolean b) throws IOException
- Throws:
IOException
-
connect
public boolean connect(SocketAddress remote) throws IOException
- Throws:
IOException
-
finishConnect
public boolean finishConnect() throws IOException- Throws:
IOException
-
socket
public Socket socket()
-
isInboundDone
public boolean isInboundDone()
-
isNeedWrite
public boolean isNeedWrite()
Description copied from interface:WrappedByteChannelreturns whether writeMore should be called write additional data.- Specified by:
isNeedWritein interfaceWrappedByteChannel- Returns:
- is a additional write needed
-
writeMore
public void writeMore() throws IOExceptionDescription copied from interface:WrappedByteChannelGets called whenWrappedByteChannel.isNeedWrite()()} requires a additional rite- Specified by:
writeMorein interfaceWrappedByteChannel- Throws:
IOException- may be thrown due to an error while writing
-
isNeedRead
public boolean isNeedRead()
Description copied from interface:WrappedByteChannelreturns whether readMore should be called to fetch data which has been decoded but not yet been returned.- Specified by:
isNeedReadin interfaceWrappedByteChannel- Returns:
- is a additional read needed
- See Also:
ReadableByteChannel.read(ByteBuffer),WrappedByteChannel.readMore(ByteBuffer)
-
readMore
public int readMore(ByteBuffer dst) throws SSLException
Description copied from interface:WrappedByteChannelThis 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 toReadableByteChannel.read(ByteBuffer).- Specified by:
readMorein interfaceWrappedByteChannel- Parameters:
dst- the destiny of the read- Returns:
- the amount of remaining data
- Throws:
SSLException
-
isBlocking
public boolean isBlocking()
Description copied from interface:WrappedByteChannelThis function returns the blocking state of the channel- Specified by:
isBlockingin interfaceWrappedByteChannel- Returns:
- is the channel blocking
-
-