Testing Spices::Net::EPOLLPOLL.
20 {
21
23
25
26 int r;
27
29
34
37
38 EPollPoller epoller(EventLoopThreadWrapper::GetInst());
39 HANDLE ephnd = epoller.GetHandle();
40
41
42 {
43 epoll_event ev;
44 ev.events = EPOLLIN | EPOLLPRI;
45 ev.data.sock = listen_sock.
Fd();
46
47 r = epoll_ctl(ephnd, EPOLL_CTL_ADD, listen_sock.
Fd(), &ev);
48 }
49
50
51 {
52 epoll_event ev;
53 ev.events = EPOLLOUT;
54 ev.data.sock = client_sock.
Fd();
55
56 r = epoll_ctl(ephnd, EPOLL_CTL_ADD, client_sock.
Fd(), &ev);
57 }
58
60
61
62 epoll_event evs[8];
63 r = epoll_wait(ephnd, evs, 8, -1);
64
67
68 for (int round = 0; round < 5; round++)
69 {
70 static char buf[1 << 20];
71 epoll_event evs[8];
72 int bytes_received, bytes_sent;
73
74 r = epoll_wait(ephnd, evs, 8, -1);
75
76 memset(buf, round, sizeof(buf));
77
78 bytes_sent = 0;
79 do {
80 client_sock.
Send(std::string(buf,
sizeof(buf)));
81 bytes_sent += sizeof(buf);
82
83 r = epoll_wait(ephnd, evs, 8, 0);
84 } while (r > 0);
85
86 bytes_received = 0;
87 do {
88 auto s = server_sock.Receive();
89 bytes_received += s.size();
90 } while (bytes_received < bytes_sent);
91 }
92
93 r = epoll_ctl(ephnd, EPOLL_CTL_DEL, client_sock.
Fd(), NULL);
94 }
#define SPICESTEST_PROFILE_FUNCTION()
This class is Wrapper of current socket address.
void Connect(InetAddress *connectAddress) const
Connect to socket.
void Send(const std::string &data) const
Send data to server.
SOCKET Accept(InetAddress *peerAddress) const
Accept connection on socket.
void BindAddress(const InetAddress &localAddress) const
Bind address to socket.
void Create()
Create Non Blocking Socket.
const SOCKET Fd() const
Get this socket fd.
void Listen() const
Listen on socket.
This class is Wrapper of socket.