RISA
|
#include <UDPServer.h>
Public Member Functions | |
UDPServer (const std::string &addr, int port) | |
~UDPServer () | |
Clean up the UDP server. More... | |
int | get_socket () const |
The socket used by this UDP server. More... | |
int | get_port () const |
The port used by this UDP server. More... | |
std::string | get_addr () const |
Return the address of this UDP server. More... | |
int | recv (char *msg, size_t max_size) |
Wait on a message. More... | |
int | timed_recv (char *msg, size_t max_size, int max_wait_ms) |
Wait for data to come in. More... | |
Private Attributes | |
int | f_socket |
int | f_port |
std::string | f_addr |
struct addrinfo * | f_addrinfo |
Definition at line 41 of file UDPServer.h.
risa::UDPServer::UDPServer | ( | const std::string & | addr, |
int | port | ||
) |
Definition at line 79 of file UDPServer.cpp.
risa::UDPServer::~UDPServer | ( | ) |
Clean up the UDP server.
This function frees the address info structures and close the socket.
Definition at line 115 of file UDPServer.cpp.
std::string risa::UDPServer::get_addr | ( | ) | const |
Return the address of this UDP server.
This function returns a verbatim copy of the address as passed to the constructor of the UDP server (i.e. it does not return the canonalized version of the address.)
Definition at line 153 of file UDPServer.cpp.
int risa::UDPServer::get_port | ( | ) | const |
The port used by this UDP server.
This function returns the port attached to the UDP server. It is a copy of the port specified in the constructor.
Definition at line 140 of file UDPServer.cpp.
int risa::UDPServer::get_socket | ( | ) | const |
The socket used by this UDP server.
This function returns the socket identifier. It can be useful if you are doing a select() on many sockets.
Definition at line 128 of file UDPServer.cpp.
int risa::UDPServer::recv | ( | char * | msg, |
size_t | max_size | ||
) |
Wait on a message.
This function waits until a message is received on this UDP server. There are no means to return from this function except by receiving a message. Remember that UDP does not have a connect state so whether another process quits does not change the status of this UDP server and thus it continues to wait forever.
Note that you may change the type of socket by making it non-blocking (use the get_socket() to retrieve the socket identifier) in which case this function will not block if no message is available. Instead it returns immediately.
[in] | msg | The buffer where the message is saved. |
[in] | max_size | The maximum size the message (i.e. size of the msg buffer.) |
Definition at line 176 of file UDPServer.cpp.
int risa::UDPServer::timed_recv | ( | char * | msg, |
size_t | max_size, | ||
int | max_wait_s | ||
) |
Wait for data to come in.
This function waits for a given amount of time for data to come in. If no data comes in after max_wait_ms, the function returns with -1 and errno set to EAGAIN.
The socket is expected to be a blocking socket (the default,) although it is possible to setup the socket as non-blocking if necessary for some other reason.
This function blocks for a maximum amount of time as defined by max_wait_ms. It may return sooner with an error or a message.
[in] | msg | The buffer where the message will be saved. |
[in] | max_size | The size of the msg buffer in bytes. |
[in] | max_wait_s | The maximum number of seconds to wait for a message. |
Definition at line 200 of file UDPServer.cpp.
|
private |
Definition at line 57 of file UDPServer.h.
|
private |
Definition at line 58 of file UDPServer.h.
|
private |
Definition at line 56 of file UDPServer.h.
|
private |
Definition at line 55 of file UDPServer.h.