forked from sorokin/echo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
echo_tester.h
53 lines (44 loc) · 1.09 KB
/
echo_tester.h
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
49
50
51
52
53
#ifndef ECHO_TESTER_H
#define ECHO_TESTER_H
#ifdef __APPLE__
#include "kqueue.hpp"
#include "socket_apple.h"
#else
#include "epoll.h"
#include "socket.h"
#endif
#include "address.h"
#include <vector>
struct echo_tester
{
struct connection
{
connection(epoll& ep, ipv4_endpoint const& remote, uint32_t number);
void do_send();
bool do_receive();
private:
void fill_buffer(uint8_t* buf, size_t size);
bool check_buffer(uint8_t* buf, size_t size);
public:
uint32_t get_number() const;
private:
client_socket socket;
uint32_t number;
uint64_t sent;
uint64_t received;
public:
bool no_disconnect;
bool no_read;
};
echo_tester(epoll& ep, ipv4_endpoint remote_endpoint);
bool do_step();
void do_n_steps(size_t n);
private:
epoll& ep;
ipv4_endpoint remote_endpoint;
std::vector<std::unique_ptr<connection>> connections;
uint32_t next_connection_number;
size_t desired_number_of_connections;
size_t number_of_permanent_connections;
};
#endif // ECHO_TESTER_H