Пример #1
0
// Cancel a <svc_handler> that was started asynchronously.
template <class SVC_HANDLER, ACE_PEER_CONNECTOR_1> int
ACE_Connector<SVC_HANDLER, ACE_PEER_CONNECTOR_2>::cancel (SVC_HANDLER *sh)
{
  ACE_TRACE ("ACE_Connector<SVC_HANDLER, ACE_PEER_CONNECTOR_2>::cancel");

  ACE_Event_Handler *handler =
    this->reactor ()->find_handler (sh->get_handle ());

  if (handler == 0)
    return -1;

  // find_handler() increments handler's refcount; ensure we decrement it.
  ACE_Event_Handler_var safe_handler (handler);

  NBCH *nbch =
    dynamic_cast<NBCH *> (handler);

  if (nbch == 0)
    return -1;

  SVC_HANDLER *tmp_sh = 0;

  if (nbch->close (tmp_sh) == false)
    return -1;

  return 0;
}
void
closed_in_upcall_event_handler (ACE_Reactor *reactor)
{
  int events = 0;
  int handle_events_result = 0;

  if (test_io)
    {
      Closed_In_Upcall_Event_Handler *handler = 0;
      ACE_NEW (handler, Closed_In_Upcall_Event_Handler (events));

      ACE_Event_Handler_var safe_handler (handler);

      ssize_t send_n_result =
        ACE::send_n (handler->pipe_.write_handle (),
                     message,
                     message_size);

      ACE_ASSERT (send_n_result == message_size);

      int register_handler_result =
        reactor->register_handler (handler->pipe_.read_handle (),
                                   handler,
                                   ACE_Event_Handler::READ_MASK);
      ACE_ASSERT (register_handler_result == 0);

      events += 1;
    }

  while (events > 0)
    {
      handle_events_result =
        reactor->handle_events ();
    }
}
Пример #3
0
template <typename SVC_HANDLER, typename PEER_CONNECTOR> int
ACE_Connector<SVC_HANDLER, PEER_CONNECTOR>::close (void)
{
  // If there are no non-blocking handle pending, return immediately.
  if (this->non_blocking_handles ().size () == 0)
    return 0;

  // Exclusive access to the Reactor.
  ACE_GUARD_RETURN (ACE_Lock, ace_mon, this->reactor ()->lock (), -1);

  // Go through all the non-blocking handles.  It is necessary to
  // create a new iterator each time because we remove from the handle
  // set when we cancel the Svc_Handler.
  ACE_HANDLE *handle = 0;
  while (1)
    {
      ACE_Unbounded_Set_Iterator<ACE_HANDLE>
        iterator (this->non_blocking_handles ());
      if (!iterator.next (handle))
        break;

      ACE_Event_Handler *handler =
        this->reactor ()->find_handler (*handle);
      if (handler == 0)
        {
          ACELIB_ERROR ((LM_ERROR,
                      ACE_TEXT ("%t: Connector::close h %d, no handler\n"),
                      *handle));
          // Remove handle from the set of non-blocking handles.
          this->non_blocking_handles ().remove (*handle);
          continue;
        }

      // find_handler() incremented handler's refcount; ensure it's decremented
      ACE_Event_Handler_var safe_handler (handler);
      NBCH *nbch = dynamic_cast<NBCH *> (handler);
      if (nbch == 0)
        {
          ACELIB_ERROR ((LM_ERROR,
                      ACE_TEXT ("%t: Connector::close h %d handler %@ ")
                      ACE_TEXT ("not a legit handler\n"),
                      *handle,
                      handler));
          // Remove handle from the set of non-blocking handles.
          this->non_blocking_handles ().remove (*handle);
          continue;
        }
      SVC_HANDLER *svc_handler = nbch->svc_handler ();

      // Cancel the non-blocking connection.
      this->cancel (svc_handler);

      // Close the associated Svc_Handler.
      svc_handler->close (NORMAL_CLOSE_OPERATION);
    }

  return 0;
}
int
ACE_Select_Reactor_Notify::notify (ACE_Event_Handler *event_handler,
                                   ACE_Reactor_Mask mask,
                                   ACE_Time_Value *timeout)
{
  ACE_TRACE ("ACE_Select_Reactor_Notify::notify");

  // Just consider this method a "no-op" if there's no
  // <ACE_Select_Reactor> configured.
  if (this->select_reactor_ == 0)
    return 0;

  ACE_Event_Handler_var safe_handler (event_handler);

  if (event_handler)
    {
      event_handler->add_reference ();
    }

  ACE_Notification_Buffer buffer (event_handler, mask);

#if defined (ACE_HAS_REACTOR_NOTIFICATION_QUEUE)
  int const notification_required =
    notification_queue_.push_new_notification(buffer);

  if (notification_required == -1)
    {
      return -1;
    }

  if (notification_required == 0)
    {
      // No failures, the handler is now owned by the notification queue
      safe_handler.release ();

      return 0;
    }
#endif /* ACE_HAS_REACTOR_NOTIFICATION_QUEUE */

  ssize_t const n = ACE::send (this->notification_pipe_.write_handle (),
                               (char *) &buffer,
                               sizeof buffer,
                               timeout);
  if (n == -1)
    {
      return -1;
    }

  // No failures.
  safe_handler.release ();

  return 0;
}
Пример #5
0
template <class SVC_HANDLER, ACE_PEER_CONNECTOR_1> int
ACE_Connector<SVC_HANDLER, ACE_PEER_CONNECTOR_2>::close (void)
{
  // If there are no non-blocking handle pending, return immediately.
  if (this->non_blocking_handles ().num_set () == 0)
    return 0;

  // Exclusive access to the Reactor.
  ACE_GUARD_RETURN (ACE_Lock, ace_mon, this->reactor ()->lock (), -1);

  // Go through all the non-blocking handles.  It is necessary to
  // create a new iterator each time because we remove from the handle
  // set when we cancel the Svc_Handler.
  while (1)
    {
      ACE_Handle_Set_Iterator iterator (this->non_blocking_handles ());
      ACE_HANDLE handle = iterator ();

      if (handle == ACE_INVALID_HANDLE)
        break;

      ACE_Event_Handler *handler =
        this->reactor ()->find_handler (handle);

      ACE_ASSERT (handler != 0);

      ACE_Event_Handler_var safe_handler (handler);

      NBCH *nbch =
        ACE_dynamic_cast (NBCH *, handler);

      ACE_ASSERT (nbch != 0);

      SVC_HANDLER *svc_handler =
        nbch->svc_handler ();

      // Cancel the non-blocking connection.
      this->cancel (svc_handler);

      // Close the associated Svc_Handler.
      svc_handler->close (0);
    }

  return 0;
}
void
expire (ACE_Timer_Queue &timer_queue,
        Expire_Function expire_function)
{
  int events = 0;
  int result = 0;

  Reference_Counted_Event_Handler *handler =
    new Reference_Counted_Event_Handler (1);

  ACE_Event_Handler_var safe_handler (handler);

  long timer_id =
    timer_queue.schedule (handler,
                          one_second_timeout,
                          ACE_Time_Value (1) + timer_queue.gettimeofday (),
                          ACE_Time_Value (1));
  ACE_ASSERT (timer_id != -1);

  result =
    timer_queue.schedule (handler,
                          two_second_timeout,
                          ACE_Time_Value (2) + timer_queue.gettimeofday ());
  ACE_ASSERT (result != -1);

  events += 4;

  for (int i = 0; i < events;)
    {
      WAIT_FOR_NEXT_EVENT (timer_queue);

      result =
        expire_function (timer_queue);

      ACE_ASSERT (result >= 0);

      i += result;
    }

  timer_queue.cancel (timer_id, 0, 0);
}
Пример #7
0
// Cancel a <svc_handler> that was started asynchronously.
template <class SVC_HANDLER, ACE_PEER_CONNECTOR_1> int
ACE_Connector<SVC_HANDLER, ACE_PEER_CONNECTOR_2>::cancel (SVC_HANDLER *sh)
{
  ACE_TRACE ("ACE_Connector<SVC_HANDLER, ACE_PEER_CONNECTOR_2>::cancel");

  ACE_Event_Handler *handler =
    this->reactor ()->find_handler (sh->get_handle ());

  if (handler == 0)
    return -1;

  ACE_Event_Handler_var safe_handler (handler);

  NBCH *nbch =
    ACE_dynamic_cast (NBCH *, handler);

  if (nbch == 0)
    return -1;

  nbch->close ();

  return 0;
}
Пример #8
0
    void
    PublisherListener::on_offered_deadline_missed (
      ::DDS::DataWriter_ptr the_Writer,
      const ::DDS::OfferedDeadlineMissedStatus & status)
    {
      DDS4CCM_TRACE ("CIAO::DDS4CCM::PublisherListener::on_offered_deadline_missed");

      DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_DDS_STATUS, (LM_DEBUG, DDS4CCM_INFO
                    ACE_TEXT ("PublisherListener::on_offered_deadline_missed: ")
                    ACE_TEXT ("total count <%d> - count change <%d> - ")
                    ACE_TEXT ("last instance handle ")
                    DDS_INSTANCE_HANDLE_FORMAT_SPECIFIER ACE_TEXT ("\n"),
                    status.total_count, status.total_count_change,
                    DDS_INSTANCE_HANDLE_LOG (status.last_instance_handle)));

      if (! ::CORBA::is_nil (this->error_listener_))
        {
          try
            {
              if (this->reactor_)
                {
                  ::CIAO::DDS4CCM::OnOfferedDeadlineMissedHandler* rh = 0;
                  ACE_NEW (rh,
                          ::CIAO::DDS4CCM::OnOfferedDeadlineMissedHandler (
                            this->error_listener_, the_Writer, status));
                  ACE_Event_Handler_var safe_handler (rh);
                  if (this->reactor_->notify (rh) != 0)
                    {
                      DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
                                    ACE_TEXT ("PublisherListener::on_offered_deadline_missed - ")
                                    ACE_TEXT ("failed to use reactor.\n")));
                    }
                }
              else
                {
                  this->error_listener_->on_offered_deadline_missed (the_Writer, status);
                }
            }
          catch (const ::CORBA::BAD_INV_ORDER& ex)
            {
              DDS4CCM_PRINT_DEBUG_CORBA_EXCEPTION (
                                      DDS4CCM_LOG_LEVEL_ACTION,
                                      ex,
                                      "PublisherListener::on_offered_deadline_missed");
            }
          catch (const ::CORBA::Exception& ex)
            {
              DDS4CCM_PRINT_CORBA_EXCEPTION (
                                      DDS4CCM_LOG_LEVEL_ERROR,
                                      ex,
                                      "PublisherListener::on_offered_deadline_missed");
            }
          catch (...)
            {
              DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
                "PublisherListener::on_offered_deadline_missed - "
                "Unexpected exception caught\n"));
            }
        }
      else
        {
          DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION, (LM_DEBUG, DDS4CCM_INFO
                        ACE_TEXT ("PublisherListener::on_offered_deadline_missed: ")
                        ACE_TEXT ("No error listener connected\n")));
        }
    }
Пример #9
0
    void
    PublisherListener::on_offered_incompatible_qos (
      ::DDS::DataWriter_ptr the_Writer,
      const ::DDS::OfferedIncompatibleQosStatus & status)
    {
      DDS4CCM_TRACE ("CIAO::DDS4CCM::PublisherListener::on_offered_incompatible_qos");

      DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_DDS_STATUS, (LM_DEBUG, DDS4CCM_INFO
                    ACE_TEXT ("PublisherListener::on_offered_incompatible_qos: ")
                    ACE_TEXT ("total count <%d> - total change <%d> - ")
                    ACE_TEXT ("last policy id <%C> - policies:\n"),
                    status.total_count, status.total_count_change,
                    translate_qospolicyid_t (status.last_policy_id)));
      for (CORBA::ULong i = 0; i < status.policies.length (); ++i)
        {
          DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_DDS_STATUS, (LM_DEBUG, DDS4CCM_INFO
                      ACE_TEXT ("\t\tid <%C> - count <%d>\n"),
                      translate_qospolicyid_t (status.policies[i].policy_id),
                      status.policies[i].count));
        }

      if (! ::CORBA::is_nil (this->error_listener_))
        {
          try
            {
              if (this->reactor_)
                {
                  ::CIAO::DDS4CCM::OnOfferedIncompatibleQoSHandler* rh = 0;
                  ACE_NEW (rh,
                          ::CIAO::DDS4CCM::OnOfferedIncompatibleQoSHandler (
                            this->error_listener_, the_Writer, status));
                  ACE_Event_Handler_var safe_handler (rh);
                  if (this->reactor_->notify (rh) != 0)
                    {
                      DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
                                    ACE_TEXT ("PublisherListener::on_offered_incompatible_qos - ")
                                    ACE_TEXT ("failed to use reactor.\n")));
                    }
                }
              else
                {
                  this->error_listener_->on_offered_incompatible_qos (the_Writer, status);
                }
            }
          catch (const ::CORBA::BAD_INV_ORDER& ex)
            {
              DDS4CCM_PRINT_DEBUG_CORBA_EXCEPTION (
                                      DDS4CCM_LOG_LEVEL_ACTION,
                                      ex,
                                      "PublisherListener::on_offered_incompatible_qos");
            }
          catch (const ::CORBA::Exception& ex)
            {
              DDS4CCM_PRINT_CORBA_EXCEPTION (
                                      DDS4CCM_LOG_LEVEL_ERROR,
                                      ex,
                                      "PublisherListener::on_offered_incompatible_qos");
            }
          catch (...)
            {
              DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
                "PublisherListener::on_offered_incompatible_qos - "
                "Unexpected exception caught\n"));
            }
        }
      else
        {
          DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION, (LM_DEBUG, DDS4CCM_INFO
                        ACE_TEXT ("PublisherListener::on_offered_incompatible_qos - ")
                        ACE_TEXT ("No error listener connected\n")));
        }
    }
Пример #10
0
    void
    PortStatusListener::on_sample_lost (
        ::DDS::DataReader_ptr the_reader,
         const ::DDS::SampleLostStatus & status)
    {
      DDS4CCM_TRACE ("CIAO::DDS4CCM::PortStatusListener::on_sample_lost");

      DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_DDS_STATUS, (LM_DEBUG, DDS4CCM_INFO
          ACE_TEXT ("PortStatusListener::on_sample_lost: ")
      ACE_TEXT ("total count <%d> - total change <%d>\n"),
      status.total_count, status.total_count_change));

      if (! ::CORBA::is_nil (this->port_status_listener_.in ()))
        {
          try
            {
              if (this->reactor_)
                {
                  ::CIAO::DDS4CCM::OnSampleLostHandler* rh = 0;
                  ACE_NEW (rh,
                      ::CIAO::DDS4CCM::OnSampleLostHandler (
                          this->port_status_listener_.in (),
                          the_reader,
                          status));
                  ACE_Event_Handler_var safe_handler (rh);
                  if (this->reactor_->notify (rh) != 0)
                    {
                      DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
                          ACE_TEXT ("PortStatusListener::on_sample_lost: ")
                      ACE_TEXT ("failed to use reactor.\n")));
                    }
                }
              else
                {
                  this->port_status_listener_->on_sample_lost (the_reader, status);
                }
            }
          catch (const ::CORBA::BAD_INV_ORDER& ex)
            {
              DDS4CCM_PRINT_DEBUG_CORBA_EXCEPTION (
                                      DDS4CCM_LOG_LEVEL_ACTION,
                                      ex,
                                      "PortStatusListener::on_sample_lost");
            }
          catch (const ::CORBA::Exception& ex)
            {
              DDS4CCM_PRINT_CORBA_EXCEPTION (
                  DDS4CCM_LOG_LEVEL_ERROR,
                  ex,
                  "PortStatusListener::on_sample_lost");
            }
          catch (...)
            {
              DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
                  "PortStatusListener::on_sample_lost - "
                  "Unexpected exception caught\n"));
            }
        }
      else
        {
          DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION, (LM_DEBUG,
              ACE_TEXT ("PortStatusListener::on_sample_lost: ")
              ACE_TEXT ("No portstatus listener installed\n")));
        }
    }
Пример #11
0
    void
    TopicListener::on_inconsistent_topic (
        ::DDS::Topic_ptr the_topic,
         const ::DDS::InconsistentTopicStatus & status)
    {
      DDS4CCM_TRACE ("CIAO::DDS4CCM::TopicListener::on_inconsistent_topic");

      DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_DDS_STATUS, (LM_DEBUG, DDS4CCM_INFO
          ACE_TEXT ("TopicListener::on_inconsistent_topic: ")
      ACE_TEXT ("total count <%d> - total change <%d> - "),
      status.total_count, status.total_count_change));

      if (! ::CORBA::is_nil (this->error_listener_.in ()))
        {
          try
          {
              if (this->reactor_)
                {
                  ::CIAO::DDS4CCM::OnInconsistentTopicHandler* rh = 0;
                  ACE_NEW (rh,
                      ::CIAO::DDS4CCM::OnInconsistentTopicHandler (
                          this->error_listener_,
                          the_topic,
                          status));
                  ACE_Event_Handler_var safe_handler (rh);
                  if (this->reactor_->notify (rh) != 0)
                    {
                      DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
                          ACE_TEXT ("TopicListener::on_inconsistent_topic - ")
                      ACE_TEXT ("failed to use reactor.\n")));
                    }
                }
              else
                {
                  this->error_listener_->on_inconsistent_topic (the_topic, status);
                }
          }
          catch (const ::CORBA::BAD_INV_ORDER& ex)
            {
              DDS4CCM_PRINT_DEBUG_CORBA_EXCEPTION (
                                      DDS4CCM_LOG_LEVEL_ACTION,
                                      ex,
                                      "TopicListener::on_inconsistent_topic");
            }
          catch (const ::CORBA::Exception& ex)
            {
                DDS4CCM_PRINT_CORBA_EXCEPTION (
                    DDS4CCM_LOG_LEVEL_ERROR,
                    ex,
                    "TopicListener::on_inconsistent_topic");
            }
          catch (...)
            {
                DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
                    "TopicListener::on_inconsistent_topic - "
                    "Unexpected exception caught\n"));
            }
        }
      else
        {
          DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION, (LM_DEBUG, DDS4CCM_INFO
              ACE_TEXT ("TopicListener::on_inconsistent_topic - ")
          ACE_TEXT ("No error listener connected\n")));
        }
    }
Пример #12
0
    void
    SubscriberListener::on_sample_rejected (
        ::DDS::DataReader_ptr reader,
         const ::DDS::SampleRejectedStatus& status)
    {
      DDS4CCM_TRACE ("CIAO::DDS4CCM::SubscriberListener::on_sample_rejected");

      DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_DDS_STATUS, (LM_DEBUG, DDS4CCM_INFO
          ACE_TEXT ("SubscriberListener::on_sample_rejected: ")
          ACE_TEXT ("total count <%d> - count change <%d> - ")
          ACE_TEXT ("last reason <%C> - last instance handle ")
          DDS_INSTANCE_HANDLE_FORMAT_SPECIFIER ACE_TEXT ("\n"),
          status.total_count, status.total_count_change,
          translate_rejectedstatuskind (status.last_reason),
          DDS_INSTANCE_HANDLE_LOG (status.last_instance_handle)));

      if (! ::CORBA::is_nil (this->error_listener_))
        {
          try
            {
              if (this->reactor_)
                {
                  ::CIAO::DDS4CCM::OnSampleRejectedHandler* rh = 0;
                  ACE_NEW (rh,
                      ::CIAO::DDS4CCM::OnSampleRejectedHandler (
                          this->error_listener_, reader, status));
                  ACE_Event_Handler_var safe_handler (rh);
                  if (this->reactor_->notify (rh) != 0)
                    {
                      DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
                          ACE_TEXT ("SubscriberListener::on_sample_rejected - ")
                      ACE_TEXT ("failed to use reactor.\n")));
                    }
                }
              else
                {
                  this->error_listener_->on_sample_rejected (reader, status);
                }
            }
          catch (const ::CORBA::BAD_INV_ORDER& ex)
            {
              DDS4CCM_PRINT_DEBUG_CORBA_EXCEPTION (
                                      DDS4CCM_LOG_LEVEL_ACTION,
                                      ex,
                                      "SubscriberListener::on_sample_rejected");
            }
          catch (const ::CORBA::Exception& ex)
            {
              DDS4CCM_PRINT_CORBA_EXCEPTION (
                  DDS4CCM_LOG_LEVEL_ERROR,
                  ex,
                  "SubscriberListener::on_sample_rejected");
            }
          catch (...)
            {
              DDS4CCM_ERROR (DDS4CCM_LOG_LEVEL_ERROR, (LM_ERROR, DDS4CCM_INFO
                  "SubscriberListener::on_sample_rejected - "
                  "Unexpected exception caught\n"));
            }
        }
      else
        {
          DDS4CCM_DEBUG (DDS4CCM_LOG_LEVEL_ACTION, (LM_DEBUG, DDS4CCM_INFO
              ACE_TEXT ("SubscriberListener::on_sample_rejected - ")
          ACE_TEXT ("No error listener connected\n")));
        }
    }
void
cancellation (ACE_Timer_Queue &timer_queue,
              int repeat_timer,
              int cancel_handler,
              int second_timer,
              int dont_call_handle_close)
{
  int result = 0;

  int expected_number_of_handle_close_calls = -1;

  if (!dont_call_handle_close)
    {
      if (cancel_handler)
        expected_number_of_handle_close_calls = 1;
      else if (second_timer)
        expected_number_of_handle_close_calls = 2;
      else
        expected_number_of_handle_close_calls = 1;
    }

  Reference_Counted_Event_Handler *handler =
    new Reference_Counted_Event_Handler (expected_number_of_handle_close_calls);

  ACE_Event_Handler_var safe_handler (handler);

  long first_timer_id = -1;
  long second_timer_id = -1;

  if (repeat_timer)
    {
      first_timer_id =
        timer_queue.schedule (handler,
                              one_second_timeout,
                              ACE_Time_Value (1) + timer_queue.gettimeofday (),
                              ACE_Time_Value (1));
      ACE_ASSERT (first_timer_id != -1);
    }
  else
    {
      first_timer_id =
        timer_queue.schedule (handler,
                              one_second_timeout,
                              ACE_Time_Value (1) + timer_queue.gettimeofday ());
      ACE_ASSERT (first_timer_id != -1);
    }

  if (second_timer)
    {
      second_timer_id =
        timer_queue.schedule (handler,
                              two_second_timeout,
                              ACE_Time_Value (2) + timer_queue.gettimeofday (),
                              ACE_Time_Value (2));
      ACE_ASSERT (second_timer_id != -1);
    }

  if (cancel_handler)
    {
      result =
        timer_queue.cancel (handler,
                            dont_call_handle_close);

      if (second_timer)
        ACE_ASSERT (result == 2);
      else
        ACE_ASSERT (result == 1);
    }
  else
    {
      result =
        timer_queue.cancel (first_timer_id,
                            0,
                            dont_call_handle_close);
      ACE_ASSERT (result == 1);

      if (second_timer)
        {
          result =
            timer_queue.cancel (second_timer_id,
                                0,
                                dont_call_handle_close);
          ACE_ASSERT (result == 1);
        }
    }
}
void
reference_counted_event_handler_test_2 (ACE_Reactor *reactor)
{
  int events = 0;
  int result = 0;
  ACE_Time_Value const one_second (1);

  if (test_find)
    {
      Reference_Counted_Event_Handler *handler =
        new Reference_Counted_Event_Handler (events);

      ACE_Event_Handler_var safe_handler (handler);

      result =
        reactor->register_handler (handler->pipe_.read_handle (),
                                   handler,
                                   ACE_Event_Handler::READ_MASK);
      ACE_ASSERT (result == 0);

      {
        ACE_Event_Handler *result_handler = 0;

        result =
          reactor->handler (handler->pipe_.read_handle (),
                            ACE_Event_Handler::READ_MASK,
                            &result_handler);
        ACE_Event_Handler_var safe_result_handler (result_handler);

        ACE_ASSERT (result == 0);
        ACE_ASSERT (result_handler == handler);
      }

      {
        ACE_Event_Handler *result_handler = 0;

        result =
          reactor->handler (handler->pipe_.read_handle (),
                            ACE_Event_Handler::WRITE_MASK,
                            &result_handler);
        ACE_Event_Handler_var safe_result_handler (result_handler);

        ACE_ASSERT (result == -1);
      }

      {
        ACE_Event_Handler_var result_handler =
          reactor->find_handler (handler->pipe_.read_handle ());

        ACE_ASSERT (result_handler.handler () == handler);
      }
    }

  if (test_io)
    {
      Reference_Counted_Event_Handler *handler =
        new Reference_Counted_Event_Handler (events);

      ACE_Event_Handler_var safe_handler (handler);

      result =
        reactor->register_handler (handler->pipe_.read_handle (),
                                   handler,
                                   ACE_Event_Handler::READ_MASK);
      ACE_ASSERT (result == 0);

      result =
        reactor->register_handler (handler->pipe_.write_handle (),
                                   handler,
                                   ACE_Event_Handler::WRITE_MASK);
      ACE_ASSERT (result == 0);

      events += 2;
    }

  if (test_timers)
    {
      Reference_Counted_Event_Handler *handler =
        new Reference_Counted_Event_Handler (events);

      ACE_Event_Handler_var safe_handler (handler);

      long timer_id =
        reactor->schedule_timer (handler,
                                 one_second_timeout,
                                 one_second,
                                 one_second);
      ACE_ASSERT (timer_id != -1);

      result =
        reactor->cancel_timer (timer_id,
                               0,
                               0);
      ACE_ASSERT (result == 1);
    }

  if (test_timers)
    {
      Reference_Counted_Event_Handler *handler =
        new Reference_Counted_Event_Handler (events);

      ACE_Event_Handler_var safe_handler (handler);

      long timer_id =
        reactor->schedule_timer (handler,
                                 one_second_timeout,
                                 one_second,
                                 one_second);
      ACE_ASSERT (timer_id != -1);

      ACE_Time_Value const two_second (2);
      timer_id =
        reactor->schedule_timer (handler,
                                 two_second_timeout,
                                 two_second);
      ACE_ASSERT (result != -1);

      events += 3;
    }

  while (events > 0)
    {
      result =
        reactor->handle_events ();
    }
}