server.h (1256B)
1 #ifndef SERVER_H 2 #define SERVER_H 3 4 #define _XOPEN_SOURCE 700 5 #define _GNU_SOURCE 6 #define _DEFAULT_SOURCE 7 8 #include <inttypes.h> 9 #include <stdio.h> 10 #include <stdlib.h> 11 #include <string.h> 12 #include <unistd.h> 13 14 #include "catan.h" 15 16 #include <signal.h> 17 18 #include <sys/wait.h> 19 20 #include <sys/types.h> 21 #include <sys/socket.h> 22 #include <netdb.h> 23 24 #include <poll.h> 25 26 #define KiB 1024ULL 27 #define MiB (1024 * KiB) 28 #define GiB (1024 * MiB) 29 30 #define ARRLEN(arr) (sizeof (arr) / sizeof (arr)[0]) 31 32 #define GAME_BOARD_SIZE 3 33 34 #define GAME_AGENTS_MIN 2 35 #define GAME_AGENTS_MAX 4 36 37 #define AGENT_ACCEPT_TIMEOUT_MS 1000 38 39 struct opts { 40 bool verbose; 41 uint32_t game_seed; 42 uint32_t agent_threads; 43 uint32_t agent_mem_mib; 44 uint32_t agent_timeout; 45 46 struct { 47 char **ptr; 48 size_t len; 49 } agents; 50 }; 51 52 struct server_state { 53 int sockfd; 54 55 char addr[NI_MAXHOST], port[NI_MAXSERV]; 56 }; 57 58 struct agent_state { 59 uint8_t id; 60 pid_t pid; 61 int sockfd; 62 63 }; 64 65 bool 66 server_init(struct server_state *server); 67 68 bool 69 server_start_agent(struct server_state *server, struct agent_state *agent, 70 uint8_t id, char *cmd, uid_t uid); 71 72 void 73 server_wait_agent(struct agent_state *agent); 74 75 void 76 server_run(struct server_state *server, struct agent_state *agents, size_t len); 77 78 #endif /* SERVER_H */