src/network.c

changeset 113
5f58df30d422
parent 96
5faa21316c85
--- a/src/network.c	Thu Apr 23 12:26:53 2026 +0200
+++ b/src/network.c	Mon Apr 27 16:55:28 2026 +0200
@@ -174,6 +174,24 @@
     }
 }
 
+uint8_t net_recieve_code_async(int socket) {
+    fd_set readfds;
+    FD_ZERO(&readfds);
+    FD_SET(socket, &readfds);
+    struct timeval timeout;
+    timeout.tv_sec = 0;
+    timeout.tv_usec = 50000;
+    int result = select(socket+1, &readfds, NULL, NULL, &timeout);
+    if (result == 0) return NETCODE_AGAIN;
+    if (result == -1) return NETCODE_ERROR;
+    uint8_t code;
+    if (recv(socket, &code, sizeof(code), 0) == sizeof(code)) {
+        return code;
+    } else {
+        return NETCODE_CONNLOST;
+    }
+}
+
 void net_recieve_data(int socket, void *data, size_t len) {
     recv(socket, data, len, MSG_WAITALL);
 }

mercurial