ACE_NonBlocking_Connect_Handler< SVC_HANDLER > Class Template Reference

Performs non-blocking connects on behalf of the Connector. More...

#include <Connector.h>

Inheritance diagram for ACE_NonBlocking_Connect_Handler< SVC_HANDLER >:

Inheritance graph
[legend]
Collaboration diagram for ACE_NonBlocking_Connect_Handler< SVC_HANDLER >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ACE_NonBlocking_Connect_Handler (ACE_Connector_Base< SVC_HANDLER > &connector, SVC_HANDLER *, long timer_id)
bool close (SVC_HANDLER *&sh)
 Close up and return underlying SVC_HANDLER through sh.

SVC_HANDLER * svc_handler (void)
 Get SVC_HANDLER.

ACE_HANDLE handle (void)
 Get handle.

void handle (ACE_HANDLE)
 Set handle.

long timer_id (void)
 Get timer id.

void timer_id (long timer_id)
 Set timer id.

virtual int handle_input (ACE_HANDLE)
 Called by ACE_Reactor when asynchronous connections fail.

virtual int handle_output (ACE_HANDLE)
 Called by ACE_Reactor when asynchronous connections succeed.

virtual int handle_exception (ACE_HANDLE fd)
virtual int handle_timeout (const ACE_Time_Value &tv, const void *arg)
virtual int resume_handler (void)
void dump (void) const
 Dump the state of an object.


Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks.


Private Attributes

ACE_Connector_Base< SVC_HANDLER > & connector_
 Connector base.

SVC_HANDLER * svc_handler_
 Associated SVC_HANDLER.

long timer_id_
 Associated timer id.


Detailed Description

template<class SVC_HANDLER>
class ACE_NonBlocking_Connect_Handler< SVC_HANDLER >

Performs non-blocking connects on behalf of the Connector.

Definition at line 61 of file Connector.h.


Constructor & Destructor Documentation

template<class SVC_HANDLER>
ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_NonBlocking_Connect_Handler< SVC_HANDLER >::ACE_NonBlocking_Connect_Handler ACE_Connector_Base< SVC_HANDLER > &  connector,
SVC_HANDLER *  ,
long  timer_id
 

Definition at line 22 of file Connector.cpp.

References ACE_TRACE.

00025   : connector_ (connector)
00026   , svc_handler_ (sh)
00027   , timer_id_ (id)
00028 {
00029   ACE_TRACE ("ACE_NonBlocking_Connect_Handler<SVC_HANDLER>::ACE_NonBlocking_Connect_Handler");
00030 
00031   this->reference_counting_policy ().value
00032     (ACE_Event_Handler::Reference_Counting_Policy::ENABLED);
00033 }


Member Function Documentation

template<class SVC_HANDLER>
bool ACE_NonBlocking_Connect_Handler< SVC_HANDLER >::close SVC_HANDLER *&  sh  ) 
 

Close up and return underlying SVC_HANDLER through sh.

If the return value is true the close was performed succesfully, implying that this object was removed from the reactor and thereby (by means of reference counting decremented to 0) deleted. If the return value is false, the close was not successful. The sh does not have any connection to the return value. The argument will return a valid svc_handler object if a valid one exists within the object. Returning a valid svc_handler pointer also invalidates the svc_handler contained in this object.

Definition at line 70 of file Connector.cpp.

References ACE_GUARD_RETURN, ACE_Reactor::cancel_timer(), ACE_Event_Handler::reactor(), and ACE_Reactor::remove_handler().

Referenced by ACE_NonBlocking_Connect_Handler< SVC_HANDLER >::handle_input(), and ACE_NonBlocking_Connect_Handler< SVC_HANDLER >::handle_output().

00071 {
00072   // Make sure that we haven't already initialized the Svc_Handler.
00073   if (!this->svc_handler_)
00074     return false;
00075 
00076   {
00077     // Exclusive access to the Reactor.
00078     ACE_GUARD_RETURN (ACE_Lock,
00079                       ace_mon,
00080                       this->reactor ()->lock (),
00081                       0);
00082 
00083     // Double check.
00084     if (!this->svc_handler_)
00085       return false;
00086 
00087     // Remember the Svc_Handler.
00088     sh = this->svc_handler_;
00089     ACE_HANDLE h = sh->get_handle ();
00090     this->svc_handler_ = 0;
00091 
00092     // Remove this handle from the set of non-blocking handles
00093     // in the Connector.
00094     this->connector_.non_blocking_handles ().remove (h);
00095 
00096     // Cancel timer.
00097     if (this->reactor ()->cancel_timer (this->timer_id (),
00098                                         0,
00099                                         0) == -1)
00100       return false;
00101 
00102     // Remove from Reactor.
00103     if (this->reactor ()->remove_handler (
00104           h,
00105           ACE_Event_Handler::ALL_EVENTS_MASK) == -1)
00106       return false;
00107   }
00108 
00109   return true;
00110 }

template<class SVC_HANDLER>
void ACE_NonBlocking_Connect_Handler< SVC_HANDLER >::dump void   )  const
 

Dump the state of an object.

Definition at line 57 of file Connector.cpp.

References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_LIB_TEXT, ACE_TRACE, and LM_DEBUG.

00058 {
00059 #if defined (ACE_HAS_DUMP)
00060   ACE_TRACE ("ACE_NonBlocking_Connect_Handler<SVC_HANDLER>::dump");
00061 
00062   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00063   ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("svc_handler_ = %x"), this->svc_handler_));
00064   ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("\ntimer_id_ = %d"), this->timer_id_));
00065   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00066 #endif /* ACE_HAS_DUMP */
00067 }

template<class SVC_HANDLER>
void ACE_NonBlocking_Connect_Handler< SVC_HANDLER >::handle ACE_HANDLE   ) 
 

Set handle.

template<class SVC_HANDLER>
ACE_HANDLE ACE_NonBlocking_Connect_Handler< SVC_HANDLER >::handle void   ) 
 

Get handle.

template<class SVC_HANDLER>
int ACE_NonBlocking_Connect_Handler< SVC_HANDLER >::handle_exception ACE_HANDLE  fd  )  [virtual]
 

Called by ACE_Reactor when asynchronous connections suceeds (on some platforms only).

Reimplemented from ACE_Event_Handler.

Definition at line 171 of file Connector.cpp.

References ACE_TRACE, and ACE_NonBlocking_Connect_Handler< SVC_HANDLER >::handle_output().

00172 {
00173   // On Win32, the except mask must also be set for asynchronous
00174   // connects.
00175   ACE_TRACE ("ACE_NonBlocking_Connect_Handler<SVC_HANDLER>::handle_exception");
00176   return this->handle_output (h);
00177 }

template<class SVC_HANDLER>
int ACE_NonBlocking_Connect_Handler< SVC_HANDLER >::handle_input ACE_HANDLE   )  [virtual]
 

Called by ACE_Reactor when asynchronous connections fail.

Reimplemented from ACE_Event_Handler.

Definition at line 137 of file Connector.cpp.

References ACE_TRACE, ACE_NonBlocking_Connect_Handler< SVC_HANDLER >::close(), and ACE_NonBlocking_Connect_Handler< SVC_HANDLER >::svc_handler().

00138 {
00139   // Called when a failure occurs during asynchronous connection
00140   // establishment.
00141   ACE_TRACE ("ACE_NonBlocking_Connect_Handler<SVC_HANDLER>::handle_input");
00142 
00143   SVC_HANDLER *svc_handler = 0;
00144   int retval = this->close (svc_handler) ? 0 : -1;
00145 
00146   // Close Svc_Handler.
00147   if (svc_handler != 0)
00148     svc_handler->close (0);
00149 
00150   return retval;
00151 }

template<class SVC_HANDLER>
int ACE_NonBlocking_Connect_Handler< SVC_HANDLER >::handle_output ACE_HANDLE   )  [virtual]
 

Called by ACE_Reactor when asynchronous connections succeed.

Reimplemented from ACE_Event_Handler.

Definition at line 154 of file Connector.cpp.

References ACE_TRACE, ACE_NonBlocking_Connect_Handler< SVC_HANDLER >::close(), ACE_Connector_Base< SVC_HANDLER >::initialize_svc_handler(), and ACE_NonBlocking_Connect_Handler< SVC_HANDLER >::svc_handler().

Referenced by ACE_NonBlocking_Connect_Handler< SVC_HANDLER >::handle_exception().

00155 {
00156   // Called when a connection is establishment asynchronous.
00157   ACE_TRACE ("ACE_NonBlocking_Connect_Handler<SVC_HANDLER>::handle_output");
00158 
00159   // Grab the connector ref before smashing ourselves in close().
00160   ACE_Connector_Base<SVC_HANDLER> &connector = this->connector_;
00161   SVC_HANDLER *svc_handler = 0;
00162   int retval = this->close (svc_handler) ? 0 : -1;
00163 
00164   if (svc_handler != 0)
00165     connector.initialize_svc_handler (handle, svc_handler);
00166 
00167   return retval;
00168 }

template<class SVC_HANDLER>
int ACE_NonBlocking_Connect_Handler< SVC_HANDLER >::handle_timeout const ACE_Time_Value tv,
const void *  arg
[virtual]
 

This method is called if a connection times out before completing.

Reimplemented from ACE_Event_Handler.

Definition at line 115 of file Connector.cpp.

References ACE_TRACE.

00117 {
00118   // This method is called if a connection times out before completing.
00119   ACE_TRACE ("ACE_NonBlocking_Connect_Handler<SVC_HANDLER>::handle_timeout");
00120 
00121   SVC_HANDLER *svc_handler = 0;
00122   int retval = this->close (svc_handler) ? 0 : -1;
00123 
00124   // Forward to the SVC_HANDLER the <arg> that was passed in as a
00125   // magic cookie during ACE_Connector::connect().  This gives the
00126   // SVC_HANDLER an opportunity to take corrective action (e.g., wait
00127   // a few milliseconds and try to reconnect again.
00128   if (svc_handler != 0 && svc_handler->handle_timeout (tv, arg) == -1)
00129     svc_handler->handle_close (svc_handler->get_handle (),
00130                                ACE_Event_Handler::TIMER_MASK);
00131 
00132   return retval;
00133 }

template<class SVC_HANDLER>
int ACE_NonBlocking_Connect_Handler< SVC_HANDLER >::resume_handler void   )  [virtual]
 

Should Reactor resume us if we have been suspended before the upcall?

Reimplemented from ACE_Event_Handler.

Definition at line 180 of file Connector.cpp.

template<class SVC_HANDLER>
SVC_HANDLER * ACE_NonBlocking_Connect_Handler< SVC_HANDLER >::svc_handler void   ) 
 

Get SVC_HANDLER.

Definition at line 36 of file Connector.cpp.

References ACE_TRACE.

Referenced by ACE_NonBlocking_Connect_Handler< SVC_HANDLER >::handle_input(), and ACE_NonBlocking_Connect_Handler< SVC_HANDLER >::handle_output().

00037 {
00038   ACE_TRACE ("ACE_NonBlocking_Connect_Handler<SVC_HANDLER>::svc_handler");
00039   return this->svc_handler_;
00040 }

template<class SVC_HANDLER>
void ACE_NonBlocking_Connect_Handler< SVC_HANDLER >::timer_id long  timer_id  ) 
 

Set timer id.

Definition at line 50 of file Connector.cpp.

References ACE_TRACE, and ACE_NonBlocking_Connect_Handler< SVC_HANDLER >::timer_id_.

00051 {
00052   ACE_TRACE ("ACE_NonBlocking_Connect_Handler<SVC_HANDLER>::timer_id");
00053   this->timer_id_ = id;
00054 }

template<class SVC_HANDLER>
long ACE_NonBlocking_Connect_Handler< SVC_HANDLER >::timer_id void   ) 
 

Get timer id.

Definition at line 43 of file Connector.cpp.

References ACE_TRACE, and ACE_NonBlocking_Connect_Handler< SVC_HANDLER >::timer_id_.

00044 {
00045   ACE_TRACE ("ACE_NonBlocking_Connect_Handler<SVC_HANDLER>::timer_id");
00046   return this->timer_id_;
00047 }


Member Data Documentation

template<class SVC_HANDLER>
ACE_NonBlocking_Connect_Handler< SVC_HANDLER >::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

Definition at line 124 of file Connector.h.

template<class SVC_HANDLER>
ACE_Connector_Base<SVC_HANDLER>& ACE_NonBlocking_Connect_Handler< SVC_HANDLER >::connector_ [private]
 

Connector base.

Definition at line 129 of file Connector.h.

template<class SVC_HANDLER>
SVC_HANDLER* ACE_NonBlocking_Connect_Handler< SVC_HANDLER >::svc_handler_ [private]
 

Associated SVC_HANDLER.

Definition at line 132 of file Connector.h.

template<class SVC_HANDLER>
long ACE_NonBlocking_Connect_Handler< SVC_HANDLER >::timer_id_ [private]
 

Associated timer id.

Definition at line 135 of file Connector.h.

Referenced by ACE_NonBlocking_Connect_Handler< SVC_HANDLER >::timer_id().


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 11:25:44 2006 for ACE by doxygen 1.3.6