#include <IIOP_Connection_Handler.h>
Inheritance diagram for TAO_IIOP_Connection_Handler:
Public Member Functions | |
TAO_IIOP_Connection_Handler (ACE_Thread_Manager *=0) | |
TAO_IIOP_Connection_Handler (TAO_ORB_Core *orb_core, CORBA::Boolean flag) | |
Constructor. | |
~TAO_IIOP_Connection_Handler (void) | |
Destructor. | |
virtual int | open (void *) |
int | close (u_long=0) |
int | add_transport_to_cache (void) |
Add ourselves to Cache. | |
int | process_listen_point_list (IIOP::ListenPointList &listen_list) |
Process the listen_list. | |
int | enable_network_priority (void) |
Check if network priority needs to be enabled. | |
int | set_dscp_codepoint (CORBA::Boolean set_network_priority) |
Set Diff-Serv codepoint on outgoing packets. | |
virtual int | open_handler (void *) |
A open () hook. | |
void | abort (void) |
Event Handler overloads | |
virtual int | resume_handler (void) |
virtual int | close_connection (void) |
Close the underlying connection. | |
virtual int | handle_input (ACE_HANDLE) |
virtual int | handle_output (ACE_HANDLE) |
virtual int | handle_close (ACE_HANDLE, ACE_Reactor_Mask) |
virtual int | handle_timeout (const ACE_Time_Value ¤t_time, const void *act=0) |
Protected Member Functions | |
TAO_IIOP_Connection_Handler (TAO_ORB_Core *orb_core) | |
Constructor that could be used by the derived classes. | |
TAO_Connection Handler overloads | |
virtual int | release_os_resources (void) |
Release the OS resources related to this handler. | |
Private Attributes | |
int | dscp_codepoint_ |
Stores the type of service value. |
The Connection handler which is common for the Acceptor and the Connector
Definition at line 61 of file IIOP_Connection_Handler.h.
|
Definition at line 24 of file IIOP_Connection_Handler.cpp. References ACE_ASSERT, IPDSFIELD_DSCP_DEFAULT, and TAO_IIOP_SVC_HANDLER.
00025 : TAO_IIOP_SVC_HANDLER (t, 0 , 0), 00026 TAO_Connection_Handler (0), 00027 dscp_codepoint_ (IPDSFIELD_DSCP_DEFAULT << 2) 00028 { 00029 // This constructor should *never* get called, it is just here to 00030 // make the compiler happy: the default implementation of the 00031 // Creation_Strategy requires a constructor with that signature, we 00032 // don't use that implementation, but some (most?) compilers 00033 // instantiate it anyway. 00034 ACE_ASSERT (0); 00035 } |
|
Constructor.
Definition at line 38 of file IIOP_Connection_Handler.cpp. References ACE_NEW, IPDSFIELD_DSCP_DEFAULT, TAO_IIOP_SVC_HANDLER, and TAO_Connection_Handler::transport().
00041 : TAO_IIOP_SVC_HANDLER (orb_core->thr_mgr (), 0, 0), 00042 TAO_Connection_Handler (orb_core), 00043 dscp_codepoint_ (IPDSFIELD_DSCP_DEFAULT << 2) 00044 { 00045 TAO_IIOP_Transport* specific_transport = 0; 00046 ACE_NEW (specific_transport, 00047 TAO_IIOP_Transport (this, orb_core, flag)); 00048 00049 // store this pointer (indirectly increment ref count) 00050 this->transport (specific_transport); 00051 } |
|
Destructor.
Definition at line 60 of file IIOP_Connection_Handler.cpp. References TAO_Connection_Handler::transport().
00061 { 00062 delete this->transport (); 00063 } |
|
Constructor that could be used by the derived classes. Sometimes new pluggable protocols which have similarities with IIOP may be tempted to this class for their use. Classical example being that of IIOP_SSL_Connection_Handler. This constructor just initializes its base class and sets all of its contents to the default value, if any Definition at line 53 of file IIOP_Connection_Handler.cpp. References IPDSFIELD_DSCP_DEFAULT, and TAO_IIOP_SVC_HANDLER.
00054 : TAO_IIOP_SVC_HANDLER (orb_core->thr_mgr (), 0, 0), 00055 TAO_Connection_Handler (orb_core), 00056 dscp_codepoint_ (IPDSFIELD_DSCP_DEFAULT << 2) 00057 { 00058 } |
|
This is used during a canceled connection attempt. Force the SO_LINGER timeout to 0 so that when the peer is closed, it won't hang around. Definition at line 501 of file IIOP_Connection_Handler.cpp. References ACE_DEBUG, ACE_TEXT, LM_DEBUG, and TAO_debug_level. Referenced by TAO_IIOP_Connector::cancel_svc_handler().
00502 { 00503 struct linger lval; 00504 lval.l_onoff = 1; 00505 lval.l_linger = 0; 00506 00507 if (this->peer ().set_option(SOL_SOCKET, 00508 SO_LINGER, 00509 (void*) &lval, 00510 sizeof (lval)) == -1) 00511 { 00512 if (TAO_debug_level) 00513 { 00514 ACE_DEBUG ((LM_DEBUG, 00515 ACE_TEXT ("TAO (%P|%t) Unable to set ") 00516 ACE_TEXT ("SO_LINGER on %d\n"), 00517 this->peer ().get_handle ())); 00518 } 00519 } 00520 } |
|
Add ourselves to Cache.
Definition at line 349 of file IIOP_Connection_Handler.cpp. References TAO::Transport_Cache_Manager::cache_idle_transport(), TAO_ORB_Core::lane_resources(), TAO_Connection_Handler::orb_core(), and TAO_Thread_Lane_Resources::transport_cache().
00350 { 00351 ACE_INET_Addr addr; 00352 00353 // Get the peername. 00354 if (this->peer ().get_remote_addr (addr) == -1) 00355 return -1; 00356 00357 // Construct an IIOP_Endpoint object 00358 TAO_IIOP_Endpoint endpoint ( 00359 addr, 00360 this->orb_core()->orb_params()->cache_incoming_by_dotted_decimal_address ()); 00361 00362 // Construct a property object 00363 TAO_Base_Transport_Property prop (&endpoint); 00364 00365 TAO::Transport_Cache_Manager &cache = 00366 this->orb_core ()->lane_resources ().transport_cache (); 00367 00368 // Idle the transport.. 00369 return cache.cache_idle_transport (&prop, 00370 this->transport ()); 00371 } |
|
Close called by the Acceptor or Connector when connection establishment fails. Definition at line 337 of file IIOP_Connection_Handler.cpp. References TAO_Connection_Handler::close_handler(). Referenced by TAO_IIOP_Connector::complete_connection(), and handle_timeout().
00338 { 00339 return this->close_handler (); 00340 } |
|
Close the underlying connection. Used by the ORB to actively close connections that are idle, stale or somehow are determined to be broken before the Reactor does.
Implements TAO_Connection_Handler. Definition at line 268 of file IIOP_Connection_Handler.cpp. References ACE_DEBUG, ACE_TEXT, TAO_Connection_Handler::close_connection_eh(), TAO_ORB_Parameters::linger(), LM_DEBUG, TAO_Connection_Handler::orb_core(), TAO_ORB_Core::orb_params(), and TAO_debug_level. Referenced by handle_output().
00269 { 00270 // To maintain maximum compatibility, we only set this socket option 00271 // if the user has provided a linger timeout. 00272 int linger = this->orb_core()->orb_params()->linger (); 00273 if (linger != -1) 00274 { 00275 struct linger lval; 00276 lval.l_onoff = 1; 00277 lval.l_linger = (u_short)linger; 00278 00279 if (this->peer ().set_option(SOL_SOCKET, 00280 SO_LINGER, 00281 (void*) &lval, 00282 sizeof (lval)) == -1) 00283 { 00284 if (TAO_debug_level) 00285 { 00286 ACE_DEBUG ((LM_DEBUG, 00287 ACE_TEXT ("TAO (%P|%t) Unable to set ") 00288 ACE_TEXT ("SO_LINGER on %d\n"), 00289 this->peer ().get_handle ())); 00290 } 00291 } 00292 } 00293 00294 return this->close_connection_eh (this); 00295 } |
|
Check if network priority needs to be enabled.
|
|
Definition at line 329 of file IIOP_Connection_Handler.cpp. References ACE_ASSERT.
00331 { 00332 ACE_ASSERT (0); 00333 return 0; 00334 } |
|
The event handler calls, here so that other objects who hold a reference to this object can call the event handler methods. Implements TAO_Connection_Handler. Definition at line 298 of file IIOP_Connection_Handler.cpp. References TAO_Connection_Handler::handle_input_eh().
00299 { 00300 return this->handle_input_eh (h, this); 00301 } |
|
Definition at line 304 of file IIOP_Connection_Handler.cpp. References close_connection(), and TAO_Connection_Handler::handle_output_eh().
00305 { 00306 const int result = 00307 this->handle_output_eh (handle, this); 00308 00309 if (result == -1) 00310 { 00311 this->close_connection (); 00312 return 0; 00313 } 00314 00315 return result; 00316 } |
|
Definition at line 319 of file IIOP_Connection_Handler.cpp. References close().
00321 { 00322 // We don't use this upcall for I/O. This is only used by the 00323 // Connector to indicate that the connection timedout. Therefore, 00324 // we should call close(). 00325 return this->close (); 00326 } |
|
Called by the Definition at line 79 of file IIOP_Connection_Handler.cpp. References ACE_CATCHANY, ACE_CHECK_RETURN, ACE_DEBUG, ACE_DECLARE_NEW_CORBA_ENV, ACE_ENDTRY, ACE_ENV_ARG_PARAMETER, ACE_ERROR, ACE_IPPROTO_TCP, ACE_NONBLOCK, ACE_TCHAR, ACE_TEXT, ACE_TRY, ACE_TRY_CHECK, ACE_INET_Addr::addr_to_string(), TAO_Protocols_Hooks::client_protocol_properties_at_orb_level(), TAO_ORB_Parameters::connect_ipv6_only(), TAO_IIOP_Protocol_Properties::dont_route_, ENOTSUP, ACE_INET_Addr::get_host_addr(), ACE_INET_Addr::get_port_number(), TAO_ORB_Core::get_protocols_hooks(), ACE_INET_Addr::is_ipv4_mapped_ipv6(), TAO_IIOP_Protocol_Properties::keep_alive_, LM_DEBUG, LM_ERROR, LM_WARNING, MAXHOSTNAMELEN, TAO_IIOP_Protocol_Properties::no_delay_, TAO_ORB_Parameters::nodelay(), TAO_Wait_Strategy::non_blocking(), TAO_Transport::opened_as(), TAO_Connection_Handler::orb_core(), TAO_ORB_Core::orb_params(), TAO_Transport::post_open(), TAO_IIOP_Protocol_Properties::recv_buffer_size_, TAO_IIOP_Protocol_Properties::send_buffer_size_, TAO_Protocols_Hooks::server_protocol_properties_at_orb_level(), TAO_Connection_Handler::set_socket_option(), TAO_ORB_Parameters::sock_dontroute(), TAO_ORB_Parameters::sock_keepalive(), TAO_ORB_Parameters::sock_rcvbuf_size(), TAO_ORB_Parameters::sock_sndbuf_size(), TAO_LF_Event::state_changed(), TAO_debug_level, TAO_Connection_Handler::transport(), and TAO_Transport::wait_strategy(). Referenced by open_handler().
00080 { 00081 TAO_IIOP_Protocol_Properties protocol_properties; 00082 00083 // Initialize values from ORB params. 00084 protocol_properties.send_buffer_size_ = 00085 this->orb_core ()->orb_params ()->sock_sndbuf_size (); 00086 protocol_properties.recv_buffer_size_ = 00087 this->orb_core ()->orb_params ()->sock_rcvbuf_size (); 00088 protocol_properties.no_delay_ = 00089 this->orb_core ()->orb_params ()->nodelay (); 00090 protocol_properties.keep_alive_ = 00091 this->orb_core ()->orb_params ()->sock_keepalive (); 00092 protocol_properties.dont_route_ = 00093 this->orb_core ()->orb_params ()->sock_dontroute (); 00094 00095 TAO_Protocols_Hooks *tph = 00096 this->orb_core ()->get_protocols_hooks (); 00097 00098 bool const client = 00099 this->transport ()->opened_as () == TAO::TAO_CLIENT_ROLE; 00100 00101 ACE_DECLARE_NEW_CORBA_ENV; 00102 00103 ACE_TRY 00104 { 00105 if (client) 00106 { 00107 tph->client_protocol_properties_at_orb_level ( 00108 protocol_properties 00109 ACE_ENV_ARG_PARAMETER); 00110 ACE_TRY_CHECK; 00111 } 00112 else 00113 { 00114 tph->server_protocol_properties_at_orb_level ( 00115 protocol_properties 00116 ACE_ENV_ARG_PARAMETER); 00117 ACE_TRY_CHECK; 00118 } 00119 } 00120 ACE_CATCHANY 00121 { 00122 return -1; 00123 } 00124 ACE_ENDTRY; 00125 ACE_CHECK_RETURN (-1); 00126 00127 if (this->set_socket_option (this->peer (), 00128 protocol_properties.send_buffer_size_, 00129 protocol_properties.recv_buffer_size_) == -1) 00130 return -1; 00131 00132 #if !defined (ACE_LACKS_TCP_NODELAY) 00133 if (this->peer ().set_option (ACE_IPPROTO_TCP, 00134 TCP_NODELAY, 00135 (void *) &protocol_properties.no_delay_, 00136 sizeof (protocol_properties.no_delay_)) == -1) 00137 return -1; 00138 #endif /* ! ACE_LACKS_TCP_NODELAY */ 00139 00140 if (protocol_properties.keep_alive_) 00141 { 00142 if (this->peer (). 00143 set_option (SOL_SOCKET, 00144 SO_KEEPALIVE, 00145 (void *) &protocol_properties.keep_alive_, 00146 sizeof (protocol_properties.keep_alive_)) == -1 00147 && errno != ENOTSUP) 00148 { 00149 return -1; 00150 } 00151 } 00152 00153 #if !defined (ACE_LACKS_SO_DONTROUTE) 00154 if (protocol_properties.dont_route_) 00155 { 00156 if (this->peer (). 00157 set_option (SOL_SOCKET, 00158 SO_DONTROUTE, 00159 (void *) &protocol_properties.dont_route_, 00160 sizeof (protocol_properties.dont_route_)) == -1 00161 && errno != ENOTSUP) 00162 { 00163 return -1; 00164 } 00165 } 00166 #endif /* ! ACE_LACKS_SO_DONTROUTE */ 00167 00168 if (this->transport ()->wait_strategy ()->non_blocking () 00169 || this->transport ()->opened_as () == TAO::TAO_SERVER_ROLE) 00170 { 00171 if (this->peer ().enable (ACE_NONBLOCK) == -1) 00172 return -1; 00173 } 00174 00175 // Called by the <Strategy_Acceptor> when the handler is 00176 // completely connected. 00177 00178 ACE_INET_Addr remote_addr; 00179 if (this->peer ().get_remote_addr (remote_addr) == -1) 00180 return -1; 00181 00182 ACE_INET_Addr local_addr; 00183 if (this->peer ().get_local_addr (local_addr) == -1) 00184 return -1; 00185 00186 if (TAO_debug_level > 2) 00187 ACE_DEBUG ((LM_DEBUG, 00188 ACE_TEXT("TAO (%P|%t) - IIOP_Connection_Handler::open, ") 00189 ACE_TEXT("The local addr is <%s:%d> \n"), 00190 local_addr.get_host_addr (), 00191 local_addr.get_port_number())); 00192 00193 if (local_addr == remote_addr) 00194 { 00195 if (TAO_debug_level > 0) 00196 { 00197 ACE_TCHAR remote_as_string[MAXHOSTNAMELEN + 16]; 00198 ACE_TCHAR local_as_string[MAXHOSTNAMELEN + 16]; 00199 00200 (void) remote_addr.addr_to_string (remote_as_string, 00201 sizeof(remote_as_string)); 00202 (void) local_addr.addr_to_string (local_as_string, 00203 sizeof(local_as_string)); 00204 ACE_ERROR ((LM_ERROR, 00205 ACE_TEXT("TAO(%P|%t) - IIOP_Connection_Handler::open, ") 00206 ACE_TEXT("Holy Cow! The remote addr and ") 00207 ACE_TEXT("local addr are identical (%s == %s)\n"), 00208 remote_as_string, local_as_string)); 00209 } 00210 return -1; 00211 } 00212 00213 #if defined (ACE_HAS_IPV6) && !defined (ACE_HAS_IPV6_V6ONLY) 00214 // Check if we need to invalidate accepted connections 00215 // from IPv4 mapped IPv6 addresses 00216 if (this->orb_core ()->orb_params ()->connect_ipv6_only () && 00217 remote_addr.is_ipv4_mapped_ipv6 ()) 00218 { 00219 if (TAO_debug_level > 0) 00220 { 00221 ACE_TCHAR remote_as_string[MAXHOSTNAMELEN + 16]; 00222 00223 (void) remote_addr.addr_to_string (remote_as_string, 00224 sizeof(remote_as_string)); 00225 00226 ACE_ERROR ((LM_WARNING, 00227 ACE_TEXT("TAO (%P|%t) - IIOP_Connection_Handler::open, ") 00228 ACE_TEXT("invalid connection from IPv4 mapped IPv6 interface <%s>!\n"), 00229 remote_as_string)); 00230 } 00231 return -1; 00232 } 00233 #endif /* ACE_HAS_IPV6 && ACE_HAS_IPV6_V6ONLY */ 00234 00235 if (TAO_debug_level > 0) 00236 { 00237 ACE_TCHAR client_addr[MAXHOSTNAMELEN + 16]; 00238 00239 // Verify that we can resolve the peer hostname. 00240 if (remote_addr.addr_to_string (client_addr, sizeof (client_addr)) == -1) 00241 return -1; 00242 00243 ACE_DEBUG ((LM_DEBUG, 00244 ACE_TEXT ("TAO (%P|%t) - IIOP_Connection_Handler::open, IIOP ") 00245 ACE_TEXT ("connection to peer <%s> on %d\n"), 00246 client_addr, this->peer ().get_handle ())); 00247 } 00248 00249 // Set that the transport is now connected, if fails we return -1 00250 // Use C-style cast b/c otherwise we get warnings on lots of 00251 // compilers 00252 if (!this->transport ()->post_open ((size_t) this->get_handle ())) 00253 return -1; 00254 00255 this->state_changed (TAO_LF_Event::LFS_SUCCESS, 00256 this->orb_core ()->leader_follower ()); 00257 00258 return 0; 00259 } |
|
A open () hook. See Thread_Per_Connection_Handler for a use case Implements TAO_Connection_Handler. Definition at line 73 of file IIOP_Connection_Handler.cpp.
00074 { 00075 return this->open (v); 00076 } |
|
Process the listen_list.
Definition at line 374 of file IIOP_Connection_Handler.cpp. References ACE_DEBUG, ACE_ERROR, ACE_TEXT, ACE_TEXT_CHAR_TO_TCHAR, IIOP::ListenPoint::host, TAO::unbounded_value_sequence< ListenPoint >::length(), LM_DEBUG, LM_ERROR, TAO_Transport::make_idle(), IIOP::ListenPoint::port, TAO_Transport::recache_transport(), TAO_Transport_Descriptor_Interface::set_bidir_flag(), TAO_debug_level, and TAO_Connection_Handler::transport(). Referenced by TAO_IIOP_Transport::tear_listen_point_list().
00376 { 00377 // Get the size of the list 00378 const CORBA::ULong len = listen_list.length (); 00379 00380 if (TAO_debug_level > 0 && len == 0) 00381 { 00382 ACE_ERROR ((LM_ERROR, 00383 ACE_TEXT("TAO (%P|%t) - IIOP_Connection_Handler::") 00384 ACE_TEXT("process_listen_point_list, ") 00385 ACE_TEXT("Received list of size 0, check client config.\n"))); 00386 } 00387 00388 for (CORBA::ULong i = 0; i < len; ++i) 00389 { 00390 IIOP::ListenPoint listen_point = listen_list[i]; 00391 ACE_INET_Addr addr (listen_point.port, 00392 listen_point.host.in ()); 00393 00394 if (TAO_debug_level > 0) 00395 { 00396 ACE_DEBUG ((LM_DEBUG, 00397 ACE_TEXT("TAO (%P|%t) - IIOP_Connection_Handler::") 00398 ACE_TEXT("process_listen_point_list, ") 00399 ACE_TEXT("Listening port [%d] on [%s]\n"), 00400 listen_point.port, 00401 ACE_TEXT_CHAR_TO_TCHAR(listen_point.host.in ()))); 00402 } 00403 00404 // Construct an IIOP_Endpoint object using the host as provided 00405 // in the listen point list. We must use host in that form because 00406 // that's also how the ORB on the other side will advertise the host 00407 // in an IOR. 00408 TAO_IIOP_Endpoint endpoint (listen_point.host.in (), 00409 listen_point.port, addr); 00410 00411 // Construct a property object 00412 TAO_Base_Transport_Property prop (&endpoint); 00413 00414 // Mark the connection as bidirectional 00415 prop.set_bidir_flag (1); 00416 00417 // The property for this handler has changed. Recache the 00418 // handler with this property 00419 int retval = 00420 this->transport ()->recache_transport (&prop); 00421 00422 if (retval == -1) 00423 return retval; 00424 00425 // Make the handler idle and ready for use 00426 this->transport ()->make_idle (); 00427 } 00428 00429 return 0; 00430 } |
|
Release the OS resources related to this handler.
Reimplemented from TAO_Connection_Handler. Definition at line 343 of file IIOP_Connection_Handler.cpp.
00344 {
00345 return this->peer ().close ();
00346 }
|
|
Definition at line 262 of file IIOP_Connection_Handler.cpp.
00263 { 00264 return ACE_Event_Handler::ACE_APPLICATION_RESUMES_HANDLER; 00265 } |
|
Set Diff-Serv codepoint on outgoing packets.
Reimplemented from TAO_Connection_Handler. Definition at line 433 of file IIOP_Connection_Handler.cpp. References ACE_DEBUG, dscp_codepoint_, TAO_Protocols_Hooks::get_dscp_codepoint(), TAO_ORB_Core::get_protocols_hooks(), ACE_Addr::get_type(), IPDSFIELD_DSCP_DEFAULT, LM_DEBUG, TAO_Connection_Handler::orb_core(), and TAO_debug_level.
00434 { 00435 int tos = IPDSFIELD_DSCP_DEFAULT << 2; 00436 00437 if (set_network_priority) 00438 { 00439 TAO_Protocols_Hooks *tph = 00440 this->orb_core ()->get_protocols_hooks (); 00441 00442 CORBA::Long codepoint = 00443 tph->get_dscp_codepoint (); 00444 00445 tos = static_cast<int> (codepoint) << 2; 00446 } 00447 00448 if (tos != this->dscp_codepoint_) 00449 { 00450 int result = 0; 00451 #if defined (ACE_HAS_IPV6) 00452 ACE_INET_Addr local_addr; 00453 if (this->peer ().get_local_addr (local_addr) == -1) 00454 return -1; 00455 else if (local_addr.get_type () == AF_INET6) 00456 # if !defined (IPV6_TCLASS) 00457 // IPv6 defines option IPV6_TCLASS for specifying traffic class/priority 00458 // but not many implementations yet (very new;-). 00459 { 00460 if (TAO_debug_level) 00461 { 00462 ACE_DEBUG ((LM_DEBUG, 00463 "TAO (%P|%t) - IIOP_Connection_Handler::" 00464 "set_dscp_codepoint -> IPV6_TCLASS not supported yet\n")); 00465 } 00466 return 0; 00467 } 00468 # else /* !IPV6_TCLASS */ 00469 result = this->peer ().set_option (IPPROTO_IPV6, 00470 IPV6_TCLASS, 00471 (int *) &tos , 00472 (int) sizeof (tos)); 00473 else 00474 # endif /* IPV6_TCLASS */ 00475 #endif /* ACE_HAS_IPV6 */ 00476 result = this->peer ().set_option (IPPROTO_IP, 00477 IP_TOS, 00478 (int *) &tos , 00479 (int) sizeof (tos)); 00480 00481 if (TAO_debug_level) 00482 { 00483 ACE_DEBUG ((LM_DEBUG, 00484 "TAO (%P|%t) - IIOP_Connection_Handler::" 00485 "set_dscp_codepoint -> dscp: %x; result: %d; %s\n", 00486 tos, 00487 result, 00488 result == -1 ? "try running as superuser" : "")); 00489 } 00490 00491 // On successful setting of TOS field. 00492 if (result == 0) 00493 this->dscp_codepoint_ = tos; 00494 00495 } 00496 00497 return 0; 00498 } |
|
Stores the type of service value.
Definition at line 137 of file IIOP_Connection_Handler.h. Referenced by set_dscp_codepoint(). |