ACE  6.1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
ACE_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 > Class Template Reference

Abstract factory for creating a service handler (SVC_HANDLER), accepting into the SVC_HANDLER, and activating the SVC_HANDLER. More...

#include <Acceptor.h>

Inheritance diagram for ACE_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >:
Inheritance graph
[legend]
Collaboration diagram for ACE_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >:
Collaboration graph
[legend]

Public Types

typedef ACE_PEER_ACCEPTOR_ADDR addr_type
 
typedef ACE_PEER_ACCEPTOR acceptor_type
 
typedef SVC_HANDLER handler_type
 
typedef SVC_HANDLER::stream_type stream_type
 

Public Member Functions

 ACE_Acceptor (ACE_Reactor *=0, int use_select=1)
 "Do-nothing" constructor.
 
 ACE_Acceptor (const ACE_PEER_ACCEPTOR_ADDR &local_addr, ACE_Reactor *reactor=ACE_Reactor::instance(), int flags=0, int use_select=1, int reuse_addr=1)
 
virtual int open (const ACE_PEER_ACCEPTOR_ADDR &local_addr, ACE_Reactor *reactor=ACE_Reactor::instance(), int flags=0, int use_select=1, int reuse_addr=1)
 
virtual ~ACE_Acceptor (void)
 Close down the Acceptor's resources.
 
virtual operator ACE_PEER_ACCEPTOR & () const
 Return the underlying PEER_ACCEPTOR object.
 
virtual ACE_PEER_ACCEPTORacceptor (void) const
 Return the underlying PEER_ACCEPTOR object.
 
virtual ACE_HANDLE get_handle (void) const
 Returns the listening acceptor's {ACE_HANDLE}.
 
virtual int close (void)
 Close down the Acceptor.
 
virtual int handle_accept_error (void)
 
void dump (void) const
 Dump the state of an object.
 
virtual int suspend (void)
 This method calls {Reactor::suspend}.
 
virtual int resume (void)
 This method calls {Reactor::resume}.
 
- Public Member Functions inherited from ACE_Service_Object
 ACE_Service_Object (ACE_Reactor *=0)
 Constructor.
 
virtual ~ACE_Service_Object (void)
 Destructor.
 
- Public Member Functions inherited from ACE_Event_Handler
virtual ~ACE_Event_Handler (void)
 Destructor is virtual to enable proper cleanup.
 
virtual void set_handle (ACE_HANDLE)
 Set the I/O handle.
 
virtual int priority (void) const
 
virtual void priority (int priority)
 Set the priority of the Event_Handler.
 
virtual int handle_output (ACE_HANDLE fd=ACE_INVALID_HANDLE)
 
virtual int handle_exception (ACE_HANDLE fd=ACE_INVALID_HANDLE)
 Called when an exceptional events occur (e.g., SIGURG).
 
virtual int handle_timeout (const ACE_Time_Value &current_time, const void *act=0)
 
virtual int handle_exit (ACE_Process *)
 Called when a process exits.
 
virtual int handle_signal (int signum, siginfo_t *=0, ucontext_t *=0)
 
virtual int resume_handler (void)
 
virtual int handle_qos (ACE_HANDLE=ACE_INVALID_HANDLE)
 
virtual int handle_group_qos (ACE_HANDLE=ACE_INVALID_HANDLE)
 
virtual void reactor (ACE_Reactor *reactor)
 Set the event demultiplexors.
 
virtual ACE_Reactorreactor (void) const
 Get the event demultiplexors.
 
virtual
ACE_Reactor_Timer_Interface
reactor_timer_interface (void) const
 Get only the reactor's timer related interface.
 
virtual Reference_Count add_reference (void)
 Increment reference count on the handler.
 
virtual Reference_Count remove_reference (void)
 Decrement reference count on the handler.
 
Reference_Counting_Policyreference_counting_policy (void)
 Current Reference_Counting_Policy.
 
- Public Member Functions inherited from ACE_Shared_Object
 ACE_Shared_Object (void)
 Constructor.
 
virtual ~ACE_Shared_Object (void)
 Destructor.
 

Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks.
 

Protected Member Functions

virtual int make_svc_handler (SVC_HANDLER *&sh)
 
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_input (ACE_HANDLE)
 
virtual int init (int argc, ACE_TCHAR *argv[])
 
virtual int fini (void)
 Calls {handle_close}.
 
virtual int info (ACE_TCHAR **buf, size_t) const
 Default version returns address info in {buf}.
 

Protected Attributes

ACE_PEER_ACCEPTOR peer_acceptor_
 Concrete factory for accepting connections from clients...
 
ACE_PEER_ACCEPTOR_ADDR peer_acceptor_addr_
 Needed to reopen the socket if {accept} fails.
 
int flags_
 
int use_select_
 
int reuse_addr_
 Needed to reopen the socket if {accept} fails.
 

Additional Inherited Members

- Static Public Member Functions inherited from ACE_Event_Handler
static ACE_THR_FUNC_RETURN read_adapter (void *event_handler)
 
static int register_stdin_handler (ACE_Event_Handler *eh, ACE_Reactor *reactor, ACE_Thread_Manager *thr_mgr, int flags=THR_DETACHED)
 
static int remove_stdin_handler (ACE_Reactor *reactor, ACE_Thread_Manager *thr_mgr)
 Performs the inverse of the register_stdin_handler() method.
 
- Protected Types inherited from ACE_Event_Handler
typedef ACE_Atomic_Op
< ACE_SYNCH_MUTEX,
Reference_Count
Atomic_Reference_Count
 Typedef for implementation of reference counting.
 

Detailed Description

template<class SVC_HANDLER, ACE_PEER_ACCEPTOR_1>
class ACE_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >

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.

Member Typedef Documentation

template<class SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >
typedef ACE_PEER_ACCEPTOR ACE_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >::acceptor_type
template<class SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >
typedef ACE_PEER_ACCEPTOR_ADDR ACE_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >::addr_type
template<class SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >
typedef SVC_HANDLER ACE_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >::handler_type
template<class SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >
typedef SVC_HANDLER::stream_type ACE_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >::stream_type

Constructor & Destructor Documentation

template<class SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >
ACE_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >::ACE_Acceptor ( ACE_Reactor = 0,
int  use_select = 1 
)

"Do-nothing" constructor.

template<class SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >
ACE_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >::ACE_Acceptor ( const ACE_PEER_ACCEPTOR_ADDR local_addr,
ACE_Reactor reactor = ACE_Reactor::instance(),
int  flags = 0,
int  use_select = 1,
int  reuse_addr = 1 
)

Open the contained PEER_ACCEPTOR object to begin listening, and register with the specified reactor for accept events. An acceptor can only listen to one port at a time, so make sure to close() the acceptor before calling open() again.

The PEER_ACCEPTOR handle is put into non-blocking mode as a safeguard against the race condition that can otherwise occur between the time when the passive-mode socket handle is "ready" and when the actual accept() call is made. During this interval, the client can shutdown the connection, in which case, the accept() call can hang.

Parameters
local_addrThe address to listen at.
reactorPointer to the ACE_Reactor instance to register this object with. The default is the singleton.
flagsFlags to control what mode an accepted socket will be put into after it is accepted. The only legal value for this argument is ACE_NONBLOCK, which enables non-blocking mode on the accepted peer stream object in SVC_HANDLER. The default is 0.
use_selectAffects behavior when called back by the reactor when a connection can be accepted. If non-zero, this object will accept all pending connections, instead of just the one that triggered the reactor callback. Uses ACE_OS::select() internally to detect any remaining acceptable connections. The default is 1.
reuse_addrPassed to the PEER_ACCEPTOR::open() method with local_addr. Generally used to request that the OS allow reuse of the listen port. The default is 1.
template<class SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >
virtual ACE_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >::~ACE_Acceptor ( void  )
virtual

Close down the Acceptor's resources.

Member Function Documentation

template<class SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >
virtual int ACE_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >::accept_svc_handler ( SVC_HANDLER *  svc_handler)
protectedvirtual

Bridge method for accepting the new connection into the svc_handler. The default behavior delegates to the PEER_ACCEPTOR::accept.

Reimplemented in ACE_Strategy_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >.

template<class SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >
virtual ACE_PEER_ACCEPTOR& ACE_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >::acceptor ( void  ) const
virtual

Return the underlying PEER_ACCEPTOR object.

Reimplemented in ACE_Strategy_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >.

template<class SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >
virtual int ACE_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >::activate_svc_handler ( SVC_HANDLER *  svc_handler)
protectedvirtual

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 making the SVC_HANDLER as an "active object" via multi-threading or multi-processing).

Reimplemented in ACE_Strategy_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >.

template<class SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >
virtual int ACE_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >::close ( void  )
virtual

Close down the Acceptor.

template<class SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >
void ACE_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >::dump ( void  ) const

Dump the state of an object.

template<class SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >
virtual int ACE_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >::fini ( void  )
protectedvirtual

Calls {handle_close}.

Reimplemented from ACE_Shared_Object.

Reimplemented in ACE_Strategy_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >.

template<class SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >
virtual ACE_HANDLE ACE_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >::get_handle ( void  ) const
virtual

Returns the listening acceptor's {ACE_HANDLE}.

Reimplemented from ACE_Event_Handler.

Reimplemented in ACE_Strategy_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >.

template<class SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >
virtual int ACE_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >::handle_accept_error ( void  )
virtual

In the event that an accept fails, this method will be called and the return value will be returned from handle_input().

template<class SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >
virtual int ACE_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >::handle_close ( ACE_HANDLE  = ACE_INVALID_HANDLE,
ACE_Reactor_Mask  = ACE_Event_Handler::ALL_EVENTS_MASK 
)
protectedvirtual

Perform termination activities when {this} is removed from the {reactor}.

Reimplemented from ACE_Event_Handler.

Reimplemented in ACE_Strategy_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >.

template<class SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >
virtual int ACE_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >::handle_input ( ACE_HANDLE  )
protectedvirtual

Accepts all pending connections from clients, and creates and activates SVC_HANDLERs.

Reimplemented from ACE_Event_Handler.

template<class SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >
virtual int ACE_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >::info ( ACE_TCHAR **  buf,
size_t   
) const
protectedvirtual

Default version returns address info in {buf}.

Reimplemented from ACE_Shared_Object.

Reimplemented in ACE_Strategy_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >.

template<class SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >
virtual int ACE_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >::init ( int  argc,
ACE_TCHAR argv[] 
)
protectedvirtual

Default version does no work and returns -1. Must be overloaded by application developer to do anything meaningful.

Reimplemented from ACE_Shared_Object.

template<class SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >
virtual int ACE_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >::make_svc_handler ( SVC_HANDLER *&  sh)
protectedvirtual

Bridge method for creating a SVC_HANDLER. 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.

Reimplemented in ACE_Strategy_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >.

template<class SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >
virtual int ACE_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >::open ( const ACE_PEER_ACCEPTOR_ADDR local_addr,
ACE_Reactor reactor = ACE_Reactor::instance(),
int  flags = 0,
int  use_select = 1,
int  reuse_addr = 1 
)
virtual

Open the contained PEER_ACCEPTOR object to begin listening, and register with the specified reactor for accept events. An acceptor can only listen to one port at a time, so make sure to close() the acceptor before calling open() again.

The PEER_ACCEPTOR handle is put into non-blocking mode as a safeguard against the race condition that can otherwise occur between the time when the passive-mode socket handle is "ready" and when the actual accept() call is made. During this interval, the client can shutdown the connection, in which case, the accept() call can hang.

Parameters
local_addrThe address to listen at.
reactorPointer to the ACE_Reactor instance to register this object with. The default is the singleton.
flagsFlags to control what mode an accepted socket will be put into after it is accepted. The only legal value for this argument is ACE_NONBLOCK, which enables non-blocking mode on the accepted peer stream object in SVC_HANDLER. The default is 0.
use_selectAffects behavior when called back by the reactor when a connection can be accepted. If non-zero, this object will accept all pending connections, instead of just the one that triggered the reactor callback. Uses ACE_OS::select() internally to detect any remaining acceptable connections. The default is 1.
reuse_addrPassed to the PEER_ACCEPTOR::open() method with local_addr. Generally used to request that the OS allow reuse of the listen port. The default is 1.
Return values
0Success
-1Failure, errno contains an error code.

Reimplemented in ACE_Strategy_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >.

template<class SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >
virtual ACE_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >::operator ACE_PEER_ACCEPTOR & ( ) const
virtual

Return the underlying PEER_ACCEPTOR object.

Reimplemented in ACE_Strategy_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >.

template<class SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >
virtual int ACE_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >::resume ( void  )
virtual

This method calls {Reactor::resume}.

Reimplemented from ACE_Service_Object.

Reimplemented in ACE_Strategy_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >.

template<class SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >
virtual int ACE_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >::suspend ( void  )
virtual

This method calls {Reactor::suspend}.

Reimplemented from ACE_Service_Object.

Reimplemented in ACE_Strategy_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >.

Member Data Documentation

template<class SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >
ACE_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >::ACE_ALLOC_HOOK_DECLARE

Declare the dynamic allocation hooks.

template<class SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >
int ACE_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >::flags_
protected

Flags that indicate how {SVC_HANDLER}'s should be initialized prior to being activated. Right now, the only flag that is processed is {ACE_NONBLOCK}, which enabled non-blocking I/O on the {SVC_HANDLER} when it is opened.

template<class SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >
ACE_PEER_ACCEPTOR ACE_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >::peer_acceptor_
protected

Concrete factory for accepting connections from clients...

template<class SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >
ACE_PEER_ACCEPTOR_ADDR ACE_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >::peer_acceptor_addr_
protected

Needed to reopen the socket if {accept} fails.

template<class SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >
int ACE_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >::reuse_addr_
protected

Needed to reopen the socket if {accept} fails.

template<class SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >
int ACE_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_1 >::use_select_
protected

Flag that indicates whether it shall use {select} in the {accept}-loop.


The documentation for this class was generated from the following file: