0
votes
  while (1)
    {
      FD_ZERO(&readfs);
      readfs = add_clients_to_readfs(list_fd);
      select(get_max_fd(list_fd) + 1, &readfs, NULL, NULL, NULL);

      if (FD_ISSET(fd_socket, &readfs))
        {
          if (fd_client = (xaccept(fd_socket, (struct sockaddr *)s_in_client, &s_in_size)) != -1)
            {
              printf("FD_CLIENT %i\n", fd_client);
              add_client_to_list(list_fd, fd_client);
            }
        }

I have the FD_ZERO at start of the loop, a function add_clients_to_readfs which reinitiate the readfds fd_set with the file descriptors in my list, a classical select. Before the loop I have pushed the select fd on my list, if FD_ISSET reacts, its a new client connection so I accept the client and add his fd in the list. But my fd_client in printf is always 1. Do you have any idea ?

1

1 Answers

1
votes

Operator precedence problem.

if (fd_client = (xaccept(fd_socket, (struct sockaddr *)s_in_client, &s_in_size)) != -1)

should be

if ((fd_client = xaccept(fd_socket, (struct sockaddr *)s_in_client, &s_in_size)) != -1)