Home
Net module

Transaction

Request/response helper for packet types emitted from a socket.

Transaction

#include <icy/net/transaction.h>
template<class PacketT>
class Transaction

Defined in src/net/include/icy/net/transaction.h:27

Inherits: PacketTransaction< PacketT >, PacketSocketEmitter

Request/response helper for packet types emitted from a socket.

List of all members

NameKindOwner
IntrusivePtrfriendDeclared here
TransactionfunctionDeclared here
sendfunctionDeclared here
cancelfunctionDeclared here
disposefunctionDeclared here
peerAddressfunctionDeclared here
_peerAddressvariableDeclared here
~TransactionfunctionDeclared here
onPacketfunctionDeclared here
onResponsefunctionDeclared here
checkResponsefunctionDeclared here
BaseTtypedefDeclared here
IntrusivePtrfriendInherited from PacketTransaction
PacketTransactionfunctionInherited from PacketTransaction
PacketTransactionfunctionInherited from PacketTransaction
sendfunctionInherited from PacketTransaction
cancelfunctionInherited from PacketTransaction
cancelledfunctionInherited from PacketTransaction
disposefunctionInherited from PacketTransaction
disposedfunctionInherited from PacketTransaction
canResendfunctionInherited from PacketTransaction
attemptsfunctionInherited from PacketTransaction
retriesfunctionInherited from PacketTransaction
requestfunctionInherited from PacketTransaction
requestfunctionInherited from PacketTransaction
responsefunctionInherited from PacketTransaction
responsefunctionInherited from PacketTransaction
_requestvariableInherited from PacketTransaction
_responsevariableInherited from PacketTransaction
_timervariableInherited from PacketTransaction
_retriesvariableInherited from PacketTransaction
_attemptsvariableInherited from PacketTransaction
_disposedvariableInherited from PacketTransaction
~PacketTransactionfunctionInherited from PacketTransaction
onStateChangefunctionInherited from PacketTransaction
handlePotentialResponsefunctionInherited from PacketTransaction
checkResponsefunctionInherited from PacketTransaction
onResponsefunctionInherited from PacketTransaction
onTimeoutfunctionInherited from PacketTransaction
PtrtypedefInherited from PacketTransaction
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
factoryvariableInherited from PacketSocketEmitter
PacketSocketEmitterfunctionInherited from PacketSocketEmitter
~PacketSocketEmitterfunctionInherited from PacketSocketEmitter
onSocketRecvfunctionInherited from PacketSocketEmitter
onPacketfunctionInherited from PacketSocketEmitter
ConnectvariableInherited from SocketEmitter
RecvvariableInherited from SocketEmitter
ErrorvariableInherited from SocketEmitter
ClosevariableInherited from SocketEmitter
implvariableInherited from SocketEmitter
SocketEmitterfunctionInherited from SocketEmitter
SocketEmitterfunctionInherited from SocketEmitter
~SocketEmitterfunctionInherited from SocketEmitter
addReceiverfunctionInherited from SocketEmitter
removeReceiverfunctionInherited from SocketEmitter
swapfunctionInherited from SocketEmitter
asfunctionInherited from SocketEmitter
operator->functionInherited from SocketEmitter
onSocketConnectfunctionInherited from SocketEmitter
onSocketRecvfunctionInherited from SocketEmitter
onSocketErrorfunctionInherited from SocketEmitter
onSocketClosefunctionInherited from SocketEmitter
priorityvariableInherited from SocketAdapter
SocketAdapterfunctionInherited from SocketAdapter
~SocketAdapterfunctionInherited from SocketAdapter
sendfunctionInherited from SocketAdapter
sendfunctionInherited from SocketAdapter
sendOwnedfunctionInherited from SocketAdapter
sendOwnedfunctionInherited from SocketAdapter
sendPacketfunctionInherited from SocketAdapter
sendPacketfunctionInherited from SocketAdapter
sendPacketfunctionInherited from SocketAdapter
setSenderfunctionInherited from SocketAdapter
senderfunctionInherited from SocketAdapter
addReceiverfunctionInherited from SocketAdapter
removeReceiverfunctionInherited from SocketAdapter
hasReceiverfunctionInherited from SocketAdapter
receiversfunctionInherited from SocketAdapter
onSocketConnectfunctionInherited from SocketAdapter
onSocketRecvfunctionInherited from SocketAdapter
onSocketErrorfunctionInherited from SocketAdapter
onSocketClosefunctionInherited from SocketAdapter
_sendervariableInherited from SocketAdapter
_receiversvariableInherited from SocketAdapter
_dirtyvariableInherited from SocketAdapter
cleanupReceiversfunctionInherited from SocketAdapter

Inherited from PacketTransaction

KindNameDescription
friendIntrusivePtr
functionPacketTransaction inline
functionPacketTransaction inline
functionsend virtual inline overrideStarts the transaction timer and sends the request. Overriding classes should implement send logic here.
functioncancel 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.
functioncancelled const inline
functiondispose 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.
functiondisposed const inline
functioncanResend virtual inline
functionattempts const inline
functionretries const inline
functionrequest inline
functionrequest const inline
functionresponse inline
functionresponse const inline
variable_request
variable_response
variable_timerThe request timeout callback.
variable_retriesThe maximum number of attempts before the transaction is considered failed.
variable_attemptsThe number of times the transaction has been sent.
variable_disposed
function~PacketTransaction virtual inline
functiononStateChange virtual inline overridePost state change hook. Calls dispose() on terminal states to stop the timer, but does not delete the object; IntrusivePtr handles that.
functionhandlePotentialResponse virtual inlineProcesses a potential response candidate and updates the state accordingly.
functioncheckResponse virtualChecks a potential response candidate and returns true on successful match.
functiononResponse virtual inlineCalled when a successful response is received.
functiononTimeout virtual inlineCalled by the timer when the transaction timeout elapses. Retransmits if retries remain, otherwise transitions to Failed.
typedefPtr

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

Inherited from PacketSocketEmitter

KindNameDescription
variablefactoryThe packet factory.
functionPacketSocketEmitterCreates the PacketSocketEmitter and attaches it to the given socket.
function~PacketSocketEmitter virtual noexcept
functiononSocketRecv virtual overrideParses raw received data into packets via the factory and forwards each parsed packet to onPacket(). Returns true if propagation should stop.
functiononPacket virtualProcess a parsed packet. Returns true to stop propagation.

Inherited from SocketEmitter

KindNameDescription
variableConnectSignals that the socket is connected.
variableRecvSignals when data is received by the socket.
variableErrorSignals that the socket is closed in error. This signal will be sent just before the Closed signal.
variableCloseSignals that the underlying socket is closed.
variableimplPointer to the underlying socket. Sent data will be proxied to this socket.
functionSocketEmitterCreates the SocketEmitter and optionally attaches it to a socket. If socket is provided, this emitter registers itself as a receiver.
functionSocketEmitterCopy constructor; copies all signal connections and attaches to the same socket.
function~SocketEmitter virtual noexceptDestroys the SocketAdapter.
functionaddReceiver virtual overrideAttaches a SocketAdapter as a receiver; wires it to all four socket signals.
functionremoveReceiver virtual overrideDetaches a SocketAdapter from all four socket signals.
functionswap virtualReplaces the underlying socket with socket.
functionas inlineReturns the underlying socket cast to type T, or nullptr if the cast fails.
functionoperator-> const inlineReturns a raw pointer to the underlying socket for direct method access. Follows shared_ptr semantics; the caller must not delete the returned pointer.
functiononSocketConnect virtual overrideForwards the connect event to chained adapters, then fires the Connect signal.
functiononSocketRecv virtual overrideForwards the recv event to chained adapters, then fires the Recv signal.
functiononSocketError virtual overrideForwards the error event to chained adapters, then fires the Error signal.
functiononSocketClose virtual overrideForwards the close event to chained adapters, then fires the Close signal.

Inherited from SocketAdapter

KindNameDescription
variablepriorityThe priority of this adapter for STL sort operations.
functionSocketAdapterCreates the SocketAdapter.
function~SocketAdapter virtual noexceptDestroys the SocketAdapter.
functionsend virtualSends the given data buffer to the connected peer. Returns the number of bytes sent or -1 on error. No exception will be thrown. For TCP sockets the given peer address must match the connected peer address.
functionsend virtual
functionsendOwned virtualSends an owned payload buffer to the connected peer.
functionsendOwned virtual
functionsendPacket virtualSends the given packet to the connected peer. Returns the number of bytes sent or -1 on error. No exception will be thrown. For TCP sockets the given peer address must match the connected peer address.
functionsendPacket virtual
functionsendPacket virtualSends the given packet to the connected peer. This method provides delegate compatibility, and unlike other send methods throws an exception if the underlying socket is closed.
functionsetSender virtualSets the pointer to the outgoing data adapter. Send methods proxy data to this adapter by default.
functionsenderReturns the output SocketAdapter pointer.
functionaddReceiver virtualSets the pointer to the incoming data adapter. Events proxy data to this adapter by default.
functionremoveReceiver virtualRemove the given receiver.
functionhasReceiver virtualReturns true if the given receiver is connected.
functionreceiversReturns all currently registered input SocketAdapter pointers. Dead (removed) entries are excluded from the returned list.
functiononSocketConnect virtualCalled when the socket establishes a connection. Forwards the event to all registered receivers in priority order. Override to intercept before the application sees the event.
functiononSocketRecv virtualCalled when data is received from the socket. Forwards the event to all registered receivers in priority order.
functiononSocketError virtualCalled when the socket encounters an error. Forwards the event to all registered receivers in priority order.
functiononSocketClose virtualCalled when the socket is closed. Forwards the event to all registered receivers in priority order.
variable_sender
variable_receivers
variable_dirty
functioncleanupReceivers virtual

Friends

NameDescription
icy::IntrusivePtr

icy::IntrusivePtr

template<typename U> friend class icy::IntrusivePtr

Defined in src/net/include/icy/net/transaction.h:81

Public Methods

ReturnNameDescription
Transaction inlineConstructs a Transaction on the given socket targeting peerAddress.
boolsend virtual inline overrideSends the request packet to the peer address and starts the timeout timer. Sets state to Failed and returns false if the packet could not be sent.
voidcancel virtual inline overrideCancels the transaction and stops the timeout timer.
voiddispose virtual inline overrideStops the timer and unregisters callbacks.
AddresspeerAddress const inlineReturns the remote peer address used for this transaction.

Transaction

inline

inline Transaction(const net::Socket::Ptr & socket, const Address & peerAddress, int timeout = 10000, int retries = 1)

Defined in src/net/include/icy/net/transaction.h:39

Constructs a Transaction on the given socket targeting peerAddress.

Parameters

  • socket The socket to send/receive packets on.

  • peerAddress The remote address for the request and response matching.

  • timeout Milliseconds to wait for a response before failing.

  • retries Number of additional send attempts on timeout.


send

virtual inline override

virtual inline bool send() override

Defined in src/net/include/icy/net/transaction.h:51

Sends the request packet to the peer address and starts the timeout timer. Sets state to Failed and returns false if the packet could not be sent.

Returns

true if the packet was sent and the timer started successfully.

Reimplements

cancel

virtual inline override

virtual inline void cancel() override

Defined in src/net/include/icy/net/transaction.h:61

Cancels the transaction and stops the timeout timer.

Reimplements

dispose

virtual inline override

virtual inline void dispose() override

Defined in src/net/include/icy/net/transaction.h:68

Stops the timer and unregisters callbacks.

Reimplements

peerAddress

const inline

inline Address peerAddress() const

Defined in src/net/include/icy/net/transaction.h:75

Returns the remote peer address used for this transaction.

Protected Attributes

ReturnNameDescription
Address_peerAddress

_peerAddress

Address _peerAddress

Defined in src/net/include/icy/net/transaction.h:118

Protected Methods

ReturnNameDescription
boolonPacket virtual inline overrideChecks whether packet is a matching response for the pending request. If it matches, the transaction completes; socket data propagation stops.
voidonResponse virtual inline overrideCalled when a confirmed response is received; emits the response via PacketSignal.
boolcheckResponse virtual inline overrideReturns true if packet is a valid response for this transaction.

onPacket

virtual inline override

virtual inline bool onPacket(IPacket & packet) override

Defined in src/net/include/icy/net/transaction.h:89

Checks whether packet is a matching response for the pending request. If it matches, the transaction completes; socket data propagation stops.

Parameters

  • packet The received packet to test.

Returns

true to stop further propagation of the socket data event.

Reimplements

onResponse

virtual inline override

virtual inline void onResponse() override

Defined in src/net/include/icy/net/transaction.h:97

Called when a confirmed response is received; emits the response via PacketSignal.

Reimplements
Reimplemented by

checkResponse

virtual inline override

virtual inline bool checkResponse(const PacketT & packet) override

Defined in src/net/include/icy/net/transaction.h:110

Returns true if packet is a valid response for this transaction.

The base implementation matches the local socket address against the PacketInfo socket address and the stored peer address against the PacketInfo peer address. Subclasses may override for stricter matching.

Parameters

  • packet The candidate response packet.

Returns

true if the packet satisfies the response criteria.

Reimplements

Public Types

NameDescription
BaseT

BaseT

using BaseT = PacketTransaction< PacketT >

Defined in src/net/include/icy/net/transaction.h:31