00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file Acceptor.h 00006 * 00007 * Acceptor.h,v 4.49 2006/03/27 14:09:30 schmidt Exp 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 ACE_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 * = 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 protected: 00393 // = Service management hooks. 00394 00395 /// This method delegates to the {Scheduling_Strategy}'s {suspend} 00396 /// method. 00397 virtual int suspend (void); 00398 00399 /// This method delegates to the {Scheduling_Strategy}'s {resume} 00400 /// method. 00401 virtual int resume (void); 00402 00403 /// Calls {handle_close} when dynamically unlinked. 00404 virtual int fini (void); 00405 00406 /// Default version returns address info in {buf}. 00407 virtual int info (ACE_TCHAR **buf, size_t) const; 00408 00409 // = The following three methods define the {Acceptor}'s strategies 00410 // for creating, accepting, and activating {SVC_HANDLER}'s, 00411 // respectively. 00412 00413 /** 00414 * Bridge method for creating a {SVC_HANDLER}. The strategy for 00415 * creating a {SVC_HANDLER} are configured into the Acceptor via 00416 * it's {creation_strategy_}. The default is to create a new 00417 * {SVC_HANDLER} if {sh} == 0, else {sh} is unchanged. However, 00418 * subclasses can override this policy to perform {SVC_HANDLER} 00419 * creation in any way that they like (such as creating subclass 00420 * instances of {SVC_HANDLER}, using a singleton, dynamically 00421 * linking the handler, etc.). Returns -1 on failure, else 0. 00422 */ 00423 virtual int make_svc_handler (SVC_HANDLER *&); 00424 00425 /** 00426 * Bridge method for accepting the new connection into the 00427 * {SVC_HANDLER}. The default behavior delegates to the 00428 * {PEER_ACCEPTOR::accept} in the {Acceptor_Strategy}. 00429 */ 00430 virtual int accept_svc_handler (SVC_HANDLER *svc_handler); 00431 00432 /** 00433 * Bridge method for activating a {SVC_HANDLER} with the appropriate 00434 * concurrency strategy. The default behavior of this method is to 00435 * activate the {SVC_HANDLER} by calling its {open} method (which 00436 * allows the {SVC_HANDLER} to define its own concurrency strategy). 00437 * However, subclasses can override this strategy to do more 00438 * sophisticated concurrency activations (such as creating the 00439 * {SVC_HANDLER} as an "active object" via multi-threading or 00440 * multi-processing). 00441 */ 00442 virtual int activate_svc_handler (SVC_HANDLER *svc_handler); 00443 00444 // = Demultiplexing hooks. 00445 /// Perform termination activities when {this} is removed from the 00446 /// {Reactor}. 00447 virtual int handle_close (ACE_HANDLE = ACE_INVALID_HANDLE, 00448 ACE_Reactor_Mask = ACE_Event_Handler::ALL_EVENTS_MASK); 00449 00450 /// Handle SIGINT. 00451 virtual int handle_signal (int signum, siginfo_t *, ucontext_t *); 00452 00453 // = These data members are "logically private" but are put in the 00454 // protected part in case subclasses want to access them. 00455 00456 // = Strategy objects. 00457 00458 /// Creation strategy for an Acceptor. 00459 CREATION_STRATEGY *creation_strategy_; 00460 00461 /// 1 if {Acceptor} created the creation strategy and thus should 00462 /// delete it, else 0. 00463 int delete_creation_strategy_; 00464 00465 /// Accept strategy for an {Acceptor}. 00466 ACCEPT_STRATEGY *accept_strategy_; 00467 00468 /// 1 if {Acceptor} created the accept strategy and thus should delete 00469 /// it, else 0. 00470 int delete_accept_strategy_; 00471 00472 /// Concurrency strategy for an {Acceptor}. 00473 CONCURRENCY_STRATEGY *concurrency_strategy_; 00474 00475 /// 1 if {Acceptor} created the concurrency strategy and thus should 00476 /// delete it, else 0. 00477 int delete_concurrency_strategy_; 00478 00479 /// Scheduling strategy for an {Acceptor}. 00480 SCHEDULING_STRATEGY *scheduling_strategy_; 00481 00482 /// 1 if {Acceptor} created the scheduling strategy and thus should 00483 /// delete it, else 0. 00484 int delete_scheduling_strategy_; 00485 00486 // = Service information objects. 00487 00488 /// Name of the service. 00489 ACE_TCHAR *service_name_; 00490 00491 /// Description of the service. 00492 ACE_TCHAR *service_description_; 00493 00494 /// Address that the {Strategy_Acceptor} uses to listen for 00495 /// connections. 00496 ACE_PEER_ACCEPTOR_ADDR service_addr_; 00497 }; 00498 00499 /** 00500 * @class ACE_Oneshot_Acceptor 00501 * 00502 * @brief Generic factory for passively connecting clients and creating 00503 * exactly one service handler (SVC_HANDLER). 00504 * 00505 * This class works similarly to the regular {ACE_Acceptor}, 00506 * with the following differences: 00507 * 1. This class doesn't automagically register {this} with the 00508 * {ACE_Reactor} since it expects to have its {accept} method 00509 * called directly. However, it stashes the {ACE_Reactor} 00510 * pointer away in case it's needed later to finish accepting 00511 * a connection asynchronously. 00512 * 2. The class doesn't need an {ACE_Creation_Strategy} (since 00513 * the user supplies the SVC_HANDLER) or an 00514 * {ACE_Accept_Strategy} (since this class only accepts one 00515 * connection and then removes all traces of itself from the 00516 * {ACE_Reactor} if it was registered for asynchronous 00517 * accepts). 00518 */ 00519 template <class SVC_HANDLER, ACE_PEER_ACCEPTOR_1> 00520 class ACE_Oneshot_Acceptor : public ACE_Service_Object 00521 { 00522 public: 00523 00524 // Useful STL-style traits. 00525 typedef ACE_PEER_ACCEPTOR_ADDR addr_type; 00526 typedef ACE_PEER_ACCEPTOR acceptor_type; 00527 typedef SVC_HANDLER handler_type; 00528 typedef ACE_TYPENAME SVC_HANDLER::stream_type stream_type; 00529 00530 /// Constructor. 00531 ACE_Oneshot_Acceptor (void); 00532 00533 /** 00534 * Initialize the appropriate strategies for concurrency and then 00535 * open the {peer_acceptor} at the designated {local_addr}. Note 00536 * that unlike the {ACE_Acceptor} and {ACE_Strategy_Acceptor}, this 00537 * method does NOT register {this} acceptor with the {reactor} at 00538 * this point -- it just stashes the {reactor} away in case it's 00539 * needed later. 00540 */ 00541 ACE_Oneshot_Acceptor (const ACE_PEER_ACCEPTOR_ADDR &local_addr, 00542 ACE_Reactor *reactor = ACE_Reactor::instance (), 00543 ACE_Concurrency_Strategy<SVC_HANDLER> * = 0); 00544 00545 /** 00546 * Initialize the appropriate strategies for concurrency and then 00547 * open the {peer_acceptor} at the designated {local_addr}. Note 00548 * that unlike the {ACE_Acceptor} and {ACE_Strategy_Acceptor}, this 00549 * method does NOT register {this} acceptor with the {reactor} at 00550 * this point -- it just stashes the {reactor} away in case it's 00551 * needed later. 00552 */ 00553 int open (const ACE_PEER_ACCEPTOR_ADDR &, 00554 ACE_Reactor *reactor = ACE_Reactor::instance (), 00555 ACE_Concurrency_Strategy<SVC_HANDLER> * = 0); 00556 00557 /// Close down the {Oneshot_Acceptor}. 00558 virtual ~ACE_Oneshot_Acceptor (void); 00559 00560 // = Explicit factory operation. 00561 /// Create a {SVC_HANDLER}, accept the connection into the 00562 /// {SVC_HANDLER}, and activate the {SVC_HANDLER}. 00563 virtual int accept (SVC_HANDLER * = 0, 00564 ACE_PEER_ACCEPTOR_ADDR *remote_addr = 0, 00565 const ACE_Synch_Options &synch_options = ACE_Synch_Options::defaults, 00566 int restart = 1, 00567 int reset_new_handle = 0); 00568 00569 /// Cancel a oneshot acceptor that was started asynchronously. 00570 virtual int cancel (void); 00571 00572 /// Return the underlying {PEER_ACCEPTOR} object. 00573 virtual operator ACE_PEER_ACCEPTOR &() const; 00574 00575 /// Return the underlying {PEER_ACCEPTOR} object. 00576 virtual ACE_PEER_ACCEPTOR &acceptor (void) const; 00577 00578 /// Close down the {Oneshot_Acceptor}. 00579 virtual int close (void); 00580 00581 /// Dump the state of an object. 00582 void dump (void) const; 00583 00584 /// Declare the dynamic allocation hooks. 00585 ACE_ALLOC_HOOK_DECLARE; 00586 00587 protected: 00588 /** 00589 * Bridge method for activating a {svc_handler} with the appropriate 00590 * concurrency strategy. Default behavior is to activate the 00591 * {SVC_HANDLER} as a "passive object." However, subclasses can 00592 * override this strategy to do more sophisticated concurrency 00593 * activations (such as creating the {SVC_HANDLER} as an "active 00594 * object" via multi-threading or multi-processing). 00595 */ 00596 virtual int activate_svc_handler (SVC_HANDLER *svc_handler); 00597 00598 /// Factors out the code shared between the {accept} and 00599 /// {handle_input} methods. 00600 int shared_accept (SVC_HANDLER *svc_handler, 00601 ACE_PEER_ACCEPTOR_ADDR *remote_addr, 00602 ACE_Time_Value *timeout, 00603 int restart, 00604 int reset_new_handle); 00605 00606 // = Demultiplexing hooks. 00607 /// Returns the listening acceptor's {ACE_HANDLE}. 00608 virtual ACE_HANDLE get_handle (void) const; 00609 00610 /// Perform termination activities when {this} is removed from the 00611 /// {reactor}. 00612 virtual int handle_close (ACE_HANDLE = ACE_INVALID_HANDLE, 00613 ACE_Reactor_Mask = ACE_Event_Handler::ALL_EVENTS_MASK); 00614 00615 /// Accept one connection from a client and activates the 00616 /// SVC_HANDLER. 00617 virtual int handle_input (ACE_HANDLE); 00618 00619 /// Called when an acceptor times out... 00620 virtual int handle_timeout (const ACE_Time_Value &tv, 00621 const void *arg); 00622 00623 // = Dynamic linking hooks. 00624 /// Default version does no work and returns -1. Must be overloaded 00625 /// by application developer to do anything meaningful. 00626 virtual int init (int argc, ACE_TCHAR *argv[]); 00627 00628 /// Default version does no work and returns -1. Must be overloaded 00629 /// by application developer to do anything meaningful. 00630 virtual int fini (void); 00631 00632 /// Default version returns address info in {buf}. 00633 virtual int info (ACE_TCHAR **, size_t) const; 00634 00635 // = Service management hooks. 00636 /// Default version does no work and returns -1. Must be overloaded 00637 /// by application developer to do anything meaningful. 00638 virtual int suspend (void); 00639 00640 /// Default version does no work and returns -1. Must be overloaded 00641 /// by application developer to do anything meaningful. 00642 virtual int resume (void); 00643 00644 private: 00645 /** 00646 * Insert ourselves into the {ACE_Reactor} so that we can continue 00647 * accepting this connection asynchronously. This method should NOT 00648 * be called by developers directly. 00649 */ 00650 int register_handler (SVC_HANDLER *svc_handler, 00651 const ACE_Synch_Options &options, 00652 int restart); 00653 00654 /// Hold the svc_handler_ across asynchrony boundaries. 00655 SVC_HANDLER *svc_handler_; 00656 00657 /// Hold the restart flag across asynchrony boundaries. 00658 int restart_; 00659 00660 /// Factory that establishes connections passively. 00661 ACE_PEER_ACCEPTOR peer_acceptor_; 00662 00663 /// Concurrency strategy for an Acceptor. 00664 ACE_Concurrency_Strategy<SVC_HANDLER> *concurrency_strategy_; 00665 00666 /// 1 if Acceptor created the concurrency strategy and thus should 00667 /// delete it, else 0. 00668 int delete_concurrency_strategy_; 00669 }; 00670 00671 ACE_END_VERSIONED_NAMESPACE_DECL 00672 00673 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE) 00674 #include "ace/Acceptor.cpp" 00675 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ 00676 00677 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) 00678 #pragma implementation ("Acceptor.cpp") 00679 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ 00680 00681 #include /**/ "ace/post.h" 00682 00683 #endif /* ACE_ACCEPTOR_H */