wip new version still
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user