Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

TAO_IIOP_Connection_Handler Class Reference

Handles requests on a single connection. More...

#include <IIOP_Connection_Handler.h>

Inheritance diagram for TAO_IIOP_Connection_Handler:

Inheritance graph
[legend]
Collaboration diagram for TAO_IIOP_Connection_Handler:

Collaboration graph
[legend]
List of all members.

Public Methods

 TAO_IIOP_Connection_Handler (ACE_Thread_Manager *t=0)
 TAO_IIOP_Connection_Handler (TAO_ORB_Core *orb_core, CORBA::Boolean flag, void *arg)
 Constructor. <arg> parameter is used by the Acceptor to pass the protocol configuration properties for this connection. More...

 ~TAO_IIOP_Connection_Handler (void)
 Destructor. More...

virtual int open (void *)
 Called by the <Strategy_Acceptor> when the handler is completely connected. Argument is unused. More...

virtual int activate (long flags=THR_NEW_LWP, int n_threads=1, int force_active=0, long priority=ACE_DEFAULT_THREAD_PRIORITY, int grp_id=-1, ACE_Task_Base *task=0, ACE_hthread_t thread_handles[]=0, void *stack[]=0, size_t stack_size[]=0, ACE_thread_t thread_names[]=0)
 = Active object activation method. More...

virtual int svc (void)
 Only used when the handler is turned into an active object by calling <activate>. This serves as the event loop in such cases. More...

int add_transport_to_cache (void)
 Add ourselves to Cache. More...

int process_listen_point_list (IIOP::ListenPointList &listen_list)
 Process the <listen_list>. More...

int enable_network_priority (void)
 Check if network priority needs to be enabled. More...

int set_dscp_codepoint (void)
 Set the Diff-Serv codepoint if the Policy dicates the setting of Network Priority. More...

int set_dscp_codepoint (int tos)
virtual void update_protocol_properties (int send_buffer_size, int recv_buffer_size, int no_delay, int enable_network_priority)
 Update the tcp properties of the hanlder to the most recent properties set after the last invocation. More...

Event Handler overloads
virtual int resume_handler (void)
virtual int close_connection (void)
 Close the underlying connection. More...

virtual int handle_input (ACE_HANDLE)
 The event handler calls, here so that other objects who hold a reference to this object can call the event handler methods. More...

virtual int handle_output (ACE_HANDLE)
virtual int handle_close (ACE_HANDLE, ACE_Reactor_Mask)

Protected Methods

 TAO_IIOP_Connection_Handler (TAO_ORB_Core *orb_core, void *arg)
 Constructor that could be used by the derived classes. More...

TAO_Connection Handler overloads
virtual int release_os_resources (void)
 Release the OS resources related to this handler, used in handle_close_eh(). More...


Private Attributes

TAO_IIOP_Properties tcp_properties_
 TCP configuration for this connection. More...

int dscp_codepoint_
 Stores the type of service value. More...


Detailed Description

Handles requests on a single connection.

The Connection handler which is common for the Acceptor and the Connector

Definition at line 71 of file IIOP_Connection_Handler.h.


Constructor & Destructor Documentation

TAO_IIOP_Connection_Handler::TAO_IIOP_Connection_Handler ACE_Thread_Manager   t = 0
 

Definition at line 27 of file IIOP_Connection_Handler.cpp.

References ACE_ASSERT.

00028   : TAO_IIOP_SVC_HANDLER (t, 0 , 0),
00029     TAO_Connection_Handler (0),
00030     dscp_codepoint_ (0)
00031 {
00032   // This constructor should *never* get called, it is just here to
00033   // make the compiler happy: the default implementation of the
00034   // Creation_Strategy requires a constructor with that signature, we
00035   // don't use that implementation, but some (most?) compilers
00036   // instantiate it anyway.
00037   ACE_ASSERT (this->orb_core () != 0);
00038 }

TAO_IIOP_Connection_Handler::TAO_IIOP_Connection_Handler TAO_ORB_Core   orb_core,
CORBA::Boolean    flag,
void *    arg
 

Constructor. <arg> parameter is used by the Acceptor to pass the protocol configuration properties for this connection.

Definition at line 41 of file IIOP_Connection_Handler.cpp.

References ACE_NEW, TAO_Transport::release, and TAO_Connection_Handler::transport.

00044   : TAO_IIOP_SVC_HANDLER (orb_core->thr_mgr (), 0, 0),
00045     TAO_Connection_Handler (orb_core),
00046     tcp_properties_ (*(ACE_static_cast
00047                        (TAO_IIOP_Properties *, arg))),
00048     dscp_codepoint_ (0)
00049 {
00050   TAO_IIOP_Transport* specific_transport = 0;
00051   ACE_NEW(specific_transport,
00052           TAO_IIOP_Transport (this, orb_core, flag));
00053 
00054   // store this pointer (indirectly increment ref count)
00055   this->transport (specific_transport);
00056   TAO_Transport::release (specific_transport);
00057 }

TAO_IIOP_Connection_Handler::~TAO_IIOP_Connection_Handler void   
 

Destructor.

Definition at line 70 of file IIOP_Connection_Handler.cpp.

00071 {
00072 }

TAO_IIOP_Connection_Handler::TAO_IIOP_Connection_Handler TAO_ORB_Core   orb_core,
void *    arg
[protected]
 

Constructor that could be used by the derived classes.

Sometimes new pluggbale protocols which have similarties 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 59 of file IIOP_Connection_Handler.cpp.

00061   : TAO_IIOP_SVC_HANDLER (orb_core->thr_mgr (), 0, 0),
00062     TAO_Connection_Handler (orb_core),
00063     tcp_properties_ (*(ACE_static_cast
00064                        (TAO_IIOP_Properties *, arg))),
00065     dscp_codepoint_ (0)
00066 {
00067 }


Member Function Documentation

int TAO_IIOP_Connection_Handler::activate long    flags = THR_NEW_LWP,
int    n_threads = 1,
int    force_active = 0,
long    priority = ACE_DEFAULT_THREAD_PRIORITY,
int    grp_id = -1,
ACE_Task_Base   task = 0,
ACE_hthread_t    thread_handles[] = 0,
void *    stack[] = 0,
size_t    stack_size[] = 0,
ACE_thread_t    thread_names[] = 0
[virtual]
 

= Active object activation method.

Reimplemented from ACE_Task_Base.

Definition at line 154 of file IIOP_Connection_Handler.cpp.

References ACE_DEBUG, ACE_hthread_t, ACE_LIB_TEXT, ACE_thread_t, ACE_Task_Base::activate, ACE_Task_Base::grp_id, TAO_Transport::id, LM_DEBUG, ACE_Event_Handler::priority, and TAO_Connection_Handler::transport.

00164 {
00165   if (TAO_debug_level)
00166     ACE_DEBUG  ((LM_DEBUG,
00167                  ACE_LIB_TEXT ("TAO (%P|%t) IIOP_Connection_Handler::activate %d ")
00168                  ACE_LIB_TEXT ("threads, flags = %d\n"),
00169                  n_threads,
00170                  flags,
00171                  THR_BOUND));
00172 
00173   // Set the id in the transport now that we're active.
00174   // Use C-style cast b/c otherwise we get warnings on lots of compilers
00175   this->transport ()->id ((size_t) this->get_handle ());
00176 
00177   return TAO_IIOP_SVC_HANDLER::activate (flags,
00178                                          n_threads,
00179                                          force_active,
00180                                          priority,
00181                                          grp_id,
00182                                          task,
00183                                          thread_handles,
00184                                          stack,
00185                                          stack_size,
00186                                          thread_names);
00187 }

int TAO_IIOP_Connection_Handler::add_transport_to_cache void   
 

Add ourselves to Cache.

Definition at line 242 of file IIOP_Connection_Handler.cpp.

References TAO_Transport_Cache_Manager::cache_idle_transport, TAO_ORB_Core::lane_resources, TAO_Connection_Handler::orb_core, ACE_Svc_Handler< ACE_SOCK_STREAM, ACE_NULL_SYNCH >::peer, and TAO_Thread_Lane_Resources::transport_cache.

00243 {
00244   ACE_INET_Addr addr;
00245 
00246   // Get the peername.
00247   if (this->peer ().get_remote_addr (addr) == -1)
00248     return -1;
00249 
00250   // Construct an  IIOP_Endpoint object
00251   TAO_IIOP_Endpoint endpoint (
00252       addr,
00253       this->orb_core()->orb_params()->use_dotted_decimal_addresses ());
00254 
00255   // Construct a property object
00256   TAO_Base_Transport_Property prop (&endpoint);
00257 
00258   TAO_Transport_Cache_Manager &cache =
00259     this->orb_core ()->lane_resources ().transport_cache ();
00260 
00261   // Idle the transport..
00262   return cache.cache_idle_transport (&prop,
00263                                      this->transport ());
00264 }

int TAO_IIOP_Connection_Handler::close_connection void    [virtual]
 

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.

Returns:
Return 0 if the connection was already closed, non-zero otherwise.

Implements TAO_Connection_Handler.

Definition at line 211 of file IIOP_Connection_Handler.cpp.

References TAO_Connection_Handler::close_connection_eh.

00212 {
00213   return this->close_connection_eh (this);
00214 }

int TAO_IIOP_Connection_Handler::enable_network_priority void   
 

Check if network priority needs to be enabled.

Definition at line 338 of file IIOP_Connection_Handler.cpp.

References TAO_IIOP_Properties::enable_network_priority, and tcp_properties_.

Referenced by set_dscp_codepoint, and update_protocol_properties.

00339 {
00340   return this->tcp_properties_.enable_network_priority;
00341 }

int TAO_IIOP_Connection_Handler::handle_close ACE_HANDLE   ,
ACE_Reactor_Mask   
[virtual]
 

Reimplemented from ACE_Svc_Handler< ACE_SOCK_STREAM, ACE_NULL_SYNCH >.

Definition at line 229 of file IIOP_Connection_Handler.cpp.

References ACE_Reactor_Mask, and TAO_Connection_Handler::handle_close_eh.

00231 {
00232   return this->handle_close_eh (handle, rm, this);
00233 }

int TAO_IIOP_Connection_Handler::handle_input ACE_HANDLE    [virtual]
 

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 217 of file IIOP_Connection_Handler.cpp.

References TAO_Connection_Handler::handle_input_eh.

00218 {
00219   return this->handle_input_eh (h, this);
00220 }

int TAO_IIOP_Connection_Handler::handle_output ACE_HANDLE    [virtual]
 

Reimplemented from ACE_Event_Handler.

Definition at line 223 of file IIOP_Connection_Handler.cpp.

References TAO_Connection_Handler::handle_output_eh.

00224 {
00225   return this->handle_output_eh (handle, this);
00226 }

int TAO_IIOP_Connection_Handler::open void *    [virtual]
 

Called by the <Strategy_Acceptor> when the handler is completely connected. Argument is unused.

Reimplemented from ACE_Svc_Handler< ACE_SOCK_STREAM, ACE_NULL_SYNCH >.

Definition at line 75 of file IIOP_Connection_Handler.cpp.

References ACE_DEBUG, ACE_ERROR, ACE_IPPROTO_TCP, ACE_LIB_TEXT, ACE_NONBLOCK, ACE_TCHAR, ACE_INET_Addr::addr_to_string, ACE_INET_Addr::get_ip_address, ACE_INET_Addr::get_port_number, TAO_Transport::id, TAO_LF_Event::LFS_SUCCESS, LM_DEBUG, LM_ERROR, MAXHOSTNAMELEN, TAO_IIOP_Properties::no_delay, TAO_Wait_Strategy::non_blocking, ACE_Svc_Handler< ACE_SOCK_STREAM, ACE_NULL_SYNCH >::peer, TAO_IIOP_Properties::recv_buffer_size, TAO_IIOP_Properties::send_buffer_size, TAO_Connection_Handler::set_socket_option, TAO_LF_Event::state_changed, tcp_properties_, TAO_Connection_Handler::transport, and TAO_Transport::wait_strategy.

00076 {
00077   if (this->set_socket_option (this->peer (),
00078                                this->tcp_properties_.send_buffer_size,
00079                                this->tcp_properties_.recv_buffer_size) == -1)
00080     return -1;
00081 
00082 #if !defined (ACE_LACKS_TCP_NODELAY)
00083 
00084   if (this->peer ().set_option (ACE_IPPROTO_TCP,
00085                                 TCP_NODELAY,
00086                                 (void *) &tcp_properties_.no_delay,
00087                                 sizeof (int)) == -1)
00088     return -1;
00089 #endif /* ! ACE_LACKS_TCP_NODELAY */
00090 
00091   if (this->transport ()->wait_strategy ()->non_blocking ())
00092     {
00093       if (this->peer ().enable (ACE_NONBLOCK) == -1)
00094         return -1;
00095     }
00096 
00097   // Called by the <Strategy_Acceptor> when the handler is
00098   // completely connected.
00099 
00100   ACE_INET_Addr remote_addr;
00101   if (this->peer ().get_remote_addr (remote_addr) == -1)
00102     return -1;
00103 
00104   ACE_INET_Addr local_addr;
00105   if (this->peer ().get_local_addr (local_addr) == -1)
00106     return -1;
00107 
00108   if (local_addr.get_ip_address () == remote_addr.get_ip_address ()
00109       && local_addr.get_port_number () == remote_addr.get_port_number ())
00110     {
00111       if (TAO_debug_level > 0)
00112         {
00113           ACE_TCHAR remote_as_string[MAXHOSTNAMELEN + 16];
00114           ACE_TCHAR local_as_string[MAXHOSTNAMELEN + 16];
00115 
00116           (void) remote_addr.addr_to_string (remote_as_string,
00117                                              sizeof(remote_as_string));
00118           (void) local_addr.addr_to_string (local_as_string,
00119                                             sizeof(local_as_string));
00120           ACE_ERROR ((LM_ERROR,
00121                       ACE_LIB_TEXT("TAO(%P|%t) - TAO_IIOP_Connection_Handler::open, ")
00122                       ACE_LIB_TEXT("Holy Cow! The remote addr and ")
00123                       ACE_LIB_TEXT("local addr are identical (%s == %s)\n"),
00124                       remote_as_string, local_as_string));
00125         }
00126       return -1;
00127     }
00128 
00129 
00130   if (TAO_debug_level > 0)
00131     {
00132       ACE_TCHAR client[MAXHOSTNAMELEN + 16];
00133 
00134       // Verify that we can resolve the peer hostname.
00135       if (remote_addr.addr_to_string (client, sizeof (client)) == -1)
00136         return -1;
00137 
00138       ACE_DEBUG ((LM_DEBUG,
00139                   ACE_LIB_TEXT ("TAO (%P|%t) IIOP connection to peer ")
00140                   ACE_LIB_TEXT ("<%s> on %d\n"),
00141                   client, this->peer ().get_handle ()));
00142     }
00143 
00144   // Set the id in the transport now that we're active.
00145   // Use C-style cast b/c otherwise we get warnings on lots of compilers
00146   this->transport ()->id ((size_t) this->get_handle ());
00147 
00148   this->state_changed (TAO_LF_Event::LFS_SUCCESS);
00149 
00150   return 0;
00151 }

int TAO_IIOP_Connection_Handler::process_listen_point_list IIOP::ListenPointList   listen_list
 

Process the <listen_list>.

Definition at line 267 of file IIOP_Connection_Handler.cpp.

References ACE_DEBUG, ACE_LIB_TEXT, ACE_TEXT_CHAR_TO_TCHAR, IIOP::ListenPoint::host, TAO_Unbounded_Base_Sequence::length, LM_DEBUG, TAO_Transport::make_idle, IIOP::ListenPoint::port, TAO_Transport::recache_transport, TAO_Transport_Descriptor_Interface::set_bidir_flag, and TAO_Connection_Handler::transport.

Referenced by TAO_IIOP_Transport::tear_listen_point_list.

00269 {
00270   // Get the size of the list
00271   CORBA::ULong len = listen_list.length ();
00272 
00273   for (CORBA::ULong i = 0; i < len; ++ i)
00274     {
00275       IIOP::ListenPoint listen_point = listen_list[i];
00276       ACE_INET_Addr addr (listen_point.port,
00277                           listen_point.host.in ());
00278 
00279       if (TAO_debug_level > 0)
00280         {
00281           ACE_DEBUG ((LM_DEBUG,
00282                       ACE_LIB_TEXT("(%P|%t) Listening port [%d] on [%s]\n"),
00283                       listen_point.port,
00284                       ACE_TEXT_CHAR_TO_TCHAR(listen_point.host.in ())));
00285         }
00286 
00287       // Construct an  IIOP_Endpoint object
00288       TAO_IIOP_Endpoint endpoint (addr,
00289         this->orb_core()->orb_params()->use_dotted_decimal_addresses ());
00290 
00291       // Construct a property object
00292       TAO_Base_Transport_Property prop (&endpoint);
00293 
00294       // Mark the connection as bidirectional
00295       prop.set_bidir_flag (1);
00296 
00297       // The property for this handler has changed. Recache the
00298       // handler with this property
00299       int retval = this->transport ()->recache_transport (&prop);
00300       if (retval == -1)
00301         return retval;
00302 
00303       // Make the handler idle and ready for use
00304       this->transport ()->make_idle ();
00305     }
00306 
00307   return 0;
00308 }

int TAO_IIOP_Connection_Handler::release_os_resources void    [protected, virtual]
 

Release the OS resources related to this handler, used in handle_close_eh().

Reimplemented from TAO_Connection_Handler.

Definition at line 236 of file IIOP_Connection_Handler.cpp.

References ACE_Svc_Handler< ACE_SOCK_STREAM, ACE_NULL_SYNCH >::peer.

00237 {
00238   return this->peer().close ();
00239 }

int TAO_IIOP_Connection_Handler::resume_handler void    [virtual]
 

Reimplemented from ACE_Event_Handler.

Definition at line 205 of file IIOP_Connection_Handler.cpp.

References ACE_Event_Handler::ACE_APPLICATION_RESUMES_HANDLER.

int TAO_IIOP_Connection_Handler::set_dscp_codepoint int    tos
 

int TAO_IIOP_Connection_Handler::set_dscp_codepoint void   
 

Set the Diff-Serv codepoint if the Policy dicates the setting of Network Priority.

Definition at line 344 of file IIOP_Connection_Handler.cpp.

References ACE_ANY_EXCEPTION, ACE_CATCHANY, ACE_CHECK_RETURN, ACE_DEBUG, ACE_DECLARE_NEW_CORBA_ENV, ACE_ENDTRY, ACE_ENV_SINGLE_ARG_PARAMETER, ACE_PRINT_EXCEPTION, ACE_TRY, ACE_TRY_CHECK, dscp_codepoint_, enable_network_priority, TAO_Protocols_Hooks::get_dscp_codepoint, TAO_ORB_Core::get_protocols_hooks, IPDSFIELD_DSCP_DEFAULT, LM_DEBUG, TAO_Connection_Handler::orb_core, and ACE_Svc_Handler< ACE_SOCK_STREAM, ACE_NULL_SYNCH >::peer.

Referenced by TAO_IIOP_Transport::send_message_shared.

00345 {
00346   int tos;
00347   if (this->enable_network_priority ())
00348     {
00349       ACE_DECLARE_NEW_CORBA_ENV;
00350       ACE_TRY
00351         {
00352           TAO_Protocols_Hooks *tph =
00353             this->orb_core ()->get_protocols_hooks (
00354               ACE_ENV_SINGLE_ARG_PARAMETER);
00355           ACE_TRY_CHECK;
00356 
00357           if (tph != 0)
00358             {
00359               CORBA::Long codepoint =
00360                 tph->get_dscp_codepoint ();
00361 
00362               tos = (int)(codepoint ) << 2;
00363             }
00364         }
00365       ACE_CATCHANY
00366         {
00367           if (TAO_debug_level > 0)
00368             ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
00369                                  "TAO_IIOP_Connection_Handler::"
00370                                  "set_dscp_codepoint - "
00371                                  "get_protocol_hooks");
00372 
00373           return -1;
00374         }
00375       ACE_ENDTRY;
00376       ACE_CHECK_RETURN (-1);
00377     }
00378   else
00379     tos = IPDSFIELD_DSCP_DEFAULT << 2;
00380 
00381   if (tos != this->dscp_codepoint_)
00382     {
00383       int ret = this->peer ().set_option (IPPROTO_IP,
00384                                           IP_TOS,
00385                                           (int *) &tos ,
00386                                           (int) sizeof (tos));
00387 
00388       if(TAO_debug_level)
00389         {
00390           ACE_DEBUG ((LM_DEBUG,
00391                       "TAO (%P|%t) - IIOP_Connection_Handler::"
00392                       "set_dscp_codepoint, failed to set Diffserv"
00393                       " codepoint - try running as superuser\n"));
00394 
00395           ACE_DEBUG((LM_DEBUG,
00396                      "TAO (%P|%t) - IIOP_Connection_Handler::"
00397                      "set_dscp_codepoint, set tos: ret: %d %x\n",
00398                      ret, tos));
00399         }
00400 
00401       this->dscp_codepoint_ = tos;
00402     }
00403 
00404   return 0;
00405 }

int TAO_IIOP_Connection_Handler::svc void    [virtual]
 

Only used when the handler is turned into an active object by calling <activate>. This serves as the event loop in such cases.

Reimplemented from ACE_Task_Base.

Definition at line 190 of file IIOP_Connection_Handler.cpp.

References ACE_NONBLOCK, ACE_Flag_Manip::clr_flags, and TAO_Connection_Handler::svc_i.

00191 {
00192   // This method is called when an instance is "activated", i.e.,
00193   // turned into an active object.  Presumably, activation spawns a
00194   // thread with this method as the "worker function".
00195 
00196   // Clear the non-blocking mode here
00197   ACE_Flag_Manip::clr_flags (this->get_handle (),
00198                              ACE_NONBLOCK);
00199 
00200   // Call the implementation here
00201   return this->svc_i ();
00202 }

void TAO_IIOP_Connection_Handler::update_protocol_properties int    send_buffer_size,
int    recv_buffer_size,
int    no_delay,
int    enable_network_priority
[virtual]
 

Update the tcp properties of the hanlder to the most recent properties set after the last invocation.

Definition at line 311 of file IIOP_Connection_Handler.cpp.

References ACE_DEBUG, TAO_IIOP_Properties::enable_network_priority, enable_network_priority, LM_DEBUG, TAO_IIOP_Properties::no_delay, TAO_IIOP_Properties::recv_buffer_size, TAO_IIOP_Properties::send_buffer_size, and tcp_properties_.

00316 {
00317   if (TAO_debug_level)
00318     ACE_DEBUG ((LM_DEBUG,
00319                 "TAO_IIOP_Connection_Handler::update_protocol_properties\n"
00320                 "enable_network_priority = %d\n",
00321                 enable_network_priority));
00322 
00323   if (this->tcp_properties_.send_buffer_size != send_buffer_size)
00324     this->tcp_properties_.send_buffer_size = send_buffer_size;
00325 
00326   if (this->tcp_properties_.recv_buffer_size != recv_buffer_size)
00327     this->tcp_properties_.recv_buffer_size = recv_buffer_size;
00328 
00329   if (this->tcp_properties_.no_delay != no_delay)
00330     this->tcp_properties_.no_delay = no_delay;
00331 
00332   if (this->tcp_properties_.enable_network_priority != enable_network_priority)
00333     this->tcp_properties_.enable_network_priority = enable_network_priority;
00334 
00335 }


Member Data Documentation

int TAO_IIOP_Connection_Handler::dscp_codepoint_ [private]
 

Stores the type of service value.

Definition at line 167 of file IIOP_Connection_Handler.h.

Referenced by set_dscp_codepoint.

TAO_IIOP_Properties TAO_IIOP_Connection_Handler::tcp_properties_ [private]
 

TCP configuration for this connection.

Definition at line 164 of file IIOP_Connection_Handler.h.

Referenced by enable_network_priority, open, and update_protocol_properties.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 15:19:12 2003 for TAO by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002