From 764ecc4127e3a2f967679be5778b263cf4927b90 Mon Sep 17 00:00:00 2001 From: Aargh Rai Date: Thu, 28 May 2026 18:34:26 +0530 Subject: now multiple connections are actually handled --- src/engine.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) (limited to 'src/engine.c') diff --git a/src/engine.c b/src/engine.c index 9c848dd..b4a4051 100644 --- a/src/engine.c +++ b/src/engine.c @@ -26,23 +26,30 @@ void comms_main() { mqd_t tx = mq_open("/engine_to_server", O_WRONLY); mqd_t rx = mq_open("/server_to_engine", O_RDONLY); - moves_t moves = moves_init(); - position_t position = position_starting(); + while (1) { + char* x = read_queue(rx); + printf("Engine received: %s", x); + free(x); + + send_queue(tx, "Sending", 8); + + moves_t moves = moves_init(); + position_t position = position_starting(); - get_moves(&moves, position); - char buf[128]; - for (int i = 0; i <= moves.length / 32; i++) { - for (int ii = 0; ii < 32; ii++) { - if (moves.length <= 4 * i + ii) continue; - // printf("%d\n", 4 * i + ii); - struct sqrstr from_str = sqr_to_str(moves.moves[4 * i + ii].from); - struct sqrstr to_str = sqr_to_str(moves.moves[4 * i + ii].to); - buf[4 * ii + 0] = from_str.data[0]; - buf[4 * ii + 1] = from_str.data[1]; - buf[4 * ii + 2] = to_str.data[0]; - buf[4 * ii + 3] = to_str.data[1]; + get_moves(&moves, position); + char buf[128]; + for (int i = 0; i <= moves.length / 32; i++) { + for (int ii = 0; ii < 32; ii++) { + if (moves.length <= 4 * i + ii) continue; + struct sqrstr from_str = sqr_to_str(moves.moves[4 * i + ii].from); + struct sqrstr to_str = sqr_to_str(moves.moves[4 * i + ii].to); + buf[4 * ii + 0] = from_str.data[0]; + buf[4 * ii + 1] = from_str.data[1]; + buf[4 * ii + 2] = to_str.data[0]; + buf[4 * ii + 3] = to_str.data[1]; + } + send_queue(tx, buf, sizeof(buf)); } - send_queue(tx, buf, sizeof(buf)); } } -- cgit v1.2.3