00001
00002
00003 #include "tao/Strategies/DIOP_Connection_Handler.h"
00004
00005 #if defined (TAO_HAS_DIOP) && (TAO_HAS_DIOP != 0)
00006
00007 #include "tao/Timeprobe.h"
00008 #include "tao/debug.h"
00009 #include "tao/ORB_Core.h"
00010 #include "tao/ORB.h"
00011 #include "tao/CDR.h"
00012 #include "tao/Server_Strategy_Factory.h"
00013 #include "tao/Transport_Cache_Manager.h"
00014 #include "tao/Thread_Lane_Resources.h"
00015 #include "tao/Base_Transport_Property.h"
00016 #include "tao/Protocols_Hooks.h"
00017 #include "tao/Resume_Handle.h"
00018
00019 #include "tao/Strategies/DIOP_Transport.h"
00020 #include "tao/Strategies/DIOP_Endpoint.h"
00021
00022 #include "ace/os_include/netinet/os_tcp.h"
00023 #include "ace/os_include/os_netdb.h"
00024
00025 ACE_RCSID(tao, DIOP_Connect, "DIOP_Connection_Handler.cpp,v 1.39 2006/03/10 07:19:18 jtc Exp")
00026
00027
00028 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00029
00030 TAO_DIOP_Connection_Handler::TAO_DIOP_Connection_Handler (ACE_Thread_Manager *t)
00031 : TAO_DIOP_SVC_HANDLER (t, 0 , 0),
00032 TAO_Connection_Handler (0),
00033 dscp_codepoint_ (IPDSFIELD_DSCP_DEFAULT << 2)
00034 {
00035
00036
00037
00038
00039
00040 ACE_ASSERT (0);
00041 }
00042
00043
00044 TAO_DIOP_Connection_Handler::TAO_DIOP_Connection_Handler (TAO_ORB_Core *orb_core,
00045 CORBA::Boolean flag)
00046 : TAO_DIOP_SVC_HANDLER (orb_core->thr_mgr (), 0, 0),
00047 TAO_Connection_Handler (orb_core),
00048 dscp_codepoint_ (IPDSFIELD_DSCP_DEFAULT << 2)
00049 {
00050 TAO_DIOP_Transport* specific_transport = 0;
00051 ACE_NEW (specific_transport,
00052 TAO_DIOP_Transport(this, orb_core, flag));
00053
00054
00055 this->transport (specific_transport);
00056 }
00057
00058
00059 TAO_DIOP_Connection_Handler::~TAO_DIOP_Connection_Handler (void)
00060 {
00061 delete this->transport ();
00062 this->udp_socket_.close ();
00063 }
00064
00065
00066 ACE_HANDLE
00067 TAO_DIOP_Connection_Handler::get_handle (void) const
00068 {
00069 return this->udp_socket_.get_handle ();
00070 }
00071
00072
00073 const ACE_INET_Addr &
00074 TAO_DIOP_Connection_Handler::addr (void)
00075 {
00076 return this->addr_;
00077 }
00078
00079
00080 void
00081 TAO_DIOP_Connection_Handler::addr (const ACE_INET_Addr &addr)
00082 {
00083 this->addr_ = addr;
00084 }
00085
00086
00087 const ACE_INET_Addr &
00088 TAO_DIOP_Connection_Handler::local_addr (void)
00089 {
00090 return local_addr_;
00091 }
00092
00093
00094 void
00095 TAO_DIOP_Connection_Handler::local_addr (const ACE_INET_Addr &addr)
00096 {
00097 local_addr_ = addr;
00098 }
00099
00100
00101 const ACE_SOCK_Dgram &
00102 TAO_DIOP_Connection_Handler::dgram (void)
00103 {
00104 return this->udp_socket_;
00105 }
00106
00107
00108 int
00109 TAO_DIOP_Connection_Handler::open_handler (void *v)
00110 {
00111 return this->open (v);
00112 }
00113
00114 int
00115 TAO_DIOP_Connection_Handler::open (void*)
00116 {
00117
00118
00119 TAO_DIOP_Protocol_Properties protocol_properties;
00120
00121 TAO_Protocols_Hooks *tph =
00122 this->orb_core ()->get_protocols_hooks ();
00123
00124 bool client =
00125 this->transport ()->opened_as () == TAO::TAO_CLIENT_ROLE;
00126
00127 ACE_DECLARE_NEW_CORBA_ENV;
00128
00129 ACE_TRY
00130 {
00131 if (client)
00132 {
00133 tph->client_protocol_properties_at_orb_level (
00134 protocol_properties
00135 ACE_ENV_ARG_PARAMETER);
00136 ACE_TRY_CHECK;
00137 }
00138 else
00139 {
00140 tph->server_protocol_properties_at_orb_level (
00141 protocol_properties
00142 ACE_ENV_ARG_PARAMETER);
00143 ACE_TRY_CHECK;
00144 }
00145 }
00146 ACE_CATCHANY
00147 {
00148 return -1;
00149 }
00150 ACE_ENDTRY;
00151 ACE_CHECK_RETURN (-1);
00152
00153 this->udp_socket_.open (this->local_addr_);
00154
00155 if (TAO_debug_level > 5)
00156 {
00157 ACE_DEBUG ((LM_DEBUG,
00158 ACE_TEXT("\nTAO (%P|%t) TAO_DIOP_Connection_Handler::open -")
00159 ACE_TEXT("listening on: <%s:%u>\n"),
00160 ACE_TEXT_CHAR_TO_TCHAR (this->local_addr_.get_host_name ()),
00161 this->local_addr_.get_port_number ()));
00162 }
00163
00164
00165
00166
00167 if (!this->transport ()->post_open ((size_t) this->get_handle ()))
00168 return -1;
00169
00170 this->state_changed (TAO_LF_Event::LFS_SUCCESS,
00171 this->orb_core ()->leader_follower ());
00172
00173 return 0;
00174 }
00175
00176 int
00177 TAO_DIOP_Connection_Handler::open_server (void)
00178 {
00179 this->udp_socket_.open (this->local_addr_);
00180 if( TAO_debug_level > 5)
00181 {
00182 ACE_DEBUG ((LM_DEBUG,
00183 ACE_TEXT("\nTAO (%P|%t) TAO_DIOP_Connection_Handler::open_server -")
00184 ACE_TEXT("listening on %s:%d\n"),
00185 ACE_TEXT_CHAR_TO_TCHAR (this->local_addr_.get_host_name ()),
00186 this->local_addr_.get_port_number ()
00187 ));
00188 }
00189
00190 this->transport ()->id ((size_t) this->get_handle ());
00191
00192 return 0;
00193 }
00194
00195 int
00196 TAO_DIOP_Connection_Handler::resume_handler (void)
00197 {
00198 return ACE_Event_Handler::ACE_APPLICATION_RESUMES_HANDLER;
00199 }
00200
00201 int
00202 TAO_DIOP_Connection_Handler::close_connection (void)
00203 {
00204 return this->close_connection_eh (this);
00205 }
00206
00207 int
00208 TAO_DIOP_Connection_Handler::handle_input (ACE_HANDLE h)
00209 {
00210 return this->handle_input_eh (h, this);
00211 }
00212
00213 int
00214 TAO_DIOP_Connection_Handler::handle_output (ACE_HANDLE handle)
00215 {
00216 int result =
00217 this->handle_output_eh (handle, this);
00218
00219 if (result == -1)
00220 {
00221 this->close_connection ();
00222 return 0;
00223 }
00224
00225 return result;
00226 }
00227
00228 int
00229 TAO_DIOP_Connection_Handler::handle_timeout (const ACE_Time_Value &,
00230 const void *)
00231 {
00232
00233
00234
00235 return 0;
00236 }
00237
00238 int
00239 TAO_DIOP_Connection_Handler::handle_close (ACE_HANDLE,
00240 ACE_Reactor_Mask)
00241 {
00242
00243
00244
00245
00246
00247 return 0;
00248 }
00249
00250 int
00251 TAO_DIOP_Connection_Handler::close (u_long)
00252 {
00253 return this->close_handler ();
00254 }
00255
00256 int
00257 TAO_DIOP_Connection_Handler::release_os_resources (void)
00258 {
00259 return this->peer ().close ();
00260 }
00261
00262 int
00263 TAO_DIOP_Connection_Handler::set_dscp_codepoint (CORBA::Boolean set_network_priority)
00264 {
00265 int tos = IPDSFIELD_DSCP_DEFAULT << 2;
00266
00267 if (set_network_priority)
00268 {
00269 TAO_Protocols_Hooks *tph =
00270 this->orb_core ()->get_protocols_hooks ();
00271
00272 CORBA::Long codepoint =
00273 tph->get_dscp_codepoint ();
00274
00275 tos = (int)(codepoint) << 2;
00276 }
00277
00278 if (tos != this->dscp_codepoint_)
00279 {
00280 int result = this->dgram ().set_option (IPPROTO_IP,
00281 IP_TOS,
00282 (int *) &tos ,
00283 (int) sizeof (tos));
00284
00285 if (TAO_debug_level)
00286 {
00287 ACE_DEBUG ((LM_DEBUG,
00288 "TAO (%P|%t) - DIOP_Connection_Handler::"
00289 "set_dscp_codepoint -> dscp: %x; result: %d; %s\n",
00290 tos,
00291 result,
00292 result == -1 ? "try running as superuser" : ""));
00293 }
00294
00295
00296 if (result == 0)
00297 this->dscp_codepoint_ = tos;
00298
00299 }
00300
00301 return 0;
00302 }
00303
00304 TAO_END_VERSIONED_NAMESPACE_DECL
00305
00306 #endif