netline.h (1227B)
1 /* netline.h - conexion TCP de lineas de texto (cliente) y tokens de partidas online. */ 2 #ifndef COMUN_NETLINE_H 3 #define COMUN_NETLINE_H 4 #include <stdbool.h> 5 6 #define LC_LINE 512 /* largo maximo de una linea del protocolo */ 7 8 typedef struct { 9 int fd; 10 char in[1 << 16]; 11 int inlen; 12 long long last_tx; 13 void (*idle)(void *ctx); /* se llama mientras se espera bloqueado (servidor embebido) */ 14 void *idle_ctx; 15 } LineConn; 16 17 int lc_dial(const char *host, int port, char *err, int errlen); /* fd o -1 */ 18 void lc_init(LineConn *c, int fd); 19 bool lc_send(LineConn *c, const char *fmt, ...); 20 bool lc_take(LineConn *c, char *line, int len); /* saca una linea ya recibida */ 21 bool lc_read_line(LineConn *c, char *line, int len, int timeout_ms); /* bloqueante */ 22 bool lc_pump(LineConn *c); /* recibe lo disponible sin bloquear; false si se corto */ 23 void lc_close(LineConn *c); 24 25 /* tokens guardados de partidas online (data_dir()/online) */ 26 typedef struct { char server[128], code[8], token[33]; int seat; } SavedGame; 27 int saved_games(const char *server, SavedGame *out, int max); 28 void saved_game_add(const char *server, const char *code, int seat, const char *token); 29 30 #endif