SatCat5
satcat5::udp::KeepAlive Class Reference

Detailed Description

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>

Inheritance diagram for satcat5::udp::KeepAlive:
[legend]
Collaboration diagram for satcat5::udp::KeepAlive:
[legend]

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::Protocolm_next
 Linked list of Protocols.
 
unsigned m_trem
 
unsigned m_tnext
 

Constructor & Destructor Documentation

◆ KeepAlive()

KeepAlive::KeepAlive ( satcat5::udp::Dispatch iface,
satcat5::udp::Port  port,
const char *  label = nullptr 
)
explicit

Bind this object to a network interface and UDP port.

Parameters
ifaceUDP network interface.
portUDP port number (incoming + outgoing).
labelOptional message for each outgoing packet.

Definition at line 11 of file udp_keep_alive.cc.

Member Function Documentation

◆ connect()

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.

◆ frame_rcvd()

void KeepAlive::frame_rcvd ( satcat5::io::LimitedRead src)
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:

  • Call m_iface->open_reply() to obtain a Writable object. (This also writes out any applicable frame headers.)
  • Write frame contents, then call write_finalize().

The child class MUST override this method.

Implements satcat5::net::Protocol.

Definition at line 44 of file udp_keep_alive.cc.


The documentation for this class was generated from the following files: