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/GIOP_Message_Lite.h"
00017 #include "tao/Transport_Cache_Manager.h"
00018 #include "tao/Resume_Handle.h"
00019 #include "tao/Thread_Lane_Resources.h"
00020 #include "tao/Protocols_Hooks.h"
00021
00022 ACE_RCSID (Strategies,
00023 UIOP_Connection_Handler,
00024 "UIOP_Connection_Handler.cpp,v 1.65 2006/03/10 07:19:19 jtc Exp")
00025
00026 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00027
00028 TAO_UIOP_Connection_Handler::TAO_UIOP_Connection_Handler (ACE_Thread_Manager *t)
00029 : TAO_UIOP_SVC_HANDLER (t, 0 , 0),
00030 TAO_Connection_Handler (0)
00031 {
00032
00033
00034
00035
00036
00037 ACE_ASSERT (0);
00038 }
00039
00040
00041 TAO_UIOP_Connection_Handler::TAO_UIOP_Connection_Handler (
00042 TAO_ORB_Core *orb_core,
00043 CORBA::Boolean flag)
00044 : TAO_UIOP_SVC_HANDLER (orb_core->thr_mgr (), 0, 0),
00045 TAO_Connection_Handler (orb_core)
00046 {
00047 TAO_UIOP_Transport* specific_transport = 0;
00048 ACE_NEW (specific_transport,
00049 TAO_UIOP_Transport (this, orb_core, flag));
00050
00051
00052 this->transport (specific_transport);
00053 }
00054
00055
00056 TAO_UIOP_Connection_Handler::~TAO_UIOP_Connection_Handler (void)
00057 {
00058 delete this->transport ();
00059 }
00060
00061 int
00062 TAO_UIOP_Connection_Handler::open_handler (void *v)
00063 {
00064 return this->open (v);
00065 }
00066
00067 int
00068 TAO_UIOP_Connection_Handler::open (void*)
00069 {
00070 TAO_UIOP_Protocol_Properties protocol_properties;
00071
00072
00073 protocol_properties.send_buffer_size_ =
00074 this->orb_core ()->orb_params ()->sock_sndbuf_size ();
00075 protocol_properties.recv_buffer_size_ =
00076 this->orb_core ()->orb_params ()->sock_rcvbuf_size ();
00077
00078 TAO_Protocols_Hooks *tph =
00079 this->orb_core ()->get_protocols_hooks ();
00080
00081 bool client =
00082 this->transport ()->opened_as () == TAO::TAO_CLIENT_ROLE;;
00083
00084 ACE_DECLARE_NEW_CORBA_ENV;
00085
00086 ACE_TRY
00087 {
00088 if (client)
00089 {
00090 tph->client_protocol_properties_at_orb_level (
00091 protocol_properties
00092 ACE_ENV_ARG_PARAMETER);
00093 ACE_TRY_CHECK;
00094 }
00095 else
00096 {
00097 tph->server_protocol_properties_at_orb_level (
00098 protocol_properties
00099 ACE_ENV_ARG_PARAMETER);
00100 ACE_TRY_CHECK;
00101 }
00102 }
00103 ACE_CATCHANY
00104 {
00105 return -1;
00106 }
00107 ACE_ENDTRY;
00108 ACE_CHECK_RETURN (-1);
00109
00110 if (this->set_socket_option (this->peer (),
00111 protocol_properties.send_buffer_size_,
00112 protocol_properties.recv_buffer_size_) == -1)
00113 return -1;
00114
00115 if (this->transport ()->wait_strategy ()->non_blocking ())
00116 {
00117 if (this->peer ().enable (ACE_NONBLOCK) == -1)
00118 return -1;
00119 }
00120
00121
00122
00123 ACE_UNIX_Addr addr;
00124
00125 if (this->peer ().get_remote_addr (addr) == -1)
00126 return -1;
00127
00128 if (TAO_debug_level > 0)
00129 ACE_DEBUG ((LM_DEBUG,
00130 ACE_TEXT ("TAO (%P|%t) UIOP connection to server ")
00131 ACE_TEXT ("<%s> on %d\n"),
00132 addr.get_path_name (), this->peer ().get_handle ()));
00133
00134
00135
00136
00137 if (!this->transport ()->post_open ((size_t) this->get_handle ()))
00138 return -1;
00139
00140 this->state_changed (TAO_LF_Event::LFS_SUCCESS,
00141 this->orb_core ()->leader_follower ());
00142
00143 return 0;
00144 }
00145
00146 int
00147 TAO_UIOP_Connection_Handler::resume_handler (void)
00148 {
00149 return ACE_Event_Handler::ACE_APPLICATION_RESUMES_HANDLER;
00150 }
00151
00152 int
00153 TAO_UIOP_Connection_Handler::close_connection (void)
00154 {
00155 return this->close_connection_eh (this);
00156 }
00157
00158 int
00159 TAO_UIOP_Connection_Handler::handle_input (ACE_HANDLE h)
00160 {
00161 return this->handle_input_eh (h, this);
00162 }
00163
00164 int
00165 TAO_UIOP_Connection_Handler::handle_output (ACE_HANDLE handle)
00166 {
00167 const int result =
00168 this->handle_output_eh (handle, this);
00169
00170 if (result == -1)
00171 {
00172 this->close_connection ();
00173 return 0;
00174 }
00175
00176 return result;
00177 }
00178
00179 int
00180 TAO_UIOP_Connection_Handler::handle_timeout (const ACE_Time_Value &,
00181 const void *)
00182 {
00183
00184
00185
00186 return this->close ();
00187 }
00188
00189 int
00190 TAO_UIOP_Connection_Handler::handle_close (ACE_HANDLE,
00191 ACE_Reactor_Mask)
00192 {
00193 ACE_ASSERT (0);
00194 return 0;
00195 }
00196
00197 int
00198 TAO_UIOP_Connection_Handler::close (u_long)
00199 {
00200 return this->close_handler ();
00201 }
00202
00203 int
00204 TAO_UIOP_Connection_Handler::release_os_resources (void)
00205 {
00206 return this->peer().close ();
00207 }
00208
00209 int
00210 TAO_UIOP_Connection_Handler::add_transport_to_cache (void)
00211 {
00212 ACE_UNIX_Addr addr;
00213
00214
00215 if (this->peer ().get_remote_addr (addr) == -1)
00216 return -1;
00217
00218
00219 TAO_UIOP_Endpoint endpoint (addr);
00220
00221
00222 TAO_Base_Transport_Property prop (&endpoint);
00223
00224 TAO::Transport_Cache_Manager &cache =
00225 this->orb_core ()->lane_resources ().transport_cache ();
00226
00227
00228 return cache.cache_idle_transport (&prop,
00229 this->transport ());
00230 }
00231
00232 TAO_END_VERSIONED_NAMESPACE_DECL
00233
00234 #endif