00001 // $Id: Wait_On_Reactor.cpp 76593 2007-01-25 19:19:27Z johnnyw $ 00002 00003 #include "tao/Wait_On_Reactor.h" 00004 #include "tao/ORB_Core.h" 00005 #include "tao/Transport.h" 00006 #include "tao/Synch_Reply_Dispatcher.h" 00007 00008 #include "ace/Reactor.h" 00009 #include "ace/Countdown_Time.h" 00010 00011 ACE_RCSID (tao, 00012 Wait_On_Reactor, 00013 "$Id: Wait_On_Reactor.cpp 76593 2007-01-25 19:19:27Z johnnyw $") 00014 00015 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00016 00017 TAO_Wait_On_Reactor::TAO_Wait_On_Reactor (TAO_Transport *transport) 00018 : TAO_Wait_Strategy (transport) 00019 { 00020 } 00021 00022 TAO_Wait_On_Reactor::~TAO_Wait_On_Reactor (void) 00023 { 00024 } 00025 00026 int 00027 TAO_Wait_On_Reactor::wait (ACE_Time_Value *max_wait_time, 00028 TAO_Synch_Reply_Dispatcher &rd) 00029 { 00030 // Start the count down timer to account for the time spent in this 00031 // method. 00032 ACE_Countdown_Time countdown (max_wait_time); 00033 00034 // Reactor does not change inside the loop. 00035 ACE_Reactor *const reactor = 00036 this->transport_->orb_core ()->reactor (); 00037 00038 // Do the event loop, till we fully receive a reply. 00039 int result = 0; 00040 00041 while (1) 00042 { 00043 // Run the event loop. 00044 result = reactor->handle_events (max_wait_time); 00045 00046 // If we got our reply, no need to run the event loop any 00047 // further. 00048 if (!rd.keep_waiting ()) 00049 { 00050 break; 00051 } 00052 00053 // Did we timeout? If so, stop running the loop. 00054 if (result == 0 00055 && max_wait_time != 0 00056 && *max_wait_time == ACE_Time_Value::zero) 00057 { 00058 break; 00059 } 00060 00061 // Other errors? If so, stop running the loop. 00062 if (result == -1) 00063 { 00064 break; 00065 } 00066 00067 // Otherwise, keep going... 00068 } 00069 00070 if (result == -1 || rd.error_detected ()) 00071 { 00072 return -1; 00073 } 00074 00075 // Return an error if there was a problem receiving the reply. 00076 if (max_wait_time != 0) 00077 { 00078 if (rd.successful () && *max_wait_time == ACE_Time_Value::zero) 00079 { 00080 result = -1; 00081 errno = ETIME; 00082 } 00083 } 00084 else 00085 { 00086 result = 0; 00087 00088 if (rd.error_detected ()) 00089 { 00090 result = -1; 00091 } 00092 } 00093 00094 return result; 00095 } 00096 00097 // Register the handler with the Reactor. 00098 int 00099 TAO_Wait_On_Reactor::register_handler (void) 00100 { 00101 if (!this->is_registered_) 00102 { 00103 return this->transport_->register_handler (); 00104 } 00105 00106 return 1; 00107 } 00108 00109 bool 00110 TAO_Wait_On_Reactor::non_blocking (void) const 00111 { 00112 return true; 00113 } 00114 00115 bool 00116 TAO_Wait_On_Reactor::can_process_upcalls (void) const 00117 { 00118 return true; 00119 } 00120 00121 TAO_END_VERSIONED_NAMESPACE_DECL