mavtables  0.2.1
MAVLink router and firewall.
Public Member Functions | Protected Member Functions | Friends | List of all members
UDPSocket Class Reference

#include <UDPSocket.hpp>

Inheritance diagram for UDPSocket:
Inheritance graph
Collaboration diagram for UDPSocket:
Collaboration graph

Public Member Functions

virtual ~UDPSocket ()
 
virtual void send (const std::vector< uint8_t > &data, const IPAddress &address)
 
virtual void send (std::vector< uint8_t >::const_iterator first, std::vector< uint8_t >::const_iterator last, const IPAddress &address)
 
virtual std::pair< std::vector< uint8_t >, IPAddressreceive (const std::chrono::nanoseconds &timeout=std::chrono::nanoseconds::zero())
 
virtual IPAddress receive (std::back_insert_iterator< std::vector< uint8_t >> it, const std::chrono::nanoseconds &timeout=std::chrono::nanoseconds::zero())
 

Protected Member Functions

virtual std::ostream & print_ (std::ostream &os) const
 

Friends

std::ostream & operator<< (std::ostream &os, const UDPSocket &udp_socket)
 

Detailed Description

A UDP socket, listening on a port/address combination.

Warning
This class should be treated as pure virtual and should never be instantiated.
Either send(const std::vector<uint8_t> &data, const IPAddress &) or send(std::vector<uint8_t>::const_iterator,std::vector<uint8_t>::const_iterator, const IPAddress &) must be overridden in child classes to avoid infinite recursion.
Either receive(const std::chrono::nanoseconds &) or receive(std::back_insert_iterator<std::vector<uint8_t>>,const std::chrono::nanoseconds &) must be overridden in child classes to avoid infinite recursion.

Definition at line 46 of file UDPSocket.hpp.

Constructor & Destructor Documentation

◆ ~UDPSocket()

UDPSocket::~UDPSocket ( )
virtual

Definition at line 31 of file UDPSocket.cpp.

Member Function Documentation

◆ print_()

std::ostream & UDPSocket::print_ ( std::ostream &  os) const
protectedvirtual

Print the UDP socket to the given output stream.

Parameters
osThe output stream to print to.
Returns
The output stream.

Reimplemented in UnixUDPSocket.

Definition at line 112 of file UDPSocket.cpp.

◆ receive() [1/2]

std::pair< std::vector< uint8_t >, IPAddress > UDPSocket::receive ( const std::chrono::nanoseconds &  timeout = std::chrono::nanoseconds::zero())
virtual

Receive data on the socket.

Note
The timeout is not guaranteed to be up to nanosecond precision, the actual precision is up to the operating system's implementation but is guaranteed to have at least millisecond precision.
Parameters
timeoutHow long to wait for data to arrive on the socket. The default is to not wait.
Returns
The data read from the socket and the IP address it was sent from.

Reimplemented in UnixUDPSocket.

Definition at line 77 of file UDPSocket.cpp.

Here is the caller graph for this function:

◆ receive() [2/2]

IPAddress UDPSocket::receive ( std::back_insert_iterator< std::vector< uint8_t >>  it,
const std::chrono::nanoseconds &  timeout = std::chrono::nanoseconds::zero() 
)
virtual

Receive data on the socket.

Note
The timeout is not guaranteed to be up to nanosecond precision, the actual precision is up to the operating system's implementation but is guaranteed to have at least millisecond precision.
Parameters
itA back insert iterator to read bytes into.
timeoutHow long to wait for data to arrive on the socket. The default is to not wait.
Returns
The IP address the data was sent from, this is where a reply should be sent to.

Definition at line 97 of file UDPSocket.cpp.

References receive().

Here is the call graph for this function:

◆ send() [1/2]

void UDPSocket::send ( const std::vector< uint8_t > &  data,
const IPAddress address 
)
virtual

Send data to the given address using the socket.

Parameters
dataThe bytes to send.
addressThe IP address (with port number) to send the bytes to, using UDP.

Reimplemented in UnixUDPSocket.

Definition at line 43 of file UDPSocket.cpp.

Here is the caller graph for this function:

◆ send() [2/2]

void UDPSocket::send ( std::vector< uint8_t >::const_iterator  first,
std::vector< uint8_t >::const_iterator  last,
const IPAddress address 
)
virtual

Send data to the given address using the socket.

Parameters
firstIterator to first byte in range to send.
lastIterator to one past the last byte to send.
addressThe IP address (with port number) to send the bytes to, using UDP.

Definition at line 56 of file UDPSocket.cpp.

References send().

Here is the call graph for this function:

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const UDPSocket udp_socket 
)
friend

Print the given UDP socket to the given output stream.

An example:

udp {
port 14555;
address 127.0.0.1;
max_bitrate 262144;
}

The base UDPSocket class will print:

unknown UDP socket
Parameters
osThe output stream to print to.
udp_socketThe UDP socket (or any child of UDPSocket) to print.
Returns
The output stream.

Definition at line 140 of file UDPSocket.cpp.


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