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 +}