Skip to content

Commit

Permalink
Merge pull request #217 from FppEpitech/feat/update-the-fds-set-in-th…
Browse files Browse the repository at this point in the history
…e-select-for-write-zappy-server
  • Loading branch information
Njord201 authored Jun 23, 2024
2 parents c155b0c + eb4d9d1 commit ed816f3
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions server/src/server/run.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,24 @@
#include "server/client.h"
#include "ai/cmd/command_ai.h"

static void reset_ai(app_t *app)
static void reset_ai(app_t *app, list_node_t *node_ai)
{
while (node_ai) {
FD_SET(node_ai->data.ai->fd, &app->server->read_fds);
if (node_ai->data.ai->list_messages->first != NULL)
FD_SET(node_ai->data.ai->fd, &app->server->write_fds);
node_ai = node_ai->next;
}
}

static void reset_ais(app_t *app)
{
list_node_t *temp = app->teams_list->first;
list_node_t *ia_temp = NULL;
team_t *team = NULL;

while (temp) {
team = temp->data.team;
ia_temp = team->list_ai->first;
while (ia_temp) {
FD_SET(ia_temp->data.ai->fd, &app->server->read_fds);
FD_SET(ia_temp->data.ai->fd, &app->server->write_fds);
ia_temp = ia_temp->next;
}
reset_ai(app, team->list_ai->first);
temp = temp->next;
}
}
Expand All @@ -34,7 +38,8 @@ static void reset_gui(app_t *app)
while (temp_gui) {
gui = temp_gui->data.gui;
FD_SET(gui->fd, &app->server->read_fds);
FD_SET(gui->fd, &app->server->write_fds);
if (temp_gui->data.gui->list_messages->first != NULL)
FD_SET(gui->fd, &app->server->write_fds);
temp_gui = temp_gui->next;
}
}
Expand All @@ -54,7 +59,7 @@ void server_reset_fd(app_t *app)
temp = temp->next;
}
reset_gui(app);
reset_ai(app);
reset_ais(app);
}

void handle_client_read(app_t *app, int fd)
Expand Down

0 comments on commit ed816f3

Please sign in to comment.