summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAargh Rai <aargh.rai+git@gmail.com>2026-05-28 18:34:26 +0530
committerAargh Rai <aargh.rai+git@gmail.com>2026-05-28 18:34:26 +0530
commit764ecc4127e3a2f967679be5778b263cf4927b90 (patch)
treed591f30923bde889c866a7d42c7b52288af615e9 /src
parentc56cc12c154b3f21411d71e10f4e8a5a9682355b (diff)
now multiple connections are actually handled
Diffstat (limited to 'src')
-rw-r--r--src/engine.c37
-rw-r--r--src/engine/moves/king.c2
-rw-r--r--src/server.c12
-rw-r--r--src/server/comms.c4
4 files changed, 38 insertions, 17 deletions
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));
}
}
diff --git a/src/engine/moves/king.c b/src/engine/moves/king.c
index 6e8d105..b2fea9e 100644
--- a/src/engine/moves/king.c
+++ b/src/engine/moves/king.c
@@ -38,7 +38,7 @@ void get_king_moves(moves_t* moves, position_t position) {
#ifdef TEST_MOD
#include <stdbool.h>
#include "../bitboard.c"
-#include "./moves.c"
+#include "./vec.c"
bool test_empty_board() {
int i = 0;
diff --git a/src/server.c b/src/server.c
index d13945f..d2ed0e5 100644
--- a/src/server.c
+++ b/src/server.c
@@ -91,7 +91,17 @@ int main(int argc, char** argv) {
unsigned opcode = hdr[0] & 0x0F;
unsigned len = hdr[1] & 0x7F;
- if (opcode == 0x8) break;
+ if (opcode == 0x8) {
+ unsigned char close_frame[2] = {0x88, 0x00};
+ send(client, close_frame, 2, 0);
+ break;
+ }
+
+ if (opcode == 0x9) {
+ unsigned char pong[2] = {0x8A, 0x00};
+ send(client, pong, 2, 0);
+ continue;
+ }
if (len >= 126) break;
unsigned char mask[4];
diff --git a/src/server/comms.c b/src/server/comms.c
index 4549bdd..5580ef5 100644
--- a/src/server/comms.c
+++ b/src/server/comms.c
@@ -46,6 +46,10 @@ struct strs handle_input(mqd_t tx, mqd_t rx, char* payload, int len) {
printf("Message: %.*s", len, payload);
fflush(stdout);
+ send_queue(tx, payload, len);
+ char* buf = read_queue(rx);
+ assert(strcmp(buf, "Sending") == 0);
+
struct strs output = init_strs();
int n = get_num_messages(rx);