Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / Wait_On_Read.cpp
blob92bcdba84676fb56f7e814d24bb1d8c71de173cf
1 #include "tao/Wait_On_Read.h"
2 #include "tao/Transport.h"
3 #include "tao/Resume_Handle.h"
4 #include "tao/Synch_Reply_Dispatcher.h"
5 #include "tao/Client_Strategy_Factory.h"
6 #include "tao/ORB_Core.h"
7 #include "tao/ORB_Time_Policy.h"
8 #include "ace/Reactor.h"
10 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
12 // Constructor.
13 TAO_Wait_On_Read::TAO_Wait_On_Read (TAO_Transport *transport)
14 : TAO_Wait_Strategy (transport)
18 int
19 TAO_Wait_On_Read::sending_request (TAO_ORB_Core *orb_core,
20 TAO_Message_Semantics msg_semantics)
22 if ((this->transport_->opened_as () == TAO::TAO_CLIENT_ROLE) &&
23 (this->transport_->bidirectional_flag () == -1))
25 // register the transport for event handling in case of AMI requests because
26 // for these requests explicitly require event handling.
27 if (msg_semantics.type_ == TAO_Message_Semantics::TAO_ONEWAY_REQUEST &&
28 msg_semantics.mode_ == TAO_Message_Semantics::TAO_ASYNCH_CALLBACK)
30 // Register the handler unless already registered (should never happen).
31 if (!this->is_registered_)
33 this->transport_->register_handler ();
38 // Send the request.
39 return this->TAO_Wait_Strategy::sending_request (orb_core, msg_semantics);
42 void
43 TAO_Wait_On_Read::finished_request ()
45 if ((this->transport_->opened_as () == TAO::TAO_CLIENT_ROLE) &&
46 (this->transport_->bidirectional_flag () == -1))
48 // ORB finished request handling so if the transport was registered for
49 // an AMI call, deregister it now
50 if (!this->transport_->orb_core ()->client_factory ()->use_cleanup_options () &&
51 this->is_registered_)
53 this->transport_->remove_handler ();
57 this->TAO_Wait_Strategy::finished_request ();
60 // Wait on the read operation.
61 int
62 TAO_Wait_On_Read::wait (ACE_Time_Value * max_wait_time,
63 TAO_Synch_Reply_Dispatcher &rd)
65 // Start the count down timer to account for the time spent in this
66 // method.
67 TAO::ORB_Countdown_Time countdown (max_wait_time);
69 TAO_Leader_Follower &leader_follower =
70 this->transport_->orb_core ()->leader_follower ();
72 rd.state_changed (TAO_LF_Event::LFS_ACTIVE, leader_follower);
74 // Do the same sort of looping that is done in other wait
75 // strategies.
76 int retval = 0;
77 TAO_Resume_Handle rh;
78 while (1)
80 retval = this->transport_->handle_input (rh, max_wait_time);
82 // If we got our reply, no need to run the loop any
83 // further.
84 if (!rd.keep_waiting (leader_follower))
85 break;
87 // @@ We are not checking for timeouts here...
89 // If we got an error just break
90 if (retval == -1)
91 break;
94 if (rd.error_detected (leader_follower) || retval == -1)
96 this->transport_->close_connection ();
99 if (rd.successful (leader_follower))
101 TAO_ORB_Core * const oc =
102 this->transport_->orb_core ();
104 if (!oc->client_factory ()->use_cleanup_options ())
105 return 0;
107 if (TAO_debug_level > 0)
108 TAOLIB_DEBUG ((LM_DEBUG,
109 ACE_TEXT ("TAO (%P|%t) - Wait_On_Read[%d]::wait (), ")
110 ACE_TEXT ("registering handle for cleanup\n"),
111 this->transport_->id ()));
113 ACE_Event_Handler * const eh =
114 this->transport_->event_handler_i ();
116 ACE_Reactor * const r =
117 this->transport_->orb_core ()->reactor ();
119 if (r->register_handler (eh,
120 ACE_Event_Handler::READ_MASK) == -1)
122 if (TAO_debug_level > 0)
123 TAOLIB_ERROR ((LM_ERROR,
124 ACE_TEXT ("TAO (%P|%t) - Wait_On_Read[%d]::wait (), ")
125 ACE_TEXT ("registration with reactor returned an error\n"),
126 this->transport_->id ()));
128 else
130 // Only set this flag when registration succeeds
131 this->is_registered_ = true;
134 return 0;
137 if (rd.error_detected (leader_follower))
138 return -1;
140 return 1;
143 // No-op.
145 TAO_Wait_On_Read::register_handler ()
147 return 0;
150 bool
151 TAO_Wait_On_Read::non_blocking () const
153 return false;
156 bool
157 TAO_Wait_On_Read::can_process_upcalls () const
159 return true;
162 TAO_END_VERSIONED_NAMESPACE_DECL