public class SocketTransport extends Object implements Transport
SocketTransport
object offers a transport that can
send and receive bytes in a non-blocking manner. The contract of
the Transport
is that it must either write the data
it is asked to write or it must queue that data for delivery. For
the vast majority of cases data is written directly to the socket
without any need for queuing or selection for write ready events.
In the event that the client TCP window is full and writing would block this makes use of a queue of buffers which can be used to append data to. The buffers are lazily instantiated so the memory required is created only in the rare case that they are needed. Once a buffer is full it is queued to an asynchronous thread where the buffer queue is drained and sent to the client when the TCP window of the client is capable of accepting it.
In order to improve the network performance of this transport the default packet size sent to the TCP stack is four kilobytes. This ensures that the fragments of response delivered to the TCP layer are sufficiently large for optimum network performance.
Constructor and Description |
---|
SocketTransport(Socket socket,
Reactor reactor)
Constructor for the
SocketTransport object. |
SocketTransport(Socket socket,
Reactor reactor,
int buffer)
Constructor for the
SocketTransport object. |
SocketTransport(Socket socket,
Reactor reactor,
int buffer,
int threshold)
Constructor for the
SocketTransport object. |
Modifier and Type | Method and Description |
---|---|
void |
close()
This method is used to flush the internal buffer and close
the underlying socket.
|
void |
flush()
This is used to flush the internal buffer to the underlying
socket.
|
Map |
getAttributes()
This method is used to get the
Map of attributes
by this pipeline. |
Certificate |
getCertificate()
This is used to acquire the SSL certificate used when the
server is using a HTTPS connection.
|
SocketChannel |
getChannel()
This method is used to acquire the
SocketChannel
for the connection. |
SSLEngine |
getEngine()
This is used to acquire the SSL engine used for https.
|
Trace |
getTrace()
This is used to acquire the trace object that is associated
with the socket.
|
int |
read(ByteBuffer data)
This is used to perform a non-blocking read on the transport.
|
void |
write(ByteBuffer data)
This method is used to deliver the provided buffer of bytes to
the underlying transport.
|
public SocketTransport(Socket socket, Reactor reactor) throws IOException
SocketTransport
object. This
requires a reactor to perform asynchronous writes and also the
pipeline which is used to read and write data. This transport
will use a queue of buffers which are lazily initialized so as
to only allocate the memory on demand.socket
- this is used to read and write the datareactor
- this is used to perform asynchronous writesIOException
public SocketTransport(Socket socket, Reactor reactor, int buffer) throws IOException
SocketTransport
object. This
requires a reactor to perform asynchronous writes and also the
pipeline which is used to read and write data. This transport
will use a queue of buffers which are lazily initialized so as
to only allocate the memory on demand.socket
- this is used to read and write the datareactor
- this is used to perform asynchronous writesbuffer
- this is the size of the output buffer to useIOException
public SocketTransport(Socket socket, Reactor reactor, int buffer, int threshold) throws IOException
SocketTransport
object. This
requires a reactor to perform asynchronous writes and also the
pipeline which is used to read and write data. This transport
will use a queue of buffers which are lazily initialized so as
to only allocate the memory on demand.socket
- this is used to read and write the datareactor
- this is used to perform asynchronous writesbuffer
- this is the size of the output buffer to usethreshold
- this is the maximum size of the output bufferIOException
public Certificate getCertificate()
getCertificate
in interface Transport
public Trace getTrace()
public Map getAttributes()
Map
of attributes
by this pipeline. The attributes map is used to maintain details
about the connection. Information such as security credentials
to client details can be placed within the attribute map.getAttributes
in interface Socket
public SSLEngine getEngine()
public SocketChannel getChannel()
SocketChannel
for the connection. This allows the server to acquire the input
and output streams with which to communicate. It can also be
used to configure the connection and perform various network
operations that could otherwise not be performed.getChannel
in interface Socket
public int read(ByteBuffer data) throws IOException
read
in interface Transport
data
- this is the buffer to append the bytes toIOException
public void write(ByteBuffer data) throws IOException
write
in interface Transport
data
- this is the array of bytes to send to the clientIOException
public void flush() throws IOException
flush
in interface Transport
IOException
public void close() throws IOException
close
in interface Transport
IOException
Copyright © 2024. All rights reserved.