Transaction
Transaction
#include <icy/net/transaction.h>template<class PacketT>
class TransactionDefined 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
| Name | Kind | Owner |
|---|---|---|
IntrusivePtr | friend | Declared here |
Transaction | function | Declared here |
send | function | Declared here |
cancel | function | Declared here |
dispose | function | Declared here |
peerAddress | function | Declared here |
_peerAddress | variable | Declared here |
~Transaction | function | Declared here |
onPacket | function | Declared here |
onResponse | function | Declared here |
checkResponse | function | Declared here |
BaseT | typedef | Declared here |
IntrusivePtr | friend | Inherited from PacketTransaction |
PacketTransaction | function | Inherited from PacketTransaction |
PacketTransaction | function | Inherited from PacketTransaction |
send | function | Inherited from PacketTransaction |
cancel | function | Inherited from PacketTransaction |
cancelled | function | Inherited from PacketTransaction |
dispose | function | Inherited from PacketTransaction |
disposed | function | Inherited from PacketTransaction |
canResend | function | Inherited from PacketTransaction |
attempts | function | Inherited from PacketTransaction |
retries | function | Inherited from PacketTransaction |
request | function | Inherited from PacketTransaction |
request | function | Inherited from PacketTransaction |
response | function | Inherited from PacketTransaction |
response | function | Inherited from PacketTransaction |
_request | variable | Inherited from PacketTransaction |
_response | variable | Inherited from PacketTransaction |
_timer | variable | Inherited from PacketTransaction |
_retries | variable | Inherited from PacketTransaction |
_attempts | variable | Inherited from PacketTransaction |
_disposed | variable | Inherited from PacketTransaction |
~PacketTransaction | function | Inherited from PacketTransaction |
onStateChange | function | Inherited from PacketTransaction |
handlePotentialResponse | function | Inherited from PacketTransaction |
checkResponse | function | Inherited from PacketTransaction |
onResponse | function | Inherited from PacketTransaction |
onTimeout | function | Inherited from PacketTransaction |
Ptr | typedef | Inherited from PacketTransaction |
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 |
factory | variable | Inherited from PacketSocketEmitter |
PacketSocketEmitter | function | Inherited from PacketSocketEmitter |
~PacketSocketEmitter | function | Inherited from PacketSocketEmitter |
onSocketRecv | function | Inherited from PacketSocketEmitter |
onPacket | function | Inherited from PacketSocketEmitter |
Connect | variable | Inherited from SocketEmitter |
Recv | variable | Inherited from SocketEmitter |
Error | variable | Inherited from SocketEmitter |
Close | variable | Inherited from SocketEmitter |
impl | variable | Inherited from SocketEmitter |
SocketEmitter | function | Inherited from SocketEmitter |
SocketEmitter | function | Inherited from SocketEmitter |
~SocketEmitter | function | Inherited from SocketEmitter |
addReceiver | function | Inherited from SocketEmitter |
removeReceiver | function | Inherited from SocketEmitter |
swap | function | Inherited from SocketEmitter |
as | function | Inherited from SocketEmitter |
operator-> | function | Inherited from SocketEmitter |
onSocketConnect | function | Inherited from SocketEmitter |
onSocketRecv | function | Inherited from SocketEmitter |
onSocketError | function | Inherited from SocketEmitter |
onSocketClose | function | Inherited from SocketEmitter |
priority | variable | Inherited from SocketAdapter |
SocketAdapter | function | Inherited from SocketAdapter |
~SocketAdapter | function | Inherited from SocketAdapter |
send | function | Inherited from SocketAdapter |
send | function | Inherited from SocketAdapter |
sendOwned | function | Inherited from SocketAdapter |
sendOwned | function | Inherited from SocketAdapter |
sendPacket | function | Inherited from SocketAdapter |
sendPacket | function | Inherited from SocketAdapter |
sendPacket | function | Inherited from SocketAdapter |
setSender | function | Inherited from SocketAdapter |
sender | function | Inherited from SocketAdapter |
addReceiver | function | Inherited from SocketAdapter |
removeReceiver | function | Inherited from SocketAdapter |
hasReceiver | function | Inherited from SocketAdapter |
receivers | function | Inherited from SocketAdapter |
onSocketConnect | function | Inherited from SocketAdapter |
onSocketRecv | function | Inherited from SocketAdapter |
onSocketError | function | Inherited from SocketAdapter |
onSocketClose | function | Inherited from SocketAdapter |
_sender | variable | Inherited from SocketAdapter |
_receivers | variable | Inherited from SocketAdapter |
_dirty | variable | Inherited from SocketAdapter |
cleanupReceivers | function | Inherited from SocketAdapter |
Inherited from PacketTransaction
| Kind | Name | Description |
|---|---|---|
friend | IntrusivePtr | |
function | PacketTransaction inline | |
function | PacketTransaction inline | |
function | send virtual inline override | Starts the transaction timer and sends the request. Overriding classes should implement send logic here. |
function | 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. |
function | cancelled const inline | |
function | 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. |
function | disposed const inline | |
function | canResend virtual inline | |
function | attempts const inline | |
function | retries const inline | |
function | request inline | |
function | request const inline | |
function | response inline | |
function | response const inline | |
variable | _request | |
variable | _response | |
variable | _timer | The request timeout callback. |
variable | _retries | The maximum number of attempts before the transaction is considered failed. |
variable | _attempts | The number of times the transaction has been sent. |
variable | _disposed | |
function | ~PacketTransaction virtual inline | |
function | 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. |
function | handlePotentialResponse virtual inline | Processes a potential response candidate and updates the state accordingly. |
function | checkResponse virtual | Checks a potential response candidate and returns true on successful match. |
function | onResponse virtual inline | Called when a successful response is received. |
function | onTimeout virtual inline | Called by the timer when the transaction timeout elapses. Retransmits if retries remain, otherwise transitions to Failed. |
typedef | Ptr |
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 |
Inherited from PacketSocketEmitter
| Kind | Name | Description |
|---|---|---|
variable | factory | The packet factory. |
function | PacketSocketEmitter | Creates the PacketSocketEmitter and attaches it to the given socket. |
function | ~PacketSocketEmitter virtual noexcept | |
function | onSocketRecv virtual override | Parses raw received data into packets via the factory and forwards each parsed packet to onPacket(). Returns true if propagation should stop. |
function | onPacket virtual | Process a parsed packet. Returns true to stop propagation. |
Inherited from SocketEmitter
| Kind | Name | Description |
|---|---|---|
variable | Connect | Signals that the socket is connected. |
variable | Recv | Signals when data is received by the socket. |
variable | Error | Signals that the socket is closed in error. This signal will be sent just before the Closed signal. |
variable | Close | Signals that the underlying socket is closed. |
variable | impl | Pointer to the underlying socket. Sent data will be proxied to this socket. |
function | SocketEmitter | Creates the SocketEmitter and optionally attaches it to a socket. If socket is provided, this emitter registers itself as a receiver. |
function | SocketEmitter | Copy constructor; copies all signal connections and attaches to the same socket. |
function | ~SocketEmitter virtual noexcept | Destroys the SocketAdapter. |
function | addReceiver virtual override | Attaches a SocketAdapter as a receiver; wires it to all four socket signals. |
function | removeReceiver virtual override | Detaches a SocketAdapter from all four socket signals. |
function | swap virtual | Replaces the underlying socket with socket. |
function | as inline | Returns the underlying socket cast to type T, or nullptr if the cast fails. |
function | operator-> const inline | Returns a raw pointer to the underlying socket for direct method access. Follows shared_ptr semantics; the caller must not delete the returned pointer. |
function | onSocketConnect virtual override | Forwards the connect event to chained adapters, then fires the Connect signal. |
function | onSocketRecv virtual override | Forwards the recv event to chained adapters, then fires the Recv signal. |
function | onSocketError virtual override | Forwards the error event to chained adapters, then fires the Error signal. |
function | onSocketClose virtual override | Forwards the close event to chained adapters, then fires the Close signal. |
Inherited from SocketAdapter
| Kind | Name | Description |
|---|---|---|
variable | priority | The priority of this adapter for STL sort operations. |
function | SocketAdapter | Creates the SocketAdapter. |
function | ~SocketAdapter virtual noexcept | Destroys the SocketAdapter. |
function | send virtual | Sends 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. |
function | send virtual | |
function | sendOwned virtual | Sends an owned payload buffer to the connected peer. |
function | sendOwned virtual | |
function | sendPacket virtual | Sends 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. |
function | sendPacket virtual | |
function | sendPacket virtual | Sends 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. |
function | setSender virtual | Sets the pointer to the outgoing data adapter. Send methods proxy data to this adapter by default. |
function | sender | Returns the output SocketAdapter pointer. |
function | addReceiver virtual | Sets the pointer to the incoming data adapter. Events proxy data to this adapter by default. |
function | removeReceiver virtual | Remove the given receiver. |
function | hasReceiver virtual | Returns true if the given receiver is connected. |
function | receivers | Returns all currently registered input SocketAdapter pointers. Dead (removed) entries are excluded from the returned list. |
function | onSocketConnect virtual | Called 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. |
function | onSocketRecv virtual | Called when data is received from the socket. Forwards the event to all registered receivers in priority order. |
function | onSocketError virtual | Called when the socket encounters an error. Forwards the event to all registered receivers in priority order. |
function | onSocketClose virtual | Called when the socket is closed. Forwards the event to all registered receivers in priority order. |
variable | _sender | |
variable | _receivers | |
variable | _dirty | |
function | cleanupReceivers virtual |
Friends
| Name | Description |
|---|---|
icy::IntrusivePtr |
icy::IntrusivePtr
template<typename U> friend class icy::IntrusivePtrDefined in src/net/include/icy/net/transaction.h:81
Public Methods
| Return | Name | Description |
|---|---|---|
Transaction inline | Constructs a Transaction on the given socket targeting peerAddress. | |
bool | send virtual inline override | 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. |
void | cancel virtual inline override | Cancels the transaction and stops the timeout timer. |
void | dispose virtual inline override | Stops the timer and unregisters callbacks. |
Address | peerAddress const inline | Returns 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
socketThe socket to send/receive packets on.peerAddressThe remote address for the request and response matching.timeoutMilliseconds to wait for a response before failing.retriesNumber of additional send attempts on timeout.
send
virtual inline override
virtual inline bool send() overrideDefined 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() overrideDefined 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() overrideDefined in src/net/include/icy/net/transaction.h:68
Stops the timer and unregisters callbacks.
Reimplements
peerAddress
const inline
inline Address peerAddress() constDefined in src/net/include/icy/net/transaction.h:75
Returns the remote peer address used for this transaction.
Protected Attributes
| Return | Name | Description |
|---|---|---|
Address | _peerAddress |
_peerAddress
Address _peerAddressDefined in src/net/include/icy/net/transaction.h:118
Protected Methods
| Return | Name | Description |
|---|---|---|
bool | onPacket virtual inline override | Checks whether packet is a matching response for the pending request. If it matches, the transaction completes; socket data propagation stops. |
void | onResponse virtual inline override | Called when a confirmed response is received; emits the response via PacketSignal. |
bool | checkResponse virtual inline override | Returns true if packet is a valid response for this transaction. |
onPacket
virtual inline override
virtual inline bool onPacket(IPacket & packet) overrideDefined 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
packetThe received packet to test.
Returns
true to stop further propagation of the socket data event.
Reimplements
onResponse
virtual inline override
virtual inline void onResponse() overrideDefined 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) overrideDefined 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
packetThe candidate response packet.
Returns
true if the packet satisfies the response criteria.
Reimplements
Public Types
| Name | Description |
|---|---|
BaseT |
BaseT
using BaseT = PacketTransaction< PacketT >