Пример #1
0
static void destroy_read_heap (void) /* {{{ */
{
	if (read_heap == NULL)
		return;

	while (42)
	{
		callback_func_t *cf;

		cf = c_heap_get_root (read_heap);
		if (cf == NULL)
			break;

		destroy_callback (cf);
	}

	c_heap_destroy (read_heap);
	read_heap = NULL;
} /* }}} void destroy_read_heap */
Пример #2
0
	gettimeofday(&now, NULL);
	return (now.tv_sec >= timeout.tv_sec && now.tv_usec >= (timeout.tv_nsec / 1000));
}

static void *plugin_read_thread (void __attribute__((unused)) *args)
{
	while (read_loop != 0)
	{
		read_func_t *rf;
		struct timeval now;
		int status;
		int rf_type;
		int rc;

		/* Get the read function that needs to be read next. */
		rf = c_heap_get_root (read_heap);
		if (rf == NULL)
		{
			struct timespec abstime;

			gettimeofday (&now, /* timezone = */ NULL);

			abstime.tv_sec = now.tv_sec + interval_g;
			abstime.tv_nsec = 1000 * now.tv_usec;

			pthread_mutex_lock (&read_lock);
			pthread_cond_timedwait (&read_cond, &read_lock,
					&abstime);
			pthread_mutex_unlock (&read_lock);
			continue;
		}
Пример #3
0
int main (int argc, char **argv) /* {{{ */
{
  int i;
  double last_time;
  int values_sent = 0;

  read_options (argc, argv);

  sigint_action.sa_handler = signal_handler;
  sigaction (SIGINT, &sigint_action, /* old = */ NULL);

  sigterm_action.sa_handler = signal_handler;
  sigaction (SIGTERM, &sigterm_action, /* old = */ NULL);


  values_heap = c_heap_create (compare_time);
  if (values_heap == NULL)
  {
    fprintf (stderr, "c_heap_create failed.\n");
    exit (EXIT_FAILURE);
  }

  net = lcc_network_create ();
  if (net == NULL)
  {
    fprintf (stderr, "lcc_network_create failed.\n");
    exit (EXIT_FAILURE);
  }
  else
  {
    lcc_server_t *srv;

    srv = lcc_server_create (net, conf_destination, conf_service);
    if (srv == NULL)
    {
      fprintf (stderr, "lcc_server_create failed.\n");
      exit (EXIT_FAILURE);
    }

    lcc_server_set_ttl (srv, 42);
#if 0
    lcc_server_set_security_level (srv, ENCRYPT,
        "admin", "password1");
#endif
  }

  fprintf (stdout, "Creating %i values ... ", conf_num_values);
  fflush (stdout);
  for (i = 0; i < conf_num_values; i++)
  {
    lcc_value_list_t *vl;

    vl = create_value_list ();
    if (vl == NULL)
    {
      fprintf (stderr, "create_value_list failed.\n");
      exit (EXIT_FAILURE);
    }

    c_heap_insert (values_heap, vl);
  }
  fprintf (stdout, "done\n");

  last_time = 0;
  while (loop)
  {
    lcc_value_list_t *vl = c_heap_get_root (values_heap);

    if (vl == NULL)
      break;

    if (vl->time != last_time)
    {
      printf ("%i values have been sent.\n", values_sent);

      /* Check if we need to sleep */
      double now = dtime ();

      while (now < vl->time)
      {
        /* 1 / 100 second */
        struct timespec ts = { 0, 10000000 };

        ts.tv_sec = (time_t) now;
        ts.tv_nsec = (long) ((now - ((double) ts.tv_sec)) * 1e9);

        nanosleep (&ts, /* remaining = */ NULL);
        now = dtime ();

        if (!loop)
          break;
      }
      last_time = vl->time;
    }

    send_value (vl);
    values_sent++;

    c_heap_insert (values_heap, vl);
  }

  fprintf (stdout, "Shutting down.\n");
  fflush (stdout);

  while (42)
  {
    lcc_value_list_t *vl = c_heap_get_root (values_heap);
    if (vl == NULL)
      break;
    destroy_value_list (vl);
  }
  c_heap_destroy (values_heap);

  lcc_network_destroy (net);
  exit (EXIT_SUCCESS);
} /* }}} int main */