-
Notifications
You must be signed in to change notification settings - Fork 0
/
cycle.h
139 lines (93 loc) · 2.34 KB
/
cycle.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#ifndef CYCLE_H
#define CYCLE_H
#include <fstream>
#include <future>
#if defined(_WIN32) || defined(_WIN64)
//#include <WinSock2.h>
//#include <WinSock.h>
#include <winsock2.h>
#endif
#ifdef __HAIKU__
#include <Socket.h>
#endif
#if defined (__unix__) || defined (__APPLE__)
#include <netinet/in.h>
#include <sys/socket.h>
//#include <arpa/inet.h>
#endif
#include "pairfile.h"
#include "utl.h"
#include "tpl.h"
#include "logrot.h"
#include "params.h"
class CProducer;
class CGenCycle
{
public:
CProducer *producer;
CParameters *params;
size_t frame_counter = 0;
CGenCycle (CProducer *prod, CParameters *prms, const std::string &fname);
virtual ~CGenCycle();
virtual void loop() = 0;
};
class CGenCycleRated: public CGenCycle
{
public:
CGenCycleRated (CProducer *prod, CParameters *prms, const std::string &fname);
void loop();
};
class CGenCycleUnrated: public CGenCycle
{
public:
CGenCycleUnrated (CProducer *prod, CParameters *prms, const std::string &fname);
void loop();
};
class CProducer
{
public:
CTpl *tpl;
std::chrono::time_point<std::chrono::high_resolution_clock> start;
std::chrono::time_point<std::chrono::high_resolution_clock> stop;
int newsockfd, portno;
#if defined(_WIN32) || defined(_WIN64)
int clilen;
#else
socklen_t clilen;
#endif
char buffer[256];
struct sockaddr_in serv_addr, cli_addr;
bool server_run;
std::future<void> f_handle;
std::string response;
std::atomic<size_t> lines_counter;
std::atomic<size_t> lines_counter_last;
std::atomic<double> bytes_per_second;
std::atomic<double> lines_per_second;
std::atomic<size_t> file_size_total;
std::atomic<size_t> seconds_counter_ev;
std::atomic<size_t> seconds_counter;
std::atomic<size_t> frame_counter;
std::vector <std::string> v_buffer;
CLogRotator *logrotator;
CParameters *params;
size_t log_current_size; //in bytes
std::ofstream file_out;
bool file_out_error;
bool no_free_space;
size_t test_string_size;
std::string fname_template;
CGenCycle *cycle;
CProducer (CParameters *prms, const std::string &fname);
~CProducer();
void run();
bool open_logfile();
void write (const std::string &s, bool rated);
void write_buffered (const std::string &s, bool rated);
void flush_buffer();
void write_results();
void server_init();
void server_done();
void server_handle();
};
#endif