Esempio n. 1
0
int			handle_newconnection(t_selfd *fd, t_server *serv)
{
  t_net			*bind_sock;
  t_net			*nsock;
  t_selfd		*tmpfd;
  t_client		*client;

  CHECKREAD(fd);
  if (!ISREADABLE(fd))
    return (EXIT_FAILURE);
  bind_sock = (t_net*)fd->data;
  if (!(nsock = accept_connection(bind_sock)))
    return (EXIT_FAILURE);
  if ((!(client = malloc(sizeof(t_client))))
      || !(tmpfd = create_fd(nsock->socket, client, &handle_client)))
    {
      free(client);
      close_connection(nsock);
      return (EXIT_FAILURE);
    }
  nsock->peer = peer(nsock);
  client->sock = nsock;
  log_connection(nsock, "New connection from:");
  return (init_new_client(serv, tmpfd, client));
}
Esempio n. 2
0
int get_uuid_and_confirm_client(agent_t *agent, int fd) 
{
   client_t * new_client; 
   struct client_hash_struct *client_hash;
   uuid_t uuid;
   
   get_uuid(agent->agent_fd_pool[fd], &uuid); 
     
   HASH_FIND_INT(agent->clients_hashes, uuid, client_hash); 

   if(client_hash == NULL) 
   {
 	   new_client = init_new_client(agent, &uuid); 
      new_client->agent_sock[new_client->num_parallel_connections] = 
         agent->agent_fd_pool[fd]; 
      new_client->agent_fd_poll[new_client->num_parallel_connections] = IN; 
      new_client->num_parallel_connections++; 

		if(check_for_transfer_request(agent, new_client, "AGENT")) {  
      	connect_host_side(agent, new_client); 
		}else { 
#ifdef DEBUG
         printf("DID NOT FIND!\n");  
#endif
      } 
      new_client->host_fd_poll  = OFF; 

   } 
   else 
   { 
      client_hash->client->agent_sock[client_hash->client->num_parallel_connections] = 
         agent->agent_fd_pool[fd]; 

      client_hash->client->agent_fd_poll[client_hash->client->num_parallel_connections] = IN; 
      client_hash->client->num_parallel_connections++; 
  
     if(client_hash->client->allowed_connections && client_hash->client->num_parallel_connections == client_hash->client->allowed_connections 
         && client_hash->client->host_fd_poll == IN)
     {
       client_hash->accept_start.tv_sec -=  TIMEOUT; 
     }
   }

 

   if(epoll_ctl(agent->event_pool, EPOLL_CTL_DEL, 
     agent->agent_fd_pool[fd], NULL)) 
   {
      perror("");
		printf("%s %d\n", __FILE__, __LINE__); 
		exit(1); 
   }

   agent->agent_fd_pool[fd] = EMPTY;  

   return EXIT_SUCCESS; 
}
Esempio n. 3
0
client_t * handle_host_side_connect(agent_t *agent) 
{

 	client_t *new_client = init_new_client(agent, NULL); 
	
	if(new_client != NULL) 
	{
		accept_host_side(agent, new_client); 

		
		if(check_for_transfer_request(agent, new_client, "CLIENT")) 
		{
	   	connect_agent_side(agent, new_client); 
		}else { 
         printf("DID NOT FIND!\n"); 
      } 
	}
	
	return new_client; 
}