#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. | |
int | dynamic_ |
Have we been dynamically created? | |
int | 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 136 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().
00139 : ACE_Task<ACE_SYNCH_USE> (tm, mq), 00140 closing_ (0), 00141 recycler_ (0), 00142 recycling_act_ (0) 00143 { 00144 ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::ACE_Svc_Handler"); 00145 00146 this->reactor (reactor); 00147 00148 // This clever idiom transparently checks if we were allocated 00149 // dynamically. This information is used by the <destroy> method to 00150 // decide if we need to delete <this>... The idiom is based on a 00151 // paper by Michael van Rooyen (mrooyen@cellnet.co.uk) that appeared 00152 // in the April '96 issue of the C++ Report. We've spruced it up to 00153 // work correctly in multi-threaded programs by using our ACE_TSS 00154 // class. 00155 this->dynamic_ = ACE_Dynamic::instance ()->is_dynamic (); 00156 00157 if (this->dynamic_ != 0) 00158 // Make sure to reset the flag. 00159 ACE_Dynamic::instance ()->reset (); 00160 } |
|
Destructor.
Definition at line 286 of file Svc_Handler.cpp. References ACE_TRACE, ACE_Svc_Handler<, >::closing_, and ACE_Svc_Handler<, >::shutdown().
00287 { 00288 ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::~ACE_Svc_Handler"); 00289 00290 if (this->closing_ == 0) 00291 { 00292 // We're closing down now, so make sure not to call ourselves 00293 // recursively via other calls to handle_close() (e.g., from the 00294 // Timer_Queue). 00295 this->closing_ = 1; 00296 00297 this->shutdown (); 00298 } 00299 } |
|
When the svc_handle is no longer needed around as a hint, call this method. In addition, reset Definition at line 228 of file Svc_Handler.cpp. References ACE_TRACE, ACE_Connection_Recycling_Strategy::cleanup_hint(), and ACE_Svc_Handler<, >::recycler().
00229 { 00230 ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::cleanup_hint"); 00231 00232 // Remove as hint. 00233 if (this->recycler ()) 00234 this->recycler ()->cleanup_hint (this->recycling_act_, 00235 act_holder); 00236 } |
|
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 320 of file Svc_Handler.cpp. References ACE_TRACE, and ACE_Svc_Handler<, >::handle_close(). Referenced by ACE_Svc_Handler<, >::idle().
00321 { 00322 ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::close"); 00323 return this->handle_close (); 00324 } |
|
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 109 of file Svc_Handler.cpp. References ACE_TRACE, ACE_Svc_Handler<, >::closing_, and ACE_Svc_Handler<, >::dynamic_. Referenced by ACE_Svc_Handler<, >::handle_close().
00110 { 00111 ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::destroy"); 00112 00113 // Only delete ourselves if we're not owned by a module and have 00114 // been allocated dynamically. 00115 if (this->mod_ == 0 && this->dynamic_ && this->closing_ == 0) 00116 // Will call the destructor, which automatically calls <shutdown>. 00117 // Note that if we are *not* allocated dynamically then the 00118 // destructor will call <shutdown> automatically when it gets run 00119 // during cleanup. 00120 delete this; 00121 } |
|
Dump the state of an object.
Reimplemented from ACE_Task< ACE_SYNCH_USE >. Reimplemented in ACE_Buffered_Svc_Handler<, >. Definition at line 239 of file Svc_Handler.cpp. References ACE_DEBUG, ACE_TRACE, and LM_DEBUG.
00240 { 00241 #if defined (ACE_HAS_DUMP) 00242 ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::dump"); 00243 00244 this->peer_.dump (); 00245 ACE_DEBUG ((LM_DEBUG, 00246 "dynamic_ = %d\n", 00247 this->dynamic_)); 00248 ACE_DEBUG ((LM_DEBUG, 00249 "closing_ = %d\n", 00250 this->closing_)); 00251 ACE_DEBUG ((LM_DEBUG, 00252 "recycler_ = %d\n", 00253 this->recycler_)); 00254 ACE_DEBUG ((LM_DEBUG, 00255 "recycling_act_ = %d\n", 00256 this->recycling_act_)); 00257 #endif /* ACE_HAS_DUMP */ 00258 } |
|
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 336 of file Svc_Handler.cpp. References ACE_TRACE.
00337 { 00338 ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::fini"); 00339 return -1; 00340 } |
|
Get the underlying handle associated with the .
Reimplemented from ACE_Event_Handler. Definition at line 270 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 302 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 312 of file Svc_Handler.cpp. References ACE_TRACE, and ACE_Svc_Handler<, >::handle_close().
00314 { 00315 ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::handle_timeout"); 00316 return this->handle_close (); 00317 } |
|
Call this method if you want to recycling the Definition at line 350 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 343 of file Svc_Handler.cpp. References ACE_TCHAR, and ACE_TRACE.
00344 { 00345 ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::info"); 00346 return -1; 00347 } |
|
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 327 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 ACE_UNUSED_ARG (argc); 00331 ACE_UNUSED_ARG (argv); 00332 return -1; 00333 } |
|
Activate the client handler. This is typically called by the ACE_Acceptor or ACE_Connector. Reimplemented from ACE_Task_Base. Definition at line 166 of file Svc_Handler.cpp. References ACE_DEBUG, ACE_ERROR_RETURN, ACE_LIB_TEXT, ACE_PEER_STREAM_ADDR, ACE_TCHAR, ACE_TRACE, LM_DEBUG, LM_ERROR, ACE_Event_Handler::reactor(), and ACE_Reactor::register_handler().
00167 { 00168 ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::open"); 00169 #if defined (ACE_DEBUGGING) 00170 ACE_TCHAR buf[BUFSIZ]; 00171 ACE_PEER_STREAM_ADDR client_addr; 00172 00173 if (this->peer_.get_remote_addr (client_addr) == -1) 00174 ACE_ERROR_RETURN ((LM_ERROR, 00175 ACE_LIB_TEXT ("%p\n"), 00176 ACE_LIB_TEXT ("get_remote_addr")), 00177 -1); 00178 else if (client_addr.addr_to_string (buf, sizeof buf) == -1) 00179 ACE_ERROR_RETURN ((LM_ERROR, 00180 ACE_LIB_TEXT ("%p\n"), 00181 ACE_LIB_TEXT ("can't obtain peer's address")), 00182 -1); 00183 ACE_DEBUG ((LM_DEBUG, 00184 ACE_LIB_TEXT ("connected to %s on fd %d\n"), 00185 buf, 00186 this->peer_.get_handle ())); 00187 #endif /* ACE_DEBUGGING */ 00188 if (this->reactor () 00189 && this->reactor ()->register_handler 00190 (this, 00191 ACE_Event_Handler::READ_MASK) == -1) 00192 ACE_ERROR_RETURN ((LM_ERROR, 00193 ACE_LIB_TEXT ("%p\n"), 00194 ACE_LIB_TEXT ("unable to register client handler")), 00195 -1); 00196 return 0; 00197 } |
|
This operator is necessary to complement the class-specific operator new above. Unfortunately, it's not portable to all C++ compilers... Definition at line 33 of file Svc_Handler.cpp. References ACE_TRACE.
00035 { 00036 ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::operator delete (NOOP, 2 parameters)"); 00037 return; 00038 } |
|
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 124 of file Svc_Handler.cpp. References ACE_TRACE.
00125 { 00126 ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::operator delete"); 00127 // You cannot delete a 'void*' (X3J16/95-0087 5.3.5.3), but we know 00128 // the pointer was created using new char[] (see operator new code), 00129 // so we use a cast: 00130 ::delete [] static_cast <char *> (obj); 00131 } |
|
This operator permits "placement new" on a per-object basis.
Definition at line 24 of file Svc_Handler.cpp. References ACE_TRACE.
00026 { 00027 ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::operator new (NOOP, 2 parameters)"); 00028 return p; 00029 } |
|
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 42 of file Svc_Handler.cpp. References ACE_ASSERT, ACE_throw_bad_alloc, ACE_TRACE, ACE_Dynamic::instance(), and ACE_Dynamic::set().
00043 { 00044 ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::operator new"); 00045 00046 ACE_Dynamic *const dynamic_instance = ACE_Dynamic::instance (); 00047 00048 if (dynamic_instance == 0) 00049 { 00050 // If this ACE_ASSERT fails, it may be due to running of out TSS 00051 // keys. Try using ACE_HAS_TSS_EMULATION, or increasing 00052 // ACE_DEFAULT_THREAD_KEYS if already using TSS emulation. 00053 ACE_ASSERT (dynamic_instance != 0); 00054 00055 ACE_throw_bad_alloc; 00056 } 00057 else 00058 { 00059 // Allocate the memory and store it (usually in thread-specific 00060 // storage, depending on config flags). 00061 dynamic_instance->set (); 00062 00063 return ::new char[n]; 00064 } 00065 } |
|
Returns the underlying PEER_STREAM. Used by <ACE_Acceptor::accept> and <ACE_Connector::connect> factories Definition at line 261 of file Svc_Handler.cpp. References ACE_PEER_STREAM, and ACE_TRACE. Referenced by ACE_Svc_Handler<, >::shutdown().
00262 { 00263 ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::peer"); 00264 return (ACE_PEER_STREAM &) this->peer_; 00265 } |
|
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 401 of file Svc_Handler.cpp. References ACE_TRACE.
00402 { 00403 ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::recycle"); 00404 // By default, the object is ready and willing to be recycled. 00405 return 0; 00406 } |
|
Definition at line 359 of file Svc_Handler.cpp. References ACE_Connection_Recycling_Strategy::recycle_state(), and ACE_Svc_Handler<, >::recycler().
00360 { 00361 if (this->recycler ()) 00362 return this->recycler ()->recycle_state (this->recycling_act_, 00363 new_state); 00364 00365 return 0; 00366 } |
|
Call this method if you want to get/set the state of the Definition at line 369 of file Svc_Handler.cpp. References ACE_RECYCLABLE_UNKNOWN, ACE_Connection_Recycling_Strategy::recycle_state(), and ACE_Svc_Handler<, >::recycler().
00370 { 00371 if (this->recycler ()) 00372 return this->recycler ()->recycle_state (this->recycling_act_); 00373 00374 return ACE_RECYCLABLE_UNKNOWN; 00375 } |
|
Get the recycler.
Definition at line 387 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 378 of file Svc_Handler.cpp. References ACE_TRACE, ACE_Svc_Handler<, >::recycler_, and ACE_Svc_Handler<, >::recycling_act_.
00380 { 00381 ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::recycler"); 00382 this->recycler_ = recycler; 00383 this->recycling_act_ = recycling_act; 00384 } |
|
Get the recycling act.
Definition at line 394 of file Svc_Handler.cpp. References ACE_TRACE, and ACE_Svc_Handler<, >::recycling_act_.
00395 { 00396 ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::recycling_act"); 00397 return this->recycling_act_; 00398 } |
|
Set the underlying handle associated with the .
Reimplemented from ACE_Event_Handler. Definition at line 279 of file Svc_Handler.cpp. References ACE_TRACE.
|
|
Close down the descriptor and unregister from the Reactor.
Definition at line 202 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().
00203 { 00204 ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::shutdown"); 00205 00206 // Deregister this handler with the ACE_Reactor. 00207 if (this->reactor ()) 00208 { 00209 ACE_Reactor_Mask mask = ACE_Event_Handler::ALL_EVENTS_MASK | 00210 ACE_Event_Handler::DONT_CALL; 00211 00212 // Make sure there are no timers. 00213 this->reactor ()->cancel_timer (this); 00214 00215 if (this->peer ().get_handle () != ACE_INVALID_HANDLE) 00216 // Remove self from reactor. 00217 this->reactor ()->remove_handler (this, mask); 00218 } 00219 00220 // Remove self from the recycler. 00221 if (this->recycler ()) 00222 this->recycler ()->purge (this->recycling_act_); 00223 00224 this->peer ().close (); 00225 } |
|
Keeps track of whether we are in the process of closing (required to avoid circular calls to ). Definition at line 239 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 235 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 232 of file Svc_Handler.h. |
|
Pointer to the connection recycler.
Definition at line 242 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 246 of file Svc_Handler.h. Referenced by ACE_Svc_Handler<, >::recycler(), and ACE_Svc_Handler<, >::recycling_act(). |