Skip to content

Exit if connecting to the receptionist fails #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions workers/c_client_direct/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ void OnEntityQueryResponse(const Worker_EntityQueryResponseOp* op) {
}

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

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

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

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

if (Worker_Connection_GetConnectionStatusCode(connection) !=
WORKER_CONNECTION_STATUS_CODE_SUCCESS) {
printf("failed to connect to receptionist. reason: %s\n",
Worker_Connection_GetConnectionStatusDetailString(connection));
Worker_Connection_Destroy(connection);
return EXIT_FAILURE;
}

/* Send a test message. */
Worker_LogMessage message = {WORKER_LOG_LEVEL_WARN, "Client", "Connected successfully", NULL};
Worker_Connection_SendLogMessage(connection, &message);
Expand Down Expand Up @@ -210,4 +220,5 @@ int main(int argc, char** argv) {
}

Worker_Connection_Destroy(connection);
return EXIT_SUCCESS;
}
11 changes: 10 additions & 1 deletion workers/c_client_vtable/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ char* GenerateWorkerId(char* worker_id_prefix) {

/* Format string. */
char* worker_id = malloc(sizeof(char) * (size + 1));
sprintf(worker_id,fmt, worker_id_prefix, id);
sprintf(worker_id, fmt, worker_id_prefix, id);
return worker_id;
}

Expand Down Expand Up @@ -170,6 +170,14 @@ int main(int argc, char** argv) {
Worker_ConnectionFuture_Destroy(connection_future);
free(worker_id);

if (Worker_Connection_GetConnectionStatusCode(connection) !=
WORKER_CONNECTION_STATUS_CODE_SUCCESS) {
printf("failed to connect to receptionist. reason: %s\n",
Worker_Connection_GetConnectionStatusDetailString(connection));
Worker_Connection_Destroy(connection);
return EXIT_FAILURE;
}

/* Send a test message. */
Worker_LogMessage message = {WORKER_LOG_LEVEL_WARN, "Client", "Connected successfully", NULL};
Worker_Connection_SendLogMessage(connection, &message);
Expand Down Expand Up @@ -228,4 +236,5 @@ int main(int argc, char** argv) {
}

Worker_Connection_Destroy(connection);
return EXIT_SUCCESS;
}