mavtables
0.2.1
MAVLink router and firewall.
|
#include <UnixUDPSocket.hpp>
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 >, IPAddress > | receive (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 |
A unix UDP socket, listening on a port/address combination.
Definition at line 36 of file UnixUDPSocket.hpp.
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.
port | The port number to listen on. |
address | The address to listen on (the port portion of the address is ignored). The default is to listen on any address. |
max_bitrate | The maximum number of bits per second to transmit on the UDP interface. The default is 0, which indicates no limit. |
syscalls | The object to use for unix system calls. It is default constructed to the production implementation. This argument is only used for testing. |
std::system_error | if a system call produces an error. |
Definition at line 54 of file UnixUDPSocket.cpp.
|
virtual |
The socket destructor.
Closes the underlying file descriptor of the UDP socket.
Definition at line 70 of file UnixUDPSocket.cpp.
|
finalprotectedvirtual |
Print the UDP socket to the given output stream.
os | The output stream to print to. |
An example:
os | The output stream to print to. |
Reimplemented from UDPSocket.
Definition at line 257 of file UnixUDPSocket.cpp.
|
finalvirtual |
Receive data on the socket.
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.timeout | How long to wait for data to arrive on the socket. The default is to not wait. |
std::system_error | if a system call produces an error. |
Reimplemented from UDPSocket.
Definition at line 122 of file UnixUDPSocket.cpp.
|
virtualinherited |
Receive data on the socket.
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.it | A back insert iterator to read bytes into. |
timeout | How long to wait for data to arrive on the socket. The default is to not wait. |
Definition at line 97 of file UDPSocket.cpp.
References UDPSocket::receive().
|
finalvirtual |
Send data to the given address using the socket.
data | The bytes to send. |
address | The IP address (with port number) to send the bytes to, using UDP. |
PartialSendError | if 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().
|
virtualinherited |
Send data to the given address using the socket.
first | Iterator to first byte in range to send. |
last | Iterator to one past the last byte to send. |
address | The IP address (with port number) to send the bytes to, using UDP. |
Definition at line 56 of file UDPSocket.cpp.
References UDPSocket::send().