Exemplo n.º 1
0
static t_client	*write_to_write(t_client *client)
{
  client->to_write = first_node(&client->to_write->node);
  if (client->to_write == NULL)
    return (client);
  if (write_fd(client->to_write->str, client->ca.cfd) == true)
    return (sup_client(client));
  free(client->to_write->str);
  client->to_write = sup_node(&client->to_write->node);
  return (client);
}
Exemplo n.º 2
0
static t_client	*read_client(fd_set const * const fd_read, t_client *list)
{
  t_client	*client;
  t_client	*client2;

  client = first_node(&list->node);
  while (client != NULL)
    {
      client2 = client->node.next;
      if (FD_ISSET(client->ca.cfd, fd_read))
	{
	  if (write_cbuf(&client->cbuf, client->ca.cfd) <= 0)
	    list = sup_client(client);
	  else
	    if (clock_gettime(CLOCK_MONOTONIC_RAW, &client->time) == -1)
	      {
		perror("clock_gettime :");
		list = sup_client(client);
	      }
	}
      client = client2;
    }
  return (list);
}
Exemplo n.º 3
0
static void	client_read(t_server *server, int fd)
{
  int		r;
  char		buf[RING_SIZE];
  t_client	*client;

  client = get_client_from_socket(server->clients, fd);
  memset(buf, 0, RING_SIZE);
  r = recv(fd, buf, RING_SIZE, 0);
  if (r > 0)
    {
      write_in_ring(client->buffer, buf);
      if (buf[r - 1] == '\n' && buf[r - 2] == '\r')
	run_cmd(server, client);
    }
  else
    {
      sup_client(&server->clients, client);
      printf("%d: Connection closed\n", fd);
      close(fd);
      server->e.fd_type[fd] = FD_FREE;
    }
}