pdcomm::TcpEvent
Class
Owned, immutable snapshot of one HSMS endpoint event.
class TcpEventTcpEndpoint::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 throwstd::bad_alloc.
Members
TcpEvent
Constructor
Creates an empty event that owns no native handle.
TcpEvent() noexcept = defaultTcpEvent
Constructor
Takes ownership of the native handle owned by other.
TcpEvent(TcpEvent &&other) noexceptParameters
| Name | Description |
|---|---|
other | Source wrapper; it becomes empty. |
TcpEvent
Constructor
Copying is disabled; the wrapper exclusively owns its native handle.
TcpEvent(const TcpEvent &) = deletebody
Method
Copies the message body of a received data message.
std::vector<uint8_t> body() constThe 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_ARGUMENTwhen the event is empty;PDCOMM_INTERNAL_ERRORwhen the library contained an internal panic.
info
Method
Decodes the kind, codes, message header and token of the event.
PdcommTcpEventInfo info() constFields 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_ARGUMENTwhen the event is empty;PDCOMM_INTERNAL_ERRORwhen the library contained an internal panic.
nativeHandle
Method
Returns the owned native handle for direct C API calls.
PdcommTcpEvent *nativeHandle() noexceptReturns
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 noexceptReturns
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 noexceptTcpEndpoint::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) noexceptParameters
| Name | Description |
|---|---|
other | Source 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~TcpEvent
Method
Releases the native event with pdcomm_tcp_event_destroy().
~TcpEvent()An empty event releases nothing. Do not destroy an event while a GEM call that borrows it is running.