-
Notifications
You must be signed in to change notification settings - Fork 110
/
ConnectionManager.h
executable file
·93 lines (72 loc) · 1.73 KB
/
ConnectionManager.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
#pragma once
#include <stddef.h>
#include <time.h>
#include <vector>
using namespace std;
class HttpRequest;
class ConnectionManager
{
public:
~ConnectionManager(void){
_connManager = NULL;
};
static ConnectionManager *getInstance() {
//multi thread lock
if (_connManager == NULL) {
_connManager = new ConnectionManager();
}
//unlock
return _connManager;
}
void connectionInc();
void requestInc();
void responseInc();
void timeoutInc();
void errorInc();
void connExcaptionInc();
void okInc();
long long getConnExceptions();
unsigned int getConnections();
long long getTotalRequests();
long long getTotalResponses();
long long getTimeoutRequests();
long long getErrorResponses();
long long getOkResponses();
void updateRequestsPerSecond();
unsigned int getCurrentRequest();
void addRecycle(HttpRequest *req);
void recycleConnection();
void clearStatictis() {
_total_request = 0;
_total_response = 0;
_timeout_response = 0;
_error_response = 0;
_conn_exception = 0;
_ok_response = 0;
_request_per_second = 0;
};
private:
ConnectionManager(void){
_total_request = 0;
_total_response = 0;
_timeout_response = 0;
_error_response = 0;
_connections = 0;
_conn_exception = 0;
_ok_response = 0;
_cur_time = time(NULL);
_request_per_second = 0;
_recycle.clear();
};
time_t _cur_time;
unsigned int _request_per_second;
long long _total_request;
long long _total_response;
long long _timeout_response;
long long _error_response;
long long _conn_exception;
long long _ok_response;
vector<HttpRequest *> _recycle;
unsigned int _connections;
static ConnectionManager *_connManager;
};