TAO_DIOP_Connection_Handler Class Reference

Handles requests on a single connection. More...

#include <DIOP_Connection_Handler.h>

Inheritance diagram for TAO_DIOP_Connection_Handler:

Inheritance graph
[legend]
Collaboration diagram for TAO_DIOP_Connection_Handler:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 TAO_DIOP_Connection_Handler (ACE_Thread_Manager *t=0)
 TAO_DIOP_Connection_Handler (TAO_ORB_Core *orb_core)
 Constructor.
 ~TAO_DIOP_Connection_Handler (void)
 Destructor.
virtual int open (void *)
virtual int open_server (void)
int close (u_long=0)
int add_transport_to_cache (void)
 Add ourselves to Cache.
int set_dscp_codepoint (CORBA::Boolean set_network_priority)
 Set Diff-Serv codepoint on outgoing packets.
int set_dscp_codepoint (CORBA::Long dscp_codepoint)
virtual int open_handler (void *)
Event Handler overloads
virtual int resume_handler (void)
virtual int close_connection (void)
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 &current_time, const void *act=0)
The DIOP Additions
const ACE_INET_Addraddr (void)
void addr (const ACE_INET_Addr &addr)
const ACE_INET_Addrlocal_addr (void)
void local_addr (const ACE_INET_Addr &addr)

Protected Member Functions

int set_tos (int tos)
 Helper method used by the set_dscp_codepoint () methods.
TAO_Connection Handler overloads
virtual int release_os_resources (void)

Protected Attributes

The DIOP Additions
ACE_INET_Addr addr_
 This is always the remote address.
ACE_INET_Addr local_addr_
 This is always the local address for the connector.

Private Attributes

int dscp_codepoint_
 Stores the type of service value.

Detailed Description

Handles requests on a single connection.

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

Definition at line 46 of file DIOP_Connection_Handler.h.


Constructor & Destructor Documentation

TAO_BEGIN_VERSIONED_NAMESPACE_DECL TAO_DIOP_Connection_Handler::TAO_DIOP_Connection_Handler ( ACE_Thread_Manager t = 0  ) 

Definition at line 30 of file DIOP_Connection_Handler.cpp.

References ACE_ASSERT.

00031   : TAO_DIOP_SVC_HANDLER (t, 0 , 0),
00032     TAO_Connection_Handler (0),
00033     dscp_codepoint_ (IPDSFIELD_DSCP_DEFAULT << 2)
00034 {
00035   // This constructor should *never* get called, it is just here to
00036   // make the compiler happy: the default implementation of the
00037   // Creation_Strategy requires a constructor with that signature, we
00038   // don't use that implementation, but some (most?) compilers
00039   // instantiate it anyway.
00040   ACE_ASSERT (0);
00041 }

TAO_DIOP_Connection_Handler::TAO_DIOP_Connection_Handler ( TAO_ORB_Core orb_core  ) 

Constructor.

Definition at line 43 of file DIOP_Connection_Handler.cpp.

References ACE_NEW, TAO_Connection_Handler::orb_core(), and TAO_Connection_Handler::transport().

00044   : TAO_DIOP_SVC_HANDLER (orb_core->thr_mgr (), 0, 0),
00045     TAO_Connection_Handler (orb_core),
00046     dscp_codepoint_ (IPDSFIELD_DSCP_DEFAULT << 2)
00047 {
00048   TAO_DIOP_Transport* specific_transport = 0;
00049   ACE_NEW (specific_transport,
00050            TAO_DIOP_Transport (this, orb_core));
00051 
00052   // store this pointer (indirectly increment ref count)
00053   this->transport (specific_transport);
00054 }

TAO_DIOP_Connection_Handler::~TAO_DIOP_Connection_Handler ( void   ) 

Destructor.

Definition at line 56 of file DIOP_Connection_Handler.cpp.

References ACE_ERROR, ACE_TEXT, LM_ERROR, release_os_resources(), TAO_debug_level, and TAO_Connection_Handler::transport().

00057 {
00058   delete this->transport ();
00059   int const result =
00060     this->release_os_resources ();
00061 
00062   if (result == -1 && TAO_debug_level)
00063     {
00064       ACE_ERROR ((LM_ERROR,
00065                   ACE_TEXT ("TAO (%P|%t) - DIOP_Connection_Handler::")
00066                   ACE_TEXT ("~DIOP_Connection_Handler, ")
00067                   ACE_TEXT ("release_os_resources() failed %m\n")));
00068     }
00069 }


Member Function Documentation

int TAO_DIOP_Connection_Handler::add_transport_to_cache ( void   ) 

Add ourselves to Cache.

Definition at line 284 of file DIOP_Connection_Handler.cpp.

References addr(), TAO_ORB_Core::lane_resources(), TAO_Connection_Handler::orb_core(), and TAO_Thread_Lane_Resources::transport_cache().

00285 {
00286   ACE_INET_Addr addr;
00287 
00288   // This function is called by the acceptor to add this
00289   // transport to the transport cache.  This is really
00290   // important for proper shutdown.  The address used
00291   // is irrelevent, since DIOP is connectionless.
00292 
00293   // Construct a DIOP_Endpoint object.
00294   TAO_DIOP_Endpoint endpoint (
00295       addr,
00296       this->orb_core ()->orb_params ()->cache_incoming_by_dotted_decimal_address ());
00297 
00298   // Construct a property object
00299   TAO_Base_Transport_Property prop (&endpoint);
00300 
00301   // Add the handler to Cache
00302   return this->orb_core ()->lane_resources ()
00303     .transport_cache ().cache_transport (&prop, this->transport ());
00304 }

void TAO_DIOP_Connection_Handler::addr ( const ACE_INET_Addr addr  ) 

Definition at line 79 of file DIOP_Connection_Handler.cpp.

References addr(), and addr_.

00080 {
00081   this->addr_ = addr;
00082 }

const ACE_INET_Addr & TAO_DIOP_Connection_Handler::addr ( void   ) 

Definition at line 73 of file DIOP_Connection_Handler.cpp.

References addr_.

Referenced by add_transport_to_cache(), addr(), local_addr(), TAO_DIOP_Connector::make_connection(), TAO_DIOP_Transport::recv(), and TAO_DIOP_Transport::send().

00074 {
00075   return this->addr_;
00076 }

int TAO_DIOP_Connection_Handler::close ( u_long  = 0  )  [virtual]

Close called by the Acceptor or Connector when connection establishment fails.

Reimplemented from ACE_Svc_Handler< ACE_SOCK_DGRAM, ACE_NULL_SYNCH >.

Definition at line 272 of file DIOP_Connection_Handler.cpp.

References TAO_Connection_Handler::close_handler().

Referenced by TAO_DIOP_Connector::make_connection(), and TAO_DIOP_Acceptor::open_i().

00273 {
00274   return this->close_handler ();
00275 }

int TAO_DIOP_Connection_Handler::close_connection ( void   )  [virtual]

Implements TAO_Connection_Handler.

Definition at line 224 of file DIOP_Connection_Handler.cpp.

References TAO_Connection_Handler::close_connection_eh().

Referenced by handle_output().

00225 {
00226   return this->close_connection_eh (this);
00227 }

int TAO_DIOP_Connection_Handler::handle_close ( ACE_HANDLE  ,
ACE_Reactor_Mask   
) [virtual]

Reimplemented from ACE_Svc_Handler< ACE_SOCK_DGRAM, ACE_NULL_SYNCH >.

Definition at line 261 of file DIOP_Connection_Handler.cpp.

00262 {
00263   // No asserts here since the handler is registered with the Reactor
00264   // and the handler ownership is given to the Reactor.  When the
00265   // Reactor closes, it will call handle_close() on the handler.  It
00266   // is however important to overwrite handle_close() to do nothing
00267   // since the base class does too much.
00268   return 0;
00269 }

int TAO_DIOP_Connection_Handler::handle_input ( ACE_HANDLE   )  [virtual]

Implements TAO_Connection_Handler.

Definition at line 230 of file DIOP_Connection_Handler.cpp.

References TAO_Connection_Handler::handle_input_eh().

00231 {
00232   return this->handle_input_eh (h, this);
00233 }

int TAO_DIOP_Connection_Handler::handle_output ( ACE_HANDLE   )  [virtual]

Reimplemented from ACE_Event_Handler.

Definition at line 236 of file DIOP_Connection_Handler.cpp.

References close_connection(), and TAO_Connection_Handler::handle_output_eh().

00237 {
00238   int result =
00239     this->handle_output_eh (handle, this);
00240 
00241   if (result == -1)
00242     {
00243       this->close_connection ();
00244       return 0;
00245     }
00246 
00247   return result;
00248 }

int TAO_DIOP_Connection_Handler::handle_timeout ( const ACE_Time_Value current_time,
const void *  act = 0 
) [virtual]

Reimplemented from ACE_Svc_Handler< ACE_SOCK_DGRAM, ACE_NULL_SYNCH >.

Definition at line 251 of file DIOP_Connection_Handler.cpp.

00253 {
00254   // We don't use this upcall from the Reactor.  However, we should
00255   // override this since the base class returns -1 which will result
00256   // in handle_close() getting called.
00257   return 0;
00258 }

void TAO_DIOP_Connection_Handler::local_addr ( const ACE_INET_Addr addr  ) 

Definition at line 91 of file DIOP_Connection_Handler.cpp.

References addr(), and local_addr_.

00092 {
00093   this->local_addr_ = addr;
00094 }

const ACE_INET_Addr & TAO_DIOP_Connection_Handler::local_addr ( void   ) 

Definition at line 85 of file DIOP_Connection_Handler.cpp.

References local_addr_.

Referenced by TAO_DIOP_Connector::make_connection(), TAO_DIOP_Acceptor::open_i(), and set_tos().

00086 {
00087   return this->local_addr_;
00088 }

int TAO_DIOP_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_DGRAM, ACE_NULL_SYNCH >.

Definition at line 104 of file DIOP_Connection_Handler.cpp.

References ACE_DEBUG, ACE_TEXT, ACE_TEXT_CHAR_TO_TCHAR, TAO_Protocols_Hooks::client_protocol_properties_at_orb_level(), TAO_ORB_Core::get_protocols_hooks(), TAO_LF_Event::LFS_SUCCESS, LM_DEBUG, TAO_Connection_Handler::orb_core(), TAO_ORB_Core::orb_params(), ACE_Svc_Handler< ACE_SOCK_DGRAM, ACE_NULL_SYNCH >::peer(), TAO_DIOP_Protocol_Properties::recv_buffer_size_, TAO_DIOP_Protocol_Properties::send_buffer_size_, TAO_Protocols_Hooks::server_protocol_properties_at_orb_level(), TAO_ORB_Parameters::sock_rcvbuf_size(), TAO_ORB_Parameters::sock_sndbuf_size(), TAO_LF_Event::state_changed(), TAO::TAO_CLIENT_ROLE, and TAO_debug_level.

Referenced by TAO_DIOP_Connector::make_connection(), and open_handler().

00105 {
00106   TAO_DIOP_Protocol_Properties protocol_properties;
00107 
00108   // Initialize values from ORB params.
00109   protocol_properties.send_buffer_size_ =
00110     this->orb_core ()->orb_params ()->sock_sndbuf_size ();
00111   protocol_properties.recv_buffer_size_ =
00112     this->orb_core ()->orb_params ()->sock_rcvbuf_size ();
00113 
00114   TAO_Protocols_Hooks *tph = this->orb_core ()->get_protocols_hooks ();
00115 
00116   if (tph != 0)
00117     {
00118       try
00119         {
00120           if (this->transport ()->opened_as () == TAO::TAO_CLIENT_ROLE)
00121             {
00122               tph->client_protocol_properties_at_orb_level (protocol_properties);
00123             }
00124           else
00125             {
00126               tph->server_protocol_properties_at_orb_level (protocol_properties);
00127             }
00128         }
00129       catch (const ::CORBA::Exception&)
00130         {
00131           return -1;
00132         }
00133     }
00134 
00135   this->peer ().open (this->local_addr_);
00136 
00137   if (this->set_socket_option (this->peer (),
00138                                protocol_properties.send_buffer_size_,
00139                                protocol_properties.recv_buffer_size_) == -1)
00140     return -1;
00141 
00142   if (TAO_debug_level > 5)
00143   {
00144      ACE_DEBUG ((LM_DEBUG,
00145                  ACE_TEXT("TAO (%P|%t) - DIOP_Connection_Handler::open, ")
00146                  ACE_TEXT("listening on: <%s:%u>\n"),
00147                  ACE_TEXT_CHAR_TO_TCHAR (this->local_addr_.get_host_name ()),
00148                  this->local_addr_.get_port_number ()));
00149   }
00150 
00151   // Set that the transport is now connected, if fails we return -1
00152   // Use C-style cast b/c otherwise we get warnings on lots of
00153   // compilers
00154   if (!this->transport ()->post_open ((size_t) this->peer ().get_handle ()))
00155     return -1;
00156 
00157   this->state_changed (TAO_LF_Event::LFS_SUCCESS,
00158                        this->orb_core ()->leader_follower ());
00159 
00160   return 0;
00161 }

int TAO_DIOP_Connection_Handler::open_handler ( void *   )  [virtual]

Connection_Handler overloads

Implements TAO_Connection_Handler.

Definition at line 98 of file DIOP_Connection_Handler.cpp.

References open().

00099 {
00100   return this->open (v);
00101 }

int TAO_DIOP_Connection_Handler::open_server ( void   )  [virtual]

Definition at line 164 of file DIOP_Connection_Handler.cpp.

References ACE_DEBUG, ACE_TEXT, ACE_TEXT_CHAR_TO_TCHAR, TAO_Protocols_Hooks::client_protocol_properties_at_orb_level(), TAO_ORB_Core::get_protocols_hooks(), TAO_Transport::id(), LM_DEBUG, TAO_Connection_Handler::orb_core(), TAO_ORB_Core::orb_params(), ACE_Svc_Handler< ACE_SOCK_DGRAM, ACE_NULL_SYNCH >::peer(), TAO_DIOP_Protocol_Properties::recv_buffer_size_, TAO_DIOP_Protocol_Properties::send_buffer_size_, TAO_Protocols_Hooks::server_protocol_properties_at_orb_level(), TAO_ORB_Parameters::sock_rcvbuf_size(), TAO_ORB_Parameters::sock_sndbuf_size(), TAO::TAO_CLIENT_ROLE, TAO_debug_level, and TAO_Connection_Handler::transport().

Referenced by TAO_DIOP_Acceptor::open_i().

00165 {
00166   TAO_DIOP_Protocol_Properties protocol_properties;
00167 
00168   // Initialize values from ORB params.
00169   protocol_properties.send_buffer_size_ =
00170     this->orb_core ()->orb_params ()->sock_sndbuf_size ();
00171   protocol_properties.recv_buffer_size_ =
00172     this->orb_core ()->orb_params ()->sock_rcvbuf_size ();
00173 
00174   TAO_Protocols_Hooks *tph = this->orb_core ()->get_protocols_hooks ();
00175 
00176   if (tph != 0)
00177     {
00178       try
00179         {
00180           if (this->transport ()->opened_as () == TAO::TAO_CLIENT_ROLE)
00181             {
00182               tph->client_protocol_properties_at_orb_level (protocol_properties);
00183             }
00184           else
00185             {
00186               tph->server_protocol_properties_at_orb_level (protocol_properties);
00187             }
00188         }
00189       catch (const ::CORBA::Exception&)
00190         {
00191           return -1;
00192         }
00193     }
00194 
00195   this->peer ().open (this->local_addr_);
00196 
00197   if (this->set_socket_option (this->peer (),
00198                                protocol_properties.send_buffer_size_,
00199                                protocol_properties.recv_buffer_size_) == -1)
00200     return -1;
00201 
00202   if (TAO_debug_level > 5)
00203     {
00204       ACE_DEBUG ((LM_DEBUG,
00205                   ACE_TEXT("TAO (%P|%t) - DIOP_Connection_Handler::open_server, ")
00206                   ACE_TEXT("listening on %s:%d\n"),
00207                   ACE_TEXT_CHAR_TO_TCHAR (this->local_addr_.get_host_name ()),
00208                   this->local_addr_.get_port_number ()
00209                 ));
00210     }
00211 
00212   this->transport ()->id ((size_t) this->peer ().get_handle ());
00213 
00214   return 0;
00215 }

int TAO_DIOP_Connection_Handler::release_os_resources ( void   )  [protected, virtual]

Reimplemented from TAO_Connection_Handler.

Definition at line 278 of file DIOP_Connection_Handler.cpp.

References ACE_Svc_Handler< ACE_SOCK_DGRAM, ACE_NULL_SYNCH >::peer().

Referenced by ~TAO_DIOP_Connection_Handler().

00279 {
00280   return this->peer ().close ();
00281 }

int TAO_DIOP_Connection_Handler::resume_handler ( void   )  [virtual]

Reimplemented from ACE_Event_Handler.

Definition at line 218 of file DIOP_Connection_Handler.cpp.

References ACE_Event_Handler::ACE_APPLICATION_RESUMES_HANDLER.

int TAO_DIOP_Connection_Handler::set_dscp_codepoint ( CORBA::Long  dscp_codepoint  )  [virtual]

Reimplemented from TAO_Connection_Handler.

Definition at line 360 of file DIOP_Connection_Handler.cpp.

References IPDSFIELD_DSCP_DEFAULT, and set_tos().

00361 {
00362   int tos = IPDSFIELD_DSCP_DEFAULT << 2;
00363   tos = (int)(dscp) << 2;
00364   this->set_tos (tos);
00365   return 0;
00366 }

int TAO_DIOP_Connection_Handler::set_dscp_codepoint ( CORBA::Boolean  set_network_priority  )  [virtual]

Set Diff-Serv codepoint on outgoing packets.

Reimplemented from TAO_Connection_Handler.

Definition at line 369 of file DIOP_Connection_Handler.cpp.

References TAO_Protocols_Hooks::get_dscp_codepoint(), TAO_ORB_Core::get_protocols_hooks(), IPDSFIELD_DSCP_DEFAULT, TAO_Connection_Handler::orb_core(), and set_tos().

00370 {
00371   int tos = IPDSFIELD_DSCP_DEFAULT << 2;
00372 
00373   if (set_network_priority)
00374     {
00375       TAO_Protocols_Hooks *tph = this->orb_core ()->get_protocols_hooks ();
00376 
00377       if (tph != 0)
00378         {
00379           CORBA::Long codepoint = tph->get_dscp_codepoint ();
00380 
00381           tos = (int)(codepoint) << 2;
00382           this->set_tos (tos);
00383         }
00384     }
00385   return 0;
00386 }

int TAO_DIOP_Connection_Handler::set_tos ( int  tos  )  [protected]

Helper method used by the set_dscp_codepoint () methods.

Definition at line 307 of file DIOP_Connection_Handler.cpp.

References ACE_DEBUG, dscp_codepoint_, ACE_Addr::get_type(), IPPROTO_IP, LM_DEBUG, local_addr(), ACE_Svc_Handler< ACE_SOCK_DGRAM, ACE_NULL_SYNCH >::peer(), and TAO_debug_level.

Referenced by set_dscp_codepoint().

00308 {
00309   if (tos != this->dscp_codepoint_)
00310     {
00311       int result = 0;
00312 #if defined (ACE_HAS_IPV6)
00313       ACE_INET_Addr local_addr;
00314       if (this->peer ().get_local_addr (local_addr) == -1)
00315         return -1;
00316       else if (local_addr.get_type () == AF_INET6)
00317 # if !defined (IPV6_TCLASS)
00318         // IPv6 defines option IPV6_TCLASS for specifying traffic class/priority
00319         // but not many implementations yet (very new;-).
00320         {
00321           if (TAO_debug_level)
00322             {
00323               ACE_DEBUG ((LM_DEBUG,
00324                           "TAO (%P|%t) - DIOP_Connection_Handler::"
00325                           "set_dscp_codepoint -> IPV6_TCLASS not supported yet\n"));
00326             }
00327           return 0;
00328         }
00329 # else /* !IPV6_TCLASS */
00330         result = this->peer ().set_option (IPPROTO_IPV6,
00331                                            IPV6_TCLASS,
00332                                            (int *) &tos ,
00333                                            (int) sizeof (tos));
00334       else
00335 # endif /* IPV6_TCLASS */
00336 #endif /* ACE_HAS_IPV6 */
00337       result = this->peer ().set_option (IPPROTO_IP,
00338                                          IP_TOS,
00339                                          (int *) &tos ,
00340                                          (int) sizeof (tos));
00341 
00342       if (TAO_debug_level)
00343         {
00344           ACE_DEBUG ((LM_DEBUG,
00345                       "TAO (%P|%t) - DIOP_Connection_Handler::"
00346                       "set_dscp_codepoint, dscp: %x; result: %d; %s\n",
00347                       tos,
00348                       result,
00349                       result == -1 ? "try running as superuser" : ""));
00350         }
00351 
00352       // On successful setting of TOS field.
00353       if (result == 0)
00354         this->dscp_codepoint_ = tos;
00355     }
00356   return 0;
00357 }


Member Data Documentation

ACE_INET_Addr TAO_DIOP_Connection_Handler::addr_ [protected]

This is always the remote address.

Definition at line 139 of file DIOP_Connection_Handler.h.

Referenced by addr().

int TAO_DIOP_Connection_Handler::dscp_codepoint_ [private]

Stores the type of service value.

Definition at line 148 of file DIOP_Connection_Handler.h.

Referenced by set_tos().

ACE_INET_Addr TAO_DIOP_Connection_Handler::local_addr_ [protected]

This is always the local address for the connector.

Definition at line 142 of file DIOP_Connection_Handler.h.

Referenced by local_addr().


The documentation for this class was generated from the following files:
Generated on Tue Feb 2 17:47:30 2010 for TAO_Strategies by  doxygen 1.4.7