Net module

Transaction

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

Transaction

#include <icy/net/transaction.h>

Inherits: PacketTransaction< PacketT >, PacketSocketEmitter

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

Public Methods

ReturnNameDescription
Transaction inlineConstructs a Transaction on the given socket targeting peerAddress.
boolsend virtual inlineSends 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 inlineCancels the transaction and stops the timeout timer.
voiddispose virtual inlineStops 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, int retries)

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

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

Returns the remote peer address used for this transaction.

Protected Attributes

ReturnNameDescription
Address_peerAddress

_peerAddress

Address _peerAddress

Protected Methods

ReturnNameDescription
boolonPacket virtual inlineChecks whether packet is a matching response for the pending request. If it matches, the transaction completes; socket data propagation stops.
voidonResponse virtual inlineCalled when a confirmed response is received; emits the response via PacketSignal.
boolcheckResponse virtual inlineReturns 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

  • packet The 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

  • packet The candidate response packet.

Returns

true if the packet satisfies the response criteria.

Public Types

NameDescription
BaseT

BaseT

PacketTransaction< PacketT > BaseT()