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)
 Constructor.
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)
 Should Reactor resume us if we have been suspended before the upcall?
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_NonBlocking_Connect_Handler< SVC_HANDLER >::ACE_NonBlocking_Connect_Handler ( ACE_Connector_Base< SVC_HANDLER > &  connector,
SVC_HANDLER *  sh,
long  timer_id 
) [inline]

Constructor.

Definition at line 22 of file Connector.cpp.

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 
00034   if (this->svc_handler_ != 0)
00035     this->svc_handler_->add_reference ();
00036 }


Member Function Documentation

template<class SVC_HANDLER >
bool ACE_NonBlocking_Connect_Handler< SVC_HANDLER >::close ( SVC_HANDLER *&  sh  )  [inline]

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 73 of file Connector.cpp.

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

template<class SVC_HANDLER >
void ACE_NonBlocking_Connect_Handler< SVC_HANDLER >::dump ( void   )  const [inline]

Dump the state of an object.

Definition at line 60 of file Connector.cpp.

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

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  )  [inline, virtual]

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

Reimplemented from ACE_Event_Handler.

Definition at line 185 of file Connector.cpp.

00186 {
00187   // On Win32, the except mask must also be set for asynchronous
00188   // connects.
00189   ACE_TRACE ("ACE_NonBlocking_Connect_Handler<SVC_HANDLER>::handle_exception");
00190   return this->handle_output (h);
00191 }

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

Called by ACE_Reactor when asynchronous connections fail.

Reimplemented from ACE_Event_Handler.

Definition at line 143 of file Connector.cpp.

00144 {
00145   // Called when a failure occurs during asynchronous connection
00146   // establishment.
00147   ACE_TRACE ("ACE_NonBlocking_Connect_Handler<SVC_HANDLER>::handle_input");
00148 
00149   SVC_HANDLER *svc_handler = 0;
00150   int const retval = this->close (svc_handler) ? 0 : -1;
00151 
00152   // Close Svc_Handler.
00153   if (svc_handler != 0)
00154     {
00155       svc_handler->close (NORMAL_CLOSE_OPERATION);
00156 
00157       svc_handler->remove_reference ();
00158     }
00159 
00160   return retval;
00161 }

template<class SVC_HANDLER >
int ACE_NonBlocking_Connect_Handler< SVC_HANDLER >::handle_output ( ACE_HANDLE  handle  )  [inline, virtual]

Called by ACE_Reactor when asynchronous connections succeed.

Reimplemented from ACE_Event_Handler.

Definition at line 164 of file Connector.cpp.

00165 {
00166   // Called when a connection is establishment asynchronous.
00167   ACE_TRACE ("ACE_NonBlocking_Connect_Handler<SVC_HANDLER>::handle_output");
00168 
00169   // Grab the connector ref before smashing ourselves in close().
00170   ACE_Connector_Base<SVC_HANDLER> &connector = this->connector_;
00171   SVC_HANDLER *svc_handler = 0;
00172   int const retval = this->close (svc_handler) ? 0 : -1;
00173 
00174   if (svc_handler != 0)
00175     {
00176       connector.initialize_svc_handler (handle, svc_handler);
00177 
00178       svc_handler->remove_reference ();
00179     }
00180 
00181   return retval;
00182 }

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

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

Reimplemented from ACE_Event_Handler.

Definition at line 118 of file Connector.cpp.

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

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

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

Reimplemented from ACE_Event_Handler.

Definition at line 194 of file Connector.cpp.

template<class SVC_HANDLER >
SVC_HANDLER * ACE_NonBlocking_Connect_Handler< SVC_HANDLER >::svc_handler ( void   )  [inline]

Get SVC_HANDLER.

Definition at line 39 of file Connector.cpp.

00040 {
00041   ACE_TRACE ("ACE_NonBlocking_Connect_Handler<SVC_HANDLER>::svc_handler");
00042   return this->svc_handler_;
00043 }

template<class SVC_HANDLER >
void ACE_NonBlocking_Connect_Handler< SVC_HANDLER >::timer_id ( long  timer_id  )  [inline]

Set timer id.

Definition at line 53 of file Connector.cpp.

00054 {
00055   ACE_TRACE ("ACE_NonBlocking_Connect_Handler<SVC_HANDLER>::timer_id");
00056   this->timer_id_ = id;
00057 }

template<class SVC_HANDLER >
long ACE_NonBlocking_Connect_Handler< SVC_HANDLER >::timer_id ( void   )  [inline]

Get timer id.

Definition at line 46 of file Connector.cpp.

00047 {
00048   ACE_TRACE ("ACE_NonBlocking_Connect_Handler<SVC_HANDLER>::timer_id");
00049   return this->timer_id_;
00050 }


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 120 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 125 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 128 of file Connector.h.

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

Associated timer id.

Definition at line 131 of file Connector.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Sun Nov 22 23:15:31 2009 for ACE by  doxygen 1.6.1