-
Notifications
You must be signed in to change notification settings - Fork 0
/
receiver.hpp
49 lines (39 loc) · 1.08 KB
/
receiver.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef RECEIVER_HPP
#define RECEIVER_HPP
#include <arpa/inet.h>
#include <vector>
#include <ext/subvector.hpp>
class receiver
{
public:
class result:
public ext::subvector<mmsghdr>
{
protected:
receiver& m_receiver;
public:
inline result(std::vector<mmsghdr>::iterator b, std::vector<mmsghdr>::iterator e, receiver& r):
ext::subvector<mmsghdr>( b, e ),
m_receiver( r )
{
}
inline ~result()
{
m_receiver.cleanup( begin(), end() );
}
};
friend class result;
receiver(size_t msg_size, int buf_n, size_t cmsg_size, int n);
result recv(int fd);
protected:
size_t m_cmsg_size;
std::vector<char> m_cmsg_buf;
std::vector<char> m_msg_buf;
std::vector<iovec> m_iovs;
std::vector<mmsghdr> m_mhdrs;
void init(size_t msg_size, int buf_n, size_t cmsg_size, int n);
void cleanup(std::vector<mmsghdr>::iterator begin, std::vector<mmsghdr>::iterator end);
result recvmsg(int fd);
result recvmmsg(int fd);
}; //class receiver
#endif