「🗑️」 clean: cleaned this shit
This commit is contained in:
23
mini_serv.c
23
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)
|
||||
|
Reference in New Issue
Block a user