🗑️」 clean: cleaned this shit

This commit is contained in:
2025-09-18 22:32:22 +02:00
parent 34d875c802
commit 96efd5e799
2 changed files with 13 additions and 12 deletions

View File

@ -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)

View File

@ -93,4 +93,4 @@ int main() {
}
else
printf("server acccept the client...\n");
}
}