/* -*- C++ -*- */ //============================================================================= /** * @file Acceptor.h * * $Id$ * * @author Doug Schmidt */ //============================================================================= #ifndef ACE_ACCEPTOR_H #define ACE_ACCEPTOR_H #include "ace/pre.h" #include "ace/Service_Config.h" #if !defined (ACE_LACKS_PRAGMA_ONCE) # pragma once #endif /* ACE_LACKS_PRAGMA_ONCE */ #include "ace/Service_Object.h" #include "ace/Svc_Handler.h" #include "ace/Strategies.h" /** * @class ACE_Acceptor * * @brief Abstract factory for creating a service handler * (SVC_HANDLER), accepting into the SVC_HANDLER, and * activating the SVC_HANDLER. * * Implements the basic strategy for passively establishing * connections with clients. An ACE_Acceptor is parameterized * by concrete types that conform to the interfaces of * PEER_ACCEPTOR and SVC_HANDLER. The PEER_ACCEPTOR is * instantiated with a transport mechanism that passively * establishes connections. The SVC_HANDLER is instantiated * with a concrete type that performs the application-specific * service. An ACE_Acceptor inherits from ACE_Service_Object, * which in turn inherits from ACE_Event_Handler. This enables * the ACE_Reactor to dispatch the ACE_Acceptor's handle_input * method when connection events occur. The handle_input method * performs the ACE_Acceptor's default creation, connection * establishment, and service activation strategies. These * strategies can be overridden by subclasses individually or as * a group. */ template class ACE_Acceptor : public ACE_Service_Object { public: // = Initialization and termination methods. /// "Do-nothing" constructor. ACE_Acceptor (ACE_Reactor * = 0, int use_select = 1); /** * Initialize and register with the Reactor and listen for * connection requests at the designated . * indicates how 's should be initialized prior to * being activated. Right now, the only flag that is processed is * , which enabled non-blocking I/O on the * when it is opened. If is non-zero * then is used to determine when to break out of the * loop. is passed down to the * . If it is non-zero this will allow the OS to * reuse this listen port. */ int open (const ACE_PEER_ACCEPTOR_ADDR &, ACE_Reactor * = ACE_Reactor::instance (), int flags = 0, int use_select = 1, int reuse_addr = 1); /// Close down the Acceptor's resources. virtual ~ACE_Acceptor (void); /// Return the underlying PEER_ACCEPTOR object. virtual operator ACE_PEER_ACCEPTOR &() const; /// Return the underlying PEER_ACCEPTOR object. virtual ACE_PEER_ACCEPTOR &acceptor (void) const; /// Returns the listening acceptor's . virtual ACE_HANDLE get_handle (void) const; /// Close down the Acceptor virtual int close (void); /// Dump the state of an object. void dump (void) const; /// Declare the dynamic allocation hooks. ACE_ALLOC_HOOK_DECLARE; protected: // = The following three methods define the Acceptor's strategies // for creating, accepting, and activating SVC_HANDLER's, // respectively. /** * Bridge method for creating a SVC_HANDLER. The default is to * create a new if == 0, else is unchanged. * However, subclasses can override this policy to perform * SVC_HANDLER creation in any way that they like (such as creating * subclass instances of SVC_HANDLER, using a singleton, dynamically * linking the handler, etc.). Returns -1 on failure, else 0. */ virtual int make_svc_handler (SVC_HANDLER *&sh); /** * Bridge method for accepting the new connection into the * . The default behavior delegates to the * PEER_ACCEPTOR::accept. */ virtual int accept_svc_handler (SVC_HANDLER *svc_handler); /** * Bridge method for activating a with the appropriate * concurrency strategy. The default behavior of this method is to * activate the SVC_HANDLER by calling its method (which * allows the SVC_HANDLER to define its own concurrency strategy). * However, subclasses can override this strategy to do more * sophisticated concurrency activations (such as making the * SVC_HANDLER as an "active object" via multi-threading or * multi-processing). */ virtual int activate_svc_handler (SVC_HANDLER *svc_handler); // = Demultiplexing hooks. /// Perform termination activities when is removed from the /// . virtual int handle_close (ACE_HANDLE = ACE_INVALID_HANDLE, ACE_Reactor_Mask = ACE_Event_Handler::ALL_EVENTS_MASK); /// Accepts all pending connections from clients, and creates and /// activates SVC_HANDLERs. virtual int handle_input (ACE_HANDLE); // = Dynamic linking hooks. /// Default version does no work and returns -1. Must be overloaded /// by application developer to do anything meaningful. virtual int init (int argc, ACE_TCHAR *argv[]); /// Calls . virtual int fini (void); /// Default version returns address info in . virtual int info (ACE_TCHAR **buf, size_t) const; public: // = Service management hooks. /// This method calls . virtual int suspend (void); /// This method calls . virtual int resume (void); protected: /// Concrete factory for accepting connections from clients... ACE_PEER_ACCEPTOR peer_acceptor_; /// Needed to reopen the socket if fails. ACE_PEER_ACCEPTOR_ADDR peer_acceptor_addr_; /** * Flags that indicate how 's should be initialized * prior to being activated. Right now, the only flag that is * processed is , which enabled non-blocking I/O on * the when it is opened. */ int flags_; /// Flag that indicates whether it shall use