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

#include <UnixUDPSocket.hpp>

Inheritance diagram for UnixUDPSocket:
Inheritance graph
Collaboration diagram for UnixUDPSocket:
Collaboration graph

Public Member Functions

 UnixUDPSocket (unsigned int port, std::optional< IPAddress > address={}, unsigned long max_bitrate=0, std::unique_ptr< UnixSyscalls > syscalls=std::make_unique< UnixSyscalls >())
 
virtual ~UnixUDPSocket ()
 
virtual void send (const std::vector< uint8_t > &data, const IPAddress &address) final
 
virtual std::pair< std::vector< uint8_t >, IPAddressreceive (const std::chrono::nanoseconds &timeout=std::chrono::nanoseconds::zero()) final
 
virtual void send (std::vector< uint8_t >::const_iterator first, std::vector< uint8_t >::const_iterator last, const IPAddress &address)
 
virtual IPAddress receive (std::back_insert_iterator< std::vector< uint8_t >> it, const std::chrono::nanoseconds &timeout=std::chrono::nanoseconds::zero())
 

Protected Member Functions

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

Detailed Description

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

Definition at line 36 of file UnixUDPSocket.hpp.

Constructor & Destructor Documentation

◆ UnixUDPSocket()

UnixUDPSocket::UnixUDPSocket ( unsigned int  port,
std::optional< IPAddress address = {},
unsigned long  max_bitrate = 0,
std::unique_ptr< UnixSyscalls syscalls = std::make_unique<UnixSyscalls>() 
)

Construct a UDP socket.

Parameters
portThe port number to listen on.
addressThe address to listen on (the port portion of the address is ignored). The default is to listen on any address.
max_bitrateThe maximum number of bits per second to transmit on the UDP interface. The default is 0, which indicates no limit.
syscallsThe object to use for unix system calls. It is default constructed to the production implementation. This argument is only used for testing.
Exceptions
std::system_errorif a system call produces an error.

Definition at line 54 of file UnixUDPSocket.cpp.

◆ ~UnixUDPSocket()

UnixUDPSocket::~UnixUDPSocket ( )
virtual

The socket destructor.

Closes the underlying file descriptor of the UDP socket.

Definition at line 70 of file UnixUDPSocket.cpp.

Member Function Documentation

◆ print_()

std::ostream & UnixUDPSocket::print_ ( std::ostream &  os) const
finalprotectedvirtual

Print the UDP socket to the given output stream.

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

An example:

udp {
port 14555;
address 127.0.0.1;
max_bitrate 262144;
}
Parameters
osThe output stream to print to.

Reimplemented from UDPSocket.

Definition at line 257 of file UnixUDPSocket.cpp.

◆ receive() [1/2]

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

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.
Note
The timeout precision of this implementation is 1 millisecond.
Exceptions
std::system_errorif a system call produces an error.

Reimplemented from UDPSocket.

Definition at line 122 of file UnixUDPSocket.cpp.

◆ receive() [2/2]

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

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 UDPSocket::receive().

Here is the call graph for this function:

◆ send() [1/2]

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

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.
Exceptions
PartialSendErrorif it fails to write all the data it is given.

Reimplemented from UDPSocket.

Definition at line 81 of file UnixUDPSocket.cpp.

References IPAddress::address(), and IPAddress::port().

Here is the call 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 
)
virtualinherited

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 UDPSocket::send().

Here is the call graph for this function:

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