#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 Methods | |
| 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. More... | |
| virtual int | open (void *=0) |
| Activate the client handler. This is typically called by the <ACE_Acceptor> or <ACE_Connector>. More... | |
| 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[]) |
| Default version does no work and returns -1. Must be overloaded by application developer to do anything meaningful. More... | |
| virtual int | fini (void) |
| Default version does no work and returns -1. Must be overloaded by application developer to do anything meaningful. More... | |
| virtual int | info (ACE_TCHAR **info_string, size_t length) const |
| Default version does no work and returns -1. Must be overloaded by application developer to do anything meaningful. More... | |
| 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 *) |
| Default behavior when timeouts occur is to close down the <Svc_Handler> by calling <handle_close>. More... | |
| virtual ACE_HANDLE | get_handle (void) const |
| Get the underlying handle associated with the <peer_>. More... | |
| virtual void | set_handle (ACE_HANDLE) |
| Set the underlying handle associated with the <peer_>. More... | |
| ACE_PEER_STREAM & | peer (void) const |
| Returns the underlying PEER_STREAM. Used by <ACE_Acceptor::accept> and <ACE_Connector::connect> factories. More... | |
| void * | operator new (size_t n) |
| Overloaded new operator. This method unobtrusively records if a <Svc_Handler> is allocated dynamically, which allows it to clean itself up correctly whether or not it's allocated statically or dynamically. More... | |
| void * | operator new (size_t n, void *p) |
| This operator permits "placement new" on a per-object basis. More... | |
| 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. More... | |
| void | dump (void) const |
| Dump the state of an object. More... | |
| virtual void | recycler (ACE_Connection_Recycling_Strategy *recycler, const void *recycling_act) |
| Set the recycler and the <recycling_act> that is used during purging and caching. More... | |
| virtual ACE_Connection_Recycling_Strategy * | recycler (void) const |
| Get the recycler. More... | |
| virtual const void * | recycling_act (void) const |
| Get the recycling act. More... | |
| virtual int | recycle (void *=0) |
Protected Attributes | |
| ACE_PEER_STREAM | peer_ |
| Maintain connection with client. More... | |
| int | dynamic_ |
| Have we been dynamically created? More... | |
| char | closing_ |
| Keeps track of whether we are in the process of closing (required to avoid circular calls to <handle_close>). More... | |
| ACE_Connection_Recycling_Strategy * | recycler_ |
| Pointer to the connection recycler. More... | |
| const void * | recycling_act_ |
| Asynchronous Completion Token (ACT) to be used to when talking to the recycler. More... | |
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 49 of file Svc_Handler.h.
|
|||||
|
Definition at line 54 of file Svc_Handler.h. |
|
|||||
|
Definition at line 55 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 125 of file Svc_Handler.cpp. References ACE_SYNCH_USE, ACE_TRACE, dynamic_, ACE_Dynamic::instance, ACE_Dynamic::is_dynamic, ACE_Event_Handler::reactor, and ACE_Dynamic::reset.
00128 : ACE_Task<ACE_SYNCH_USE> (tm, mq), 00129 closing_ (0), 00130 recycler_ (0), 00131 recycling_act_ (0) 00132 { 00133 ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::ACE_Svc_Handler"); 00134 00135 this->reactor (reactor); 00136 00137 // This clever idiom transparently checks if we were allocated 00138 // dynamically. This information is used by the <destroy> method to 00139 // decide if we need to delete <this>... The idiom is based on a 00140 // paper by Michael van Rooyen (mrooyen@cellnet.co.uk) that appeared 00141 // in the April '96 issue of the C++ Report. We've spruced it up to 00142 // work correctly in multi-threaded programs by using our ACE_TSS 00143 // class. 00144 this->dynamic_ = ACE_Dynamic::instance ()->is_dynamic (); 00145 00146 if (this->dynamic_ != 0) 00147 // Make sure to reset the flag. 00148 ACE_Dynamic::instance ()->reset (); 00149 } |
|
||||||||||
|
Destructor.
Definition at line 273 of file Svc_Handler.cpp. References ACE_TRACE, closing_, and shutdown.
00274 {
00275 ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::~ACE_Svc_Handler");
00276
00277 if (this->closing_ == 0)
00278 {
00279 // We're closing down now, so make sure not to call ourselves
00280 // recursively via other calls to handle_close() (e.g., from the
00281 // Timer_Queue).
00282 this->closing_ = 1;
00283
00284 this->shutdown ();
00285 }
00286 }
|
|
||||||||||
|
When the svc_handle is no longer needed around as a hint, call this method. In addition, reset <*act_holder> to zero if <act_holder != 0>. Definition at line 217 of file Svc_Handler.cpp. References ACE_TRACE, ACE_Connection_Recycling_Strategy::cleanup_hint, and recycler.
00218 {
00219 ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::cleanup_hint");
00220
00221 // Remove as hint.
00222 if (this->recycler ())
00223 this->recycler ()->cleanup_hint (this->recycling_act_,
00224 act_holder);
00225 }
|
|
||||||||||
|
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 307 of file Svc_Handler.cpp. References ACE_TRACE, and handle_close. Referenced by idle.
00308 {
00309 ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::close");
00310 return this->handle_close ();
00311 }
|
|
||||||||||
|
Call this to free up dynamically allocated <Svc_Handlers> (otherwise you will get memory leaks). In general, you should call this method rather than <delete> 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 97 of file Svc_Handler.cpp. References ACE_TRACE, closing_, dynamic_, and ACE_Task< ACE_SYNCH_USE >::mod_. Referenced by handle_close.
00098 {
00099 ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::destroy");
00100
00101 // Only delete ourselves if we're not owned by a module and have
00102 // been allocated dynamically.
00103 if (this->mod_ == 0 && this->dynamic_ && this->closing_ == 0)
00104 // Will call the destructor, which automatically calls <shutdown>.
00105 // Note that if we are *not* allocated dynamically then the
00106 // destructor will call <shutdown> automatically when it gets run
00107 // during cleanup.
00108 delete this;
00109 }
|
|
||||||||||
|
Dump the state of an object.
Reimplemented from ACE_Task< ACE_SYNCH_USE >. Reimplemented in ACE_Buffered_Svc_Handler. Definition at line 228 of file Svc_Handler.cpp. References ACE_DEBUG, ACE_TRACE, LM_DEBUG, and peer_.
00229 {
00230 ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::dump");
00231
00232 this->peer_.dump ();
00233 ACE_DEBUG ((LM_DEBUG,
00234 "dynamic_ = %d\n",
00235 this->dynamic_));
00236 ACE_DEBUG ((LM_DEBUG,
00237 "closing_ = %d\n",
00238 this->closing_));
00239 ACE_DEBUG ((LM_DEBUG,
00240 "recycler_ = %d\n",
00241 this->recycler_));
00242 ACE_DEBUG ((LM_DEBUG,
00243 "recycling_act_ = %d\n",
00244 this->recycling_act_));
00245 }
|
|
||||||||||
|
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 323 of file Svc_Handler.cpp. References ACE_TRACE.
00324 {
00325 ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::fini");
00326 return -1;
00327 }
|
|
||||||||||
|
Get the underlying handle associated with the <peer_>.
Reimplemented from ACE_Event_Handler. Definition at line 257 of file Svc_Handler.cpp. References ACE_TRACE, and peer_.
|
|
||||||||||||||||
|
Perform termination activities on the SVC_HANDLER. The default behavior is to close down the <peer_> (to avoid descriptor leaks) and to <destroy> 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 289 of file Svc_Handler.cpp. References ACE_Reactor_Mask, ACE_TRACE, and destroy. Referenced by close, and handle_timeout.
|
|
||||||||||||||||
|
Default behavior when timeouts occur is to close down the <Svc_Handler> by calling <handle_close>.
Reimplemented from ACE_Event_Handler. Reimplemented in ACE_Buffered_Svc_Handler. Definition at line 299 of file Svc_Handler.cpp. References ACE_TRACE, and handle_close.
00301 {
00302 ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::handle_timeout");
00303 return this->handle_close ();
00304 }
|
|
||||||||||
|
Call this method if you want to recycling the <Svc_Handler> instead of closing it. If the object does not have a recycler, it will be closed. Definition at line 337 of file Svc_Handler.cpp. References ACE_Connection_Recycling_Strategy::cache, close, and 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 330 of file Svc_Handler.cpp. References ACE_TCHAR, and ACE_TRACE.
00331 {
00332 ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::info");
00333 return -1;
00334 }
|
|
||||||||||||||||
|
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 314 of file Svc_Handler.cpp. References ACE_TCHAR, and ACE_TRACE.
00315 {
00316 ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::init");
00317 ACE_UNUSED_ARG (argc);
00318 ACE_UNUSED_ARG (argv);
00319 return -1;
00320 }
|
|
||||||||||
|
Activate the client handler. This is typically called by the <ACE_Acceptor> or <ACE_Connector>.
Reimplemented from ACE_Task_Base. Definition at line 155 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, peer_, ACE_Event_Handler::reactor, ACE_Event_Handler::READ_MASK, and ACE_Reactor::register_handler.
00156 {
00157 ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::open");
00158 #if defined (ACE_DEBUGGING)
00159 ACE_TCHAR buf[BUFSIZ];
00160 ACE_PEER_STREAM_ADDR client_addr;
00161
00162 if (this->peer_.get_remote_addr (client_addr) == -1)
00163 ACE_ERROR_RETURN ((LM_ERROR,
00164 ACE_LIB_TEXT ("%p\n"),
00165 ACE_LIB_TEXT ("get_remote_addr")),
00166 -1);
00167 else if (client_addr.addr_to_string (buf, sizeof buf) == -1)
00168 ACE_ERROR_RETURN ((LM_ERROR,
00169 ACE_LIB_TEXT ("%p\n"),
00170 ACE_LIB_TEXT ("can't obtain peer's address")),
00171 -1);
00172 ACE_DEBUG ((LM_DEBUG,
00173 ACE_LIB_TEXT ("connected to %s on fd %d\n"),
00174 buf,
00175 this->peer_.get_handle ()));
00176 #endif /* ACE_DEBUGGING */
00177 if (this->reactor ()
00178 && this->reactor ()->register_handler
00179 (this,
00180 ACE_Event_Handler::READ_MASK) == -1)
00181 ACE_ERROR_RETURN ((LM_ERROR,
00182 ACE_LIB_TEXT ("%p\n"),
00183 ACE_LIB_TEXT ("unable to register client handler")),
00184 -1);
00185 return 0;
00186 }
|
|
||||||||||||||||
|
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 <destroy>. 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 <destroy> instead, unless you know for sure that you've allocated the object dynamically. Definition at line 112 of file Svc_Handler.cpp. References ACE_TRACE.
00113 {
00114 ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::operator delete");
00115 // You cannot delete a 'void*' (X3J16/95-0087 5.3.5.3), but we know
00116 // the pointer was created using new char[] (see operator new code),
00117 // so we use a cast:
00118 char *tmp = (char *) obj;
00119 ::delete [] tmp;
00120 }
|
|
||||||||||||||||
|
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 <Svc_Handler> 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 248 of file Svc_Handler.cpp. References ACE_PEER_STREAM, ACE_TRACE, and peer_. Referenced by shutdown.
00249 {
00250 ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::peer");
00251 return (ACE_PEER_STREAM &) this->peer_;
00252 }
|
|
||||||||||
|
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 388 of file Svc_Handler.cpp. References ACE_TRACE.
00389 {
00390 ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::recycle");
00391 // By default, the object is ready and willing to be recycled.
00392 return 0;
00393 }
|
|
||||||||||
|
Definition at line 346 of file Svc_Handler.cpp. References ACE_Recyclable_State, ACE_Connection_Recycling_Strategy::recycle_state, and recycler.
00347 {
00348 if (this->recycler ())
00349 return this->recycler ()->recycle_state (this->recycling_act_,
00350 new_state);
00351
00352 return 0;
00353 }
|
|
||||||||||
|
Call this method if you want to get/set the state of the <Svc_Handler>. If the object does not have a recycler, this call will have no effect (and the accessor will return ACE_RECYCLABLE_UNKNOWN). Definition at line 356 of file Svc_Handler.cpp. References ACE_RECYCLABLE_UNKNOWN, ACE_Connection_Recycling_Strategy::recycle_state, and recycler.
00357 {
00358 if (this->recycler ())
00359 return this->recycler ()->recycle_state (this->recycling_act_);
00360
00361 return ACE_RECYCLABLE_UNKNOWN;
00362 }
|
|
||||||||||
|
Get the recycler.
Definition at line 374 of file Svc_Handler.cpp. References ACE_TRACE, and recycler_. Referenced by cleanup_hint, idle, recycle_state, and shutdown.
|
|
||||||||||||||||
|
Set the recycler and the <recycling_act> that is used during purging and caching.
Definition at line 365 of file Svc_Handler.cpp. References ACE_TRACE, recycler_, recycling_act, and recycling_act_.
00367 {
00368 ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::recycler");
00369 this->recycler_ = recycler;
00370 this->recycling_act_ = recycling_act;
00371 }
|
|
||||||||||
|
Get the recycling act.
Definition at line 381 of file Svc_Handler.cpp. References ACE_TRACE, and recycling_act_. Referenced by recycler.
00382 {
00383 ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::recycling_act");
00384 return this->recycling_act_;
00385 }
|
|
||||||||||
|
Set the underlying handle associated with the <peer_>.
Reimplemented from ACE_Event_Handler. Definition at line 266 of file Svc_Handler.cpp. References ACE_TRACE, and peer_.
|
|
||||||||||
|
Close down the descriptor and unregister from the Reactor.
Definition at line 191 of file Svc_Handler.cpp. References ACE_Reactor_Mask, ACE_TRACE, ACE_Event_Handler::ALL_EVENTS_MASK, ACE_Reactor::cancel_timer, ACE_Event_Handler::DONT_CALL, peer, ACE_Connection_Recycling_Strategy::purge, ACE_Event_Handler::reactor, recycler, and ACE_Reactor::remove_handler. Referenced by ~ACE_Svc_Handler.
00192 {
00193 ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_USE>::shutdown");
00194
00195 // Deregister this handler with the ACE_Reactor.
00196 if (this->reactor ())
00197 {
00198 ACE_Reactor_Mask mask = ACE_Event_Handler::ALL_EVENTS_MASK |
00199 ACE_Event_Handler::DONT_CALL;
00200
00201 // Make sure there are no timers.
00202 this->reactor ()->cancel_timer (this);
00203
00204 if (this->peer ().get_handle () != ACE_INVALID_HANDLE)
00205 // Remove self from reactor.
00206 this->reactor ()->remove_handler (this, mask);
00207 }
00208
00209 // Remove self from the recycler.
00210 if (this->recycler ())
00211 this->recycler ()->purge (this->recycling_act_);
00212
00213 this->peer ().close ();
00214 }
|
|
|||||
|
Keeps track of whether we are in the process of closing (required to avoid circular calls to <handle_close>).
Definition at line 234 of file Svc_Handler.h. Referenced by destroy, and ~ACE_Svc_Handler. |
|
|||||
|
Have we been dynamically created?
Definition at line 230 of file Svc_Handler.h. Referenced by ACE_Svc_Handler, and destroy. |
|
|||||
|
Maintain connection with client.
Definition at line 227 of file Svc_Handler.h. Referenced by dump, get_handle, open, peer, and set_handle. |
|
|||||
|
Pointer to the connection recycler.
Definition at line 237 of file Svc_Handler.h. Referenced by recycler. |
|
|||||
|
Asynchronous Completion Token (ACT) to be used to when talking to the recycler.
Definition at line 241 of file Svc_Handler.h. Referenced by recycler, and recycling_act. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002