diff --git a/a.out b/a.out index cf5e790..70086a8 100755 Binary files a/a.out and b/a.out differ diff --git a/mini_serv_2.c b/mini_serv_2.c index 836e7b1..0ff5b19 100644 --- a/mini_serv_2.c +++ b/mini_serv_2.c @@ -91,10 +91,31 @@ char *str_join(char *buf, char *add) return (newbuf); } +void add_client(t_client *first_client, int fd, int id) { + t_client *new_client; + t_client *client; + + new_client = calloc(1, sizeof(*new_client)); + if (!new_client) + error("Fatal error\n"); + new_client->fd = fd; + new_client->id = id; + new_client->next = NULL; + if (!first_client) + first_client = new_client; + else { + client = first_client; + while (client) + client = client->next; + client->next = new_client; + } +} + int main(int ac, char **av) { int sockfd; int client_fd; int maxfd; + int id; struct sockaddr_in servaddr; fd_set read_set; fd_set write_set; @@ -104,6 +125,7 @@ int main(int ac, char **av) { if (ac != 2) error("Wrong number of arguments\n"); client = NULL; + id = 0; first_client = client; // socket create and verification @@ -129,6 +151,8 @@ int main(int ac, char **av) { FD_ZERO(&write_set); client = first_client; while(client) { +write(1, "1", 1); +printf("id: %i\n", client->id); FD_SET(client->fd, &read_set); FD_SET(client->fd, &write_set); if (client->fd > maxfd) @@ -140,7 +164,8 @@ int main(int ac, char **av) { if (FD_ISSET(sockfd, &read_set)) { client_fd = accept(sockfd, NULL, NULL); - + add_client(first_client, client_fd, id); + id++; } } return (0);