Пример #1
0
int
TAO_Wait_On_Reactor::wait (ACE_Time_Value *max_wait_time,
                           TAO_Synch_Reply_Dispatcher &rd)
{
  // Start the count down timer to account for the time spent in this
  // method.
  TAO::ORB_Countdown_Time countdown (max_wait_time);

  // Reactor does not change inside the loop.
  ACE_Reactor *const reactor =
    this->transport_->orb_core ()->reactor ();

  TAO_Leader_Follower &leader_follower =
    this->transport_->orb_core ()->leader_follower ();

  // Do the event loop, till we fully receive a reply.
  int result = 0;

  while (1)
    {
      // Run the event loop.
      result = reactor->handle_events (max_wait_time);

      // If we got our reply, no need to run the event loop any
      // further.
      if (!rd.keep_waiting (leader_follower))
        {
          break;
        }

      // Did we timeout? If so, stop running the loop.
      if (result == 0
          && max_wait_time != 0
          && *max_wait_time == ACE_Time_Value::zero)
        {
          break;
        }

      // Other errors? If so, stop running the loop.
      if (result == -1)
        {
          break;
        }

      // Otherwise, keep going...
    }

  if (result == -1 || rd.error_detected (leader_follower))
    {
      return -1;
    }

  // Return an error if there was a problem receiving the reply.
  if (max_wait_time != 0)
    {
      if (rd.successful (leader_follower) && *max_wait_time == ACE_Time_Value::zero)
        {
          result = -1;
          errno = ETIME;
        }
    }
  else
    {
      result = 0;

      if (rd.error_detected (leader_follower))
        {
          result = -1;
        }
    }

  return result;
}
Пример #2
0
// Wait on the read operation.
int
TAO_Wait_On_Read::wait (ACE_Time_Value * max_wait_time,
                        TAO_Synch_Reply_Dispatcher &rd)
{
  // Start the count down timer to account for the time spent in this
  // method.
  TAO::ORB_Countdown_Time countdown (max_wait_time);

  rd.state_changed (TAO_LF_Event::LFS_ACTIVE,
                    this->transport_->orb_core ()->leader_follower ());

  // Do the same sort of looping that is done in other wait
  // strategies.
  int retval = 0;
  TAO_Resume_Handle rh;
  while (1)
    {
      retval = this->transport_->handle_input (rh, max_wait_time);

      // If we got our reply, no need to run the loop any
      // further.
      if (!rd.keep_waiting ())
        break;

      // @@ We are not checking for timeouts here...

      // If we got an error just break
      if (retval == -1)
        break;
    }

  if (rd.error_detected () == -1 || retval == -1)
    {
      this->transport_->close_connection ();
    }

  if (rd.successful ())
     {
       TAO_ORB_Core * const oc =
         this->transport_->orb_core ();

       if (!oc->client_factory ()->use_cleanup_options ())
         return 0;

       if (TAO_debug_level > 0)
         TAOLIB_DEBUG ((LM_DEBUG,
                     ACE_TEXT ("TAO (%P|%t) - Wait_On_Read[%d]::wait (), ")
                     ACE_TEXT ("registering handle for cleanup\n"),
                     this->transport_->id ()));

       ACE_Event_Handler * const eh =
         this->transport_->event_handler_i ();

       ACE_Reactor * const r =
         this->transport_->orb_core ()->reactor ();

       if (r->register_handler (eh,
                                ACE_Event_Handler::READ_MASK) == -1)
         {
           if (TAO_debug_level > 0)
             TAOLIB_ERROR ((LM_ERROR,
                         ACE_TEXT ("TAO (%P|%t) - Wait_On_Read[%d]::wait (), ")
                         ACE_TEXT ("registration with reactor returned an error\n"),
                         this->transport_->id ()));
        }
       else
        {
          // Only set this flag when registration succeeds
          this->is_registered_ = true;
        }

       return 0;
     }

  if (rd.error_detected ())
    return -1;

  return 1;
}