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]
List of all members.

Public Member Functions

 ACE_Asynch_Acceptor (void)
 A do nothing constructor.

virtual ~ACE_Asynch_Acceptor (void)
 Virtual destruction.

virtual int open (const ACE_INET_Addr &address, size_t bytes_to_read=0, int pass_addresses=0, int backlog=ACE_DEFAULT_ASYNCH_BACKLOG, int reuse_addr=1, ACE_Proactor *proactor=0, int validate_new_connection=0, int reissue_accept=1, int number_of_initial_accepts=-1)
virtual ACE_HANDLE get_handle (void) const
 Get the underlying handle.

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.

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 validate_new_connection (const ACE_INET_Addr &remote_address)
virtual int should_reissue_accept (void)
virtual int pass_addresses (void) const
virtual void pass_addresses (int new_value)
virtual int validate_new_connection (void) const
 Get flag that indicates if address validation is required.

virtual void validate_new_connection (int new_value)
 Set flag that indicates if address validation is required.

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 call.

virtual void bytes_to_read (size_t new_value)
 Set bytes to be read with the call.


Static Public Member Functions

size_t address_size (void)

Protected Member Functions

virtual void handle_accept (const ACE_Asynch_Accept::Result &result)
 This is called when an outstanding accept completes.

ACE_HANDLE handle (void) const
 Return the listen handle.

void handle (ACE_HANDLE h)
 Set the listen handle.

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.

ACE_Asynch_Acceptasynch_accept (void)
 Return the asynch accept object.

virtual HANDLER * make_handler (void)

Private Attributes

ACE_HANDLE listen_handle_
 Handle used to listen for new connections.

ACE_Asynch_Accept asynch_accept_
 Asynch_Accept used to make life easier :-).

int pass_addresses_
 Flag that indicates if parsing of addresses is necessary.

int validate_new_connection_
 Flag that indicates if address validation is required.

int reissue_accept_
size_t bytes_to_read_
 Bytes to be read with the call.

int addr_family_

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.

Definition at line 46 of file Asynch_Acceptor.h.


Constructor & Destructor Documentation

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

A do nothing constructor.

Definition at line 30 of file Asynch_Acceptor.cpp.

00031   : listen_handle_ (ACE_INVALID_HANDLE),
00032     pass_addresses_ (0),
00033     validate_new_connection_ (0),
00034     reissue_accept_ (1),
00035     bytes_to_read_ (0)
00036 {
00037 }

template<class HANDLER>
ACE_Asynch_Acceptor< HANDLER >::~ACE_Asynch_Acceptor void   )  [virtual]
 

Virtual destruction.

Definition at line 40 of file Asynch_Acceptor.cpp.

References ACE_OS::closesocket(), and ACE_Asynch_Acceptor< HANDLER >::listen_handle_.

00041 {
00042   // Close down the listen socket
00043   if (this->listen_handle_ != ACE_INVALID_HANDLE)
00044     {
00045       ACE_OS::closesocket (this->listen_handle_);
00046       this->listen_handle_ = ACE_INVALID_HANDLE;
00047     }
00048 }


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.

Definition at line 204 of file Asynch_Acceptor.cpp.

References ACE_Asynch_Accept::accept(), ACE_NEW_RETURN, ACE_SIGRTMIN, ACE_TRACE, ACE_Asynch_Acceptor< HANDLER >::addr_family_, ACE_Asynch_Acceptor< HANDLER >::asynch_accept_, and ACE_Message_Block::release().

Referenced by ACE_Asynch_Acceptor< HANDLER >::handle_accept(), and ACE_Asynch_Acceptor< HANDLER >::open().

00205 {
00206   ACE_TRACE ("ACE_Asynch_Acceptor<>::accept");
00207 
00208   ACE_Message_Block *message_block = 0;
00209   // The space_needed calculation is drive by needs of Windows. POSIX doesn't
00210   // need to extra 16 bytes, but it doesn't hurt.
00211   size_t space_needed = sizeof (sockaddr_in) + 16;
00212 #if defined (ACE_HAS_IPV6)
00213   if (PF_INET6 == this->addr_family_)
00214     space_needed = sizeof (sockaddr_in6) + 16;
00215 #endif /* ACE_HAS_IPV6 */
00216   space_needed = (2 * space_needed) + bytes_to_read;
00217 
00218   // Create a new message block big enough for the addresses and data
00219   ACE_NEW_RETURN (message_block,
00220                   ACE_Message_Block (space_needed),
00221                   -1);
00222 
00223   // Initiate asynchronous accepts
00224   if (this->asynch_accept_.accept (*message_block,
00225                                    bytes_to_read,
00226                                    ACE_INVALID_HANDLE,
00227                                    act,
00228                                    0,
00229                                    ACE_SIGRTMIN,
00230                                    this->addr_family_) == -1)
00231     {
00232       // Cleanup on error
00233       message_block->release ();
00234       return -1;
00235     }
00236   return 0;
00237 }

template<class HANDLER>
size_t ACE_Asynch_Acceptor< HANDLER >::address_size void   )  [static]
 

Deprecated:
address_size() assumes IPv4 use, so is not always valid. This method will be removed after ACE 5.5. Internal uses have been changes to base needed sizes on the addr_family_ member.

Definition at line 465 of file Asynch_Acceptor.cpp.

00466 {
00467   return sizeof (sockaddr) + sizeof (sockaddr_in);
00468 }

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

Return the asynch accept object.

Definition at line 447 of file Asynch_Acceptor.cpp.

References ACE_Asynch_Acceptor< HANDLER >::asynch_accept_.

00448 {
00449   return this->asynch_accept_;
00450 }

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

Set bytes to be read with the call.

Definition at line 513 of file Asynch_Acceptor.cpp.

References ACE_Asynch_Acceptor< HANDLER >::bytes_to_read_.

00514 {
00515   this->bytes_to_read_ = new_value;
00516 }

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

Get bytes to be read with the call.

Definition at line 507 of file Asynch_Acceptor.cpp.

References ACE_Asynch_Acceptor< HANDLER >::bytes_to_read_.

00508 {
00509   return this->bytes_to_read_;
00510 }

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.

Definition at line 366 of file Asynch_Acceptor.cpp.

References ACE_TRACE, ACE_Asynch_Acceptor< HANDLER >::asynch_accept_, ACE_Asynch_Operation::cancel(), and ACE_Asynch_Acceptor< HANDLER >::listen_handle_.

00367 {
00368   ACE_TRACE ("ACE_Asynch_Acceptor<>::cancel");
00369 
00370   // All I/O operations that are canceled will complete with the error
00371   // ERROR_OPERATION_ABORTED. All completion notifications for the I/O
00372   // operations will occur normally.
00373 #if (defined (ACE_HAS_WINNT4) && (ACE_HAS_WINNT4 != 0)) \
00374     && (    defined (_MSC_VER) || (defined (__BORLANDC__)))
00375   return (int) ::CancelIo (this->listen_handle_);
00376 #else
00377   // Supported now
00378   return this->asynch_accept_.cancel();
00379 
00380 #endif /* (defined (ACE_HAS_WINNT4) && (ACE_HAS_WINNT4 != 0)) && ((defined (_MSC_VER)) || (defined (__BORLANDC__))) */
00381 }

template<class HANDLER>
ACE_HANDLE ACE_Asynch_Acceptor< HANDLER >::get_handle void   )  const [virtual]
 

Get the underlying handle.

Definition at line 198 of file Asynch_Acceptor.cpp.

References ACE_Asynch_Acceptor< HANDLER >::listen_handle_.

00199 {
00200   return this->listen_handle_;
00201 }

template<class HANDLER>
void ACE_Asynch_Acceptor< HANDLER >::handle ACE_HANDLE  h  )  [protected, virtual]
 

Set the listen handle.

Reimplemented from ACE_Handler.

Definition at line 441 of file Asynch_Acceptor.cpp.

References ACE_Handler::handle().

00442 {
00443   ACE_Handler::handle (h);
00444 }

template<class HANDLER>
ACE_HANDLE ACE_Asynch_Acceptor< HANDLER >::handle void   )  const [protected, virtual]
 

Return the listen handle.

Reimplemented from ACE_Handler.

Definition at line 435 of file Asynch_Acceptor.cpp.

References ACE_Asynch_Acceptor< HANDLER >::listen_handle_.

00436 {
00437   return this->listen_handle_;
00438 }

template<class HANDLER>
void ACE_Asynch_Acceptor< HANDLER >::handle_accept const ACE_Asynch_Accept::Result result  )  [protected, virtual]
 

This is called when an outstanding accept completes.

Reimplemented from ACE_Handler.

Definition at line 240 of file Asynch_Acceptor.cpp.

References ACE_Asynch_Acceptor< HANDLER >::accept(), ACE_Asynch_Accept::Result::accept_handle(), ACE_TRACE, ACE_Asynch_Result::act(), ACE_OS::closesocket(), ACE_Asynch_Result::error(), ACE_Asynch_Acceptor< HANDLER >::listen_handle_, ACE_Asynch_Acceptor< HANDLER >::make_handler(), ACE_Asynch_Accept::Result::message_block(), ACE_Asynch_Acceptor< HANDLER >::parse_address(), ACE_Asynch_Acceptor< HANDLER >::pass_addresses_, ACE_Message_Block::release(), ACE_OS::setsockopt(), ACE_Asynch_Acceptor< HANDLER >::should_reissue_accept(), ACE_Asynch_Result::success(), ACE_Asynch_Acceptor< HANDLER >::validate_connection(), ACE_Asynch_Acceptor< HANDLER >::validate_new_connection(), and ACE_Asynch_Acceptor< HANDLER >::validate_new_connection_.

00241 {
00242 #if (defined (ACE_HAS_WINNT4) && (ACE_HAS_WINNT4 != 0)) || (defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0)) || defined (ACE_HAS_AIO_CALLS)
00243 
00244   ACE_TRACE ("ACE_Asynch_Acceptor<>::handle_accept");
00245 
00246   // Variable for error tracking
00247   int error = 0;
00248 
00249   // If the asynchronous accept fails.
00250   if (!result.success () || result.accept_handle () == ACE_INVALID_HANDLE)
00251     {
00252       error = 1;
00253     }
00254 
00255 #if !defined (ACE_HAS_AIO_CALLS)
00256   // In order to use accept handle with other Window Sockets 1.1
00257   // functions, we call the setsockopt function with the
00258   // SO_UPDATE_ACCEPT_CONTEXT option. This option initializes the
00259   // socket so that other Windows Sockets routines to access the
00260   // socket correctly.
00261   if (!error &&
00262       ACE_OS::setsockopt (result.accept_handle (),
00263                           SOL_SOCKET,
00264                           SO_UPDATE_ACCEPT_CONTEXT,
00265                           (char *) &this->listen_handle_,
00266                           sizeof (this->listen_handle_)) == -1)
00267     {
00268       error = 1;
00269     }
00270 #endif /* ACE_HAS_AIO_CALLS */
00271 
00272   // Parse address.
00273   ACE_INET_Addr local_address;
00274   ACE_INET_Addr remote_address;
00275   if (!error &&
00276       (this->validate_new_connection_ || this->pass_addresses_))
00277     // Parse the addresses.
00278     this->parse_address (result,
00279                          remote_address,
00280                          local_address);
00281 
00282   // Validate remote address
00283   if (!error &&
00284       this->validate_new_connection_ &&
00285       (this->validate_connection (result, remote_address, local_address) == -1
00286        || this->validate_new_connection (remote_address) == -1))
00287     {
00288       error = 1;
00289     }
00290 
00291   HANDLER *new_handler = 0;
00292   if (!error)
00293     {
00294       // The Template method
00295       new_handler = this->make_handler ();
00296       if (new_handler == 0)
00297         {
00298           error = 1;
00299         }
00300     }
00301 
00302   // If no errors
00303   if (!error)
00304     {
00305       // Update the Proactor.
00306       new_handler->proactor (this->proactor ());
00307 
00308       // Pass the addresses
00309       if (this->pass_addresses_)
00310         new_handler->addresses (remote_address,
00311                                 local_address);
00312 
00313       // Pass the ACT
00314       if (result.act () != 0)
00315         new_handler->act (result.act ());
00316 
00317       // Set up the handler's new handle value
00318       new_handler->handle (result.accept_handle ());
00319 
00320       // Initiate the handler
00321       new_handler->open (result.accept_handle (),
00322                          result.message_block ());
00323     }
00324 
00325   // On failure, no choice but to close the socket
00326   if (error &&
00327       result.accept_handle() != ACE_INVALID_HANDLE )
00328     ACE_OS::closesocket (result.accept_handle ());
00329 
00330   // Delete the dynamically allocated message_block
00331   result.message_block ().release ();
00332 
00333   // Start off another asynchronous accept to keep the backlog going,
00334   // unless we closed the listen socket already (from the destructor),
00335   // or this callback is the result of a canceled/aborted accept.
00336   if (this->should_reissue_accept () &&
00337       this->listen_handle_ != ACE_INVALID_HANDLE
00338 #if defined (ACE_WIN32)
00339       && result.error () != ERROR_OPERATION_ABORTED
00340 #else
00341       && result.error () != ECANCELED
00342 #endif
00343       )
00344     this->accept (this->bytes_to_read_);
00345 #endif /* (defined (ACE_HAS_WINNT4) && (ACE_HAS_WINNT4 != 0)) || (defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0)) || defined (ACE_HAS_AIO_CALLS */
00346 }

template<class HANDLER>
HANDLER * ACE_Asynch_Acceptor< HANDLER >::make_handler void   )  [protected, virtual]
 

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

Definition at line 453 of file Asynch_Acceptor.cpp.

References ACE_NEW_RETURN.

Referenced by ACE_Asynch_Acceptor< HANDLER >::handle_accept().

00454 {
00455   // Default behavior
00456   HANDLER *handler = 0;
00457   ACE_NEW_RETURN (handler,
00458                   HANDLER,
00459                   0);
00460   return handler;
00461 }

template<class HANDLER>
int ACE_Asynch_Acceptor< HANDLER >::open const ACE_INET_Addr address,
size_t  bytes_to_read = 0,
int  pass_addresses = 0,
int  backlog = ACE_DEFAULT_ASYNCH_BACKLOG,
int  reuse_addr = 1,
ACE_Proactor proactor = 0,
int  validate_new_connection = 0,
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:
address The address to listen/accept connections on. If the address does not specify a port, a random port is selected and bound.
bytes_to_read Optional, 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_addresses Optional, 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.
backlog Optional, 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_addr Optional, indicates whether the SO_REUSEADDR option is set on the listening socket or not.
proactor Optional, pointer to the ACE_Proactor to use for demultiplexing asynchronous accepts. If 0, the process's singleton ACE_Proactor is used.
validate_new_connection Optional, if non-zero, 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_accept Optional, 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_accepts Optional, 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

Definition at line 51 of file Asynch_Acceptor.cpp.

References ACE_Asynch_Acceptor< HANDLER >::accept(), ACE_ERROR, ACE_ERROR_RETURN, ACE_LIB_TEXT, ACE_TRACE, ACE_Asynch_Acceptor< HANDLER >::addr_family_, ACE_Asynch_Acceptor< HANDLER >::asynch_accept_, ACE_OS::bind(), ACE::bind_port(), ACE_Asynch_Acceptor< HANDLER >::bytes_to_read_, ACE_OS::closesocket(), ACE_INET_Addr::get_addr(), ACE_Addr::get_size(), ACE_Addr::get_type(), ACE_OS::listen(), ACE_Asynch_Acceptor< HANDLER >::listen_handle_, LM_ERROR, ACE_Asynch_Accept::open(), ACE_Asynch_Acceptor< HANDLER >::pass_addresses_, ACE_Handler::proactor(), ACE_Asynch_Acceptor< HANDLER >::reissue_accept_, ACE_OS::setsockopt(), ACE_OS::socket(), and ACE_Asynch_Acceptor< HANDLER >::validate_new_connection_.

00060 {
00061   ACE_TRACE ("ACE_Asynch_Acceptor<>::open");
00062 
00063   this->proactor (proactor);
00064   this->pass_addresses_ = pass_addresses;
00065   this->bytes_to_read_ = bytes_to_read;
00066   this->validate_new_connection_ = validate_new_connection;
00067   this->reissue_accept_ = reissue_accept;
00068   this->addr_family_ = address.get_type ();
00069 
00070   // Create the listener socket
00071   this->listen_handle_ = ACE_OS::socket (address.get_type (), SOCK_STREAM, 0);
00072   if (this->listen_handle_ == ACE_INVALID_HANDLE)
00073     ACE_ERROR_RETURN ((LM_ERROR,
00074                        ACE_LIB_TEXT ("%p\n"),
00075                        ACE_LIB_TEXT ("ACE_OS::socket")),
00076                       -1);
00077   // Initialize the ACE_Asynch_Accept
00078   if (this->asynch_accept_.open (*this,
00079                                  this->listen_handle_,
00080                                  0,
00081                                  this->proactor ()) == -1)
00082     {
00083       ACE_Errno_Guard g (errno);
00084       ACE_ERROR ((LM_ERROR,
00085                   ACE_LIB_TEXT ("%p\n"),
00086                   ACE_LIB_TEXT ("ACE_Asynch_Accept::open")));
00087       ACE_OS::closesocket (this->listen_handle_);
00088       this->listen_handle_ = ACE_INVALID_HANDLE;
00089       return -1;
00090     }
00091 
00092   if (reuse_addr)
00093     {
00094       // Reuse the address
00095       int one = 1;
00096       if (ACE_OS::setsockopt (this->listen_handle_,
00097                               SOL_SOCKET,
00098                               SO_REUSEADDR,
00099                               (const char*) &one,
00100                               sizeof one) == -1)
00101         {
00102           ACE_Errno_Guard g (errno);
00103           ACE_ERROR ((LM_ERROR,
00104                       ACE_LIB_TEXT ("%p\n"),
00105                       ACE_LIB_TEXT ("ACE_OS::setsockopt")));
00106           ACE_OS::closesocket (this->listen_handle_);
00107           this->listen_handle_ = ACE_INVALID_HANDLE;
00108           return -1;
00109         }
00110     }
00111 
00112   // If port is not specified, bind to any port.
00113   static ACE_INET_Addr sa (ACE_sap_any_cast (const ACE_INET_Addr &));
00114 
00115   if (address == sa &&
00116       ACE::bind_port (this->listen_handle_,
00117                       INADDR_ANY,
00118                       address.get_type()) == -1)
00119     {
00120       ACE_Errno_Guard g (errno);
00121       ACE_ERROR ((LM_ERROR,
00122                   ACE_LIB_TEXT ("%p\n"),
00123                   ACE_LIB_TEXT ("ACE::bind_port")));
00124       ACE_OS::closesocket (this->listen_handle_);
00125       this->listen_handle_ = ACE_INVALID_HANDLE;
00126       return -1;
00127     }
00128 
00129   // Bind to the specified port.
00130   if (ACE_OS::bind (this->listen_handle_,
00131                     reinterpret_cast<sockaddr *> (address.get_addr ()),
00132                     address.get_size ()) == -1)
00133     {
00134       ACE_Errno_Guard g (errno);
00135       ACE_ERROR ((LM_ERROR,
00136                   ACE_LIB_TEXT ("%p\n"),
00137                   ACE_LIB_TEXT ("ACE_OS::bind")));
00138       ACE_OS::closesocket (this->listen_handle_);
00139       this->listen_handle_ = ACE_INVALID_HANDLE;
00140       return -1;
00141     }
00142 
00143   // Start listening.
00144   if (ACE_OS::listen (this->listen_handle_, backlog) == -1)
00145     {
00146       ACE_Errno_Guard g (errno);
00147       ACE_ERROR ((LM_ERROR,
00148                   ACE_LIB_TEXT ("%p\n"),
00149                   ACE_LIB_TEXT ("ACE_OS::listen")));
00150       ACE_OS::closesocket (this->listen_handle_);
00151       this->listen_handle_ = ACE_INVALID_HANDLE;
00152       return -1;
00153     }
00154 
00155   // For the number of <intial_accepts>.
00156   if (number_of_initial_accepts == -1)
00157     number_of_initial_accepts = backlog;
00158 
00159   for (int i = 0; i < number_of_initial_accepts; i++)
00160     {
00161       // Initiate accepts.
00162       if (this->accept (bytes_to_read) == -1)
00163         {
00164           ACE_Errno_Guard g (errno);
00165           ACE_ERROR ((LM_ERROR,
00166                       ACE_LIB_TEXT ("%p\n"),
00167                       ACE_LIB_TEXT ("ACE_Asynch_Acceptor::accept")));
00168           ACE_OS::closesocket (this->listen_handle_);
00169           this->listen_handle_ = ACE_INVALID_HANDLE;
00170           return -1;
00171         }
00172     }
00173 
00174   return 0;
00175 }

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.

Definition at line 384 of file Asynch_Acceptor.cpp.

References ACE_Asynch_Accept::Result::accept_handle(), ACE_TRACE, ACE_Asynch_Acceptor< HANDLER >::addr_family_, ACE_Asynch_Acceptor< HANDLER >::bytes_to_read_, ENOTSUP, ACE_SOCK::get_local_addr(), ACE_SOCK::get_remote_addr(), ACE_Asynch_Accept::Result::message_block(), ACE_Message_Block::rd_ptr(), and ACE_INET_Addr::set().

Referenced by ACE_Asynch_Acceptor< HANDLER >::handle_accept().

00388 {
00389   ACE_TRACE ("ACE_Asynch_Acceptor<>::parse_address");
00390 
00391 #if defined (ACE_HAS_AIO_CALLS)
00392 
00393   // Use an ACE_SOCK to get the addresses - it knows how to deal with
00394   // ACE_INET_Addr objects and get IPv4/v6 addresses.
00395   ACE_SOCK_Stream str (result.accept_handle ());
00396   str.get_local_addr (local_address);
00397   str.get_remote_addr (remote_address);
00398 
00399 #elif (defined (ACE_HAS_WINNT4) && (ACE_HAS_WINNT4 != 0)) || (defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0))
00400 
00401   ACE_Message_Block &message_block = result.message_block ();
00402 
00403   sockaddr *local_addr = 0;
00404   sockaddr *remote_addr = 0;
00405   int local_size = 0;
00406   int remote_size = 0;
00407   // This matches setup in accept().
00408   size_t addr_size = sizeof (sockaddr_in) + 16;
00409 #if defined (ACE_HAS_IPV6)
00410   if (this->addr_family_ == PF_INET6)
00411     addr_size = sizeof (sockaddr_in6) + 16;
00412 #endif /* ACE_HAS_IPV6 */
00413 
00414   ::GetAcceptExSockaddrs (message_block.rd_ptr (),
00415                           static_cast<DWORD> (this->bytes_to_read_),
00416                           static_cast<DWORD> (addr_size),
00417                           static_cast<DWORD> (addr_size),
00418                           &local_addr,
00419                           &local_size,
00420                           &remote_addr,
00421                           &remote_size);
00422 
00423   local_address.set (reinterpret_cast<sockaddr_in *> (local_addr),
00424                      local_size);
00425   remote_address.set (reinterpret_cast<sockaddr_in *> (remote_addr),
00426                       remote_size);
00427 #else
00428   // just in case
00429   errno = ENOTSUP;
00430 #endif /* (defined (ACE_HAS_WINNT4) && (ACE_HAS_WINNT4 != 0)) || (defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0)) */
00431   return;
00432 }

template<class HANDLER>
void ACE_Asynch_Acceptor< HANDLER >::pass_addresses int  new_value  )  [virtual]
 

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

Definition at line 477 of file Asynch_Acceptor.cpp.

References ACE_Asynch_Acceptor< HANDLER >::pass_addresses_.

00478 {
00479   this->pass_addresses_ = new_value;
00480 }

template<class HANDLER>
int 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.

Definition at line 471 of file Asynch_Acceptor.cpp.

References ACE_Asynch_Acceptor< HANDLER >::pass_addresses_.

00472 {
00473   return this->pass_addresses_;
00474 }

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.

Definition at line 501 of file Asynch_Acceptor.cpp.

References ACE_Asynch_Acceptor< HANDLER >::reissue_accept_.

00502 {
00503   this->reissue_accept_ = new_value;
00504 }

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.

Definition at line 495 of file Asynch_Acceptor.cpp.

References ACE_Asynch_Acceptor< HANDLER >::reissue_accept_.

00496 {
00497   return this->reissue_accept_;
00498 }

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.

Definition at line 178 of file Asynch_Acceptor.cpp.

References ACE_ERROR_RETURN, ACE_LIB_TEXT, ACE_TRACE, ACE_Asynch_Acceptor< HANDLER >::asynch_accept_, ACE_Asynch_Acceptor< HANDLER >::listen_handle_, LM_ERROR, and ACE_Asynch_Accept::open().

00179 {
00180   ACE_TRACE ("ACE_Asynch_Acceptor<>::set_handle");
00181 
00182   // Take ownership of the <listen_handle>
00183   this->listen_handle_ = listen_handle;
00184 
00185   // Reinitialize the ACE_Asynch_Accept
00186   if (this->asynch_accept_.open (*this,
00187                                  this->listen_handle_,
00188                                  0,
00189                                  this->proactor ()) == -1)
00190     ACE_ERROR_RETURN ((LM_ERROR,
00191                        ACE_LIB_TEXT ("%p\n"),
00192                        ACE_LIB_TEXT ("ACE_Asynch_Accept::open")),
00193                       -1);
00194   return 0;
00195 }

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 implemenation always returns the value passed as the open() method's reissue_accept argument. That value can also be changed using the reissue_accept() method.

Definition at line 519 of file Asynch_Acceptor.cpp.

References ACE_Asynch_Acceptor< HANDLER >::reissue_accept_.

Referenced by ACE_Asynch_Acceptor< HANDLER >::handle_accept().

00520 {
00521   return this->reissue_accept_;
00522 }

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:
result Result of the connection acceptance.
remote Peer's address.
local Local address connection was accepted at.
Return values:
-1 ACE_Asynch_Acceptor will close the connection, and the service will not be opened.
0 Service opening will proceeed.

Definition at line 350 of file Asynch_Acceptor.cpp.

References ACE_INET_Addr.

Referenced by ACE_Asynch_Acceptor< HANDLER >::handle_accept().

00353 {
00354   // Default implementation always validates the remote address.
00355   return 0;
00356 }

template<class HANDLER>
void ACE_Asynch_Acceptor< HANDLER >::validate_new_connection int  new_value  )  [virtual]
 

Set flag that indicates if address validation is required.

Definition at line 489 of file Asynch_Acceptor.cpp.

References ACE_Asynch_Acceptor< HANDLER >::validate_new_connection_.

00490 {
00491   this->validate_new_connection_ = new_value;
00492 }

template<class HANDLER>
int ACE_Asynch_Acceptor< HANDLER >::validate_new_connection void   )  const [virtual]
 

Get flag that indicates if address validation is required.

Definition at line 483 of file Asynch_Acceptor.cpp.

References ACE_Asynch_Acceptor< HANDLER >::validate_new_connection_.

Referenced by ACE_Asynch_Acceptor< HANDLER >::handle_accept().

00484 {
00485   return this->validate_new_connection_;
00486 }

template<class HANDLER>
int ACE_Asynch_Acceptor< HANDLER >::validate_new_connection const ACE_INET_Addr remote_address  )  [virtual]
 

Deprecated:
Use validate_connection() instead. Will be removed after ACE 5.3.
Template method for address validation.

This hook method is called after a connection is accepted if so specified on the call to the open() method. If this method returns -1, the connection is immediately closed and the service handler is not opened.

The default implemenation always return 0.

Definition at line 359 of file Asynch_Acceptor.cpp.

00360 {
00361   // Default implementation always validates the remote address.
00362   return 0;
00363 }


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().

Definition at line 281 of file Asynch_Acceptor.h.

Referenced by ACE_Asynch_Acceptor< HANDLER >::accept(), ACE_Asynch_Acceptor< HANDLER >::open(), and ACE_Asynch_Acceptor< HANDLER >::parse_address().

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

Asynch_Accept used to make life easier :-).

Definition at line 264 of file Asynch_Acceptor.h.

Referenced by ACE_Asynch_Acceptor< HANDLER >::accept(), ACE_Asynch_Acceptor< HANDLER >::asynch_accept(), ACE_Asynch_Acceptor< HANDLER >::cancel(), ACE_Asynch_Acceptor< HANDLER >::open(), and ACE_Asynch_Acceptor< HANDLER >::set_handle().

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

Bytes to be read with the call.

Definition at line 277 of file Asynch_Acceptor.h.

Referenced by ACE_Asynch_Acceptor< HANDLER >::bytes_to_read(), ACE_Asynch_Acceptor< HANDLER >::open(), and ACE_Asynch_Acceptor< HANDLER >::parse_address().

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

Handle used to listen for new connections.

Definition at line 261 of file Asynch_Acceptor.h.

Referenced by ACE_Asynch_Acceptor< HANDLER >::cancel(), ACE_Asynch_Acceptor< HANDLER >::get_handle(), ACE_Asynch_Acceptor< HANDLER >::handle(), ACE_Asynch_Acceptor< HANDLER >::handle_accept(), ACE_Asynch_Acceptor< HANDLER >::open(), ACE_Asynch_Acceptor< HANDLER >::set_handle(), and ACE_Asynch_Acceptor< HANDLER >::~ACE_Asynch_Acceptor().

template<class HANDLER>
int ACE_Asynch_Acceptor< HANDLER >::pass_addresses_ [private]
 

Flag that indicates if parsing of addresses is necessary.

Definition at line 267 of file Asynch_Acceptor.h.

Referenced by ACE_Asynch_Acceptor< HANDLER >::handle_accept(), ACE_Asynch_Acceptor< HANDLER >::open(), and ACE_Asynch_Acceptor< HANDLER >::pass_addresses().

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.

Definition at line 274 of file Asynch_Acceptor.h.

Referenced by ACE_Asynch_Acceptor< HANDLER >::open(), ACE_Asynch_Acceptor< HANDLER >::reissue_accept(), and ACE_Asynch_Acceptor< HANDLER >::should_reissue_accept().

template<class HANDLER>
int ACE_Asynch_Acceptor< HANDLER >::validate_new_connection_ [private]
 

Flag that indicates if address validation is required.

Definition at line 270 of file Asynch_Acceptor.h.

Referenced by ACE_Asynch_Acceptor< HANDLER >::handle_accept(), ACE_Asynch_Acceptor< HANDLER >::open(), and ACE_Asynch_Acceptor< HANDLER >::validate_new_connection().


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 11:19:21 2006 for ACE by doxygen 1.3.6