|
SatCat5
|
Send and receive keep-alive messages.
In some networks, idle endpoints may be expected to periodically send UDP messages to a designated UDP port, to indicate that the connection is still valid. Recipients should immediately discard such messages with no further action.
This class binds the incoming UDP port, to prevent false-alarm "port-unreachable" ICMP errors from being sent in response.
Optionally, this class may also be used to send keep-alive messages, defaulting to the broadcast addresss (255.255.255.255). To enable this feature, call timer_once or timer_every.
Definition at line 25 of file udp_keep_alive.h.
#include <udp_keep_alive.h>
Public Member Functions | |
| KeepAlive (satcat5::udp::Dispatch *iface, satcat5::udp::Port port, const char *label=nullptr) | |
| Bind this object to a network interface and UDP port. More... | |
| void | connect (const satcat5::ip::Addr &dstaddr, const satcat5::eth::VlanTag &vtag=satcat5::eth::VTAG_NONE) |
| Connect to a specific destination address. More... | |
| void | send_now (const char *msg) |
| Immediately send a keep-alive, with an optional message. | |
| void | timer_once (unsigned msec) |
| Configure a one-time notification after X milliseconds. | |
| void | timer_every (unsigned msec) |
| Configure a repeating notification every X milliseconds. | |
| void | timer_stop () |
| Stop all future notifications. | |
| unsigned | timer_interval () const |
| Accessor for recurring timer interval, if one is set. | |
| unsigned | timer_remaining () const |
| Accessor for time to next event, if one is set. | |
Static Public Member Functions | |
| static unsigned | count_timer () |
| Count all objects of this type, including idle timers. | |
Protected Member Functions | |
| void | frame_rcvd (satcat5::io::LimitedRead &src) override |
| Dispatch calls frame_rcvd(...) for each incoming frame with with a matching net::Type value. More... | |
| void | timer_event () override |
| Child class MUST override this method. | |
Protected Attributes | |
| satcat5::udp::Address | m_addr |
| const char *const | m_label |
| satcat5::net::Type | m_filter |
| Incoming packet filter. | |
Private Member Functions | |
| void | query (unsigned elapsed_msec) |
Private Attributes | |
| satcat5::net::Protocol * | m_next |
| Linked list of Protocols. | |
| unsigned | m_trem |
| unsigned | m_tnext |
|
explicit |
Bind this object to a network interface and UDP port.
| iface | UDP network interface. |
| port | UDP port number (incoming + outgoing). |
| label | Optional message for each outgoing packet. |
Definition at line 11 of file udp_keep_alive.cc.
| void KeepAlive::connect | ( | const satcat5::ip::Addr & | dstaddr, |
| const satcat5::eth::VlanTag & | vtag = satcat5::eth::VTAG_NONE |
||
| ) |
Connect to a specific destination address.
During object creation, the destination defaults to broadcast (255.255.255.255). This method changes the destination address.
Definition at line 27 of file udp_keep_alive.cc.
|
overrideprotectedvirtual |
Dispatch calls frame_rcvd(...) for each incoming frame with with a matching net::Type value.
The child class SHOULD read the frame contents from the provided "src" object, which is only valid until the function returns.
To send a reply:
The child class MUST override this method.
Implements satcat5::net::Protocol.
Definition at line 44 of file udp_keep_alive.cc.