Package org.java_websocket
Class SSLSocketChannel2
- java.lang.Object
-
- org.java_websocket.SSLSocketChannel2
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,java.nio.channels.ByteChannel,java.nio.channels.Channel,java.nio.channels.ReadableByteChannel,java.nio.channels.WritableByteChannel,WrappedByteChannel
public class SSLSocketChannel2 extends java.lang.Object implements java.nio.channels.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 java.nio.ByteBufferemptybufferThis object is used to feed theSSLEngine's wrap and unwrap methods during the handshake phase.protected java.util.concurrent.ExecutorServiceexecprotected java.nio.ByteBufferinCryptencrypted data incomingprotected java.nio.ByteBufferinDataraw payload incommingprotected java.nio.ByteBufferoutCryptencrypted data outgoingprotected javax.net.ssl.SSLEngineResultreadEngineResultprotected java.nio.channels.SelectionKeyselectionKeyused to set interestOP SelectionKey.OP_WRITE for the underlying channelprotected java.nio.channels.SocketChannelsocketChannelthe underlying channelprotected javax.net.ssl.SSLEnginesslEngineprotected java.util.List<java.util.concurrent.Future<?>>tasksprotected javax.net.ssl.SSLEngineResultwriteEngineResult
-
Constructor Summary
Constructors Constructor Description SSLSocketChannel2(java.nio.channels.SocketChannel channel, javax.net.ssl.SSLEngine sslEngine, java.util.concurrent.ExecutorService exec, java.nio.channels.SelectionKey key)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()java.nio.channels.SelectableChannelconfigureBlocking(boolean b)booleanconnect(java.net.SocketAddress remote)protected voidconsumeDelegatedTasks()protected voidcreateBuffers(javax.net.ssl.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(java.nio.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(java.nio.ByteBuffer dst)This function does not read data from the underlying channel at all.java.net.Socketsocket()intwrite(java.nio.ByteBuffer src)voidwriteMore()Gets called whenWrappedByteChannel.isNeedWrite()()} requires a additional rite
-
-
-
Field Detail
-
emptybuffer
protected static java.nio.ByteBuffer emptybuffer
This object is used to feed theSSLEngine's wrap and unwrap methods during the handshake phase.
-
exec
protected java.util.concurrent.ExecutorService exec
-
tasks
protected java.util.List<java.util.concurrent.Future<?>> tasks
-
inData
protected java.nio.ByteBuffer inData
raw payload incomming
-
outCrypt
protected java.nio.ByteBuffer outCrypt
encrypted data outgoing
-
inCrypt
protected java.nio.ByteBuffer inCrypt
encrypted data incoming
-
socketChannel
protected java.nio.channels.SocketChannel socketChannel
the underlying channel
-
selectionKey
protected java.nio.channels.SelectionKey selectionKey
used to set interestOP SelectionKey.OP_WRITE for the underlying channel
-
sslEngine
protected javax.net.ssl.SSLEngine sslEngine
-
readEngineResult
protected javax.net.ssl.SSLEngineResult readEngineResult
-
writeEngineResult
protected javax.net.ssl.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.
-
-
Method Detail
-
consumeDelegatedTasks
protected void consumeDelegatedTasks()
-
createBuffers
protected void createBuffers(javax.net.ssl.SSLSession session)
-
write
public int write(java.nio.ByteBuffer src) throws java.io.IOException- Specified by:
writein interfacejava.nio.channels.WritableByteChannel- Throws:
java.io.IOException
-
read
public int read(java.nio.ByteBuffer dst) throws java.io.IOExceptionBlocks when in blocking mode until at least one byte has been decoded.
When not in blocking mode 0 may be returned.- Specified by:
readin interfacejava.nio.channels.ReadableByteChannel- Returns:
- the number of bytes read.
- Throws:
java.io.IOException
-
isConnected
public boolean isConnected()
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.nio.channels.Channel- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
configureBlocking
public java.nio.channels.SelectableChannel configureBlocking(boolean b) throws java.io.IOException- Throws:
java.io.IOException
-
connect
public boolean connect(java.net.SocketAddress remote) throws java.io.IOException- Throws:
java.io.IOException
-
finishConnect
public boolean finishConnect() throws java.io.IOException- Throws:
java.io.IOException
-
socket
public java.net.Socket socket()
-
isInboundDone
public boolean isInboundDone()
-
isOpen
public boolean isOpen()
- Specified by:
isOpenin interfacejava.nio.channels.Channel
-
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 java.io.IOExceptionDescription copied from interface:WrappedByteChannelGets called whenWrappedByteChannel.isNeedWrite()()} requires a additional rite- Specified by:
writeMorein interfaceWrappedByteChannel- Throws:
java.io.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(java.nio.ByteBuffer dst) throws javax.net.ssl.SSLExceptionDescription 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:
javax.net.ssl.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
-
-