「🗑️」 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);
|
close(cli_fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
int read_client(int fd) {
|
int read_client(int cli_fd) {
|
||||||
char tmp[3000];
|
char tmp[3000];
|
||||||
int bytes;
|
int bytes = recv(cli_fd, tmp, 3000, 0);
|
||||||
if ((bytes = recv(fd, tmp, 3000, 0)) <= 0)
|
|
||||||
return (rm_client(fd), 0);
|
if (bytes <= 0)
|
||||||
tmp[bytes] = 0;
|
return (rm_client(cli_fd), 0);
|
||||||
clients[fd].msg = str_join(clients[fd].msg, tmp);
|
|
||||||
char *line = 0;
|
tmp[bytes] = '\0';
|
||||||
while (extract_message(&clients[fd].msg, &line)) {
|
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);
|
bzero(send_buf, 3000);
|
||||||
sprintf(send_buf, "client %d: %s", clients[fd].id, line);
|
sprintf(send_buf, "client %d: %s", clients[cli_fd].id, line);
|
||||||
send_all(fd);
|
send_all(cli_fd);
|
||||||
free(line);
|
free(line);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
@ -110,7 +112,6 @@ int read_client(int fd) {
|
|||||||
|
|
||||||
void send_all(int cli_fd) {
|
void send_all(int cli_fd) {
|
||||||
size_t len = strlen(send_buf);
|
size_t len = strlen(send_buf);
|
||||||
printf("%s", send_buf);
|
|
||||||
|
|
||||||
for (int i = 0; i <= maxfd; i++)
|
for (int i = 0; i <= maxfd; i++)
|
||||||
if (FD_ISSET(i, &main_fd) != 0 && i != cli_fd && i != sockfd)
|
if (FD_ISSET(i, &main_fd) != 0 && i != cli_fd && i != sockfd)
|
||||||
|
@ -93,4 +93,4 @@ int main() {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
printf("server acccept the client...\n");
|
printf("server acccept the client...\n");
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user