#include <icy/packettransaction.h>Inherits:
Sendable,Stateful< TransactionState >,RefCounted< PacketTransaction< PacketT > >Subclassed by:Transaction< Message >,Transaction< PacketT >
Request/response transaction with timeout and retry logic.
Lifetime is managed by IntrusivePtr via the RefCounted base class. The transaction is kept alive as long as at least one IntrusivePtr references it. The owning client holds a Ptr in its transaction list; callbacks should capture a Ptr copy to prevent premature deletion.
When a terminal state (Success or Failed) is reached, the transaction cleans up its timer but does NOT delete itself. The IntrusivePtr destructor handles deletion when the last reference is released.
| Return | Name | Description |
|---|---|---|
PacketTransaction inline | #### Parameters | |
PacketTransaction inline | #### Parameters | |
bool | send virtual inline | Starts the transaction timer and sends the request. Overriding classes should implement send logic here. |
void | cancel virtual inline | Cancellation means that the agent will not retransmit the request, will not treat the lack of response to be a failure, but will wait the duration of the transaction timeout for a response. Transitions the transaction to the Cancelled state. |
bool | cancelled const inline | #### Returns |
void | dispose virtual inline | Stops the timer and unregisters callbacks. Does NOT delete the object; the IntrusivePtr destructor handles deletion when the last reference is released. Safe to call multiple times. |
bool | disposed const inline | #### Returns |
bool | canResend virtual inline | #### Returns |
int | attempts const inline | #### Returns |
int | retries const inline | #### Returns |
PacketT & | request inline | #### Returns |
PacketT | request const inline | #### Returns |
PacketT & | response inline | #### Returns |
PacketT | response const inline | #### Returns |
inline
inline PacketTransaction(long timeout, int retries, uv::Loop * loop)timeout Transaction timeout in milliseconds before failure or retry.
retries Maximum number of retransmissions (0 means one attempt only).
loop Event loop for the timeout timer.
inline
inline PacketTransaction(const PacketT & request, long timeout, int retries, uv::Loop * loop)request Initial request packet to store and send.
timeout Transaction timeout in milliseconds before failure or retry.
retries Maximum number of retransmissions (0 means one attempt only).
loop Event loop for the timeout timer.
virtual inline
virtual inline bool send()Starts the transaction timer and sends the request. Overriding classes should implement send logic here.
virtual inline
virtual inline void cancel()Cancellation means that the agent will not retransmit the request, will not treat the lack of response to be a failure, but will wait the duration of the transaction timeout for a response. Transitions the transaction to the Cancelled state.
const inline
inline bool cancelled() constTrue if the transaction is in the Cancelled state.
virtual inline
virtual inline void dispose()Stops the timer and unregisters callbacks. Does NOT delete the object; the IntrusivePtr destructor handles deletion when the last reference is released. Safe to call multiple times.
const inline
inline bool disposed() constTrue if dispose() has been called.
virtual inline
virtual inline bool canResend()True if the transaction is not cancelled and has attempts remaining.
const inline
inline int attempts() constThe number of times [send()](#send) has been called for this transaction.
const inline
inline int retries() constThe configured maximum number of retransmissions.
inline
inline PacketT & request()Mutable reference to the outgoing request packet.
const inline
inline PacketT request() constCopy of the outgoing request packet.
inline
inline PacketT & response()Mutable reference to the received response packet.
const inline
inline PacketT response() constCopy of the received response packet.
| Return | Name | Description |
|---|---|---|
PacketT | _request | |
PacketT | _response | |
Timer | _timer | The request timeout callback. |
int | _retries | The maximum number of attempts before the transaction is considered failed. |
int | _attempts | The number of times the transaction has been sent. |
bool | _disposed |
PacketT _requestPacketT _responseTimer _timerThe request timeout callback.
int _retriesThe maximum number of attempts before the transaction is considered failed.
int _attemptsThe number of times the transaction has been sent.
bool _disposed = false| Return | Name | Description |
|---|---|---|
void | onStateChange virtual inline | Post state change hook. Calls dispose() on terminal states to stop the timer, but does not delete the object; IntrusivePtr handles that. |
bool | handlePotentialResponse virtual inline | Processes a potential response candidate and updates the state accordingly. |
bool | checkResponse | Checks a potential response candidate and returns true on successful match. |
void | onResponse virtual inline | Called when a successful response is received. |
void | onTimeout virtual inline | Called by the timer when the transaction timeout elapses. Retransmits if retries remain, otherwise transitions to Failed. |
virtual inline
virtual inline void onStateChange(TransactionState & state, const TransactionState &)Post state change hook. Calls dispose() on terminal states to stop the timer, but does not delete the object; IntrusivePtr handles that.
virtual inline
virtual inline bool handlePotentialResponse(const PacketT & packet)Processes a potential response candidate and updates the state accordingly.
bool checkResponse(const PacketT & packet)Checks a potential response candidate and returns true on successful match.
virtual inline
virtual inline void onResponse()Called when a successful response is received.
virtual inline
virtual inline void onTimeout()Called by the timer when the transaction timeout elapses. Retransmits if retries remain, otherwise transitions to Failed.
| Name | Description |
|---|---|
Ptr |
IntrusivePtr< PacketTransaction< PacketT > > Ptr()