Ejemplo n.º 1
0
int
ixp_serverloop(IxpServer *s) {
	timeval *tvp;
	timeval tv;
	long timeout;
	int r;

	s->running = 1;
	thread->initmutex(&s->lk);
	while(s->running) {
		if(s->preselect)
			s->preselect(s);

		tvp = nil;
		timeout = ixp_nexttimer(s);
		if(timeout > 0) {
			tv.tv_sec = timeout/1000;
			tv.tv_usec = timeout%1000 * 1000;
			tvp = &tv;
		}

		prepare_select(s);
		r = thread->select(s->maxfd + 1, &s->rd, 0, 0, tvp);
		if(r < 0) {
			if(errno == EINTR)
				continue;
			return 1;
		}
		handle_conns(s);
	}
	return 0;
}
Ejemplo n.º 2
0
int process_file(FILE* file, struct srv_connection *conn){
	struct select s_val;
	int count[CHAR_CT];
	int res;

	init_count(count);

	while(1){
		if (!prepare_select(conn, &s_val)){
			printf("File has processed, All clients ended");
			break;
		}

		res = select(s_val.max_d+1, &(s_val.readfds), NULL, NULL, &(s_val.t));

		if (res<0) {
			printf("err select\n");
			continue;
		} else if (res==0){
			printf("\ns timeout s\n");
			continue;
		}

		process_select(conn, s_val, file, count);
	}

	print_result(count, CHAR_CT);	

	return 0;
}
Ejemplo n.º 3
0
Archivo: poll.c Proyecto: aissat/vde2
int vde_poll(struct pollfd *ufds, nfds_t nfds, int timeout)
{
	fd_set rfds, wfds, efds;
	struct timeval stimeout;
	struct timeval *pstimeout = &stimeout;
	int maxfdp1;
	int pretval, sretval, tretval;

	FD_ZERO(&rfds);
	FD_ZERO(&wfds);
	FD_ZERO(&efds);

	tretval = prepare_select(ufds, nfds, timeout, &pstimeout, &maxfdp1, &rfds, &wfds, &efds);
	if (!tretval)
		return -1;

	sretval = select(maxfdp1, &rfds, &wfds, &efds, pstimeout);
	if (sretval <= 0)
		return sretval;
	
	pretval = convert_results(ufds, nfds, &rfds, &wfds, &efds);

	return pretval;
}
Ejemplo n.º 4
0
int			do_server(t_conf *conf)
{
  fd_set		rfds;
  int			retval;
  int			max_fd;
  t_simple_list		*client;
  t_simple_list		*tmp;
  struct timeval	tv;
  struct timezone	tz;

#ifdef DEBUG
  char		        buffer[MINI_BUFF];
#endif

  while (1)
    {     
      max_fd = prepare_select(conf, &rfds, &tv);
      retval = select(max_fd + 1 , &rfds, NULL, NULL, &tv);
      queue_flush_expired_data(conf);
      if (retval == -1)
	{
	  perror("");
	  MYERROR("select");
	  return (-1);
	}
      if (!retval)
	{ 
	  if (gettimeofday(&tv, &tz))
	    {
	      MYERROR("Time Error");
	      return (-1);
	    }
	  delete_zombie(conf);
	  continue;
	}
#ifdef DEBUG
      if ((conf->foreground) && (FD_ISSET(0, &rfds)))
	{
	  read(0, buffer, MINI_BUFF); 
	  queue_dump(conf->client);
	  continue;
	}
#endif
      if (FD_ISSET(conf->sd_udp, &rfds))
	get_incoming_request(conf);
      else
	{
	  for (client = conf->client;  client; client = tmp)
	    {
	      tmp = client->next;
	      if ((client->sd_tcp != -1) && (FD_ISSET(client->sd_tcp, &rfds)))
	      {
		if (queue_read_tcp(conf, client))
		  {
		    if (client->sd_tcp != -1)
		      close(client->sd_tcp);
		    delete_client(conf, client);
		  }
	      }
	    }
	}
      delete_zombie(conf);
    }
}