-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGT_center.cpp
77 lines (54 loc) · 1.64 KB
/
GT_center.cpp
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
#include"clock_sync.h"
#include<stdio.h>
#include<string.h>
#include<fstream>
#include<assert.h>
#include <csignal>
#include <unistd.h>
int main(){
uint32_t count;
char** addr_list;
int* port_list;
char buff[64];
std::fstream ifs("ifconfig", std::ios::in);
if(!ifs){
printf("Open config file failed\n");
return 0;
}
ifs>>count;
addr_list = (char**) malloc(count*sizeof(char*));
port_list = (int*) malloc(count*sizeof(int));
for(uint32_t idx=0; idx<count; idx++){
addr_list[idx] = new char[64];
ifs>>buff;
strcpy(addr_list[idx], buff);
port_list[idx] = 12450+233*idx;
}
ifs.close();
GTCenter gtCenter(addr_list, port_list, count);
gtCenter.build_connection_config(TREE_LAYOUT);
printf("Send connection config finish\n");
// collect warmup finish info
msg2cent msg_array[count];
gtCenter.collect_info(msg_array);
for(uint32_t i=0; i<count; i++){
assert(msg_array[i].is_warmup_done);
assert(msg_array[i].msg_id==111);
}
printf("collect msg finish.\n");
// send start msg to all nodes
msg2master msg_array2[count];
for(uint32_t i=0; i<count; i++)
msg_array2[i].msg_id = 222;
gtCenter.broadcast_info(msg_array2);
// build TCP connection with other nodes
printf("Warmup finish.\n");
free(port_list);
for(uint32_t idx=0; idx<count; idx++){
delete addr_list[idx];
}
free(addr_list);
gtCenter.finalize();
printf("Releasing resources success\n");
return 0;
}