acl/lib_acl_cpp/samples/udp/udp_sock.h

97 lines
2.4 KiB
C
Raw Normal View History

2018-12-12 11:16:12 +08:00
/**
* Copyright (C) 2015-2018
* All rights reserved.
*
* AUTHOR(S)
* Zheng Shuxin
* E-mail: zhengshuxin@qiyi.com
*
* VERSION
* Wed 30 May 2017 11:33:48 AM CST
*/
#pragma once
#include <vector>
#include "sock_addr.h"
class udp_pkt;
class udp_pkts;
/**
* UDP
*/
class udp_sock
{
public:
udp_sock(void);
~udp_sock(void);
/**
* UDP UDP
* @param fd {int} > 0
* @return {bool} false
*/
bool open(int fd);
/**
* UDP
* @param local {const char*} ip:port
* @param peer {const char*} ip:port
* @return {bool} false
*/
bool client_open(const char* local, const char* peer);
/**
* UDP
* @param local {const char*} ip:port
* @return {bool} false
*/
bool server_open(const char* local);
/**
*
* @param data {const void*}
* @param len {size_t}
* @return {ssize_t} < 0
*/
ssize_t send(const void* data, size_t len);
/**
*
* @param buf {void*}
* @param len {size_t}
* @return {ssize_t} < 0
*/
ssize_t recv(void* buf, size_t len);
/**
* UDP
* @param pkts {udp_pkts&}
* @param {int} < 0
*/
int recv(udp_pkts& pkts);
/**
* UDP
* @param pkts {udp_pkts&}
* @param {int} < 0
*/
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);
};