Skip to content
Start free evaluation

pdcomm::TcpEvent

Class

Owned, immutable snapshot of one HSMS endpoint event.

class TcpEvent

Declared in: #include <pdcomm_tcp.hpp>

TcpEndpoint::nextEvent() returns events in the order they occurred. info() decodes the kind (state change, received data message, failed transaction, protocol error, transport error or completed W0 write), its codes, the message header and the token. body() copies the SECS-II body of a received data message.

The event owns its data, including the message body. It stays readable after the endpoint is destroyed and after GemEndpoint::handleEvent() has processed it.

Notes

  • Move-only RAII wrapper over PdcommTcpEvent. info() and body() may run concurrently on one event, but not concurrently with its destruction or a move. body() can also throw std::bad_alloc.

Members

TcpEvent

Constructor

Creates an empty event that owns no native handle.

TcpEvent() noexcept = default

Declared in: #include <pdcomm_tcp.hpp>

TcpEvent

Constructor

Takes ownership of the native handle owned by other.

TcpEvent(TcpEvent &&other) noexcept

Declared in: #include <pdcomm_tcp.hpp>

Parameters

NameDescription
otherSource wrapper; it becomes empty.

TcpEvent

Constructor

Copying is disabled; the wrapper exclusively owns its native handle.

TcpEvent(const TcpEvent &) = delete

Declared in: #include <pdcomm_tcp.hpp>

body

Method

Copies the message body of a received data message.

std::vector<uint8_t> body() const

Declared in: #include <pdcomm_tcp.hpp>

The bytes are the encoded SECS-II item exactly as received. The copy is empty for a message without a body and for every event kind other than PDCOMM_TCP_RECEIVED.

Returns

An independent copy of the body.

Notes

  • Throws pdcomm::Error: PDCOMM_INVALID_ARGUMENT when the event is empty; PDCOMM_INTERNAL_ERROR when the library contained an internal panic.

info

Method

Decodes the kind, codes, message header and token of the event.

PdcommTcpEventInfo info() const

Declared in: #include <pdcomm_tcp.hpp>

Fields that do not apply to the event kind are 0. For a PDCOMM_TCP_RECEIVED event, is_reply tells a reply to one of your requests from a primary sent by the peer, and the token of a reply equals the token that TcpEndpoint::request() returned.

Returns

The description filled by pdcomm_tcp_event_info().

Notes

  • Throws pdcomm::Error: PDCOMM_INVALID_ARGUMENT when the event is empty; PDCOMM_INTERNAL_ERROR when the library contained an internal panic.

nativeHandle

Method

Returns the owned native handle for direct C API calls.

PdcommTcpEvent *nativeHandle() noexcept

Declared in: #include <pdcomm_tcp.hpp>

Returns

The handle, or nullptr for an empty event. Ownership stays with this wrapper.

nativeHandle

Method

Returns the owned native handle for read-only C API calls.

const PdcommTcpEvent *nativeHandle() const noexcept

Declared in: #include <pdcomm_tcp.hpp>

Returns

The handle, or nullptr for an empty event. Ownership stays with this wrapper.

operator bool

Method

Reports whether the wrapper owns a native event.

explicit operator bool() const noexcept

Declared in: #include <pdcomm_tcp.hpp>

TcpEndpoint::nextEvent() returns an empty event when its queue is empty, so while (auto event = endpoint.nextEvent()) drains the queue.

Returns

true when an event is owned.

operator=

Method

Releases the current handle, then takes ownership of the handle owned by other.

TcpEvent &operator=(TcpEvent &&other) noexcept

Declared in: #include <pdcomm_tcp.hpp>

Parameters

NameDescription
otherSource wrapper; it becomes empty.

Returns

This wrapper.

operator=

Method

Copy assignment is disabled; the wrapper exclusively owns its native handle.

TcpEvent &operator=(const TcpEvent &) = delete

Declared in: #include <pdcomm_tcp.hpp>

~TcpEvent

Method

Releases the native event with pdcomm_tcp_event_destroy().

~TcpEvent()

Declared in: #include <pdcomm_tcp.hpp>

An empty event releases nothing. Do not destroy an event while a GEM call that borrows it is running.