acl/lib_acl_cpp/samples/udp/udp_pkt.h

124 lines
3.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_sock;
/**
* UDP
2018-12-12 11:16:12 +08:00
*/
class udp_pkt
{
public:
/**
* <EFBFBD>
* @param size {size_t} <EFBFBD> udp у<EFBFBD>
2018-12-12 11:16:12 +08:00
*/
udp_pkt(size_t size = 1460);
~udp_pkt(void);
/**
* <EFBFBD>
* @param data {const void*} NULL
* @param len {size_t} <EFBFBD> > 0 <EFBFBD> <= у<EFBFBD>
* @return {bool} <EFBFBD> false
2018-12-12 11:16:12 +08:00
*/
bool set_data(const void* data, size_t len);
/**
* <EFBFBD>
* @param addr {const char*} udp
* @return {bool} false
2018-12-12 11:16:12 +08:00
*/
bool set_peer(const char* addr);
/**
* get_dlen у
2018-12-12 11:16:12 +08:00
* @return {void*}
*/
void* get_data(void) const
{
return iov_.iov_base;
}
/**
* у
2018-12-12 11:16:12 +08:00
* @return {size_t}
*/
size_t get_dlen(void) const
{
return iov_.iov_len;
}
/**
* 彿
* @return {int} <EFBFBD> < 0
2018-12-12 11:16:12 +08:00
*/
int get_port(void) const;
/**
* <EFBFBD> IP
* @return {const char*} NULL
2018-12-12 11:16:12 +08:00
*/
const char* get_ip(void) const;
private:
friend class udp_sock;
struct iovec iov_; // 瀛樻斁鏀<E69681>/鍙戠殑鏁版嵁鍦板潃鍙婇暱搴<E69AB1>
const size_t size_; // 鏋勯€犳椂璁惧畾鍚庝笉鑳藉啀淇敼
SOCK_ADDR addr_; // 婧愬湴鍧€
2018-12-12 11:16:12 +08:00
socklen_t addr_len_;
char ipbuf_[64];
};
/**
* UDP <EFBFBD>
2018-12-12 11:16:12 +08:00
*/
class udp_pkts
{
public:
/**
* <EFBFBD>
* @param max {size_t} UDP х > 0
2018-12-12 11:16:12 +08:00
*/
udp_pkts(size_t max);
~udp_pkts(void);
/**
*
* @param i {size_t} <EFBFBD>
* @return {udp_pkt*} NULL
2018-12-12 11:16:12 +08:00
*/
udp_pkt* operator[](size_t i);
/**
* <EFBFBD>
2018-12-12 11:16:12 +08:00
* @return {size_t}
*/
size_t get_npkt(void) const
{
return npkt_;
}
/**
*
* upd_sock
* @param n {size_t} у<EFBFBD>
2018-12-12 11:16:12 +08:00
*/
void set_npkt(size_t n);
protected:
friend class udp_sock;
std::vector<udp_pkt*>& get_pkts(void)
{
return pkts_;
}
private:
std::vector<udp_pkt*> pkts_;
size_t max_;
size_t npkt_;
};