#include <Svc_Handler.h>
Inheritance diagram for ACE_Svc_Handler<, >:


Public Types | |
| typedef ACE_PEER_STREAM_ADDR | addr_type | 
| typedef ACE_PEER_STREAM | stream_type | 
Public Member Functions | |
| ACE_Svc_Handler (ACE_Thread_Manager *thr_mgr=0, ACE_Message_Queue< ACE_SYNCH_USE > *mq=0, ACE_Reactor *reactor=ACE_Reactor::instance()) | |
| virtual | ~ACE_Svc_Handler (void) | 
| Destructor.   | |
| virtual int | open (void *=0) | 
| virtual int | close (u_long flags=0) | 
| virtual int | idle (u_long flags=0) | 
| virtual ACE_Recyclable_State | recycle_state (void) const | 
| virtual int | recycle_state (ACE_Recyclable_State new_state) | 
| virtual void | cleanup_hint (void **act_holder=0) | 
| virtual int | init (int argc, ACE_TCHAR *argv[]) | 
| virtual int | fini (void) | 
| virtual int | info (ACE_TCHAR **info_string, size_t length) const | 
| virtual int | handle_close (ACE_HANDLE=ACE_INVALID_HANDLE, ACE_Reactor_Mask=ACE_Event_Handler::ALL_EVENTS_MASK) | 
| virtual int | handle_timeout (const ACE_Time_Value &time, const void *) | 
| virtual ACE_HANDLE | get_handle (void) const | 
| Get the underlying handle associated with the .   | |
| virtual void | set_handle (ACE_HANDLE) | 
| Set the underlying handle associated with the .   | |
| ACE_PEER_STREAM & | peer (void) const | 
| void * | operator new (size_t n) | 
| void * | operator new (size_t n, void *p) | 
| This operator permits "placement new" on a per-object basis.   | |
| virtual void | destroy (void) | 
| void | operator delete (void *) | 
| void | operator delete (void *, void *) | 
| void | shutdown (void) | 
| Close down the descriptor and unregister from the Reactor.   | |
| void | dump (void) const | 
| Dump the state of an object.   | |
| virtual void | recycler (ACE_Connection_Recycling_Strategy *recycler, const void *recycling_act) | 
| virtual ACE_Connection_Recycling_Strategy * | recycler (void) const | 
| Get the recycler.   | |
| virtual const void * | recycling_act (void) const | 
| Get the recycling act.   | |
| virtual int | recycle (void *=0) | 
Protected Attributes | |
| ACE_PEER_STREAM | peer_ | 
| Maintain connection with client.   | |
| bool | dynamic_ | 
| Have we been dynamically created?   | |
| bool | closing_ | 
| ACE_Connection_Recycling_Strategy * | recycler_ | 
| Pointer to the connection recycler.   | |
| const void * | recycling_act_ | 
This class provides a well-defined interface that the Acceptor and Connector pattern factories use as their target. Typically, client applications will subclass ACE_Svc_Handler and do all the interesting work in the subclass. One thing that the ACE_Svc_Handler does contain is a PEER_STREAM endpoint that is initialized by an ACE_Acceptor or ACE_Connector when a connection is established successfully. This endpoint is used to exchange data between a ACE_Svc_Handler and the peer it is connected with.
Definition at line 51 of file Svc_Handler.h.
      
  | 
  |||||
| 
 
 Definition at line 56 of file Svc_Handler.h.  | 
  
      
  | 
  |||||
| 
 
 Definition at line 57 of file Svc_Handler.h.  | 
  
      
  | 
  ||||||||||||||||||||
| 
 Constructor initializes the thr_mgr and mq by passing them down to the ACE_Task base class. The reactor is passed to the ACE_Event_Handler. Definition at line 134 of file Svc_Handler.cpp. References ACE_SYNCH_USE, ACE_TRACE, ACE_Svc_Handler<, >::dynamic_, ACE_Dynamic::instance(), ACE_Dynamic::is_dynamic(), ACE_Event_Handler::reactor(), and ACE_Dynamic::reset(). 
 00137 : ACE_Task<ACE_SYNCH_USE> (tm, mq), 00138 closing_ (false), 00139 recycler_ (0), 00140 recycling_act_ (0) 00141 { 00142 ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::ACE_Svc_Handler"); 00143 00144 this->reactor (reactor); 00145 00146 // This clever idiom transparently checks if we were allocated 00147 // dynamically. This information is used by the <destroy> method to 00148 // decide if we need to delete <this>... The idiom is based on a 00149 // paper by Michael van Rooyen (mrooyen@cellnet.co.uk) that appeared 00150 // in the April '96 issue of the C++ Report. We've spruced it up to 00151 // work correctly in multi-threaded programs by using our ACE_TSS 00152 // class. 00153 this->dynamic_ = ACE_Dynamic::instance ()->is_dynamic (); 00154 00155 if (this->dynamic_) 00156 // Make sure to reset the flag. 00157 ACE_Dynamic::instance ()->reset (); 00158 }  | 
  
      
  | 
  ||||||||||
| 
 Destructor. 
 Definition at line 284 of file Svc_Handler.cpp. References ACE_TRACE, ACE_Svc_Handler<, >::closing_, and ACE_Svc_Handler<, >::shutdown(). 
 00285 {
00286   ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::~ACE_Svc_Handler");
00287 
00288   if (this->closing_ == false)
00289     {
00290       // We're closing down now, so make sure not to call ourselves
00291       // recursively via other calls to handle_close() (e.g., from the
00292       // Timer_Queue).
00293       this->closing_ = true;
00294 
00295       this->shutdown ();
00296     }
00297 }
 | 
  
      
  | 
  ||||||||||
| 
 
When the svc_handle is no longer needed around as a hint, call this method. In addition, reset  Definition at line 226 of file Svc_Handler.cpp. References ACE_TRACE, ACE_Connection_Recycling_Strategy::cleanup_hint(), and ACE_Svc_Handler<, >::recycler(). 
 00227 {
00228   ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::cleanup_hint");
00229 
00230   // Remove as hint.
00231   if (this->recycler ())
00232     this->recycler ()->cleanup_hint (this->recycling_act_,
00233                                      act_holder);
00234 }
 | 
  
      
  | 
  ||||||||||
| 
 Object termination hook -- application-specific cleanup code goes here. This function is called by the idle() function if the object does not have a ACE_Connection_Recycling_Strategy associated with it. Also, due to this class's derivation from ACE_Task, close() is also called when a thread activated with this object exits. See ACE_Task::close() for further details. The default action of this function is to call handle_close() with the default arguments. Reimplemented from ACE_Task_Base. Definition at line 319 of file Svc_Handler.cpp. References ACE_TRACE, and ACE_Svc_Handler<, >::handle_close(). Referenced by ACE_Svc_Handler<, >::idle(). 
 00320 {
00321   ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::close");
00322   return this->handle_close ();
00323 }
 | 
  
      
  | 
  ||||||||||
| 
 Call this to free up dynamically allocated (otherwise you will get memory leaks). In general, you should call this method rather than since this method knows whether or not the object was allocated dynamically, and can act accordingly (i.e., deleting it if it was allocated dynamically). Definition at line 107 of file Svc_Handler.cpp. References ACE_TRACE, ACE_Svc_Handler<, >::closing_, and ACE_Svc_Handler<, >::dynamic_. Referenced by ACE_Svc_Handler<, >::handle_close(). 
 00108 {
00109   ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::destroy");
00110 
00111   // Only delete ourselves if we're not owned by a module and have
00112   // been allocated dynamically.
00113   if (this->mod_ == 0 && this->dynamic_ && this->closing_ == false)
00114     // Will call the destructor, which automatically calls <shutdown>.
00115     // Note that if we are *not* allocated dynamically then the
00116     // destructor will call <shutdown> automatically when it gets run
00117     // during cleanup.
00118     delete this;
00119 }
 | 
  
      
  | 
  ||||||||||
| 
 Dump the state of an object. 
 Reimplemented from ACE_Task< ACE_SYNCH_USE >. Reimplemented in ACE_Buffered_Svc_Handler<, >. Definition at line 237 of file Svc_Handler.cpp. References ACE_DEBUG, ACE_TRACE, and LM_DEBUG. 
 00238 {
00239 #if defined (ACE_HAS_DUMP)
00240   ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::dump");
00241 
00242   this->peer_.dump ();
00243   ACE_DEBUG ((LM_DEBUG,
00244               "dynamic_ = %d\n",
00245               this->dynamic_));
00246   ACE_DEBUG ((LM_DEBUG,
00247               "closing_ = %d\n",
00248               this->closing_));
00249   ACE_DEBUG ((LM_DEBUG,
00250               "recycler_ = %d\n",
00251               this->recycler_));
00252   ACE_DEBUG ((LM_DEBUG,
00253               "recycling_act_ = %d\n",
00254               this->recycling_act_));
00255 #endif /* ACE_HAS_DUMP */
00256 }
 | 
  
      
  | 
  ||||||||||
| 
 Default version does no work and returns -1. Must be overloaded by application developer to do anything meaningful. Reimplemented from ACE_Shared_Object. Definition at line 334 of file Svc_Handler.cpp. References ACE_TRACE. 
 00335 {
00336   ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::fini");
00337   return -1;
00338 }
 | 
  
      
  | 
  ||||||||||
| 
 Get the underlying handle associated with the . 
 Reimplemented from ACE_Event_Handler. Definition at line 268 of file Svc_Handler.cpp. References ACE_TRACE. 
  | 
  
      
  | 
  ||||||||||||||||
| 
 Perform termination activities on the SVC_HANDLER. The default behavior is to close down the (to avoid descriptor leaks) and to this object (to avoid memory leaks)! If you don't want this behavior make sure you override this method... Reimplemented from ACE_Event_Handler. Definition at line 300 of file Svc_Handler.cpp. References ACE_Reactor_Mask, ACE_TRACE, and ACE_Svc_Handler<, >::destroy(). Referenced by ACE_Svc_Handler<, >::close(), and ACE_Svc_Handler<, >::handle_timeout(). 
  | 
  
      
  | 
  ||||||||||||||||
| 
 Default behavior when timeouts occur is to close down the by calling . Reimplemented from ACE_Event_Handler. Reimplemented in ACE_Buffered_Svc_Handler<, >. Definition at line 311 of file Svc_Handler.cpp. References ACE_TRACE, and ACE_Svc_Handler<, >::handle_close(). 
 00313 {
00314   ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::handle_timeout");
00315   return this->handle_close ();
00316 }
 | 
  
      
  | 
  ||||||||||
| 
 
Call this method if you want to recycling the  Definition at line 348 of file Svc_Handler.cpp. References ACE_Connection_Recycling_Strategy::cache(), ACE_Svc_Handler<, >::close(), and ACE_Svc_Handler<, >::recycler(). 
  | 
  
      
  | 
  ||||||||||||||||
| 
 Default version does no work and returns -1. Must be overloaded by application developer to do anything meaningful. Reimplemented from ACE_Shared_Object. Definition at line 341 of file Svc_Handler.cpp. References ACE_TCHAR, and ACE_TRACE. 
 00342 {
00343   ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::info");
00344   return -1;
00345 }
 | 
  
      
  | 
  ||||||||||||||||
| 
 Default version does no work and returns -1. Must be overloaded by application developer to do anything meaningful. Reimplemented from ACE_Shared_Object. Definition at line 326 of file Svc_Handler.cpp. References ACE_TCHAR, and ACE_TRACE. 
 00328 {
00329   ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::init");
00330   return -1;
00331 }
 | 
  
      
  | 
  ||||||||||
| 
 Activate the client handler. This is typically called by the ACE_Acceptor or ACE_Connector. Reimplemented from ACE_Task_Base. Definition at line 164 of file Svc_Handler.cpp. References ACE_DEBUG, ACE_ERROR_RETURN, ACE_PEER_STREAM_ADDR, ACE_TCHAR, ACE_TEXT, ACE_TRACE, LM_DEBUG, LM_ERROR, ACE_Event_Handler::reactor(), and ACE_Reactor::register_handler(). 
 00165 {
00166   ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::open");
00167 #if defined (ACE_DEBUGGING)
00168   ACE_TCHAR buf[BUFSIZ];
00169   ACE_PEER_STREAM_ADDR client_addr;
00170 
00171   if (this->peer_.get_remote_addr (client_addr) == -1)
00172     ACE_ERROR_RETURN ((LM_ERROR,
00173                        ACE_TEXT ("%p\n"),
00174                        ACE_TEXT ("get_remote_addr")),
00175                       -1);
00176   else if (client_addr.addr_to_string (buf, sizeof buf) == -1)
00177     ACE_ERROR_RETURN ((LM_ERROR,
00178                        ACE_TEXT ("%p\n"),
00179                        ACE_TEXT ("can't obtain peer's address")),
00180                       -1);
00181   ACE_DEBUG ((LM_DEBUG,
00182               ACE_TEXT ("connected to %s on fd %d\n"),
00183               buf,
00184               this->peer_.get_handle ()));
00185 #endif /* ACE_DEBUGGING */
00186   if (this->reactor ()
00187       && this->reactor ()->register_handler
00188       (this,
00189        ACE_Event_Handler::READ_MASK) == -1)
00190     ACE_ERROR_RETURN ((LM_ERROR,
00191                        ACE_TEXT ("%p\n"),
00192                        ACE_TEXT ("unable to register client handler")),
00193                       -1);
00194   return 0;
00195 }
 | 
  
      
  | 
  ||||||||||||||||
| 
 This operator is necessary to complement the class-specific operator new above. Unfortunately, it's not portable to all C++ compilers... Definition at line 32 of file Svc_Handler.cpp. References ACE_TRACE. 
 00033 {
00034   ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::operator delete (NOOP, 2 parameters)");
00035   return;
00036 }
 | 
  
      
  | 
  ||||||||||
| 
 This really should be private so that users are forced to call . Unfortunately, the C++ standard doesn't allow there to be a public new and a private delete. It is a bad idea to call this method directly, so use instead, unless you know for sure that you've allocated the object dynamically. Definition at line 122 of file Svc_Handler.cpp. References ACE_TRACE. 
 00123 {
00124   ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::operator delete");
00125   // You cannot delete a 'void*' (X3J16/95-0087 5.3.5.3), but we know
00126   // the pointer was created using new char[] (see operator new code),
00127   // so we use a cast:
00128   ::delete [] static_cast <char *> (obj);
00129 }
 | 
  
      
  | 
  ||||||||||||||||
| 
 This operator permits "placement new" on a per-object basis. 
 Definition at line 24 of file Svc_Handler.cpp. References ACE_TRACE. 
 00025 {
00026   ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::operator new (NOOP, 2 parameters)");
00027   return p;
00028 }
 | 
  
      
  | 
  ||||||||||
| 
 Overloaded new operator. This method unobtrusively records if a is allocated dynamically, which allows it to clean itself up correctly whether or not it's allocated statically or dynamically. Definition at line 40 of file Svc_Handler.cpp. References ACE_ASSERT, ACE_throw_bad_alloc, ACE_TRACE, ACE_Dynamic::instance(), and ACE_Dynamic::set(). 
 00041 {
00042   ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::operator new");
00043 
00044   ACE_Dynamic *const dynamic_instance = ACE_Dynamic::instance ();
00045 
00046   if (dynamic_instance == 0)
00047     {
00048       // If this ACE_ASSERT fails, it may be due to running of out TSS
00049       // keys.  Try using ACE_HAS_TSS_EMULATION, or increasing
00050       // ACE_DEFAULT_THREAD_KEYS if already using TSS emulation.
00051       ACE_ASSERT (dynamic_instance != 0);
00052 
00053       ACE_throw_bad_alloc;
00054     }
00055   else
00056     {
00057       // Allocate the memory and store it (usually in thread-specific
00058       // storage, depending on config flags).
00059       dynamic_instance->set ();
00060 
00061       return ::new char[n];
00062     }
00063 }
 | 
  
      
  | 
  ||||||||||
| 
 Returns the underlying PEER_STREAM. Used by <ACE_Acceptor::accept> and <ACE_Connector::connect> factories Definition at line 259 of file Svc_Handler.cpp. References ACE_PEER_STREAM, and ACE_TRACE. Referenced by ACE_Svc_Handler<, >::shutdown(). 
 00260 {
00261   ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::peer");
00262   return (ACE_PEER_STREAM &) this->peer_;
00263 }
 | 
  
      
  | 
  ||||||||||
| 
 Upcall made by the recycler when it is about to recycle the connection. This gives the object a chance to prepare itself for recycling. Return 0 if the object is ready for recycling, -1 on failures. Definition at line 399 of file Svc_Handler.cpp. References ACE_TRACE. 
 00400 {
00401   ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::recycle");
00402   // By default, the object is ready and willing to be recycled.
00403   return 0;
00404 }
 | 
  
      
  | 
  ||||||||||
| 
 
 Definition at line 357 of file Svc_Handler.cpp. References ACE_Connection_Recycling_Strategy::recycle_state(), and ACE_Svc_Handler<, >::recycler(). 
 00358 {
00359   if (this->recycler ())
00360     return this->recycler ()->recycle_state (this->recycling_act_,
00361                                              new_state);
00362 
00363   return 0;
00364 }
 | 
  
      
  | 
  ||||||||||
| 
 
Call this method if you want to get/set the state of the  Definition at line 367 of file Svc_Handler.cpp. References ACE_RECYCLABLE_UNKNOWN, ACE_Connection_Recycling_Strategy::recycle_state(), and ACE_Svc_Handler<, >::recycler(). 
 00368 {
00369   if (this->recycler ())
00370     return this->recycler ()->recycle_state (this->recycling_act_);
00371 
00372   return ACE_RECYCLABLE_UNKNOWN;
00373 }
 | 
  
      
  | 
  ||||||||||
| 
 Get the recycler. 
 Definition at line 385 of file Svc_Handler.cpp. References ACE_TRACE, and ACE_Svc_Handler<, >::recycler_. Referenced by ACE_Svc_Handler<, >::cleanup_hint(), ACE_Svc_Handler<, >::idle(), ACE_Svc_Handler<, >::recycle_state(), and ACE_Svc_Handler<, >::shutdown(). 
  | 
  
      
  | 
  ||||||||||||||||
| 
 Set the recycler and the that is used during purging and caching. Definition at line 376 of file Svc_Handler.cpp. References ACE_TRACE, ACE_Svc_Handler<, >::recycler_, and ACE_Svc_Handler<, >::recycling_act_. 
 00378 {
00379   ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::recycler");
00380   this->recycler_ = recycler;
00381   this->recycling_act_ = recycling_act;
00382 }
 | 
  
      
  | 
  ||||||||||
| 
 Get the recycling act. 
 Definition at line 392 of file Svc_Handler.cpp. References ACE_TRACE, and ACE_Svc_Handler<, >::recycling_act_. 
 00393 {
00394   ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::recycling_act");
00395   return this->recycling_act_;
00396 }
 | 
  
      
  | 
  ||||||||||
| 
 Set the underlying handle associated with the . 
 Reimplemented from ACE_Event_Handler. Definition at line 277 of file Svc_Handler.cpp. References ACE_TRACE. 
  | 
  
      
  | 
  ||||||||||
| 
 Close down the descriptor and unregister from the Reactor. 
 Definition at line 200 of file Svc_Handler.cpp. References ACE_Reactor_Mask, ACE_TRACE, ACE_Reactor::cancel_timer(), ACE_Svc_Handler<, >::peer(), ACE_Connection_Recycling_Strategy::purge(), ACE_Event_Handler::reactor(), ACE_Svc_Handler<, >::recycler(), and ACE_Reactor::remove_handler(). Referenced by ACE_Svc_Handler<, >::~ACE_Svc_Handler(). 
 00201 {
00202   ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::shutdown");
00203 
00204   // Deregister this handler with the ACE_Reactor.
00205   if (this->reactor ())
00206     {
00207       ACE_Reactor_Mask mask = ACE_Event_Handler::ALL_EVENTS_MASK |
00208         ACE_Event_Handler::DONT_CALL;
00209 
00210       // Make sure there are no timers.
00211       this->reactor ()->cancel_timer (this);
00212 
00213       if (this->peer ().get_handle () != ACE_INVALID_HANDLE)
00214         // Remove self from reactor.
00215         this->reactor ()->remove_handler (this, mask);
00216     }
00217 
00218   // Remove self from the recycler.
00219   if (this->recycler ())
00220     this->recycler ()->purge (this->recycling_act_);
00221 
00222   this->peer ().close ();
00223 }
 | 
  
      
  | 
  |||||
| 
 Keeps track of whether we are in the process of closing (required to avoid circular calls to ). Definition at line 238 of file Svc_Handler.h. Referenced by ACE_Svc_Handler<, >::destroy(), and ACE_Svc_Handler<, >::~ACE_Svc_Handler().  | 
  
      
  | 
  |||||
| 
 Have we been dynamically created? 
 Definition at line 234 of file Svc_Handler.h. Referenced by ACE_Svc_Handler<, >::ACE_Svc_Handler(), and ACE_Svc_Handler<, >::destroy().  | 
  
      
  | 
  |||||
| 
 Maintain connection with client. 
 Definition at line 231 of file Svc_Handler.h.  | 
  
      
  | 
  |||||
| 
 Pointer to the connection recycler. 
 Definition at line 241 of file Svc_Handler.h. Referenced by ACE_Svc_Handler<, >::recycler().  | 
  
      
  | 
  |||||
| 
 Asynchronous Completion Token (ACT) to be used to when talking to the recycler. Definition at line 245 of file Svc_Handler.h. Referenced by ACE_Svc_Handler<, >::recycler(), and ACE_Svc_Handler<, >::recycling_act().  | 
  
 
1.3.6