-
Notifications
You must be signed in to change notification settings - Fork 146
/
main.c
73 lines (58 loc) · 1.36 KB
/
main.c
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
#include <stdio.h>
#include "debug.h"
#include "config.h"
#include "ib.h"
#include "setup_ib.h"
#include "client.h"
#include "server.h"
FILE *log_fp = NULL;
int init_env ();
void destroy_env ();
int main (int argc, char *argv[])
{
int ret = 0;
if (argc != 3) {
printf ("Usage: %s config_file sock_port\n", argv[0]);
return 0;
}
ret = parse_config_file (argv[1]);
check (ret == 0, "Failed to parse config file");
config_info.sock_port = argv[2];
ret = init_env ();
check (ret == 0, "Failed to init env");
ret = setup_ib ();
check (ret == 0, "Failed to setup IB");
if (config_info.is_server) {
ret = run_server ();
} else {
ret = run_client ();
}
check (ret == 0, "Failed to run workload");
error:
close_ib_connection ();
destroy_env ();
return ret;
}
int init_env ()
{
char fname[64] = {'\0'};
if (config_info.is_server) {
sprintf (fname, "server[%d].log", config_info.rank);
} else {
sprintf (fname, "client[%d].log", config_info.rank);
}
log_fp = fopen (fname, "w");
check (log_fp != NULL, "Failed to open log file");
log (LOG_HEADER, "IB Echo Server");
print_config_info ();
return 0;
error:
return -1;
}
void destroy_env ()
{
log (LOG_HEADER, "Run Finished");
if (log_fp != NULL) {
fclose (log_fp);
}
}