ACE  6.4.2
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
ACE_Asynch_Acceptor< HANDLER > Class Template Reference

This class is an example of the Acceptor Pattern. This class will accept new connections and create new HANDLER to handle the new connections. More...

#include <Asynch_Acceptor.h>

Inheritance diagram for ACE_Asynch_Acceptor< HANDLER >:
Inheritance graph
[legend]
Collaboration diagram for ACE_Asynch_Acceptor< HANDLER >:
Collaboration graph
[legend]

Public Member Functions

 ACE_Asynch_Acceptor (void)
 A do nothing constructor. More...
 
virtual ~ACE_Asynch_Acceptor (void)
 Virtual destruction. More...
 
virtual int open (const ACE_INET_Addr &address, size_t bytes_to_read=0, bool pass_addresses=false, int backlog=ACE_DEFAULT_ASYNCH_BACKLOG, int reuse_addr=1, ACE_Proactor *proactor=0, bool validate_new_connection=false, int reissue_accept=1, int number_of_initial_accepts=-1)
 
virtual ACE_HANDLE get_handle (void) const
 Get the underlying handle. More...
 
virtual int set_handle (ACE_HANDLE handle)
 
virtual int accept (size_t bytes_to_read=0, const void *act=0)
 This initiates a new asynchronous accept operation. More...
 
virtual int cancel (void)
 
virtual int validate_connection (const ACE_Asynch_Accept::Result &result, const ACE_INET_Addr &remote, const ACE_INET_Addr &local)
 
virtual int should_reissue_accept (void)
 
virtual bool pass_addresses (void) const
 
virtual void pass_addresses (bool new_value)
 
virtual bool validate_new_connection (void) const
 Get flag that indicates if address validation is required. More...
 
virtual void validate_new_connection (bool new_value)
 Set flag that indicates if address validation is required. More...
 
virtual int reissue_accept (void) const
 
virtual void reissue_accept (int new_value)
 
virtual size_t bytes_to_read (void) const
 Get bytes to be read with the <accept> call. More...
 
virtual void bytes_to_read (size_t new_value)
 Set bytes to be read with the <accept> call. More...
 
- Public Member Functions inherited from ACE_Handler
 ACE_Handler (void)
 A do nothing constructor. More...
 
 ACE_Handler (ACE_Proactor *p)
 A do nothing constructor which allows proactor to be set to <p>. More...
 
virtual ~ACE_Handler (void)
 Virtual destruction. More...
 
virtual void handle_read_stream (const ACE_Asynch_Read_Stream::Result &result)
 
virtual void handle_write_dgram (const ACE_Asynch_Write_Dgram::Result &result)
 
virtual void handle_read_dgram (const ACE_Asynch_Read_Dgram::Result &result)
 
virtual void handle_write_stream (const ACE_Asynch_Write_Stream::Result &result)
 
virtual void handle_read_file (const ACE_Asynch_Read_File::Result &result)
 
virtual void handle_write_file (const ACE_Asynch_Write_File::Result &result)
 
virtual void handle_connect (const ACE_Asynch_Connect::Result &result)
 This method will be called when an asynchronous connect completes. More...
 
virtual void handle_transmit_file (const ACE_Asynch_Transmit_File::Result &result)
 
virtual void handle_time_out (const ACE_Time_Value &tv, const void *act=0)
 
virtual void handle_wakeup (void)
 
ACE_Proactorproactor (void)
 Get the proactor associated with this handler. More...
 
void proactor (ACE_Proactor *p)
 Set the proactor. More...
 
Proxy_Ptrproxy (void)
 

Protected Member Functions

virtual void handle_accept (const ACE_Asynch_Accept::Result &result)
 This is called when an outstanding accept completes. More...
 
ACE_HANDLE handle (void) const
 Return the listen handle. More...
 
void handle (ACE_HANDLE h)
 Set the listen handle. More...
 
void parse_address (const ACE_Asynch_Accept::Result &result, ACE_INET_Addr &remote_address, ACE_INET_Addr &local_address)
 This parses the address from read buffer. More...
 
ACE_Asynch_Acceptasynch_accept (void)
 Return the asynch accept object. More...
 
virtual HANDLER * make_handler (void)
 

Private Attributes

ACE_HANDLE listen_handle_
 Handle used to listen for new connections. More...
 
ACE_Asynch_Accept asynch_accept_
 Asynch_Accept used to make life easier :-) More...
 
bool pass_addresses_
 Flag that indicates if parsing of addresses is necessary. More...
 
bool validate_new_connection_
 Flag that indicates if address validation is required. More...
 
int reissue_accept_
 
size_t bytes_to_read_
 Bytes to be read with the <accept> call. More...
 
int addr_family_
 

Additional Inherited Members

- Public Types inherited from ACE_Handler
typedef ACE_Refcounted_Auto_Ptr< Proxy, ACE_SYNCH_MUTEXProxy_Ptr
 
- Protected Attributes inherited from ACE_Handler
ACE_Proactorproactor_
 The proactor associated with this handler. More...
 
ACE_HANDLE handle_
 The ACE_HANDLE in use with this handler. More...
 
ACE_Refcounted_Auto_Ptr< Proxy, ACE_SYNCH_MUTEXproxy_
 Refers to proxy for this handler. More...
 

Detailed Description

template<class HANDLER>
class ACE_Asynch_Acceptor< HANDLER >

This class is an example of the Acceptor Pattern. This class will accept new connections and create new HANDLER to handle the new connections.

Unlike the ACE_Acceptor, however, this class is designed to be used asynchronously.

Constructor & Destructor Documentation

template<class HANDLER >
ACE_Asynch_Acceptor< HANDLER >::ACE_Asynch_Acceptor ( void  )

A do nothing constructor.

template<class HANDLER >
ACE_Asynch_Acceptor< HANDLER >::~ACE_Asynch_Acceptor ( void  )
virtual

Virtual destruction.

Member Function Documentation

template<class HANDLER >
int ACE_Asynch_Acceptor< HANDLER >::accept ( size_t  bytes_to_read = 0,
const void *  act = 0 
)
virtual

This initiates a new asynchronous accept operation.

You need only call this method if the reissue_accept argument passed to open() was 0.

template<class HANDLER >
ACE_Asynch_Accept & ACE_Asynch_Acceptor< HANDLER >::asynch_accept ( void  )
protected

Return the asynch accept object.

template<class HANDLER >
size_t ACE_Asynch_Acceptor< HANDLER >::bytes_to_read ( void  ) const
virtual

Get bytes to be read with the <accept> call.

template<class HANDLER >
void ACE_Asynch_Acceptor< HANDLER >::bytes_to_read ( size_t  new_value)
virtual

Set bytes to be read with the <accept> call.

template<class HANDLER >
int ACE_Asynch_Acceptor< HANDLER >::cancel ( void  )
virtual

Cancels all pending accepts operations issued by this object.

Note
On Windows, only accept operations initiated by the calling thread are canceled.
template<class HANDLER >
ACE_HANDLE ACE_Asynch_Acceptor< HANDLER >::get_handle ( void  ) const
virtual

Get the underlying handle.

template<class HANDLER >
ACE_HANDLE ACE_Asynch_Acceptor< HANDLER >::handle ( void  ) const
protectedvirtual

Return the listen handle.

Reimplemented from ACE_Handler.

template<class HANDLER >
void ACE_Asynch_Acceptor< HANDLER >::handle ( ACE_HANDLE  h)
protectedvirtual

Set the listen handle.

Reimplemented from ACE_Handler.

template<class HANDLER >
void ACE_Asynch_Acceptor< HANDLER >::handle_accept ( const ACE_Asynch_Accept::Result result)
protectedvirtual

This is called when an outstanding accept completes.

Reimplemented from ACE_Handler.

template<class HANDLER >
HANDLER * ACE_Asynch_Acceptor< HANDLER >::make_handler ( void  )
protectedvirtual

This is the template method used to create new handler. Subclasses must overwrite this method if a new handler creation strategy is required.

template<class HANDLER >
int ACE_Asynch_Acceptor< HANDLER >::open ( const ACE_INET_Addr address,
size_t  bytes_to_read = 0,
bool  pass_addresses = false,
int  backlog = ACE_DEFAULT_ASYNCH_BACKLOG,
int  reuse_addr = 1,
ACE_Proactor proactor = 0,
bool  validate_new_connection = false,
int  reissue_accept = 1,
int  number_of_initial_accepts = -1 
)
virtual

open starts one or more asynchronous accept requests on a address. Each accept operation may optionally read an initial buffer from the new connection when accepted.

Parameters
addressThe address to listen/accept connections on. If the address does not specify a port, a random port is selected and bound.
bytes_to_readOptional, specifies the maximum number of bytes to read with the accept. The buffer for the initial data is allocated internally and passed to the ACE_Service_Handler::open() hook method. It is legitimate only during the open() method and must be copied if required after open() returns. This pre-read function works only on Windows.
pass_addressesOptional, a non-zero value indicates that the local and peer addresses should be passed to the associated ACE_Service_Handler::addresses() method after any call to validate_new_connection() and prior to the open() hook method call.
backlogOptional, defaulting to ACE_DEFAULT_ASYNCH_BACKLOG (which can be adjusted in your platform's config.h file). Specifies the listening backlog for the listening socket.
reuse_addrOptional, indicates whether the SO_REUSEADDR option is set on the listening socket or not.
proactorOptional, pointer to the ACE_Proactor to use for demultiplexing asynchronous accepts. If 0, the process's singleton ACE_Proactor is used.
validate_new_connectionOptional, if true, this object's validate_connection() method is called after the accept completes, but before the service handler's open() hook method is called. If validate_connection() returns -1, the newly-accepted socket is immediately closed, and the addresses() method is not called.
reissue_acceptOptional, if non-zero (the default), a new asynchronous accept operation is started after each completion, whether the completion is for success or failure, and whether or not a successfully-accepted connection is subsequently refused.
number_of_initial_acceptsOptional, the number of asynchronous accepts that are started immediately. If -1 (the default), the value of backlog is used.
Note
On Windows, the peer address is only available at the time the connection is accepted. Therefore, if you require the peer address on Windows, do not rely on the ACE_SOCK::get_remote_addr() method - it won't work. You must supply a non-zero value for pass_addresses and obtain the peer address in the ACE_Service_Handler::addresses() method.
See also
ACE_INET_Addr
ACE_Service_Handler
template<class HANDLER >
void ACE_Asynch_Acceptor< HANDLER >::parse_address ( const ACE_Asynch_Accept::Result result,
ACE_INET_Addr remote_address,
ACE_INET_Addr local_address 
)
protected

This parses the address from read buffer.

template<class HANDLER >
bool ACE_Asynch_Acceptor< HANDLER >::pass_addresses ( void  ) const
virtual

Get flag that indicates if parsing and passing of addresses to the service_handler is necessary.

template<class HANDLER >
void ACE_Asynch_Acceptor< HANDLER >::pass_addresses ( bool  new_value)
virtual

Set flag that indicates if parsing and passing of addresses to the service_handler is necessary.

template<class HANDLER >
int ACE_Asynch_Acceptor< HANDLER >::reissue_accept ( void  ) const
virtual

Get flag that indicates if a new accept should be reissued when a accept completes.

template<class HANDLER >
void ACE_Asynch_Acceptor< HANDLER >::reissue_accept ( int  new_value)
virtual

Set flag that indicates if a new accept should be reissued when a accept completes.

template<class HANDLER >
int ACE_Asynch_Acceptor< HANDLER >::set_handle ( ACE_HANDLE  handle)
virtual

Set the underlying listen handle. It is the user's responsibility to make sure that the old listen handle has been appropriately closed and the all outstanding asynchronous operations have either completed or have been canceled on the old listen handle.

template<class HANDLER >
int ACE_Asynch_Acceptor< HANDLER >::should_reissue_accept ( void  )
virtual

Template method for deciding whether to reissue accept.

This hook method is called after each accept completes to decide if another accept should be initiated. If the method returns a non-zero value, another accept is initiated.

The default implementation always returns the value passed as the open() method's reissue_accept argument. That value can also be changed using the reissue_accept() method.

template<class HANDLER >
int ACE_Asynch_Acceptor< HANDLER >::validate_connection ( const ACE_Asynch_Accept::Result result,
const ACE_INET_Addr remote,
const ACE_INET_Addr local 
)
virtual

Template method to validate peer before service is opened. This method is called after a new connection is accepted if the validate_connection argument to open() was non-zero or the validate_new_connection() method is called to turn this feature on. The default implementation returns 0. Users can reimplement this method to perform validation of the peer using it's address, running an authentication procedure (such as SSL) or anything else necessary or desireable. The return value from this method determines whether or not ACE will continue opening the service or abort the connection.

Parameters
resultResult of the connection acceptance.
remotePeer's address.
localLocal address connection was accepted at.
Return values
-1ACE_Asynch_Acceptor will close the connection, and the service will not be opened.
0Service opening will proceeed.
template<class HANDLER >
bool ACE_Asynch_Acceptor< HANDLER >::validate_new_connection ( void  ) const
virtual

Get flag that indicates if address validation is required.

template<class HANDLER >
void ACE_Asynch_Acceptor< HANDLER >::validate_new_connection ( bool  new_value)
virtual

Set flag that indicates if address validation is required.

Member Data Documentation

template<class HANDLER >
int ACE_Asynch_Acceptor< HANDLER >::addr_family_
private

Address family used to open this object. Obtained from address passed to open().

template<class HANDLER >
ACE_Asynch_Accept ACE_Asynch_Acceptor< HANDLER >::asynch_accept_
private

Asynch_Accept used to make life easier :-)

template<class HANDLER >
size_t ACE_Asynch_Acceptor< HANDLER >::bytes_to_read_
private

Bytes to be read with the <accept> call.

template<class HANDLER >
ACE_HANDLE ACE_Asynch_Acceptor< HANDLER >::listen_handle_
private

Handle used to listen for new connections.

template<class HANDLER >
bool ACE_Asynch_Acceptor< HANDLER >::pass_addresses_
private

Flag that indicates if parsing of addresses is necessary.

template<class HANDLER >
int ACE_Asynch_Acceptor< HANDLER >::reissue_accept_
private

Flag that indicates if a new accept should be reissued when a accept completes.

template<class HANDLER >
bool ACE_Asynch_Acceptor< HANDLER >::validate_new_connection_
private

Flag that indicates if address validation is required.


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