blob: 6aa7fb7948bb646b7252de67c8d886dfde6a7828 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#include <stdio.h>
#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
|