PacketTransaction
PacketTransaction
#include <icy/packettransaction.h>template<class PacketT>
class PacketTransactionDefined in src/base/include/icy/packettransaction.h:70
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.
List of all members
| Name | Kind | Owner |
|---|---|---|
IntrusivePtr | friend | Declared here |
PacketTransaction | function | Declared here |
PacketTransaction | function | Declared here |
send | function | Declared here |
cancel | function | Declared here |
cancelled | function | Declared here |
dispose | function | Declared here |
disposed | function | Declared here |
canResend | function | Declared here |
attempts | function | Declared here |
retries | function | Declared here |
request | function | Declared here |
request | function | Declared here |
response | function | Declared here |
response | function | Declared here |
_request | variable | Declared here |
_response | variable | Declared here |
_timer | variable | Declared here |
_retries | variable | Declared here |
_attempts | variable | Declared here |
_disposed | variable | Declared here |
~PacketTransaction | function | Declared here |
onStateChange | function | Declared here |
handlePotentialResponse | function | Declared here |
checkResponse | function | Declared here |
onResponse | function | Declared here |
onTimeout | function | Declared here |
Ptr | typedef | Declared here |
send | function | Inherited from Sendable |
cancel | function | Inherited from Sendable |
StateChange | variable | Inherited from Stateful |
Stateful | function | Inherited from Stateful |
~Stateful | function | Inherited from Stateful |
stateEquals | function | Inherited from Stateful |
stateBetween | function | Inherited from Stateful |
state | function | Inherited from Stateful |
state | function | Inherited from Stateful |
_state | variable | Inherited from Stateful |
beforeStateChange | function | Inherited from Stateful |
onStateChange | function | Inherited from Stateful |
setState | function | Inherited from Stateful |
setState | function | Inherited from Stateful |
RefCounted | function | Inherited from RefCounted |
RefCounted | function | Inherited from RefCounted |
operator= | function | Inherited from RefCounted |
addRef | function | Inherited from RefCounted |
releaseRef | function | Inherited from RefCounted |
refCount | function | Inherited from RefCounted |
~RefCounted | function | Inherited from RefCounted |
_refCount | variable | Inherited from RefCounted |
Inherited from Sendable
| Kind | Name | Description |
|---|---|---|
function | send virtual | Initiates the send operation. |
function | cancel virtual | Cancels a pending send operation. |
Inherited from Stateful
| Kind | Name | Description |
|---|---|---|
variable | StateChange | Signals when the state changes. |
function | Stateful inline | |
function | ~Stateful virtual inline | |
function | stateEquals virtual const inline | Returns true if the current state ID equals the given ID. |
function | stateBetween virtual const inline | Returns true if the current state ID is in the inclusive range [lid, rid]. |
function | state virtual inline | Returns a mutable reference to the current state. |
function | state virtual const inline | Returns a copy of the current state. |
variable | _state | |
function | beforeStateChange virtual inline | Override to handle pre state change logic. Return false to prevent state change. |
function | onStateChange virtual inline | Override to handle post state change logic. |
function | setState virtual inline | Sets the state and sends the state signal if the state change was successful. |
function | setState virtual inline | Sets the state and sends the state signal if the state change was successful. |
Inherited from RefCounted
| Kind | Name | Description |
|---|---|---|
function | RefCounted | Defaulted constructor. |
function | RefCounted inline noexcept | |
function | operator= inline noexcept | |
function | addRef const inline noexcept | Increments the reference count. Called by IntrusivePtr on acquisition. |
function | releaseRef const inline noexcept | Decrements the reference count. |
function | refCount const inline noexcept | Returns the current reference count. |
function | ~RefCounted | Defaulted destructor. |
variable | _refCount |
Friends
| Name | Description |
|---|---|
IntrusivePtr |
IntrusivePtr
template<typename U> friend class IntrusivePtrDefined in src/base/include/icy/packettransaction.h:165
Public Methods
| Return | Name | Description |
|---|---|---|
PacketTransaction inline | ||
PacketTransaction inline | ||
bool | send virtual inline override | Starts the transaction timer and sends the request. Overriding classes should implement send logic here. |
void | cancel virtual inline override | 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 | |
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 | |
bool | canResend virtual inline | |
int | attempts const inline | |
int | retries const inline | |
PacketT & | request inline | |
PacketT | request const inline | |
PacketT & | response inline | |
PacketT | response const inline |
PacketTransaction
inline
inline PacketTransaction(long timeout = 10000, int retries = 0, uv::Loop * loop = uv::defaultLoop())Defined in src/base/include/icy/packettransaction.h:80
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 = 10000, int retries = 0, uv::Loop * loop = uv::defaultLoop())Defined in src/base/include/icy/packettransaction.h:92
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 override
virtual inline bool send() overrideDefined in src/base/include/icy/packettransaction.h:103
Starts the transaction timer and sends the request. Overriding classes should implement send logic here.
Reimplements
Reimplemented by
cancel
virtual inline override
virtual inline void cancel() overrideDefined in src/base/include/icy/packettransaction.h:122
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.
Reimplements
Reimplemented by
cancelled
const inline
inline bool cancelled() constDefined in src/base/include/icy/packettransaction.h:125
Returns
True if the transaction is in the Cancelled state.
dispose
virtual inline
virtual inline void dispose()Defined in src/base/include/icy/packettransaction.h:130
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.
Reimplemented by
disposed
const inline
inline bool disposed() constDefined in src/base/include/icy/packettransaction.h:141
Returns
True if dispose() has been called.
canResend
virtual inline
virtual inline bool canResend()Defined in src/base/include/icy/packettransaction.h:144
Returns
True if the transaction is not cancelled and has attempts remaining.
attempts
const inline
inline int attempts() constDefined in src/base/include/icy/packettransaction.h:147
Returns
The number of times [send()](#send) has been called for this transaction.
retries
const inline
inline int retries() constDefined in src/base/include/icy/packettransaction.h:150
Returns
The configured maximum number of retransmissions.
request
inline
inline PacketT & request()Defined in src/base/include/icy/packettransaction.h:153
Returns
Mutable reference to the outgoing request packet.
request
const inline
inline PacketT request() constDefined in src/base/include/icy/packettransaction.h:156
Returns
Copy of the outgoing request packet.
response
inline
inline PacketT & response()Defined in src/base/include/icy/packettransaction.h:159
Returns
Mutable reference to the received response packet.
response
const inline
inline PacketT response() constDefined in src/base/include/icy/packettransaction.h:162
Returns
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 _requestDefined in src/base/include/icy/packettransaction.h:219
_response
PacketT _responseDefined in src/base/include/icy/packettransaction.h:220
_timer
Timer _timerDefined in src/base/include/icy/packettransaction.h:221
The request timeout callback.
_retries
int _retriesDefined in src/base/include/icy/packettransaction.h:222
The maximum number of attempts before the transaction is considered failed.
_attempts
int _attemptsDefined in src/base/include/icy/packettransaction.h:223
The number of times the transaction has been sent.
_disposed
bool _disposed = falseDefined in src/base/include/icy/packettransaction.h:224
Protected Methods
| Return | Name | Description |
|---|---|---|
void | onStateChange virtual inline override | 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 virtual | 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 override
virtual inline void onStateChange(TransactionState & state, const TransactionState &) overrideDefined in src/base/include/icy/packettransaction.h:174
Post state change hook. Calls dispose() on terminal states to stop the timer, but does not delete the object; IntrusivePtr handles that.
Reimplements
handlePotentialResponse
virtual inline
virtual inline bool handlePotentialResponse(const PacketT & packet)Defined in src/base/include/icy/packettransaction.h:185
Processes a potential response candidate and updates the state accordingly.
checkResponse
virtual
virtual bool checkResponse(const PacketT & packet)Defined in src/base/include/icy/packettransaction.h:198
Checks a potential response candidate and returns true on successful match.
Reimplemented by
onResponse
virtual inline
virtual inline void onResponse()Defined in src/base/include/icy/packettransaction.h:201
Called when a successful response is received.
Reimplemented by
onTimeout
virtual inline
virtual inline void onTimeout()Defined in src/base/include/icy/packettransaction.h:208
Called by the timer when the transaction timeout elapses. Retransmits if retries remain, otherwise transitions to Failed.
Public Types
| Name | Description |
|---|---|
Ptr |
Ptr
using Ptr = IntrusivePtr< PacketTransaction< PacketT > >