Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Acceptor.h

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

Generated on Mon Jun 16 11:19:00 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002