Transaction
Transaction
#include <icy/net/transaction.h>Inherits:
PacketTransaction< PacketT >,PacketSocketEmitter
Request/response helper for packet types emitted from a socket.
Public Methods
| Return | Name | Description |
|---|---|---|
Transaction inline | Constructs a Transaction on the given socket targeting peerAddress. | |
bool | send virtual inline | 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 | Cancels the transaction and stops the timeout timer. |
void | dispose virtual inline | 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, int retries)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
virtual inline bool send()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.
cancel
virtual inline
virtual inline void cancel()Cancels the transaction and stops the timeout timer.
dispose
virtual inline
virtual inline void dispose()Stops the timer and unregisters callbacks.
peerAddress
const inline
inline Address peerAddress() constReturns the remote peer address used for this transaction.
Protected Attributes
| Return | Name | Description |
|---|---|---|
Address | _peerAddress |
_peerAddress
Address _peerAddressProtected Methods
| Return | Name | Description |
|---|---|---|
bool | onPacket virtual inline | 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 | Called when a confirmed response is received; emits the response via PacketSignal. |
bool | checkResponse virtual inline | Returns true if packet is a valid response for this transaction. |
onPacket
virtual inline
virtual inline bool onPacket(IPacket & packet)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.
onResponse
virtual inline
virtual inline void onResponse()Called when a confirmed response is received; emits the response via PacketSignal.
checkResponse
virtual inline
virtual inline bool checkResponse(const PacketT & packet)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.
Public Types
| Name | Description |
|---|---|
BaseT |
BaseT
PacketTransaction< PacketT > BaseT()