#ifndef _SIMPLEUDPPEER_H_
|
#define _SIMPLEUDPPEER_H_
|
|
#include <cstdint>
|
#include <string>
|
#include <linux/in.h>
|
|
struct AsyncStub;
|
|
class SimpleUDPPeer
|
{
|
friend struct AsyncStub;
|
|
public:
|
struct Config
|
{
|
timeval defaultTimeout;
|
size_t maxBuffSize;
|
std::string local_ip;
|
short local_port;
|
std::string remote_ip;
|
short remote_port;
|
|
Config() : defaultTimeout(), maxBuffSize(60000), local_ip(), local_port(0), remote_ip(), remote_port(0)
|
{
|
defaultTimeout.tv_sec = 0;
|
defaultTimeout.tv_usec = 0;
|
}
|
};
|
|
typedef void (*proc_func_t)(void* args, uint8_t* buffer, size_t buffSize);
|
|
SimpleUDPPeer();
|
~SimpleUDPPeer();
|
|
void set_config(const Config& _cfg);
|
const Config& get_config() const;
|
|
bool init();
|
void teardown();
|
bool send_sync(const uint8_t* buffer, size_t& buffSize);
|
bool send_async(const uint8_t* buffer, size_t buffSize);
|
bool recv_sync(uint8_t* buffer, size_t& buffSize);
|
bool recv_async_start(proc_func_t proc, void* args = nullptr);
|
void recv_async_stop();
|
//#todo error callback
|
|
private:
|
Config cfg;
|
sockaddr_in local_address;
|
sockaddr_in remote_address;
|
int fd;
|
AsyncStub* asyncStub;
|
};
|
|
#endif
|