Go to the documentation of this file.00001
00002
00003 #include "tao/Strategies/UIOP_Connection_Handler.h"
00004
00005 #if TAO_HAS_UIOP == 1
00006
00007 #include "tao/Strategies/UIOP_Transport.h"
00008 #include "tao/Strategies/UIOP_Endpoint.h"
00009 #include "tao/debug.h"
00010 #include "tao/ORB_Core.h"
00011 #include "tao/ORB.h"
00012 #include "tao/CDR.h"
00013 #include "tao/Timeprobe.h"
00014 #include "tao/Server_Strategy_Factory.h"
00015 #include "tao/Base_Transport_Property.h"
00016 #include "tao/Transport_Cache_Manager.h"
00017 #include "tao/Resume_Handle.h"
00018 #include "tao/Thread_Lane_Resources.h"
00019 #include "tao/Protocols_Hooks.h"
00020
00021 ACE_RCSID (Strategies,
00022 UIOP_Connection_Handler,
00023 "$Id: UIOP_Connection_Handler.cpp 85817 2009-06-26 20:44:58Z mitza $")
00024
00025 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00026
00027 TAO_UIOP_Connection_Handler::TAO_UIOP_Connection_Handler (ACE_Thread_Manager *t)
00028 : TAO_UIOP_SVC_HANDLER (t, 0 , 0),
00029 TAO_Connection_Handler (0)
00030 {
00031
00032
00033
00034
00035
00036 ACE_ASSERT (0);
00037 }
00038
00039
00040 TAO_UIOP_Connection_Handler::TAO_UIOP_Connection_Handler (TAO_ORB_Core *orb_core)
00041 : TAO_UIOP_SVC_HANDLER (orb_core->thr_mgr (), 0, 0),
00042 TAO_Connection_Handler (orb_core)
00043 {
00044 TAO_UIOP_Transport* specific_transport = 0;
00045 ACE_NEW (specific_transport,
00046 TAO_UIOP_Transport (this, orb_core));
00047
00048
00049 this->transport (specific_transport);
00050 }
00051
00052
00053 TAO_UIOP_Connection_Handler::~TAO_UIOP_Connection_Handler (void)
00054 {
00055 delete this->transport ();
00056 int const result =
00057 this->release_os_resources ();
00058
00059 if (result == -1 && TAO_debug_level)
00060 {
00061 ACE_ERROR ((LM_ERROR,
00062 ACE_TEXT("TAO (%P|%t) - UIOP_Connection_Handler::")
00063 ACE_TEXT("~UIOP_Connection_Handler, ")
00064 ACE_TEXT("release_os_resources() failed %m\n")));
00065 }
00066 }
00067
00068 int
00069 TAO_UIOP_Connection_Handler::open_handler (void *v)
00070 {
00071 return this->open (v);
00072 }
00073
00074 int
00075 TAO_UIOP_Connection_Handler::open (void*)
00076 {
00077 if (this->shared_open() == -1)
00078 return -1;
00079
00080 TAO_UIOP_Protocol_Properties protocol_properties;
00081
00082
00083 protocol_properties.send_buffer_size_ =
00084 this->orb_core ()->orb_params ()->sock_sndbuf_size ();
00085 protocol_properties.recv_buffer_size_ =
00086 this->orb_core ()->orb_params ()->sock_rcvbuf_size ();
00087
00088 TAO_Protocols_Hooks *tph = this->orb_core ()->get_protocols_hooks ();
00089
00090 if (tph != 0)
00091 {
00092 try
00093 {
00094 if (this->transport ()->opened_as () == TAO::TAO_CLIENT_ROLE)
00095 {
00096 tph->client_protocol_properties_at_orb_level (protocol_properties);
00097 }
00098 else
00099 {
00100 tph->server_protocol_properties_at_orb_level (protocol_properties);
00101 }
00102 }
00103 catch (const ::CORBA::Exception&)
00104 {
00105 return -1;
00106 }
00107 }
00108
00109 if (this->set_socket_option (this->peer (),
00110 protocol_properties.send_buffer_size_,
00111 protocol_properties.recv_buffer_size_) == -1)
00112 return -1;
00113
00114 if (this->transport ()->wait_strategy ()->non_blocking ())
00115 {
00116 if (this->peer ().enable (ACE_NONBLOCK) == -1)
00117 return -1;
00118 }
00119
00120
00121
00122 ACE_UNIX_Addr addr;
00123
00124 if (this->peer ().get_remote_addr (addr) == -1)
00125 return -1;
00126
00127 if (TAO_debug_level > 0)
00128 ACE_DEBUG ((LM_DEBUG,
00129 ACE_TEXT ("TAO (%P|%t) UIOP connection to server ")
00130 ACE_TEXT ("<%C> on %d\n"),
00131 addr.get_path_name (), this->peer ().get_handle ()));
00132
00133
00134
00135
00136 if (!this->transport ()->post_open ((size_t) this->get_handle ()))
00137 return -1;
00138
00139 this->state_changed (TAO_LF_Event::LFS_SUCCESS,
00140 this->orb_core ()->leader_follower ());
00141
00142 return 0;
00143 }
00144
00145 int
00146 TAO_UIOP_Connection_Handler::resume_handler (void)
00147 {
00148 return ACE_Event_Handler::ACE_APPLICATION_RESUMES_HANDLER;
00149 }
00150
00151 int
00152 TAO_UIOP_Connection_Handler::close_connection (void)
00153 {
00154 return this->close_connection_eh (this);
00155 }
00156
00157 int
00158 TAO_UIOP_Connection_Handler::handle_input (ACE_HANDLE h)
00159 {
00160 return this->handle_input_eh (h, this);
00161 }
00162
00163 int
00164 TAO_UIOP_Connection_Handler::handle_output (ACE_HANDLE handle)
00165 {
00166 int const result = this->handle_output_eh (handle, this);
00167
00168 if (result == -1)
00169 {
00170 this->close_connection ();
00171 return 0;
00172 }
00173
00174 return result;
00175 }
00176
00177 int
00178 TAO_UIOP_Connection_Handler::handle_timeout (const ACE_Time_Value &,
00179 const void *)
00180 {
00181
00182
00183
00184
00185
00186
00187 TAO_Auto_Reference<TAO_UIOP_Connection_Handler> safeguard (*this);
00188
00189
00190
00191
00192
00193
00194
00195 int const ret = this->close ();
00196 this->reset_state (TAO_LF_Event::LFS_TIMEOUT);
00197 return ret;
00198 }
00199
00200 int
00201 TAO_UIOP_Connection_Handler::handle_close (ACE_HANDLE, ACE_Reactor_Mask)
00202 {
00203 ACE_ASSERT (0);
00204 return 0;
00205 }
00206
00207 int
00208 TAO_UIOP_Connection_Handler::close (u_long flags)
00209 {
00210 return this->close_handler (flags);
00211 }
00212
00213 int
00214 TAO_UIOP_Connection_Handler::release_os_resources (void)
00215 {
00216 return this->peer().close ();
00217 }
00218
00219 int
00220 TAO_UIOP_Connection_Handler::add_transport_to_cache (void)
00221 {
00222 ACE_UNIX_Addr addr;
00223
00224
00225 if (this->peer ().get_remote_addr (addr) == -1)
00226 return -1;
00227
00228
00229 TAO_UIOP_Endpoint endpoint (addr);
00230
00231
00232 TAO_Base_Transport_Property prop (&endpoint);
00233
00234 TAO::Transport_Cache_Manager &cache =
00235 this->orb_core ()->lane_resources ().transport_cache ();
00236
00237
00238 return cache.cache_transport (&prop, this->transport ());
00239 }
00240
00241 int
00242 TAO_UIOP_Connection_Handler::handle_write_ready (const ACE_Time_Value *t)
00243 {
00244 return ACE::handle_write_ready (this->peer ().get_handle (), t);
00245 }
00246
00247 TAO_END_VERSIONED_NAMESPACE_DECL
00248
00249 #endif