summaryrefslogtreecommitdiff
path: root/src/chess.c
diff options
context:
space:
mode:
authorKai Stevenson <kai@kaistevenson.com>2023-03-20 03:51:08 -0700
committerKai Stevenson <kai@kaistevenson.com>2023-03-20 03:51:08 -0700
commitad900636080477eb2c8df7a225a71825e5380d3d (patch)
tree2fabfebada8ac863b6b4e2e0a128a3146a887be1 /src/chess.c
parent1a3b3fb05f86e357b099812c0a09a084934fd111 (diff)
added proper cancellation token handling; cleanup when host is found to be unresponsive
Diffstat (limited to 'src/chess.c')
-rw-r--r--src/chess.c9
1 files changed, 5 insertions, 4 deletions
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');