From 96efd5e799a25d37cc5f2911398f8c95b9367eda Mon Sep 17 00:00:00 2001 From: adjoly Date: Thu, 18 Sep 2025 22:32:22 +0200 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=F0=9F=97=91=EF=B8=8F=E3=80=8D=20clean?= =?UTF-8?q?:=20cleaned=20this=20shit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mini_serv.c | 23 ++++++++++++----------- subjects/main.c | 2 +- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/mini_serv.c b/mini_serv.c index 59fd124..dd439a9 100644 --- a/mini_serv.c +++ b/mini_serv.c @@ -91,18 +91,20 @@ void rm_client(int cli_fd) { close(cli_fd); } -int read_client(int fd) { +int read_client(int cli_fd) { char tmp[3000]; - int bytes; - if ((bytes = recv(fd, tmp, 3000, 0)) <= 0) - return (rm_client(fd), 0); - tmp[bytes] = 0; - clients[fd].msg = str_join(clients[fd].msg, tmp); - char *line = 0; - while (extract_message(&clients[fd].msg, &line)) { + int bytes = recv(cli_fd, tmp, 3000, 0); + + if (bytes <= 0) + return (rm_client(cli_fd), 0); + + tmp[bytes] = '\0'; + clients[cli_fd].msg = str_join(clients[cli_fd].msg, tmp); + char *line = NULL; + while (extract_message(&clients[cli_fd].msg, &line)) { bzero(send_buf, 3000); - sprintf(send_buf, "client %d: %s", clients[fd].id, line); - send_all(fd); + sprintf(send_buf, "client %d: %s", clients[cli_fd].id, line); + send_all(cli_fd); free(line); } return 1; @@ -110,7 +112,6 @@ int read_client(int fd) { void send_all(int cli_fd) { size_t len = strlen(send_buf); - printf("%s", send_buf); for (int i = 0; i <= maxfd; i++) if (FD_ISSET(i, &main_fd) != 0 && i != cli_fd && i != sockfd) diff --git a/subjects/main.c b/subjects/main.c index e649113..6284533 100644 --- a/subjects/main.c +++ b/subjects/main.c @@ -93,4 +93,4 @@ int main() { } else printf("server acccept the client...\n"); -} \ No newline at end of file +}