-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMsgServInfo.h
125 lines (102 loc) · 3.15 KB
/
MsgServInfo.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
/*
* MsgServInfo.h
*
* Created on: 2014-12-14
* Author: liguangyu
*/
#ifndef MSG_SERVINFO_H_
#define MSG_SERVINFO_H_
#include "util.h"
#include "imconn.h"
#include "ConfigFileReader.h"
#include <algorithm>
#define MAX_RECONNECT_CNT 64
#define MIN_RECONNECT_CNT 4
typedef struct msg_serv_info{
msg_serv_info(){memset(this,0,sizeof(msg_serv_info));}
char server_ip[64];
uint16_t server_port;
uint32_t idle_cnt;
uint32_t reconnect_cnt;
uint32_t num_connection;//到底多少个线程压?
char szUserName[64];
char szPassword[64];
uint32_t nCurrentUserID;
uint32_t nUserIDStart;
uint32_t nReceiveResultID;
uint32_t nSendMsgInterval;
uint32_t nStartedClient;//启动的客户端,目的是分批启动
//CImConn* serv_conn;
//
} msg_serv_info_t;
//extern static ConnMap_t g_msg_server_conn_map;
/*
g_msg_conn_map.insert(make_pair(handle, this));
*/
//template <class T>
template <class T>
void msg_serv_init(msg_serv_info_t* server_list, uint32_t server_count)
{
for (uint32_t i = 0; i < server_count; i++) {
server_list[i].idle_cnt = 0;
server_list[i].reconnect_cnt = MIN_RECONNECT_CNT / 2;
uint32_t nStart = server_list[i].nStartedClient;
uint32_t nEnd = min(server_list[i].num_connection,nStart+1000);
if(nStart >= nEnd)
{//m_bStartTest
T::StartAll();
continue;
}
printf("start client connection: [%d to %d) \n",nStart,nEnd);
for(uint32_t nUser=nStart;nUser<nEnd;nUser++)
{
//printf("-------------start client connection: %d \n",nUser);
T::CreateClient(&server_list[i],nUser);
server_list[i].nStartedClient++;
/*T* pConn = new T();
memcpy(&pConn->m_serv_info,&server_list[i],sizeof(msg_serv_info_t));
sprintf(pConn->m_serv_info.szUserName,"%s%d",server_list[i].szUserName,nUser);
strcpy(pConn->m_serv_info.szPassword,server_list[i].szPassword);
pConn->Connect(server_list[i].server_ip.c_str(), server_list[i].server_port, i);
*/
}
}
}
template <class T>
void msg_serv_check_reconnect(msg_serv_info_t* server_list, uint32_t server_count)
{
T* pConn;
/*
for (uint32_t i = 0; i < server_count; i++) {
pConn = (T*)server_list[i].serv_conn;
if (!pConn) {
server_list[i].idle_cnt++;
if (server_list[i].idle_cnt >= server_list[i].reconnect_cnt) {
pConn = new T();
pConn->Connect(server_list[i].server_ip.c_str(), server_list[i].server_port, i);
server_list[i].serv_conn = pConn;
}
}
}
*/
}
template <class T>
void msg_serv_reset(msg_serv_info_t* server_list, uint32_t server_count, uint32_t serv_idx)
{
if (serv_idx >= server_count) {
return;
}
/*
server_list[serv_idx].serv_conn = NULL;
server_list[serv_idx].idle_cnt = 0;
server_list[serv_idx].reconnect_cnt *= 2;
if (server_list[serv_idx].reconnect_cnt > MAX_RECONNECT_CNT) {
server_list[serv_idx].reconnect_cnt = MIN_RECONNECT_CNT;
}
*/
}
//读取配置文件,到底多少个msgserver 需要压力测试,而且每个msgserver要多少个线程去压
msg_serv_info_t* read_msg_server_config(CConfigFileReader* config_file, const char* server_ip_format,
const char* server_port_format,const char* server_num_format
,const char* server_username_format,const char* server_password_format, uint32_t& server_count);
#endif /* MSG_SERVINFO_H_ */