Agora
1.2.0
Agora project
|
#include <udp_comm.h>
Public Member Functions | |
UDPComm (std::string local_addr, uint16_t local_port, size_t rx_buffer_size, size_t tx_buffer_size) | |
UDPComm (std::string local_addr, const std::string &local_port, size_t rx_buffer_size, size_t tx_buffer_size) | |
getaddrinfo() -> socket -> bind (for local address/port assignment) More... | |
UDPComm & | operator= (const UDPComm &)=delete |
UDPComm (const UDPComm &)=delete | |
~UDPComm () | |
ssize_t | Connect (const std::string &remote_address, uint16_t remote_port) const |
The remote_address | remote_port is the address to which datagrams are sent. 1:1 association me<->remote. More... | |
ssize_t | Connect (const std::string &remote_address, const std::string &remote_port) const |
Locate and connect to a remote address. More... | |
void | Send (const std::string &rem_hostname, uint16_t rem_port, const std::byte *msg, size_t len) |
Send one UDP packet to a remote server. The client caches the the remote server's addrinfo after resolving it for the first time. After the first time, sending data does not require expensive addrinfo resolution. More... | |
void | Send (const std::byte *msg, size_t len) |
Send one UDP packet to the connected remote server. More... | |
ssize_t | Recv (std::byte *buf, size_t len) const |
Try to receive up to len bytes in buf by default this will not block. More... | |
ssize_t | Recv (const std::string &src_address, uint16_t src_port, std::byte *buf, size_t len) |
Try once to receive up to len bytes in buf. More... | |
void | EnableRecording () |
void | MakeBlocking (size_t rx_timeout_sec=0) const |
Configures the socket in blocking mode. Any calls to recv / send will now block. More... | |
Static Public Attributes | |
static constexpr bool | kDebugPrintUdpInit = false |
static constexpr bool | kDebugPrintUdpSend = false |
static constexpr bool | kDebugPrintUdpRecv = false |
Private Attributes | |
int | sock_fd_ = -1 |
The raw socket file descriptor. More... | |
std::map< std::string, addrinfo * > | addrinfo_map_ |
A cache mapping hostname:udp_port to addrinfo. More... | |
std::mutex | map_insert_access_ |
Variable to control write access to the non-thread safe data structures. More... | |
std::vector< std::vector< uint8_t > > | sent_vec_ |
All packets sent, maintained if recording is enabled. More... | |
bool | enable_recording_flag_ = false |
If set to ture, we record all sent packets, otherwise we dont. More... | |
|
explicit |
|
explicit |
getaddrinfo() -> socket -> bind (for local address/port assignment)
loop through all the results and bind to the first we can
NON blocking by default
|
delete |
UDPComm::~UDPComm | ( | ) |
ssize_t UDPComm::Connect | ( | const std::string & | remote_address, |
const std::string & | remote_port | ||
) | const |
Locate and connect to a remote address.
Find the local interface
ssize_t UDPComm::Connect | ( | const std::string & | remote_address, |
uint16_t | remote_port | ||
) | const |
The remote_address | remote_port is the address to which datagrams are sent. 1:1 association me<->remote.
remote_address | Hostname or IP address of the endpoint |
remote_port | UDP port of the endpoint |
|
inline |
void UDPComm::MakeBlocking | ( | size_t | rx_timeout_sec = 0 | ) | const |
Configures the socket in blocking mode. Any calls to recv / send will now block.
ssize_t UDPComm::Recv | ( | const std::string & | src_address, |
uint16_t | src_port, | ||
std::byte * | buf, | ||
size_t | len | ||
) |
Try once to receive up to len bytes in buf.
ssize_t UDPComm::Recv | ( | std::byte * | buf, |
size_t | len | ||
) | const |
Try to receive up to len bytes in buf by default this will not block.
void UDPComm::Send | ( | const std::byte * | msg, |
size_t | len | ||
) |
Send one UDP packet to the connected remote server.
msg | Pointer to the message to send |
len | Length in bytes of the message to send |
void UDPComm::Send | ( | const std::string & | rem_hostname, |
uint16_t | rem_port, | ||
const std::byte * | msg, | ||
size_t | len | ||
) |
Send one UDP packet to a remote server. The client caches the the remote server's addrinfo after resolving it for the first time. After the first time, sending data does not require expensive addrinfo resolution.
to_hostname | Hostname or IP address of the remote server |
to_port | UDP port that the remote server is listening on |
msg | Pointer to the message to send |
len | Length in bytes of the message to send |
rem_hostname | Hostname or IP address of the remote server |
rem_port | UDP port that the remote server is listening on |
msg | Pointer to the message to send |
len | Length in bytes of the message to send |
|
private |
A cache mapping hostname:udp_port to addrinfo.
|
private |
If set to ture, we record all sent packets, otherwise we dont.
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
private |
Variable to control write access to the non-thread safe data structures.
|
private |
All packets sent, maintained if recording is enabled.
|
private |
The raw socket file descriptor.