Workspace 6.21.5
Public Slots | Signals | Public Member Functions | List of all members
TcpMessageSocketAdapter Class Reference

#include <Workspace/DataExecution/Execution/tcpmessagesocketadapter.h>

Inherits QObject.

Public Slots

void onReadyRead ()
 

Signals

void readyReadMessage (CSIRO::DataExecution::TcpMessage *, CSIRO::DataExecution::TcpMessageSocketAdapter *)
 

Public Member Functions

 TcpMessageSocketAdapter ()
 
 TcpMessageSocketAdapter (QTcpSocket &)
 
 ~TcpMessageSocketAdapter () override
 
QTcpSocket * getSocket ()
 
void setSocket (QTcpSocket *socket)
 

Detailed Description

Adapts a QTcpSocket by adding support for the reading and notifying of messages. The QTcpSocket class is used to read network data in response to the emitted readyRead() signal however, when readyRead() is emitted the data buffered in the QTcpSocket may be greater than or less than the data required to re-constitute a message. In other words, a message's data may be delivered accross several readyRead() emits. As such, this class and the associated TcpMessage class have been created to adapt a QTcpSocket in order to buffer incoming data until a "message" can be read in full. Once a message has been read (perhaps in response to data notifications from the wrapped QTcpSocket across several readyRead() emits) a readyReadMessage() signal is emitted that contains a reference to the fully-read TcpMessage.

Note: Clients MUST connect to the readyReadMessage() signal and must ensure that one of the connected slots deletes the message. Otherwise this class will cause a memory leak as each message is ready.

See also
TcpMessage

Constructor & Destructor Documentation

◆ TcpMessageSocketAdapter() [1/2]

Constructs a TcpMessageSocketAdapter. The socket which this adapts should be provided via the setSocket() method.

◆ TcpMessageSocketAdapter() [2/2]

TcpMessageSocketAdapter ( QTcpSocket &  socket)

Constructs a TcpMessageSocketAdapter adapting the provided socket.

Parameters
socketThe socket to adapt.

◆ ~TcpMessageSocketAdapter()

~TcpMessageSocketAdapter ( )
override

Member Function Documentation

◆ getSocket()

QTcpSocket * getSocket ( )
Returns
The current QTcpSocket

◆ onReadyRead

void onReadyRead ( )
slot

Intercepts the adapted socket's readyRead() signal to provide message data buffering that may occurr over several readyRead() signals. When a message has been fully read, this method emits a readyReadMessage() signal.

See also
readyReadMessage()

◆ readyReadMessage

Clients MUST connect to the readyReadMessage() signal and must ensure that one of the connected slots deletes the message. Otherwise this class will cause a memory leak as each message is ready.

◆ setSocket()

void setSocket ( QTcpSocket *  socket)

Enables the setting of the adapted socket.

Parameters
socketThe socket to adapt.