Wait_On_Read.cpp

Go to the documentation of this file.
00001 // Wait_On_Read.cpp,v 1.22 2006/06/20 06:02:15 jwillemsen Exp
00002 
00003 #include "tao/Wait_On_Read.h"
00004 #include "tao/Transport.h"
00005 #include "tao/Resume_Handle.h"
00006 #include "tao/Synch_Reply_Dispatcher.h"
00007 #include "tao/Client_Strategy_Factory.h"
00008 #include "tao/ORB_Core.h"
00009 #include "ace/Reactor.h"
00010 #include "ace/Countdown_Time.h"
00011 
00012 ACE_RCSID (tao,
00013            Wait_On_Read,
00014            "Wait_On_Read.cpp,v 1.22 2006/06/20 06:02:15 jwillemsen Exp")
00015 
00016 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00017 
00018 // Constructor.
00019 TAO_Wait_On_Read::TAO_Wait_On_Read (TAO_Transport *transport)
00020   : TAO_Wait_Strategy (transport)
00021 {
00022 }
00023 
00024 // Destructor.
00025 TAO_Wait_On_Read::~TAO_Wait_On_Read (void)
00026 {
00027 }
00028 
00029 /*
00030  * Hook to specialize the wait strategy when the concrete strategy is
00031  * a simple "rw" strategy. Add all public/protected/private methods
00032  * within the *COPY* hooks.
00033  */
00034 
00035 //@@ WAIT_STRATEGY_SPL_COPY_HOOK_START
00036 
00037 // Wait on the read operation.
00038 int
00039 TAO_Wait_On_Read::wait (ACE_Time_Value * max_wait_time,
00040                         TAO_Synch_Reply_Dispatcher &rd)
00041 {
00042   // Start the count down timer to account for the time spent in this
00043   // method.
00044   ACE_Countdown_Time countdown (max_wait_time);
00045 
00046   rd.state_changed (TAO_LF_Event::LFS_ACTIVE,
00047                     this->transport_->orb_core ()->leader_follower ());
00048 
00049   // Do the same sort of looping that is done in other wait
00050   // strategies.
00051   int retval = 0;
00052   TAO_Resume_Handle rh;
00053   while (1)
00054     {
00055       retval =
00056         this->transport_->handle_input (rh,
00057                                         max_wait_time,
00058                                         1);
00059 
00060       // If we got our reply, no need to run the loop any
00061       // further.
00062       if (!rd.keep_waiting ())
00063         break;
00064 
00065       // @@ We are not checking for timeouts here...
00066 
00067       // If we got an error just break
00068       if (retval == -1)
00069         break;
00070     }
00071 
00072   if (rd.error_detected () == -1 || retval == -1)
00073     {
00074       this->transport_->close_connection ();
00075     }
00076 
00077   if (rd.successful ())
00078      {
00079        TAO_ORB_Core *oc =
00080          this->transport_->orb_core ();
00081 
00082        if (!oc->client_factory ()->use_cleanup_options ())
00083          return 0;
00084 
00085        if (TAO_debug_level > 0)
00086          ACE_DEBUG ((LM_DEBUG,
00087                      ACE_TEXT ("TAO (%P|%t) - TAO_Wait_On_Read[%d]::wait (), ")
00088                      ACE_TEXT ("registering handle for cleanup \n"),
00089                      this->transport_->id ()));
00090 
00091        ACE_Event_Handler * const eh =
00092          this->transport_->event_handler_i ();
00093 
00094        ACE_Reactor * const r =
00095          this->transport_->orb_core ()->reactor ();
00096 
00097        if (r->register_handler (eh,
00098                                 ACE_Event_Handler::READ_MASK) == -1)
00099          {
00100            if (TAO_debug_level > 0)
00101              ACE_ERROR ((LM_ERROR,
00102                          ACE_TEXT ("TAO (%P|%t) - TAO_Wait_On_Read[%d]::wait (), ")
00103                         ACE_TEXT ("registration with reactor returned an error \n"),
00104                          this->transport_->id ()));
00105         }
00106 
00107        this->is_registered_ = true;
00108 
00109        return 0;
00110      }
00111 
00112   if (rd.error_detected ())
00113     return -1;
00114 
00115   return 1;
00116 }
00117 
00118 // No-op.
00119 int
00120 TAO_Wait_On_Read::register_handler (void)
00121 {
00122   return 0;
00123 }
00124 
00125 bool
00126 TAO_Wait_On_Read::non_blocking (void) const
00127 {
00128   return false;
00129 }
00130 
00131 bool
00132 TAO_Wait_On_Read::can_process_upcalls (void) const
00133 {
00134   return true;
00135 }
00136 
00137 //@@ WAIT_STRATEGY_SPL_COPY_HOOK_END
00138 /*
00139  * End copy hook.
00140  */
00141 
00142 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 11:54:28 2006 for TAO by doxygen 1.3.6