acl/lib_acl_cpp/samples/udp/server/udp_sock.h

85 lines
2.2 KiB
C
Raw Normal View History

#pragma once
2018-12-12 11:16:12 +08:00
#include <vector>
#include "sock_addr.h"
class udp_pkt;
class udp_pkts;
/**
* UDP
2018-12-12 11:16:12 +08:00
*/
class udp_sock
{
public:
udp_sock(void);
~udp_sock(void);
/**
* UDP UDP
* @param fd {int} > 0
* @return {bool} false
2018-12-12 11:16:12 +08:00
*/
bool open(int fd);
/**
* UDP
* @param local {const char*} ip:port
* @param peer {const char*} ip:port
* @return {bool} false
2018-12-12 11:16:12 +08:00
*/
bool client_open(const char* local, const char* peer);
/**
* UDP
* @param local {const char*} ip:port
* @return {bool} false
2018-12-12 11:16:12 +08:00
*/
bool server_open(const char* local);
/**
*
* @param data {const void*}
* @param len {size_t}
* @return {ssize_t} < 0
2018-12-12 11:16:12 +08:00
*/
ssize_t send(const void* data, size_t len);
/**
*
* @param buf {void*}
* @param len {size_t}
* @return {ssize_t} < 0
2018-12-12 11:16:12 +08:00
*/
ssize_t recv(void* buf, size_t len);
/**
* UDP
* @param pkts {udp_pkts&}
* @param {int} < 0
2018-12-12 11:16:12 +08:00
*/
int recv(udp_pkts& pkts);
/**
* UDP
* @param pkts {udp_pkts&}
* @param {int} < 0
2018-12-12 11:16:12 +08:00
*/
int send(udp_pkts& pkts);
private:
int fd_;
SOCK_ADDR sa_local_;
socklen_t sa_local_len_;
SOCK_ADDR sa_peer_;
socklen_t sa_peer_len_;
struct mmsghdr* msgvec_;
size_t vlen_;
bool bind(const char* addr);
int recv(std::vector<udp_pkt*>& pkts);
int send(std::vector<udp_pkt*>& pkts, size_t max);
};