-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlam-ssi-ckptrd-sock-write.c
162 lines (126 loc) · 3.9 KB
/
lam-ssi-ckptrd-sock-write.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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include "lam-ssi-ckptrd-includes.h"
#define MAX_CHARARRAY_SIZE 150
/* Local functions */
bool write_sock_dctrlmesg(int , const lam_cr_dctrlmesg *);
bool write_sock_dinfomesg(int , const lam_cr_dinfomesg *);
bool write_sock_dbootmesg(int , const lam_cr_dbootmesg *);
bool write_sock_debug_info(int , const struct debug_info *);
bool write_sock_int(int, const int *);
bool write_sock_long(int, const long *);
bool write_sock_charArray(int, const char *);
bool write_sock_struct_gpsArray(int, const struct _gps *);
bool
lam_ssi_ckptrd_write_dsockdmesg(int connfd, const lam_cr_dsockmesg *dsockmesg)
{
bool success = true;
success &= write_sock_int(connfd, &dsockmesg->dmesg_type);
if(success)
{
if(dsockmesg->dmesg_type == DINFO)
success &= write_sock_dinfomesg(connfd, &dsockmesg->dmesg.dinfomesg);
else if(dsockmesg->dmesg_type == DCTRL)
success &= write_sock_dctrlmesg(connfd, &dsockmesg->dmesg.dctrlmesg);
else if(dsockmesg->dmesg_type == DBOOT)
success &= write_sock_dbootmesg(connfd, &dsockmesg->dmesg.dbootmesg);
else
{
printf("Unknows code - %d\n",dsockmesg->dmesg_type);
success = false;
}
}
return success;
}
bool
write_sock_dinfomesg(int connfd, const lam_cr_dinfomesg *dinfomesg)
{
bool success = true;
success &= write_sock_int(connfd, &dinfomesg->info_type);
success &= write_sock_int(connfd, &dinfomesg->mpirun_pid);
success &= write_sock_charArray(connfd, dinfomesg->name);
success &= write_sock_int(connfd, &dinfomesg->mpiworld_n);
if(success && (dinfomesg->mpiworld_n > 0))
{
int i;
for(i = 0 ; i < dinfomesg->mpiworld_n; i++)
success |= write_sock_struct_gpsArray(connfd, &dinfomesg->mpi_gps[i]);
}
success &= write_sock_debug_info(connfd, &dinfomesg->mpi_debug_info);
return success;
}
bool
write_sock_dctrlmesg(int connfd, const lam_cr_dctrlmesg *dctrlmesg)
{
bool success = true;
success &= write_sock_int(connfd, &dctrlmesg->mesg_type);
success &= write_sock_int(connfd, &dctrlmesg->ctrl_type);
success &= write_sock_int(connfd, &dctrlmesg->mpi_pid);
success &= write_sock_charArray(connfd, dctrlmesg->filename);
success &= write_sock_long(connfd, &dctrlmesg->size);
return success;
}
bool
write_sock_dbootmesg(int connfd, const lam_cr_dbootmesg *dbootmesg)
{
bool success = true;
success &= write_sock_int(connfd, &dbootmesg->node_count);
int i;
for(i=0;i<dbootmesg->node_count;i++)
{
success &= write_sock_charArray(connfd, dbootmesg->node_ips[i]);
}
return success;
}
bool
write_sock_debug_info(int connfd, const struct debug_info *var)
{
ssize_t sent_bytes;
sent_bytes = write(connfd, var, sizeof(struct debug_info));
if(sent_bytes != sizeof(struct debug_info))
return false;
return true;
}
bool
write_sock_int(int connfd, const int *var)
{
ssize_t sent_bytes;
sent_bytes = write(connfd, var, sizeof(int));
if(sent_bytes != sizeof(int))
return false;
return true;
}
bool
write_sock_long(int connfd, const long *var)
{
ssize_t sent_bytes;
sent_bytes = write(connfd, var, sizeof(long));
if(sent_bytes != sizeof(long))
return false;
return true;
}
bool
write_sock_charArray(int connfd, const char *var)
{
char *temp_var;
if(var == NULL)
temp_var = strdup("");
else
temp_var = strdup(var);
ssize_t sent_bytes;
sent_bytes = write(connfd, temp_var, strlen(temp_var) + 1);
if(sent_bytes != (strlen(temp_var) + 1))
{
free(temp_var);
return false;
}
free(temp_var);
return true;
}
bool
write_sock_struct_gpsArray(int connfd, const struct _gps *var)
{
ssize_t sent_bytes;
sent_bytes = write(connfd, var, sizeof(struct _gps));
if(sent_bytes != sizeof(struct _gps))
return false;
return true;
}