#include #ifndef FSCOMCH #define FSCOMCH /* 1/2 second */ static const unsigned long int awaitMatchNs = 500000000L; /* 1/4 second */ static const unsigned long int awaitMoveNs = 250000000L; typedef struct Match { char* uuid; FILE* streamIn; FILE* streamOut; } match_t; match_t init_match(char* uuid, FILE* streamIn, FILE* streamOut); void destroy_match(match_t match); typedef struct CancellationToken { int timeout; volatile char* value; } cancelToken_t; cancelToken_t init_cancel_token_timeout(int seconds); cancelToken_t init_cancel_token_never(); /* returns null if the matchfile is already extant */ FILE* try_lock_match(); /* creates a new match, waits for it to be joined by another player */ match_t await_match(FILE* matchFile, cancelToken_t cancelToken); /* joins an existing match */ match_t join_match(); void send_message(char* content, match_t match); /* blocks */ char* read_message(match_t match, cancelToken_t cancelToken); char* make_uuid(); void* cancel_in_secs(void* token); #endif