00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file Acceptor.h 00006 * 00007 * $Id: Acceptor.h 81460 2008-04-28 11:34:23Z elliott_c $ 00008 * 00009 * @author Douglas C. Schmidt <schmidt@cs.wustl.edu> 00010 */ 00011 //============================================================================= 00012 00013 #ifndef ACE_ACCEPTOR_H 00014 #define ACE_ACCEPTOR_H 00015 00016 #include /**/ "ace/pre.h" 00017 00018 #include "ace/Service_Object.h" 00019 00020 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00021 # pragma once 00022 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00023 00024 #include "ace/Strategies_T.h" 00025 #include "ace/Synch_Options.h" 00026 00027 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00028 00029 /** 00030 * @class ACE_Acceptor 00031 * 00032 * @brief Abstract factory for creating a service handler 00033 * (SVC_HANDLER), accepting into the SVC_HANDLER, and 00034 * activating the SVC_HANDLER. 00035 * 00036 * Implements the basic strategy for passively establishing 00037 * connections with clients. An ACE_Acceptor is parameterized 00038 * by concrete types that conform to the interfaces of 00039 * PEER_ACCEPTOR and SVC_HANDLER. The PEER_ACCEPTOR is 00040 * instantiated with a transport mechanism that passively 00041 * establishes connections. The SVC_HANDLER is instantiated 00042 * with a concrete type that performs the application-specific 00043 * service. An ACE_Acceptor inherits from ACE_Service_Object, 00044 * which in turn inherits from ACE_Event_Handler. This enables 00045 * the ACE_Reactor to dispatch the ACE_Acceptor's handle_input 00046 * method when connection events occur. The handle_input method 00047 * performs the ACE_Acceptor's default creation, connection 00048 * establishment, and service activation strategies. These 00049 * strategies can be overridden by subclasses individually or as 00050 * a group. 00051 */ 00052 template <class SVC_HANDLER, ACE_PEER_ACCEPTOR_1> 00053 class ACE_Acceptor : public ACE_Service_Object 00054 { 00055 public: 00056 00057 // Useful STL-style traits. 00058 typedef ACE_PEER_ACCEPTOR_ADDR addr_type; 00059 typedef ACE_PEER_ACCEPTOR acceptor_type; 00060 typedef SVC_HANDLER handler_type; 00061 typedef typename SVC_HANDLER::stream_type stream_type; 00062 00063 /// "Do-nothing" constructor. 00064 ACE_Acceptor (ACE_Reactor * = 0, 00065 int use_select = 1); 00066 00067 /** 00068 * Open the contained @c PEER_ACCEPTOR object to begin listening, and 00069 * register with the specified reactor for accept events. An 00070 * acceptor can only listen to one port at a time, so make sure to 00071 * @c close() the acceptor before calling @c open() again. 00072 * 00073 * The @c PEER_ACCEPTOR handle is put into non-blocking mode as a 00074 * safeguard against the race condition that can otherwise occur 00075 * between the time when the passive-mode socket handle is "ready" 00076 * and when the actual @c accept() call is made. During this 00077 * interval, the client can shutdown the connection, in which case, 00078 * the @c accept() call can hang. 00079 * 00080 * @param local_addr The address to listen at. 00081 * @param reactor Pointer to the ACE_Reactor instance to register 00082 * this object with. The default is the singleton. 00083 * @param flags Flags to control what mode an accepted socket 00084 * will be put into after it is accepted. The only 00085 * legal value for this argument is @c ACE_NONBLOCK, 00086 * which enables non-blocking mode on the accepted 00087 * peer stream object in @c SVC_HANDLER. The default 00088 * is 0. 00089 * @param use_select Affects behavior when called back by the reactor 00090 * when a connection can be accepted. If non-zero, 00091 * this object will accept all pending connections, 00092 * intead of just the one that triggered the reactor 00093 * callback. Uses ACE_OS::select() internally to 00094 * detect any remaining acceptable connections. 00095 * The default is 1. 00096 * @param reuse_addr Passed to the @c PEER_ACCEPTOR::open() method with 00097 * @p local_addr. Generally used to request that the 00098 * OS allow reuse of the listen port. The default is 1. 00099 */ 00100 ACE_Acceptor (const ACE_PEER_ACCEPTOR_ADDR &local_addr, 00101 ACE_Reactor *reactor = ACE_Reactor::instance (), 00102 int flags = 0, 00103 int use_select = 1, 00104 int reuse_addr = 1); 00105 00106 /** 00107 * Open the contained @c PEER_ACCEPTOR object to begin listening, and 00108 * register with the specified reactor for accept events. An 00109 * acceptor can only listen to one port at a time, so make sure to 00110 * @c close() the acceptor before calling @c open() again. 00111 * 00112 * The @c PEER_ACCEPTOR handle is put into non-blocking mode as a 00113 * safeguard against the race condition that can otherwise occur 00114 * between the time when the passive-mode socket handle is "ready" 00115 * and when the actual @c accept() call is made. During this 00116 * interval, the client can shutdown the connection, in which case, 00117 * the @c accept() call can hang. 00118 * 00119 * @param local_addr The address to listen at. 00120 * @param reactor Pointer to the ACE_Reactor instance to register 00121 * this object with. The default is the singleton. 00122 * @param flags Flags to control what mode an accepted socket 00123 * will be put into after it is accepted. The only 00124 * legal value for this argument is @c ACE_NONBLOCK, 00125 * which enables non-blocking mode on the accepted 00126 * peer stream object in @c SVC_HANDLER. The default 00127 * is 0. 00128 * @param use_select Affects behavior when called back by the reactor 00129 * when a connection can be accepted. If non-zero, 00130 * this object will accept all pending connections, 00131 * intead of just the one that triggered the reactor 00132 * callback. Uses ACE_OS::select() internally to 00133 * detect any remaining acceptable connections. 00134 * The default is 1. 00135 * @param reuse_addr Passed to the @c PEER_ACCEPTOR::open() method with 00136 * @p local_addr. Generally used to request that the 00137 * OS allow reuse of the listen port. The default is 1. 00138 * 00139 * @retval 0 Success 00140 * @retval -1 Failure, @c errno contains an error code. 00141 */ 00142 virtual int open (const ACE_PEER_ACCEPTOR_ADDR &local_addr, 00143 ACE_Reactor *reactor = ACE_Reactor::instance (), 00144 int flags = 0, 00145 int use_select = 1, 00146 int reuse_addr = 1); 00147 00148 /// Close down the Acceptor's resources. 00149 virtual ~ACE_Acceptor (void); 00150 00151 /// Return the underlying PEER_ACCEPTOR object. 00152 virtual operator ACE_PEER_ACCEPTOR &() const; 00153 00154 /// Return the underlying PEER_ACCEPTOR object. 00155 virtual ACE_PEER_ACCEPTOR &acceptor (void) const; 00156 00157 /// Returns the listening acceptor's {ACE_HANDLE}. 00158 virtual ACE_HANDLE get_handle (void) const; 00159 00160 /// Close down the Acceptor 00161 virtual int close (void); 00162 00163 /// In the event that an accept fails, this method will be called and 00164 /// the return value will be returned from handle_input(). 00165 virtual int handle_accept_error (void); 00166 00167 /// Dump the state of an object. 00168 void dump (void) const; 00169 00170 /// Declare the dynamic allocation hooks. 00171 ACE_ALLOC_HOOK_DECLARE; 00172 00173 protected: 00174 // = The following three methods define the Acceptor's strategies 00175 // for creating, accepting, and activating SVC_HANDLER's, 00176 // respectively. 00177 00178 /** 00179 * Bridge method for creating a SVC_HANDLER. The default is to 00180 * create a new {SVC_HANDLER} if {sh} == 0, else {sh} is unchanged. 00181 * However, subclasses can override this policy to perform 00182 * SVC_HANDLER creation in any way that they like (such as creating 00183 * subclass instances of SVC_HANDLER, using a singleton, dynamically 00184 * linking the handler, etc.). Returns -1 on failure, else 0. 00185 */ 00186 virtual int make_svc_handler (SVC_HANDLER *&sh); 00187 00188 /** 00189 * Bridge method for accepting the new connection into the 00190 * <svc_handler>. The default behavior delegates to the 00191 * PEER_ACCEPTOR::accept. 00192 */ 00193 virtual int accept_svc_handler (SVC_HANDLER *svc_handler); 00194 00195 /** 00196 * Bridge method for activating a {svc_handler} with the appropriate 00197 * concurrency strategy. The default behavior of this method is to 00198 * activate the SVC_HANDLER by calling its {open} method (which 00199 * allows the SVC_HANDLER to define its own concurrency strategy). 00200 * However, subclasses can override this strategy to do more 00201 * sophisticated concurrency activations (such as making the 00202 * SVC_HANDLER as an "active object" via multi-threading or 00203 * multi-processing). 00204 */ 00205 virtual int activate_svc_handler (SVC_HANDLER *svc_handler); 00206 00207 // = Demultiplexing hooks. 00208 /// Perform termination activities when {this} is removed from the 00209 /// {reactor}. 00210 virtual int handle_close (ACE_HANDLE = ACE_INVALID_HANDLE, 00211 ACE_Reactor_Mask = ACE_Event_Handler::ALL_EVENTS_MASK); 00212 00213 /// Accepts all pending connections from clients, and creates and 00214 /// activates SVC_HANDLERs. 00215 virtual int handle_input (ACE_HANDLE); 00216 00217 // = Dynamic linking hooks. 00218 /// Default version does no work and returns -1. Must be overloaded 00219 /// by application developer to do anything meaningful. 00220 virtual int init (int argc, ACE_TCHAR *argv[]); 00221 00222 /// Calls {handle_close}. 00223 virtual int fini (void); 00224 00225 /// Default version returns address info in {buf}. 00226 virtual int info (ACE_TCHAR **buf, size_t) const; 00227 00228 public: 00229 // = Service management hooks. 00230 /// This method calls {Reactor::suspend}. 00231 virtual int suspend (void); 00232 00233 /// This method calls {Reactor::resume}. 00234 virtual int resume (void); 00235 00236 protected: 00237 /// Concrete factory for accepting connections from clients... 00238 ACE_PEER_ACCEPTOR peer_acceptor_; 00239 00240 /// Needed to reopen the socket if {accept} fails. 00241 ACE_PEER_ACCEPTOR_ADDR peer_acceptor_addr_; 00242 00243 /** 00244 * Flags that indicate how {SVC_HANDLER}'s should be initialized 00245 * prior to being activated. Right now, the only flag that is 00246 * processed is {ACE_NONBLOCK}, which enabled non-blocking I/O on 00247 * the {SVC_HANDLER} when it is opened. 00248 */ 00249 int flags_; 00250 00251 /// Flag that indicates whether it shall use {select} in the 00252 /// {accept}-loop. 00253 int use_select_; 00254 00255 /// Needed to reopen the socket if {accept} fails. 00256 int reuse_addr_; 00257 }; 00258 00259 /** 00260 * @class ACE_Strategy_Acceptor 00261 * 00262 * @brief Abstract factory for creating a service handler 00263 * (SVC_HANDLER), accepting into the SVC_HANDLER, and activating 00264 * the SVC_HANDLER. 00265 * 00266 * Implements a flexible and extensible set of strategies for 00267 * passively establishing connections with clients. There are 00268 * three main strategies: (1) creating a SVC_HANDLER, (2) 00269 * passively accepting a new connection from a client into the 00270 * SVC_HANDLER, and (3) activating the SVC_HANDLER with a 00271 * particular concurrency mechanism. 00272 */ 00273 template <class SVC_HANDLER, ACE_PEER_ACCEPTOR_1> 00274 class ACE_Strategy_Acceptor 00275 : public ACE_Acceptor <SVC_HANDLER, ACE_PEER_ACCEPTOR_2> 00276 { 00277 public: 00278 00279 // Useful STL-style traits. 00280 typedef ACE_Creation_Strategy<SVC_HANDLER> 00281 creation_strategy_type; 00282 typedef ACE_Accept_Strategy<SVC_HANDLER, ACE_PEER_ACCEPTOR_2> 00283 accept_strategy_type; 00284 typedef ACE_Concurrency_Strategy<SVC_HANDLER> 00285 concurrency_strategy_type; 00286 typedef ACE_Scheduling_Strategy<SVC_HANDLER> scheduling_strategy_type; 00287 typedef ACE_Acceptor <SVC_HANDLER, ACE_PEER_ACCEPTOR_2> 00288 base_type; 00289 00290 // = Define some useful (old style) traits. 00291 typedef ACE_Creation_Strategy<SVC_HANDLER> CREATION_STRATEGY; 00292 typedef ACE_Accept_Strategy<SVC_HANDLER, ACE_PEER_ACCEPTOR_2> ACCEPT_STRATEGY; 00293 typedef ACE_Concurrency_Strategy<SVC_HANDLER> CONCURRENCY_STRATEGY; 00294 typedef ACE_Scheduling_Strategy<SVC_HANDLER> SCHEDULING_STRATEGY; 00295 00296 00297 00298 /// Default constructor. 00299 ACE_Strategy_Acceptor (const ACE_TCHAR service_name[] = 0, 00300 const ACE_TCHAR service_description[] = 0, 00301 int use_select = 1, 00302 int reuse_addr = 1); 00303 00304 /** 00305 * Initialize the appropriate strategies for creation, passive 00306 * connection acceptance, and concurrency, and then register {this} 00307 * with the Reactor and listen for connection requests at the 00308 * designated {local_addr}. 00309 */ 00310 ACE_Strategy_Acceptor (const ACE_PEER_ACCEPTOR_ADDR &local_addr, 00311 ACE_Reactor * = ACE_Reactor::instance (), 00312 ACE_Creation_Strategy<SVC_HANDLER> * = 0, 00313 ACE_Accept_Strategy<SVC_HANDLER, ACE_PEER_ACCEPTOR_2> * = 0, 00314 ACE_Concurrency_Strategy<SVC_HANDLER> * = 0, 00315 ACE_Scheduling_Strategy<SVC_HANDLER> * = 0, 00316 const ACE_TCHAR service_name[] = 0, 00317 const ACE_TCHAR service_description[] = 0, 00318 int use_select = 1, 00319 int reuse_addr = 1); 00320 00321 /** 00322 * Open the contained @c PEER_ACCEPTOR object to begin listening, and 00323 * register with the specified reactor for accept events. 00324 * 00325 * The @c PEER_ACCEPTOR handle is put into non-blocking mode as a 00326 * safeguard against the race condition that can otherwise occur 00327 * between the time when the passive-mode socket handle is "ready" 00328 * and when the actual @c accept call is made. During this 00329 * interval, the client can shutdown the connection, in which case, 00330 * the {accept} call can hang. 00331 * 00332 * @param local_addr The address to listen at. 00333 * @param reactor Pointer to the ACE_Reactor instance to register 00334 * this object with. The default is the singleton. 00335 * @param flags Flags to control what mode an accepted socket 00336 * will be put into after it is accepted. The only 00337 * legal value for this argument is @c ACE_NONBLOCK, 00338 * which enables non-blocking mode on the accepted 00339 * peer stream object in @c SVC_HANDLER. The default 00340 * is 0. 00341 * @param use_select Affects behavior when called back by the reactor 00342 * when a connection can be accepted. If non-zero, 00343 * this object will accept all pending connections, 00344 * intead of just the one that triggered the reactor 00345 * callback. Uses ACE_OS::select() internally to 00346 * detect any remaining acceptable connections. 00347 * The default is 1. 00348 * @param reuse_addr Passed to the @c PEER_ACCEPTOR::open() method with 00349 * @p local_addr. Generally used to request that the 00350 * OS allow reuse of the listen port. The default is 1. 00351 * 00352 * @retval 0 Success 00353 * @retval -1 Failure, @c errno contains an error code. 00354 */ 00355 virtual int open (const ACE_PEER_ACCEPTOR_ADDR &local_addr, 00356 ACE_Reactor *reactor, 00357 int flags = 0, 00358 int use_select = 1, 00359 int reuse_addr = 1); 00360 00361 /** 00362 * Initialize the appropriate strategies for creation, passive 00363 * connection acceptance, and concurrency, and then register {this} 00364 * with the Reactor and listen for connection requests at the 00365 * designated {local_addr}. 00366 */ 00367 virtual int open (const ACE_PEER_ACCEPTOR_ADDR &, 00368 ACE_Reactor * = ACE_Reactor::instance (), 00369 ACE_Creation_Strategy<SVC_HANDLER> * = 0, 00370 ACE_Accept_Strategy<SVC_HANDLER, ACE_PEER_ACCEPTOR_2> * =0, 00371 ACE_Concurrency_Strategy<SVC_HANDLER> * = 0, 00372 ACE_Scheduling_Strategy<SVC_HANDLER> * = 0, 00373 const ACE_TCHAR *service_name = 0, 00374 const ACE_TCHAR *service_description = 0, 00375 int use_select = 1, 00376 int reuse_addr = 1); 00377 00378 /// Close down the Strategy_Acceptor's resources. 00379 virtual ~ACE_Strategy_Acceptor (void); 00380 00381 /// Return the underlying PEER_ACCEPTOR object. 00382 virtual operator ACE_PEER_ACCEPTOR &() const; 00383 00384 /// Return the underlying PEER_ACCEPTOR object. 00385 virtual ACE_PEER_ACCEPTOR &acceptor (void) const; 00386 00387 /// Returns the listening acceptor's {ACE_HANDLE}. 00388 virtual ACE_HANDLE get_handle (void) const; 00389 00390 /// Dump the state of an object. 00391 void dump (void) const; 00392 00393 /// Declare the dynamic allocation hooks. 00394 ACE_ALLOC_HOOK_DECLARE; 00395 00396 // = Service management hooks. 00397 00398 /// This method delegates to the {Scheduling_Strategy}'s {suspend} 00399 /// method. 00400 virtual int suspend (void); 00401 00402 /// This method delegates to the {Scheduling_Strategy}'s {resume} 00403 /// method. 00404 virtual int resume (void); 00405 00406 protected: 00407 00408 /// Calls {handle_close} when dynamically unlinked. 00409 virtual int fini (void); 00410 00411 /// Default version returns address info in {buf}. 00412 virtual int info (ACE_TCHAR **buf, size_t) const; 00413 00414 // = The following three methods define the {Acceptor}'s strategies 00415 // for creating, accepting, and activating {SVC_HANDLER}'s, 00416 // respectively. 00417 00418 /** 00419 * Bridge method for creating a {SVC_HANDLER}. The strategy for 00420 * creating a {SVC_HANDLER} are configured into the Acceptor via 00421 * it's {creation_strategy_}. The default is to create a new 00422 * {SVC_HANDLER} if {sh} == 0, else {sh} is unchanged. However, 00423 * subclasses can override this policy to perform {SVC_HANDLER} 00424 * creation in any way that they like (such as creating subclass 00425 * instances of {SVC_HANDLER}, using a singleton, dynamically 00426 * linking the handler, etc.). Returns -1 on failure, else 0. 00427 */ 00428 virtual int make_svc_handler (SVC_HANDLER *&); 00429 00430 /** 00431 * Bridge method for accepting the new connection into the 00432 * {SVC_HANDLER}. The default behavior delegates to the 00433 * {PEER_ACCEPTOR::accept} in the {Acceptor_Strategy}. 00434 */ 00435 virtual int accept_svc_handler (SVC_HANDLER *svc_handler); 00436 00437 /** 00438 * Bridge method for activating a {SVC_HANDLER} with the appropriate 00439 * concurrency strategy. The default behavior of this method is to 00440 * activate the {SVC_HANDLER} by calling its {open} method (which 00441 * allows the {SVC_HANDLER} to define its own concurrency strategy). 00442 * However, subclasses can override this strategy to do more 00443 * sophisticated concurrency activations (such as creating the 00444 * {SVC_HANDLER} as an "active object" via multi-threading or 00445 * multi-processing). 00446 */ 00447 virtual int activate_svc_handler (SVC_HANDLER *svc_handler); 00448 00449 // = Demultiplexing hooks. 00450 /// Perform termination activities when {this} is removed from the 00451 /// {Reactor}. 00452 virtual int handle_close (ACE_HANDLE = ACE_INVALID_HANDLE, 00453 ACE_Reactor_Mask = ACE_Event_Handler::ALL_EVENTS_MASK); 00454 00455 /// Handle SIGINT. 00456 virtual int handle_signal (int signum, siginfo_t *, ucontext_t *); 00457 00458 // = These data members are "logically private" but are put in the 00459 // protected part in case subclasses want to access them. 00460 00461 // = Strategy objects. 00462 00463 /// Creation strategy for an Acceptor. 00464 CREATION_STRATEGY *creation_strategy_; 00465 00466 /// true if {Acceptor} created the creation strategy and thus should 00467 /// delete it, else false. 00468 bool delete_creation_strategy_; 00469 00470 /// Accept strategy for an {Acceptor}. 00471 ACCEPT_STRATEGY *accept_strategy_; 00472 00473 /// true if {Acceptor} created the accept strategy and thus should delete 00474 /// it, else false. 00475 bool delete_accept_strategy_; 00476 00477 /// Concurrency strategy for an {Acceptor}. 00478 CONCURRENCY_STRATEGY *concurrency_strategy_; 00479 00480 /// true if {Acceptor} created the concurrency strategy and thus should 00481 /// delete it, else false. 00482 bool delete_concurrency_strategy_; 00483 00484 /// Scheduling strategy for an {Acceptor}. 00485 SCHEDULING_STRATEGY *scheduling_strategy_; 00486 00487 /// true if {Acceptor} created the scheduling strategy and thus should 00488 /// delete it, else false. 00489 bool delete_scheduling_strategy_; 00490 00491 // = Service information objects. 00492 00493 /// Name of the service. 00494 ACE_TCHAR *service_name_; 00495 00496 /// Description of the service. 00497 ACE_TCHAR *service_description_; 00498 00499 /// Address that the {Strategy_Acceptor} uses to listen for 00500 /// connections. 00501 ACE_PEER_ACCEPTOR_ADDR service_addr_; 00502 }; 00503 00504 /** 00505 * @class ACE_Oneshot_Acceptor 00506 * 00507 * @brief Generic factory for passively connecting clients and creating 00508 * exactly one service handler (SVC_HANDLER). 00509 * 00510 * This class works similarly to the regular {ACE_Acceptor}, 00511 * with the following differences: 00512 * 1. This class doesn't automagically register {this} with the 00513 * {ACE_Reactor} since it expects to have its {accept} method 00514 * called directly. However, it stashes the {ACE_Reactor} 00515 * pointer away in case it's needed later to finish accepting 00516 * a connection asynchronously. 00517 * 2. The class doesn't need an {ACE_Creation_Strategy} (since 00518 * the user supplies the SVC_HANDLER) or an 00519 * {ACE_Accept_Strategy} (since this class only accepts one 00520 * connection and then removes all traces of itself from the 00521 * {ACE_Reactor} if it was registered for asynchronous 00522 * accepts). 00523 */ 00524 template <class SVC_HANDLER, ACE_PEER_ACCEPTOR_1> 00525 class ACE_Oneshot_Acceptor : public ACE_Service_Object 00526 { 00527 public: 00528 00529 // Useful STL-style traits. 00530 typedef ACE_PEER_ACCEPTOR_ADDR addr_type; 00531 typedef ACE_PEER_ACCEPTOR acceptor_type; 00532 typedef SVC_HANDLER handler_type; 00533 typedef typename SVC_HANDLER::stream_type stream_type; 00534 00535 /// Constructor. 00536 ACE_Oneshot_Acceptor (void); 00537 00538 /** 00539 * Initialize the appropriate strategies for concurrency and then 00540 * open the {peer_acceptor} at the designated {local_addr}. Note 00541 * that unlike the {ACE_Acceptor} and {ACE_Strategy_Acceptor}, this 00542 * method does NOT register {this} acceptor with the {reactor} at 00543 * this point -- it just stashes the {reactor} away in case it's 00544 * needed later. 00545 */ 00546 ACE_Oneshot_Acceptor (const ACE_PEER_ACCEPTOR_ADDR &local_addr, 00547 ACE_Reactor *reactor = ACE_Reactor::instance (), 00548 ACE_Concurrency_Strategy<SVC_HANDLER> * = 0); 00549 00550 /** 00551 * Initialize the appropriate strategies for concurrency and then 00552 * open the {peer_acceptor} at the designated {local_addr}. Note 00553 * that unlike the {ACE_Acceptor} and {ACE_Strategy_Acceptor}, this 00554 * method does NOT register {this} acceptor with the {reactor} at 00555 * this point -- it just stashes the {reactor} away in case it's 00556 * needed later. 00557 */ 00558 int open (const ACE_PEER_ACCEPTOR_ADDR &, 00559 ACE_Reactor *reactor = ACE_Reactor::instance (), 00560 ACE_Concurrency_Strategy<SVC_HANDLER> * = 0); 00561 00562 /// Close down the {Oneshot_Acceptor}. 00563 virtual ~ACE_Oneshot_Acceptor (void); 00564 00565 // = Explicit factory operation. 00566 /// Create a {SVC_HANDLER}, accept the connection into the 00567 /// {SVC_HANDLER}, and activate the {SVC_HANDLER}. 00568 virtual int accept (SVC_HANDLER * = 0, 00569 ACE_PEER_ACCEPTOR_ADDR *remote_addr = 0, 00570 const ACE_Synch_Options &synch_options = ACE_Synch_Options::defaults, 00571 int restart = 1, 00572 int reset_new_handle = 0); 00573 00574 /// Cancel a oneshot acceptor that was started asynchronously. 00575 virtual int cancel (void); 00576 00577 /// Return the underlying {PEER_ACCEPTOR} object. 00578 virtual operator ACE_PEER_ACCEPTOR &() const; 00579 00580 /// Return the underlying {PEER_ACCEPTOR} object. 00581 virtual ACE_PEER_ACCEPTOR &acceptor (void) const; 00582 00583 /// Close down the {Oneshot_Acceptor}. 00584 virtual int close (void); 00585 00586 /// Dump the state of an object. 00587 void dump (void) const; 00588 00589 /// Declare the dynamic allocation hooks. 00590 ACE_ALLOC_HOOK_DECLARE; 00591 00592 protected: 00593 /** 00594 * Bridge method for activating a {svc_handler} with the appropriate 00595 * concurrency strategy. Default behavior is to activate the 00596 * {SVC_HANDLER} as a "passive object." However, subclasses can 00597 * override this strategy to do more sophisticated concurrency 00598 * activations (such as creating the {SVC_HANDLER} as an "active 00599 * object" via multi-threading or multi-processing). 00600 */ 00601 virtual int activate_svc_handler (SVC_HANDLER *svc_handler); 00602 00603 /// Factors out the code shared between the {accept} and 00604 /// {handle_input} methods. 00605 int shared_accept (SVC_HANDLER *svc_handler, 00606 ACE_PEER_ACCEPTOR_ADDR *remote_addr, 00607 ACE_Time_Value *timeout, 00608 int restart, 00609 int reset_new_handle); 00610 00611 // = Demultiplexing hooks. 00612 /// Returns the listening acceptor's {ACE_HANDLE}. 00613 virtual ACE_HANDLE get_handle (void) const; 00614 00615 /// Perform termination activities when {this} is removed from the 00616 /// {reactor}. 00617 virtual int handle_close (ACE_HANDLE = ACE_INVALID_HANDLE, 00618 ACE_Reactor_Mask = ACE_Event_Handler::ALL_EVENTS_MASK); 00619 00620 /// Accept one connection from a client and activates the 00621 /// SVC_HANDLER. 00622 virtual int handle_input (ACE_HANDLE); 00623 00624 /// Called when an acceptor times out... 00625 virtual int handle_timeout (const ACE_Time_Value &tv, 00626 const void *arg); 00627 00628 // = Dynamic linking hooks. 00629 /// Default version does no work and returns -1. Must be overloaded 00630 /// by application developer to do anything meaningful. 00631 virtual int init (int argc, ACE_TCHAR *argv[]); 00632 00633 /// Default version does no work and returns -1. Must be overloaded 00634 /// by application developer to do anything meaningful. 00635 virtual int fini (void); 00636 00637 /// Default version returns address info in {buf}. 00638 virtual int info (ACE_TCHAR **, size_t) const; 00639 00640 // = Service management hooks. 00641 /// Default version does no work and returns -1. Must be overloaded 00642 /// by application developer to do anything meaningful. 00643 virtual int suspend (void); 00644 00645 /// Default version does no work and returns -1. Must be overloaded 00646 /// by application developer to do anything meaningful. 00647 virtual int resume (void); 00648 00649 private: 00650 /** 00651 * Insert ourselves into the {ACE_Reactor} so that we can continue 00652 * accepting this connection asynchronously. This method should NOT 00653 * be called by developers directly. 00654 */ 00655 int register_handler (SVC_HANDLER *svc_handler, 00656 const ACE_Synch_Options &options, 00657 int restart); 00658 00659 /// Hold the svc_handler_ across asynchrony boundaries. 00660 SVC_HANDLER *svc_handler_; 00661 00662 /// Hold the restart flag across asynchrony boundaries. 00663 int restart_; 00664 00665 /// Factory that establishes connections passively. 00666 ACE_PEER_ACCEPTOR peer_acceptor_; 00667 00668 /// Concurrency strategy for an Acceptor. 00669 ACE_Concurrency_Strategy<SVC_HANDLER> *concurrency_strategy_; 00670 00671 /// true if Acceptor created the concurrency strategy and thus should 00672 /// delete it, else false. 00673 bool delete_concurrency_strategy_; 00674 }; 00675 00676 ACE_END_VERSIONED_NAMESPACE_DECL 00677 00678 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE) 00679 #include "ace/Acceptor.cpp" 00680 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ 00681 00682 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) 00683 #pragma implementation ("Acceptor.cpp") 00684 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ 00685 00686 #include /**/ "ace/post.h" 00687 00688 #endif /* ACE_ACCEPTOR_H */