ITcpMsgSessionHandler

Handler for reading and writing messages


struct ITcpMsgSessionHandler
{
    virtual void Release() = 0;
    virtual void OnFailure(ESessionFailureType type, std::error_code ec) = 0;
    virtual std::error_code ReadMessage(const octet_t* payload, ssize_t payloadSize) = 0;
    virtual WriteMessageResult WriteMessage(octet_t* payload, ssize_t payloadSizeAvailable) = 0;
};

The methods of this interface are never called concurrently, and Release() is called last and exactly once.



void Release()

Called from the implementation of Close() on the TcpMsgSession Guaranteed to be called exactly once and after every other method in this interface. Therefore this is a good opportunity to delete this ITcpMsgSessionHandler


void OnFailure(ESessionFailureType type, std::error_code ec)

Indicates an error occurred while reading or writing messages. The type of error is returned in the given ESessionFailureType.

Besides various system error codes, the following error codes may be generated:

Values Description
MakeCedaErrorCode(ECedaErrorCode::ReadValidEndOfStream) When the peer's implementation of GetSizeOfNextMessageToWrite returned -2 indicating there are no more messages, causing EOF to be read on the socket.
MakeCedaErrorCode(ECedaErrorCode::ReadInvalidEndOfStream) When EOF was read on the socket part way through reading a message (this should never happen with a valid peer)
MakeCedaErrorCode(ECedaErrorCode::ReadInvalidMessageSize) A message was received with an unexpected size


std::error_code ReadMessage(const octet_t* payload, ssize_t payloadSize)

Deserialise and process a single message stored in a contiguous buffer in memory.

'payload' points at the the payload of the message (i.e. not including the message size).

'payloadSize' is the size of the message payload in bytes.

Note that if payloadSize == 0 then payload might be nullptr.

The returned std::error_code either indicates that the message was read successfully, or else indicates a fatal error with reading from the stream.

Must not throw an exception.


WriteMessageResult WriteMessage(octet_t* payload, ssize_t payloadSizeAvailable)

Try to write a single message to the given buffer which has size payloadSizeAvailable.

The returned WriteMessageResult provides information about the message that was written and whether there are more messages to write.

Must not throw an exception.