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
13 TAO_Wait_On_Read::TAO_Wait_On_Read (TAO_Transport
*transport
)
14 : TAO_Wait_Strategy (transport
)
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 ();
39 return this->TAO_Wait_Strategy::sending_request (orb_core
, msg_semantics
);
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 () &&
53 this->transport_
->remove_handler ();
57 this->TAO_Wait_Strategy::finished_request ();
60 // Wait on the read operation.
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
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
80 retval
= this->transport_
->handle_input (rh
, max_wait_time
);
82 // If we got our reply, no need to run the loop any
84 if (!rd
.keep_waiting (leader_follower
))
87 // @@ We are not checking for timeouts here...
89 // If we got an error just 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 ())
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 ()));
130 // Only set this flag when registration succeeds
131 this->is_registered_
= true;
137 if (rd
.error_detected (leader_follower
))
145 TAO_Wait_On_Read::register_handler ()
151 TAO_Wait_On_Read::non_blocking () const
157 TAO_Wait_On_Read::can_process_upcalls () const
162 TAO_END_VERSIONED_NAMESPACE_DECL