From cfd57bdc677337c3abd48aec3a6d80eb5fd77102 Mon Sep 17 00:00:00 2001 From: 8nl <8nlight@disroot.org> Date: Tue, 27 Feb 2024 10:59:19 +0000 Subject: [PATCH] Upload files to "/" --- server.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/server.c b/server.c index a01117d..9da50ce 100644 --- a/server.c +++ b/server.c @@ -11,7 +11,7 @@ #define PORT 8888 #define BUFF_SIZE 2048 -#define MAX_CLIENTS 10 +#define MAX_CLIENTS 45 typedef struct { int fd; @@ -41,6 +41,9 @@ int main(void) { goto ERROR_WITHOUTCLOSE; struct timeval tv = {.tv_sec = 1, .tv_usec = 0}; + if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0) + goto ERROR; + if (setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)) < 0) goto ERROR; @@ -64,11 +67,16 @@ int main(void) { int last = 0; char buf[25]; - socklen_t len = sizeof(data.clients[last]); + socklen_t len = sizeof(data.clients[0]); while (1) { - if (recvfrom(fd, buf, sizeof(buf), 0, (struct sockaddr *)&data.clients[last], &len) > 0) - if (last <= MAX_CLIENTS) - last++; + if (last <= MAX_CLIENTS) { + if (recvfrom(fd, buf, sizeof(buf), 0, (struct sockaddr *)&data.clients[last], &len) > 0) + if (!strcmp(buf, "JOIN")) + last++; + } + + else + last = 0; } ERROR: