Home
Base module

PacketTransaction

Request/response transaction with timeout and retry logic.

PacketTransaction

#include <icy/packettransaction.h>
template<class PacketT>
class PacketTransaction

Defined 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

NameKindOwner
IntrusivePtrfriendDeclared here
PacketTransactionfunctionDeclared here
PacketTransactionfunctionDeclared here
sendfunctionDeclared here
cancelfunctionDeclared here
cancelledfunctionDeclared here
disposefunctionDeclared here
disposedfunctionDeclared here
canResendfunctionDeclared here
attemptsfunctionDeclared here
retriesfunctionDeclared here
requestfunctionDeclared here
requestfunctionDeclared here
responsefunctionDeclared here
responsefunctionDeclared here
_requestvariableDeclared here
_responsevariableDeclared here
_timervariableDeclared here
_retriesvariableDeclared here
_attemptsvariableDeclared here
_disposedvariableDeclared here
~PacketTransactionfunctionDeclared here
onStateChangefunctionDeclared here
handlePotentialResponsefunctionDeclared here
checkResponsefunctionDeclared here
onResponsefunctionDeclared here
onTimeoutfunctionDeclared here
PtrtypedefDeclared here
sendfunctionInherited from Sendable
cancelfunctionInherited from Sendable
StateChangevariableInherited from Stateful
StatefulfunctionInherited from Stateful
~StatefulfunctionInherited from Stateful
stateEqualsfunctionInherited from Stateful
stateBetweenfunctionInherited from Stateful
statefunctionInherited from Stateful
statefunctionInherited from Stateful
_statevariableInherited from Stateful
beforeStateChangefunctionInherited from Stateful
onStateChangefunctionInherited from Stateful
setStatefunctionInherited from Stateful
setStatefunctionInherited from Stateful
RefCountedfunctionInherited from RefCounted
RefCountedfunctionInherited from RefCounted
operator=functionInherited from RefCounted
addReffunctionInherited from RefCounted
releaseReffunctionInherited from RefCounted
refCountfunctionInherited from RefCounted
~RefCountedfunctionInherited from RefCounted
_refCountvariableInherited from RefCounted

Inherited from Sendable

KindNameDescription
functionsend virtualInitiates the send operation.
functioncancel virtualCancels a pending send operation.

Inherited from Stateful

KindNameDescription
variableStateChangeSignals when the state changes.
functionStateful inline
function~Stateful virtual inline
functionstateEquals virtual const inlineReturns true if the current state ID equals the given ID.
functionstateBetween virtual const inlineReturns true if the current state ID is in the inclusive range [lid, rid].
functionstate virtual inlineReturns a mutable reference to the current state.
functionstate virtual const inlineReturns a copy of the current state.
variable_state
functionbeforeStateChange virtual inlineOverride to handle pre state change logic. Return false to prevent state change.
functiononStateChange virtual inlineOverride to handle post state change logic.
functionsetState virtual inlineSets the state and sends the state signal if the state change was successful.
functionsetState virtual inlineSets the state and sends the state signal if the state change was successful.

Inherited from RefCounted

KindNameDescription
functionRefCountedDefaulted constructor.
functionRefCounted inline noexcept
functionoperator= inline noexcept
functionaddRef const inline noexceptIncrements the reference count. Called by IntrusivePtr on acquisition.
functionreleaseRef const inline noexceptDecrements the reference count.
functionrefCount const inline noexceptReturns the current reference count.
function~RefCountedDefaulted destructor.
variable_refCount

Friends

NameDescription
IntrusivePtr

IntrusivePtr

template<typename U> friend class IntrusivePtr

Defined in src/base/include/icy/packettransaction.h:165

Public Methods

ReturnNameDescription
PacketTransaction inline
PacketTransaction inline
boolsend virtual inline overrideStarts the transaction timer and sends the request. Overriding classes should implement send logic here.
voidcancel virtual inline overrideCancellation 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.
boolcancelled const inline
voiddispose virtual inlineStops 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.
booldisposed const inline
boolcanResend virtual inline
intattempts const inline
intretries const inline
PacketT &request inline
PacketTrequest const inline
PacketT &response inline
PacketTresponse 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

  • 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.


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

  • 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.


send

virtual inline override

virtual inline bool send() override

Defined 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() override

Defined 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() const

Defined 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() const

Defined 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() const

Defined 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() const

Defined 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() const

Defined 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() const

Defined in src/base/include/icy/packettransaction.h:162

Returns

Copy of the received response packet.

Protected Attributes

ReturnNameDescription
PacketT_request
PacketT_response
Timer_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

_request

PacketT _request

Defined in src/base/include/icy/packettransaction.h:219


_response

PacketT _response

Defined in src/base/include/icy/packettransaction.h:220


_timer

Timer _timer

Defined in src/base/include/icy/packettransaction.h:221

The request timeout callback.


_retries

int _retries

Defined in src/base/include/icy/packettransaction.h:222

The maximum number of attempts before the transaction is considered failed.


_attempts

int _attempts

Defined in src/base/include/icy/packettransaction.h:223

The number of times the transaction has been sent.


_disposed

bool _disposed = false

Defined in src/base/include/icy/packettransaction.h:224

Protected Methods

ReturnNameDescription
voidonStateChange virtual inline overridePost state change hook. Calls dispose() on terminal states to stop the timer, but does not delete the object; IntrusivePtr handles that.
boolhandlePotentialResponse virtual inlineProcesses a potential response candidate and updates the state accordingly.
boolcheckResponse virtualChecks a potential response candidate and returns true on successful match.
voidonResponse virtual inlineCalled when a successful response is received.
voidonTimeout virtual inlineCalled 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 &) override

Defined 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

NameDescription
Ptr

Ptr

using Ptr = IntrusivePtr< PacketTransaction< PacketT > >

Defined in src/base/include/icy/packettransaction.h:75