1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
int boucle(int s, struct sockaddr_in *client_sin, int *client_sin_len, t_param *params)
{
struct timeval tv;
int cs;
int fd_max;
t_client *begin_cl;
fd_set readf;
fd_set writef;
typedef struct s_message
{
char *message;
struct s_message *next;
} t_message;
typedef struct s_client
{
int fd;
t_message *snd_msg;
struct s_client *next;
} t_client;
tv.tv_sec = 1;
tv.tv_usec = 0;
begin_cl = NULL;
while (1)
{
fd_max = ini_fd_set(&readf, begin_cl, s);
fd_max = ini_fd_set_out(&writef, begin_cl, fd_max);
if (select(fd_max + 1, &readf, &writef, NULL, &tv) < 0)
{
perror(PROJ_NAME);
my_putstr("close\n");
fd_max = ini_fd_set(&readf, begin_cl, s);
fd_max = ini_fd_set_out(&writef, begin_cl, fd_max);
}
else if (FD_ISSET(s, &readf))
{
cs = accept(s, (struct sockaddr *)client_sin, client_sin_len);
my_putstr("accept\n");
begin_cl = ajoute_liste(cs, begin_cl);
}
my_putstr("select\n");
begin_cl = parse_fd_set(&readf, begin_cl);
parse_fd_set_out(&writef, begin_cl);
}
} |
Partager