ACE_WIN32_Asynch_Accept Class Reference

This class is a factory for starting off asynchronous accepts on a listen handle. More...

#include <WIN32_Asynch_IO.h>

Inheritance diagram for ACE_WIN32_Asynch_Accept:

Inheritance graph
[legend]
Collaboration diagram for ACE_WIN32_Asynch_Accept:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ACE_WIN32_Asynch_Accept (ACE_WIN32_Proactor *win32_proactor)
 Constructor.

int accept (ACE_Message_Block &message_block, size_t bytes_to_read, ACE_HANDLE accept_handle, const void *act, int priority, int signal_number=0, int addr_family=AF_INET)
 ~ACE_WIN32_Asynch_Accept (void)
 Destructor.

int open (const ACE_Handler::Proxy_Ptr &handler_proxy, ACE_HANDLE handle, const void *completion_key, ACE_Proactor *proactor)
int cancel (void)
ACE_Proactorproactor (void) const
 Return the underlying proactor.


Detailed Description

This class is a factory for starting off asynchronous accepts on a listen handle.

Once is called, multiple asynchronous s can started using this class. A ACE_Asynch_Accept::Result will be passed back to the when the asynchronous accept completes through the <ACE_Handler::handle_accept> callback.

Definition at line 1085 of file WIN32_Asynch_IO.h.


Constructor & Destructor Documentation

ACE_WIN32_Asynch_Accept::ACE_WIN32_Asynch_Accept ACE_WIN32_Proactor win32_proactor  ) 
 

Constructor.

Definition at line 2028 of file WIN32_Asynch_IO.cpp.

02029   : ACE_Asynch_Operation_Impl (),
02030     ACE_Asynch_Accept_Impl (),
02031     ACE_WIN32_Asynch_Operation (win32_proactor)
02032 {
02033 }

ACE_WIN32_Asynch_Accept::~ACE_WIN32_Asynch_Accept void   ) 
 

Destructor.

Definition at line 2160 of file WIN32_Asynch_IO.cpp.

02161 {
02162 }


Member Function Documentation

int ACE_WIN32_Asynch_Accept::accept ACE_Message_Block message_block,
size_t  bytes_to_read,
ACE_HANDLE  accept_handle,
const void *  act,
int  priority,
int  signal_number = 0,
int  addr_family = AF_INET
[virtual]
 

This starts off an asynchronous accept. The asynchronous accept call also allows any initial data to be returned to the . Upto will be read and stored in the . The will be used for the call. If ( == INVALID_HANDLE), a new handle will be created.

must be specified. This is because the address of the new connection is placed at the end of this buffer.

Implements ACE_Asynch_Accept_Impl.

Definition at line 2036 of file WIN32_Asynch_IO.cpp.

References ACE_WIN32_Asynch_Accept_Result::accept_handle(), ACE_DEBUG, ACE_ERROR_RETURN, ACE_LIB_TEXT, ACE_NEW_RETURN, ACE_NOTSUP_RETURN, ACE_OS::closesocket(), ACE::debug(), ACE_WIN32_Asynch_Accept_Result::listen_handle(), LM_ERROR, ACE_WIN32_Asynch_Accept_Result::message_block(), ACE_OS::set_errno_to_last_error(), ACE_OS::socket(), ACE_Message_Block::space(), and ACE_Message_Block::wr_ptr().

02043 {
02044 #if (defined (ACE_HAS_WINNT4) && (ACE_HAS_WINNT4 != 0)) || (defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0))
02045   // Sanity check: make sure that enough space has been allocated by
02046   // the caller.
02047   size_t address_size =
02048 #if defined (ACE_HAS_IPV6)
02049     addr_family == AF_INET ? sizeof (sockaddr_in) : sizeof (sockaddr_in6);
02050 #else
02051     sizeof (sockaddr_in);
02052 #endif /* ACE_HAS_IPV6 */
02053   address_size += 16;     // AcceptEx requires address size + 16 (minimum)
02054   size_t available_space = message_block.space ();
02055   size_t space_needed = bytes_to_read + 2 * address_size;
02056   if (available_space < space_needed)
02057     ACE_ERROR_RETURN ((LM_ERROR, ACE_LIB_TEXT ("Buffer too small\n")), -1);
02058 
02059   // WIN Specific.
02060 
02061   // AcceptEx API limits us to DWORD range.
02062   if (bytes_to_read > MAXDWORD)
02063     {
02064       errno = ERANGE;
02065       return -1;
02066     }
02067   DWORD dword_bytes_to_read = static_cast<DWORD> (bytes_to_read);
02068 
02069   int close_accept_handle = 0;
02070   // If the <accept_handle> is invalid, we will create a new socket.
02071   if (accept_handle == ACE_INVALID_HANDLE)
02072     {
02073       accept_handle = ACE_OS::socket (addr_family,
02074                                       SOCK_STREAM,
02075                                       0);
02076       if (accept_handle == ACE_INVALID_HANDLE)
02077         {
02078           if (ACE::debug ())
02079             {
02080               ACE_DEBUG ((LM_ERROR,
02081                           ACE_LIB_TEXT ("%p\n"),
02082                           ACE_LIB_TEXT ("ACE_OS::socket")));
02083             }
02084           return -1;
02085         }
02086       else
02087         // Remember to close the socket down if failures occur.
02088         close_accept_handle = 1;
02089     }
02090 
02091   // Common code for both WIN and POSIX.
02092   ACE_WIN32_Asynch_Accept_Result *result = 0;
02093   ACE_NEW_RETURN (result,
02094                   ACE_WIN32_Asynch_Accept_Result (this->handler_proxy_,
02095                                                   this->handle_,
02096                                                   accept_handle,
02097                                                   message_block,
02098                                                   bytes_to_read,
02099                                                   act,
02100                                                   this->win32_proactor_->get_handle (),
02101                                                   priority,
02102                                                   signal_number),
02103                   -1);
02104 
02105   u_long bytes_read;
02106 
02107   // Initiate the accept.
02108   int initiate_result = ::AcceptEx ((SOCKET) result->listen_handle (),
02109                                     (SOCKET) result->accept_handle (),
02110                                     result->message_block ().wr_ptr (),
02111                                     dword_bytes_to_read,
02112                                     static_cast<DWORD> (address_size),
02113                                     static_cast<DWORD> (address_size),
02114                                     &bytes_read,
02115                                     result);
02116   if (initiate_result == 1)
02117     // Immediate success: the OVERLAPPED will still get queued.
02118     return 1;
02119 
02120   // If initiate failed, check for a bad error.
02121   ACE_OS::set_errno_to_last_error ();
02122   switch (errno)
02123     {
02124     case ERROR_IO_PENDING:
02125       // The IO will complete proactively: the OVERLAPPED will still
02126       // get queued.
02127       return 0;
02128 
02129     default:
02130       // Something else went wrong: the OVERLAPPED will not get
02131       // queued.
02132 
02133       if (close_accept_handle == 1)
02134         // Close the newly created socket
02135         ACE_OS::closesocket (accept_handle);
02136 
02137       // Cleanup dynamically allocated Asynch_Result.
02138       delete result;
02139 
02140       if (ACE::debug ())
02141         {
02142           ACE_DEBUG ((LM_ERROR,
02143                       ACE_LIB_TEXT ("%p\n"),
02144                       ACE_LIB_TEXT ("AcceptEx")));
02145         }
02146       return -1;
02147     }
02148 #else /* ACE_HAS_WINNT4 .......|| ACE_HAS_AIO_CALLS */
02149   ACE_UNUSED_ARG (message_block);
02150   ACE_UNUSED_ARG (bytes_to_read);
02151   ACE_UNUSED_ARG (accept_handle);
02152   ACE_UNUSED_ARG (act);
02153   ACE_UNUSED_ARG (priority);
02154   ACE_UNUSED_ARG (signal_number);
02155   ACE_UNUSED_ARG (addr_family);
02156   ACE_NOTSUP_RETURN (-1);
02157 #endif /* (defined (ACE_HAS_WINNT4) && (ACE_HAS_WINNT4 != 0)) || (defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0)) || (defined (ACE_HAS_AIO_CALLS) */
02158 }

int ACE_WIN32_Asynch_Accept::cancel void   )  [virtual]
 

This cancels all pending accepts operations that were issued by the calling thread. The function does not cancel asynchronous operations issued by other threads.

Reimplemented from ACE_WIN32_Asynch_Operation.

Definition at line 2181 of file WIN32_Asynch_IO.cpp.

References ACE_WIN32_Asynch_Operation::cancel().

02182 {
02183   return ACE_WIN32_Asynch_Operation::cancel ();
02184 }

int ACE_WIN32_Asynch_Accept::open const ACE_Handler::Proxy_Ptr handler_proxy,
ACE_HANDLE  handle,
const void *  completion_key,
ACE_Proactor proactor
[virtual]
 

Initializes the factory with information which will be used with each asynchronous call. If ( == ACE_INVALID_HANDLE), <ACE_Handler::handle> will be called on the to get the correct handle.

Reimplemented from ACE_WIN32_Asynch_Operation.

Definition at line 2169 of file WIN32_Asynch_IO.cpp.

References ACE_WIN32_Asynch_Operation::open(), and ACE_Handler::Proxy_Ptr.

02173 {
02174   return ACE_WIN32_Asynch_Operation::open (handler_proxy,
02175                                            handle,
02176                                            completion_key,
02177                                            proactor);
02178 }

ACE_Proactor * ACE_WIN32_Asynch_Accept::proactor void   )  const [virtual]
 

Return the underlying proactor.

Reimplemented from ACE_WIN32_Asynch_Operation.

Definition at line 2187 of file WIN32_Asynch_IO.cpp.

References ACE_WIN32_Asynch_Operation::proactor().

02188 {
02189   return ACE_WIN32_Asynch_Operation::proactor ();
02190 }


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