From ad900636080477eb2c8df7a225a71825e5380d3d Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Mon, 20 Mar 2023 03:51:08 -0700 Subject: added proper cancellation token handling; cleanup when host is found to be unresponsive --- src/chess.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/chess.c') diff --git a/src/chess.c b/src/chess.c index adb5ce2..5e52482 100644 --- a/src/chess.c +++ b/src/chess.c @@ -44,7 +44,7 @@ int main(int argc, char **argv) { isHost = 1; /* we are acting as the host--await a connection */ printf("Awaiting connection\n"); - match = await_match(matchFile, NULL); + match = await_match(matchFile, init_cancel_token_never()); printf("Connection completed. Match is %s\n", match.uuid); } else { @@ -52,11 +52,12 @@ int main(int argc, char **argv) { /* we are joining an existing match */ printf("Attempting to join existing match\n"); match = join_match(); - if (match.uuid != NULL) { + if (strlen(match.uuid) == 36) { printf("Joined match %s\n", match.uuid); } else { - printf("Error joining match. reload the program\n"); + printf("Error joining match. Reload the program\n"); + exit(1); } } sleep(2); @@ -71,7 +72,7 @@ int main(int argc, char **argv) { /* awaiting the remote player */ printf("Waiting for %s's move\n", turn ? "black" : "white"); while (1) { - char* message = read_message(match, NULL); + char* message = read_message(match, init_cancel_token_never()); /* try to parse the message as a move */ if (strncmp(message, "move=", 5) == 0) { vector_t rOrigin = init_vector(message[5] - '0', message[6] - '0'); -- cgit v1.3.1