NAME
ACE_Strategy_Acceptor - Abstract factory for creating a service handler (SVC_HANDLER), accepting into the SVC_HANDLER, and activating the SVC_HANDLER.
SYNOPSIS
#include <ace/Acceptor.h>
template<class SVC_HANDLER, ACE_PEER_ACCEPTOR_1>
class ACE_Strategy_Acceptor :
public ACE_Acceptor <SVC_HANDLER, ACE_PEER_ACCEPTOR_2>
{
public:
ACE_Strategy_Acceptor (
const ASYS_TCHAR service_name[] = 0,
const ASYS_TCHAR service_description[] = 0,
int use_select = 1
);
ACE_Strategy_Acceptor (
const ACE_PEER_ACCEPTOR_ADDR &local_addr,
ACE_Reactor * = ACE_Reactor::instance (),
ACE_Creation_Strategy<SVC_HANDLER> * = 0,
ACE_Accept_Strategy<SVC_HANDLER, ACE_PEER_ACCEPTOR_2> * = 0,
ACE_Concurrency_Strategy<SVC_HANDLER> * = 0,
ACE_Scheduling_Strategy<SVC_HANDLER> * = 0,
const ASYS_TCHAR service_name[] = 0,
const ASYS_TCHAR service_description[] = 0,
int use_select = 1
);
int open (
const ACE_PEER_ACCEPTOR_ADDR &,
ACE_Reactor * = ACE_Reactor::instance (),
ACE_Creation_Strategy<SVC_HANDLER> * = 0,
ACE_Accept_Strategy<SVC_HANDLER, ACE_PEER_ACCEPTOR_2> * = 0,
ACE_Concurrency_Strategy<SVC_HANDLER> * = 0,
ACE_Scheduling_Strategy<SVC_HANDLER> * = 0,
const ASYS_TCHAR *service_name = 0,
const ASYS_TCHAR *service_description = 0,
int use_select = 1
);
virtual ~ACE_Strategy_Acceptor (void);
virtual operator ACE_PEER_ACCEPTOR &() const;
virtual ACE_PEER_ACCEPTOR &acceptor (void) const;
virtual ACE_HANDLE get_handle (void) const;
void dump (void) const;
ACE_ALLOC_HOOK_DECLARE;
protected:
virtual int suspend (void);
virtual int resume (void);
virtual int fini (void);
virtual int info (ASYS_TCHAR **buf, size_t) const;
virtual int make_svc_handler (SVC_HANDLER *&);
virtual int accept_svc_handler (SVC_HANDLER *svc_handler);
virtual int activate_svc_handler (SVC_HANDLER *svc_handler);
virtual int handle_close (
ACE_HANDLE = ACE_INVALID_HANDLE,
ACE_Reactor_Mask = ACE_Event_Handler::ALL_EVENTS_MASK
);
virtual int handle_signal (int signum, siginfo_t *, ucontext_t *);
typedef ACE_Creation_Strategy<SVC_HANDLER> CREATION_STRATEGY;
typedef ACE_Accept_Strategy<SVC_HANDLER, ACE_PEER_ACCEPTOR_2> ACCEPT_STRATEGY;
typedef ACE_Concurrency_Strategy<SVC_HANDLER> CONCURRENCY_STRATEGY;
typedef ACE_Scheduling_Strategy<SVC_HANDLER> SCHEDULING_STRATEGY;
CREATION_STRATEGY *creation_strategy_;
int delete_creation_strategy_;
ACCEPT_STRATEGY *accept_strategy_;
int delete_accept_strategy_;
CONCURRENCY_STRATEGY *concurrency_strategy_;
int delete_concurrency_strategy_;
SCHEDULING_STRATEGY *scheduling_strategy_;
int delete_scheduling_strategy_;
ASYS_TCHAR *service_name_;
ASYS_TCHAR *service_description_;
u_short service_port_;
ACE_PEER_ACCEPTOR_ADDR service_addr_;
};
DESCRIPTION
Implements a flexible and extensible set of strategies for passively establishing connections with clients. There are three main strategies: (1) creating a SVC_HANDLER, (2) passively accepting a new connection from a client into the SVC_HANDLER, and (3) activating the SVC_HANDLER with a particular concurrency mechanism.
Initialization and termination methods.
ACE_Strategy_Acceptor (
const ASYS_TCHAR service_name[] = 0,
const ASYS_TCHAR service_description[] = 0,
int use_select = 1
);
Default constructor.
ACE_Strategy_Acceptor (
const ACE_PEER_ACCEPTOR_ADDR &local_addr,
ACE_Reactor * = ACE_Reactor::instance (),
ACE_Creation_Strategy<SVC_HANDLER> * = 0,
ACE_Accept_Strategy<SVC_HANDLER, ACE_PEER_ACCEPTOR_2> * = 0,
ACE_Concurrency_Strategy<SVC_HANDLER> * = 0,
ACE_Scheduling_Strategy<SVC_HANDLER> * = 0,
const ASYS_TCHAR service_name[] = 0,
const ASYS_TCHAR service_description[] = 0,
int use_select = 1
);
Initialize the appropriate strategies for creation, passive connection acceptance, and concurrency, and then register this with the Reactor and listen for connection requests at the designated local_addr.
int open (
const ACE_PEER_ACCEPTOR_ADDR &,
ACE_Reactor * = ACE_Reactor::instance (),
ACE_Creation_Strategy<SVC_HANDLER> * = 0,
ACE_Accept_Strategy<SVC_HANDLER, ACE_PEER_ACCEPTOR_2> * = 0,
ACE_Concurrency_Strategy<SVC_HANDLER> * = 0,
ACE_Scheduling_Strategy<SVC_HANDLER> * = 0,
const ASYS_TCHAR *service_name = 0,
const ASYS_TCHAR *service_description = 0,
int use_select = 1
);
Initialize the appropriate strategies for creation, passive connection acceptance, and concurrency, and then register this with the Reactor and listen for connection requests at the designated local_addr.
virtual ~ACE_Strategy_Acceptor (void);
Close down the Strategy_Acceptor's resources.
virtual operator ACE_PEER_ACCEPTOR &() const;
Return the underlying PEER_ACCEPTOR object.
virtual ACE_PEER_ACCEPTOR &acceptor (void) const;
Return the underlying PEER_ACCEPTOR object.
virtual ACE_HANDLE get_handle (void) const;
Returns the listening acceptor's ACE_HANDLE.
void dump (void) const;
Dump the state of an object.
ACE_ALLOC_HOOK_DECLARE;
Declare the dynamic allocation hooks.
Service management hooks.
virtual int suspend (void);
This method delegates to the Scheduling_Strategy's suspend method.
virtual int resume (void);
This method delegates to the Scheduling_Strategy's resume method.
virtual int fini (void);
Calls handle_close when dynamically unlinked.
virtual int info (ASYS_TCHAR **buf, size_t) const;
Default version returns address info in buf.
= The following three methods define the Acceptor's strategies for creating, accepting, and activating SVC_HANDLER's, respectively.
virtual int make_svc_handler (SVC_HANDLER *&);
Bridge method for creating a SVC_HANDLER. The strategy for creating a SVC_HANDLER are configured into the Acceptor via it's creation_strategy_. The default is to create a new SVC_HANDLER if sh == 0, else sh 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 accept_svc_handler (SVC_HANDLER *svc_handler);
Bridge method for accepting the new connection into the SVC_HANDLER. The default behavior delegates to the PEER_ACCEPTOR::accept in the Acceptor_Strategy.
virtual int activate_svc_handler (SVC_HANDLER *svc_handler);
Bridge method for activating a SVC_HANDLER with the appropriate concurrency strategy. The default behavior of this method is to activate the SVC_HANDLER by calling its open 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 creating the SVC_HANDLER as an "active object" via multi-threading or multi-processing).
Demultiplexing hooks.
virtual int handle_close (
ACE_HANDLE = ACE_INVALID_HANDLE,
ACE_Reactor_Mask = ACE_Event_Handler::ALL_EVENTS_MASK
);
Perform termination activities when this is removed from the Reactor.
virtual int handle_signal (int signum, siginfo_t *, ucontext_t *);
Handle SIGINT.
These data members are logically private" but are put in the"
protected part in case subclasses want to access them.
Define some useful typedefs.
typedef ACE_Creation_Strategy<SVC_HANDLER> CREATION_STRATEGY;
typedef ACE_Accept_Strategy<SVC_HANDLER, ACE_PEER_ACCEPTOR_2> ACCEPT_STRATEGY;
typedef ACE_Concurrency_Strategy<SVC_HANDLER> CONCURRENCY_STRATEGY;
typedef ACE_Scheduling_Strategy<SVC_HANDLER> SCHEDULING_STRATEGY;
Strategy objects.
CREATION_STRATEGY *creation_strategy_;
Creation strategy for an Acceptor.
int delete_creation_strategy_;
1 if Acceptor created the creation strategy and thus should delete it, else 0.
ACCEPT_STRATEGY *accept_strategy_;
Accept strategy for an Acceptor.
int delete_accept_strategy_;
1 if Acceptor created the accept strategy and thus should delete it, else 0.
CONCURRENCY_STRATEGY *concurrency_strategy_;
Concurrency strategy for an Acceptor.
int delete_concurrency_strategy_;
1 if Acceptor created the concurrency strategy and thus should delete it, else 0.
SCHEDULING_STRATEGY *scheduling_strategy_;
Scheduling strategy for an Acceptor.
int delete_scheduling_strategy_;
1 if Acceptor created the scheduling strategy and thus should delete it, else 0.
Service information objects.
ASYS_TCHAR *service_name_;
Name of the service.
ASYS_TCHAR *service_description_;
Description of the service.
u_short service_port_;
Port number for the server.
ACE_PEER_ACCEPTOR_ADDR service_addr_;
Address that the Strategy_Acceptor uses to listen for connections.
AUTHOR
Doug Schmidt
LIBRARY
ace