Skip to content

Commit 3b8ef53

Browse files
author
Mudit
committed
Exit if connecting to the receptionist fails
1 parent 56e3009 commit 3b8ef53

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

workers/c_client_direct/client.c

+15-3
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ void OnEntityQueryResponse(const Worker_EntityQueryResponseOp* op) {
5656
}
5757

5858
void OnAddEntity(const Worker_AddEntityOp* op) {
59-
printf("received add entity op (entity: %" PRId64 ")\n", op->entity_id);
59+
printf("received add entity op (entity: %" PRId64 ")\n", op->entity_id);
6060
}
6161

6262
void OnRemoveEntity(const Worker_RemoveEntityOp* op) {
63-
printf("received remove entity op (entity: %" PRId64 ")\n", op->entity_id);
63+
printf("received remove entity op (entity: %" PRId64 ")\n", op->entity_id);
6464
}
6565

6666
void OnAddComponent(const Worker_AddComponentOp* op) {
@@ -125,7 +125,9 @@ int main(int argc, char** argv) {
125125
printf("Connects to SpatialOS\n");
126126
printf(" <hostname> - hostname of the receptionist to connect to.\n");
127127
printf(" <port> - port to use\n");
128-
printf(" <worker_id> - name of the worker assigned by SpatialOS. A random prefix will be added to it to ensure uniqueness.\n");
128+
printf(
129+
" <worker_id> - name of the worker assigned by SpatialOS. A random prefix will be "
130+
"added to it to ensure uniqueness.\n");
129131
return EXIT_FAILURE;
130132
}
131133

@@ -148,6 +150,14 @@ int main(int argc, char** argv) {
148150
Worker_ConnectionFuture_Destroy(connection_future);
149151
free(worker_id);
150152

153+
if (Worker_Connection_GetConnectionStatusCode(connection) !=
154+
WORKER_CONNECTION_STATUS_CODE_SUCCESS) {
155+
printf("failed to connect to receptionist. reason: %s\n",
156+
Worker_Connection_GetConnectionStatusDetailString(connection));
157+
Worker_Connection_Destroy(connection);
158+
return EXIT_FAILURE;
159+
}
160+
151161
/* Send a test message. */
152162
Worker_LogMessage message = {WORKER_LOG_LEVEL_WARN, "Client", "Connected successfully", NULL};
153163
Worker_Connection_SendLogMessage(connection, &message);
@@ -210,4 +220,6 @@ int main(int argc, char** argv) {
210220
}
211221

212222
Worker_Connection_Destroy(connection);
223+
224+
return EXIT_SUCCESS;
213225
}

workers/c_client_vtable/client.c

+10-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ char* GenerateWorkerId(char* worker_id_prefix) {
1515

1616
/* Format string. */
1717
char* worker_id = malloc(sizeof(char) * (size + 1));
18-
sprintf(worker_id,fmt, worker_id_prefix, id);
18+
sprintf(worker_id, fmt, worker_id_prefix, id);
1919
return worker_id;
2020
}
2121

@@ -170,6 +170,14 @@ int main(int argc, char** argv) {
170170
Worker_ConnectionFuture_Destroy(connection_future);
171171
free(worker_id);
172172

173+
if (Worker_Connection_GetConnectionStatusCode(connection) !=
174+
WORKER_CONNECTION_STATUS_CODE_SUCCESS) {
175+
printf("failed to connect to receptionist. reason: %s\n",
176+
Worker_Connection_GetConnectionStatusDetailString(connection));
177+
Worker_Connection_Destroy(connection);
178+
return EXIT_FAILURE;
179+
}
180+
173181
/* Send a test message. */
174182
Worker_LogMessage message = {WORKER_LOG_LEVEL_WARN, "Client", "Connected successfully", NULL};
175183
Worker_Connection_SendLogMessage(connection, &message);
@@ -228,4 +236,5 @@ int main(int argc, char** argv) {
228236
}
229237

230238
Worker_Connection_Destroy(connection);
239+
return EXIT_SUCCESS;
231240
}

0 commit comments

Comments
 (0)