Example #1
0
int
Timer::handle_timeout(ACE_Time_Value const &, void const *)
{
  if (iteration_ == 0)
    {
      send_data_through_handlers();
    }

  ++iteration_;
  if (iteration_ < initial_iterations)
    {
      return 0;
    }

  if (iteration_ == initial_iterations)
    {
      remove_some_handlers();
      recorded_count_  = special_handler().handle_input_count();
      return 0;
    }

  if (iteration_ < total_iterations)
    {
      return 0;
    }

  reactor()->end_reactor_event_loop();

  return 0;
}
int Timer::handle_timeout(ACE_Time_Value const &, void const *)
{
    if (iteration_ == 0)
    {
      // Sending data on the first iteration makes the handles always
      // "ready" for reading because the Handler::handle_input() function
      // never consumes the data.
      send_data_through_handlers();
    }

    ++iteration_;
    if (iteration_ < initial_iterations)
    {
      // The first iterations are there just to prime things.
      return 0;
    }
    
    if (iteration_ == initial_iterations)
    {
      // We expect the special_handler() to work normally after this
      // iteration, i.e., more calls to handle_input() should be delivered
      // to it.
      recorded_count_  = special_handler().handle_input_count();

      // Remove the handlers the next time the loop runs
      remove_some_handlers();

      // Run the event loop, this causes the handlers to be removed from the
      // reactor, except for special_handler()
      ACE_Time_Value interval(0, ACE_ONE_SECOND_IN_USECS / 50);
      reactor()->handle_events(&interval);

      return 0;
    }

    if (iteration_ < total_iterations)
    {
      // Run a while more to make sure the special_handler() is used.
      return 0;
    }

    reactor()->end_reactor_event_loop();

    return 0;
}