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