PacketTransaction
PacketTransaction
#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.
Public Methods
| 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 |
PacketTransaction
inline
inline PacketTransaction(long timeout, int retries, uv::Loop * loop)Parameters
timeoutTransaction timeout in milliseconds before failure or retry.retriesMaximum number of retransmissions (0 means one attempt only).loopEvent loop for the timeout timer.
PacketTransaction
inline
inline PacketTransaction(const PacketT & request, long timeout, int retries, uv::Loop * loop)Parameters
requestInitial request packet to store and send.timeoutTransaction timeout in milliseconds before failure or retry.retriesMaximum number of retransmissions (0 means one attempt only).loopEvent loop for the timeout timer.
send
virtual inline
virtual inline bool send()Starts the transaction timer and sends the request. Overriding classes should implement send logic here.
cancel
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.
cancelled
const inline
inline bool cancelled() constReturns
True if the transaction is in the Cancelled state.
dispose
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.
disposed
const inline
inline bool disposed() constReturns
True if dispose() has been called.
canResend
virtual inline
virtual inline bool canResend()Returns
True if the transaction is not cancelled and has attempts remaining.
attempts
const inline
inline int attempts() constReturns
The number of times [send()](#send) has been called for this transaction.
retries
const inline
inline int retries() constReturns
The configured maximum number of retransmissions.
request
inline
inline PacketT & request()Returns
Mutable reference to the outgoing request packet.
request
const inline
inline PacketT request() constReturns
Copy of the outgoing request packet.
response
inline
inline PacketT & response()Returns
Mutable reference to the received response packet.
response
const inline
inline PacketT response() constReturns
Copy of the received response packet.
Protected Attributes
| 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 |
_request
PacketT _request_response
PacketT _response_timer
Timer _timerThe request timeout callback.
_retries
int _retriesThe maximum number of attempts before the transaction is considered failed.
_attempts
int _attemptsThe number of times the transaction has been sent.
_disposed
bool _disposed = falseProtected Methods
| 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. |
onStateChange
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.
handlePotentialResponse
virtual inline
virtual inline bool handlePotentialResponse(const PacketT & packet)Processes a potential response candidate and updates the state accordingly.
checkResponse
bool checkResponse(const PacketT & packet)Checks a potential response candidate and returns true on successful match.
onResponse
virtual inline
virtual inline void onResponse()Called when a successful response is received.
onTimeout
virtual inline
virtual inline void onTimeout()Called by the timer when the transaction timeout elapses. Retransmits if retries remain, otherwise transitions to Failed.
Public Types
| Name | Description |
|---|---|
Ptr |
Ptr
IntrusivePtr< PacketTransaction< PacketT > > Ptr()