Ejemplo n.º 1
0
void test_normal_queue() {
    buffer_queue* queue = queue_init();

    printf("head: %p, tail: %p, fixed: %p\n", queue->head, queue->tail, queue->fixed);

    printf("-------- enqueue test: \n");
    queue_enqueue(queue, 1, "test_enqueue 1", strlen("test_enqueue 1")); 
    queue_enqueue(queue, 2, "test_enqueue 2", strlen("test_enqueue 2")); 
    queue_enqueue(queue, 3, "test_enqueue 3", strlen("test_enqueue 3")); 
    queue_enqueue(queue, 4, "test_enqueue 4", strlen("test_enqueue 4")); 

    queue_dump(queue);
    buffer term;
    queue_dequeue(queue, &term);
    printf("dequeue: buff=%s, fd=%d, size=%u\n", term.buffer, term.ud, term.szbuf);
    FREE(term.buffer);

    queue_dequeue(queue, &term);
    printf("dequeue: buff=%s, fd=%d, size=%u\n", term.buffer, term.ud, term.szbuf);
    FREE(term.buffer);

    queue_dequeue(queue, &term);
    printf("dequeue: buff=%s, fd=%d, size=%u\n", term.buffer, term.ud, term.szbuf);
    FREE(term.buffer);

    queue_dequeue(queue, &term);
    printf("dequeue: buff=%s, fd=%d, size=%u\n", term.buffer, term.ud, term.szbuf);
    FREE(term.buffer);

    int ret = queue_dequeue(queue, &term);
    assert(ret< 0);
    queue_dump(queue);

    queue_release(queue);
}
Ejemplo n.º 2
0
int		queue_flush(t_conf *conf, t_simple_list *client)
{
  t_list	*queue;
  t_list	*free_cell;

  queue = client->queue;
  if (!(free_cell = queue_find_empty_data_cell(client)))
    return (-1);
  while ((queue) && (queue->status == RECEIVED))
    {
      if (!free_cell)
	{
	  MYERROR("Queue design is too small\n");
	  queue_dump(client);
	  while (1);
	  return (-1);
	}
      queue_prepare_ack(free_cell,queue->info.num_seq);
      if (extract_data(conf, client, queue) == -1)
	return (-1);
      queue = queue->next;
      free_cell = free_cell->next;
    }
  if (queue == client->queue)
    return (-1);
  return (queue_change_root(client, queue));
}
Ejemplo n.º 3
0
Archivo: signals.c Proyecto: hyper/rq
void sighup_handler(evutil_socket_t fd, short what, void *arg)
{
	system_data_t *sysdata = (system_data_t *) arg;
	expbuf_t *buf;
	queue_t *q;
	
	assert(sysdata);
	assert(sysdata->bufpool);
	buf = expbuf_pool_new(sysdata->bufpool, 1024);

	expbuf_print(buf, "Complete data dump\n");

	assert(sysdata->msg_list);
	expbuf_print(buf, "Messages:\n\tMax=%d\n\tActive=%d\n\n", sysdata->msg_max, sysdata->msg_used);

	assert(sysdata->in_buf);
	assert(sysdata->build_buf);
	expbuf_print(buf, "In Buffer size: %d\n", BUF_MAX(sysdata->in_buf));
	expbuf_print(buf, "Build Buffer size: %d\n", BUF_MAX(sysdata->build_buf));

	expbuf_print(buf, "\nEvents:\n");
	expbuf_print(buf, "\tsigint: %s\n",  sysdata->sigint_event  ? "yes" : "no");
	expbuf_print(buf, "\tsighup: %s\n",  sysdata->sighup_event  ? "yes" : "no");
	expbuf_print(buf, "\tsigusr1: %s\n", sysdata->sigusr1_event ? "yes" : "no");
	expbuf_print(buf, "\tsigusr2: %s\n", sysdata->sigusr2_event ? "yes" : "no");

// 	list_t *servers;

// 	list_t *controllers;

// 	list_t *nodelist;

	expbuf_print(buf, "\nQueues:\n");
	assert(sysdata->queues);
	ll_start(sysdata->queues);
	while ((q = ll_next(sysdata->queues))) {
		queue_dump(q, buf);
	}
	ll_finish(sysdata->queues);


	assert(sysdata->logging);
	expbuf_print(buf, "\nLogging:\n");
	expbuf_print(buf, "\tLog Level: %d\n", log_getlevel(sysdata->logging));
  expbuf_print(buf, "\tDump string length: ");
	expbuf_print(buf, "%d\n", BUF_LENGTH(buf));

	logger(sysdata->logging, 1, "%s", expbuf_string(buf));
	expbuf_clear(buf);

	// return the buffer to the pool.
	expbuf_pool_return(sysdata->bufpool, buf);
}
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);
    }
}