Package org.java_websocket
Class SSLSocketChannel2
java.lang.Object
org.java_websocket.SSLSocketChannel2
- All Implemented Interfaces:
Closeable
,AutoCloseable
,ByteChannel
,Channel
,ReadableByteChannel
,WritableByteChannel
,ISSLChannel
,WrappedByteChannel
public class SSLSocketChannel2
extends Object
implements ByteChannel, WrappedByteChannel, ISSLChannel
Implements the relevant portions of the SocketChannel interface with the SSLEngine wrapper.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
Should be used to count the buffer allocations.protected static ByteBuffer
This object is used to feed theSSLEngine
's wrap and unwrap methods during the handshake phase.protected ExecutorService
protected ByteBuffer
encrypted data incomingprotected ByteBuffer
raw payload incomingprotected ByteBuffer
encrypted data outgoingprotected SSLEngineResult
protected SelectionKey
used to set interestOP SelectionKey.OP_WRITE for the underlying channelprotected SocketChannel
the underlying channelprotected SSLEngine
protected SSLEngineResult
-
Constructor Summary
ConstructorsConstructorDescriptionSSLSocketChannel2
(SocketChannel channel, SSLEngine sslEngine, ExecutorService exec, SelectionKey key) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
configureBlocking
(boolean b) boolean
connect
(SocketAddress remote) protected void
protected void
createBuffers
(SSLSession session) boolean
Get the ssl engine used for the de- and encryption of the communication.boolean
This function returns the blocking state of the channelboolean
boolean
boolean
returns whether readMore should be called to fetch data which has been decoded but not yet been returned.boolean
returns whether writeMore should be called write additional data.boolean
isOpen()
int
read
(ByteBuffer dst) Blocks when in blocking mode until at least one byte has been decoded.
When not in blocking mode 0 may be returned.int
readMore
(ByteBuffer dst) This function does not read data from the underlying channel at all.socket()
int
write
(ByteBuffer src) void
Gets called whenWrappedByteChannel.isNeedWrite()
()} requires a additional rite
-
Field Details
-
emptybuffer
This object is used to feed theSSLEngine
's wrap and unwrap methods during the handshake phase. -
exec
-
tasks
-
inData
raw payload incoming -
outCrypt
encrypted data outgoing -
inCrypt
encrypted data incoming -
socketChannel
the underlying channel -
selectionKey
used to set interestOP SelectionKey.OP_WRITE for the underlying channel -
sslEngine
-
readEngineResult
-
writeEngineResult
-
bufferallocations
protected int bufferallocationsShould 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 Details
-
SSLSocketChannel2
public SSLSocketChannel2(SocketChannel channel, SSLEngine sslEngine, ExecutorService exec, SelectionKey key) throws IOException - Throws:
IOException
-
-
Method Details
-
consumeDelegatedTasks
protected void consumeDelegatedTasks() -
createBuffers
-
write
- Specified by:
write
in interfaceWritableByteChannel
- Throws:
IOException
-
read
Blocks when in blocking mode until at least one byte has been decoded.
When not in blocking mode 0 may be returned.- Specified by:
read
in interfaceReadableByteChannel
- Returns:
- the number of bytes read.
- Throws:
IOException
-
isConnected
public boolean isConnected() -
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceChannel
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
configureBlocking
- Throws:
IOException
-
connect
- Throws:
IOException
-
finishConnect
- Throws:
IOException
-
socket
-
isInboundDone
public boolean isInboundDone() -
isOpen
public boolean isOpen() -
isNeedWrite
public boolean isNeedWrite()Description copied from interface:WrappedByteChannel
returns whether writeMore should be called write additional data.- Specified by:
isNeedWrite
in interfaceWrappedByteChannel
- Returns:
- is a additional write needed
-
writeMore
Description copied from interface:WrappedByteChannel
Gets called whenWrappedByteChannel.isNeedWrite()
()} requires a additional rite- Specified by:
writeMore
in interfaceWrappedByteChannel
- Throws:
IOException
- may be thrown due to an error while writing
-
isNeedRead
public boolean isNeedRead()Description copied from interface:WrappedByteChannel
returns whether readMore should be called to fetch data which has been decoded but not yet been returned.- Specified by:
isNeedRead
in interfaceWrappedByteChannel
- Returns:
- is a additional read needed
- See Also:
-
readMore
Description copied from interface:WrappedByteChannel
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 toReadableByteChannel.read(ByteBuffer)
.- Specified by:
readMore
in interfaceWrappedByteChannel
- Parameters:
dst
- the destiny of the read- Returns:
- the amount of remaining data
- Throws:
SSLException
-
isBlocking
public boolean isBlocking()Description copied from interface:WrappedByteChannel
This function returns the blocking state of the channel- Specified by:
isBlocking
in interfaceWrappedByteChannel
- Returns:
- is the channel blocking
-
getSSLEngine
Description copied from interface:ISSLChannel
Get the ssl engine used for the de- and encryption of the communication.- Specified by:
getSSLEngine
in interfaceISSLChannel
- Returns:
- the ssl engine of this channel
-