Package org.omegazero.net.socket.impl
Class TLSConnection
java.lang.Object
org.omegazero.net.socket.SocketConnection
org.omegazero.net.socket.ChannelConnection
org.omegazero.net.socket.impl.TLSConnection
- All Implemented Interfaces:
AutoCloseable
-
Field Summary
FieldsFields inherited from class org.omegazero.net.socket.ChannelConnection
readBuf, writeBufFields inherited from class org.omegazero.net.socket.SocketConnection
readLock, writeLock -
Constructor Summary
ConstructorsConstructorDescriptionTLSConnection(SelectionKey selectionKey, ChannelProvider provider, SocketAddress remote, SSLContext sslContext, boolean client, String[] alpnNames, String[] requestedServerNames) TLSConnection(SelectionKey selectionKey, ChannelProvider provider, SSLContext sslContext, boolean client, String[] alpnNames) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidclose0()Forcibly closes this connection.protected voidMust be called by subclass constructors.voidbooleanflush()Attempts to flush any queued data after a call toSocketConnection.writeQueue(byte[])or data that could not be written previously because the socket was busy.booleanReturnstrueif this socket is connected.byte[]read()Reads data received from the peer host on this connection.voidwrite(byte[] data, int offset, int length) Writes data to this connection for delivery to the peer host.voidwriteQueue(byte[] data, int offset, int length) Similar toSocketConnection.write(byte[], int, int), except that no attempt will be made to immediately flush the data to the socket, if supported by the implementation.Methods inherited from class org.omegazero.net.socket.ChannelConnection
close, connect, destroy, flushWriteBacklog, getLastIOTime, getLocalAddress, getProvider, getRemoteAddress, isWritable, readFromSocket, setReadBlock, writeBuffered, writeToSocketMethods inherited from class org.omegazero.net.socket.SocketConnection
getApparentRemoteAddress, getAttachment, getReadLock, getWriteLock, handleClose, handleConnect, handleData, handleError, handleTimeout, handleWritable, hasConnected, hasDisconnected, localClose, localConnect, queueWrite, setApparentRemoteAddress, setAttachment, setOnClose, setOnConnect, setOnData, setOnError, setOnLocalClose, setOnLocalConnect, setOnTimeout, setOnWritable, write, write, writeQueue
-
Field Details
-
readBufUnwrapped
-
writeBufUnwrapped
-
-
Constructor Details
-
TLSConnection
public TLSConnection(SelectionKey selectionKey, ChannelProvider provider, SSLContext sslContext, boolean client, String[] alpnNames) throws IOException - Throws:
IOException
-
TLSConnection
public TLSConnection(SelectionKey selectionKey, ChannelProvider provider, SocketAddress remote, SSLContext sslContext, boolean client, String[] alpnNames, String[] requestedServerNames) throws IOException - Throws:
IOException
-
-
Method Details
-
createBuffers
protected void createBuffers()Description copied from class:ChannelConnectionMust be called by subclass constructors. This method creates theChannelConnection.readBufandChannelConnection.writeBufbuffers and any additional buffers required.- Specified by:
createBuffersin classChannelConnection
-
read
public byte[] read()Description copied from class:SocketConnectionReads data received from the peer host on this connection.This function is non-blocking. If no data was available,
nullis returned.- Specified by:
readin classSocketConnection- Returns:
- The read data or
nullif no data is available.
-
write
public void write(byte[] data, int offset, int length) Description copied from class:SocketConnectionWrites data to this connection for delivery to the peer host.This function is non-blocking and may store data in a temporary write buffer if the underlying socket is busy. An application should try to respect the value of
SocketConnection.isWritable()to reduce memory consumption by such write buffer if a lot of data is being written.If this method is called before the
onConnectevent, the data is queued in a temporary buffer and written out when the socket connects.- Specified by:
writein classSocketConnection- Parameters:
data- The data to writeoffset- The start index of the data to write in the data byte arraylength- The total number of bytes to write from the data byte array, starting at offset- See Also:
-
writeQueue
public void writeQueue(byte[] data, int offset, int length) Description copied from class:SocketConnectionSimilar toSocketConnection.write(byte[], int, int), except that no attempt will be made to immediately flush the data to the socket, if supported by the implementation.- Overrides:
writeQueuein classSocketConnection- Parameters:
data- The data to writeoffset- The start index of the data to write in the data byte arraylength- The total number of bytes to write from the data byte array, starting at offset- See Also:
-
flush
public boolean flush()Description copied from class:ChannelConnectionAttempts to flush any queued data after a call toSocketConnection.writeQueue(byte[])or data that could not be written previously because the socket was busy.- Overrides:
flushin classChannelConnection- Returns:
trueif all data could be written to the socket- See Also:
-
close0
protected void close0()Description copied from class:ChannelConnectionForcibly closes this connection.- Overrides:
close0in classChannelConnection
-
isConnected
public boolean isConnected()Description copied from class:ChannelConnectionReturnstrueif this socket is connected.- Overrides:
isConnectedin classChannelConnection- Returns:
trueifChannelConnection.isConnected()returnstrueand the TLS handshake has completed
-
getAlpnProtocol
- Returns:
- The negotiated ALPN protocol name, or
nullif ALPN did not occur
-
doTLSHandshake
- Throws:
IOException
-