Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

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 Methods

 ACE_WIN32_Asynch_Accept (ACE_WIN32_Proactor *win32_proactor)
 Constructor. More...

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)
 ~ACE_WIN32_Asynch_Accept (void)
 Destructor. More...

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


Detailed Description

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

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

Definition at line 1083 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 1970 of file WIN32_Asynch_IO.cpp.

01971   : ACE_Asynch_Operation_Impl (),
01972     ACE_Asynch_Accept_Impl (),
01973     ACE_WIN32_Asynch_Operation (win32_proactor)
01974 {
01975 }

ACE_WIN32_Asynch_Accept::~ACE_WIN32_Asynch_Accept void   
 

Destructor.

Definition at line 2096 of file WIN32_Asynch_IO.cpp.

02097 {
02098 }


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
[virtual]
 

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

<message_block> 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 1978 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_Message_Block::base, 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_Message_Block::size, ACE_OS::socket, and ACE_Message_Block::wr_ptr.

01984 {
01985 #if (defined (ACE_HAS_WINNT4) && (ACE_HAS_WINNT4 != 0)) || (defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0))
01986   // Sanity check: make sure that enough space has been allocated by
01987   // the caller.
01988   size_t address_size = sizeof (sockaddr_in) + sizeof (sockaddr);
01989   size_t space_in_use = message_block.wr_ptr () - message_block.base ();
01990   size_t total_size = message_block.size ();
01991   size_t available_space = total_size - space_in_use;
01992   size_t space_needed = bytes_to_read + 2 * address_size;
01993   if (available_space < space_needed)
01994     ACE_ERROR_RETURN ((LM_ERROR, ACE_LIB_TEXT ("Buffer too small\n")), -1);
01995 
01996   // WIN Specific.
01997 
01998   // AcceptEx API limits us to DWORD range.
01999   if (bytes_to_read > MAXDWORD)
02000     {
02001       errno = ERANGE;
02002       return -1;
02003     }
02004   DWORD dword_bytes_to_read = ACE_static_cast (DWORD, bytes_to_read);
02005 
02006   int close_accept_handle = 0;
02007   // If the <accept_handle> is invalid, we will create a new socket.
02008   if (accept_handle == ACE_INVALID_HANDLE)
02009     {
02010       accept_handle = ACE_OS::socket (PF_INET,
02011                                       SOCK_STREAM,
02012                                       0);
02013       if (accept_handle == ACE_INVALID_HANDLE)
02014         {
02015           if (ACE::debug ())
02016             {
02017               ACE_DEBUG ((LM_ERROR,
02018                           ACE_LIB_TEXT ("%p\n"),
02019                           ACE_LIB_TEXT ("ACE_OS::socket")));
02020             }
02021           return -1;
02022         }
02023       else
02024         // Remember to close the socket down if failures occur.
02025         close_accept_handle = 1;
02026     }
02027 
02028   // Common code for both WIN and POSIX.
02029   ACE_WIN32_Asynch_Accept_Result *result = 0;
02030   ACE_NEW_RETURN (result,
02031                   ACE_WIN32_Asynch_Accept_Result (*this->handler_,
02032                                                   this->handle_,
02033                                                   accept_handle,
02034                                                   message_block,
02035                                                   bytes_to_read,
02036                                                   act,
02037                                                   this->win32_proactor_->get_handle (),
02038                                                   priority,
02039                                                   signal_number),
02040                   -1);
02041 
02042   u_long bytes_read;
02043 
02044   // Initiate the accept.
02045   int initiate_result = ::AcceptEx ((SOCKET) result->listen_handle (),
02046                                     (SOCKET) result->accept_handle (),
02047                                     result->message_block ().wr_ptr (),
02048                                     dword_bytes_to_read,
02049                                     ACE_static_cast (DWORD, address_size),
02050                                     ACE_static_cast (DWORD, address_size),
02051                                     &bytes_read,
02052                                     result);
02053   if (initiate_result == 1)
02054     // Immediate success: the OVERLAPPED will still get queued.
02055     return 1;
02056 
02057   // If initiate failed, check for a bad error.
02058   ACE_OS::set_errno_to_last_error ();
02059   switch (errno)
02060     {
02061     case ERROR_IO_PENDING:
02062       // The IO will complete proactively: the OVERLAPPED will still
02063       // get queued.
02064       return 0;
02065 
02066     default:
02067       // Something else went wrong: the OVERLAPPED will not get
02068       // queued.
02069 
02070       if (close_accept_handle == 1)
02071         // Close the newly created socket
02072         ACE_OS::closesocket (accept_handle);
02073 
02074       // Cleanup dynamically allocated Asynch_Result.
02075       delete result;
02076 
02077       if (ACE::debug ())
02078         {
02079           ACE_DEBUG ((LM_ERROR,
02080                       ACE_LIB_TEXT ("%p\n"),
02081                       ACE_LIB_TEXT ("ReadFile")));
02082         }
02083       return -1;
02084     }
02085 #else /* ACE_HAS_WINNT4 .......|| ACE_HAS_AIO_CALLS */
02086   ACE_UNUSED_ARG (message_block);
02087   ACE_UNUSED_ARG (bytes_to_read);
02088   ACE_UNUSED_ARG (accept_handle);
02089   ACE_UNUSED_ARG (act);
02090   ACE_UNUSED_ARG (priority);
02091   ACE_UNUSED_ARG (signal_number);
02092   ACE_NOTSUP_RETURN (-1);
02093 #endif /* (defined (ACE_HAS_WINNT4) && (ACE_HAS_WINNT4 != 0)) || (defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0)) || (defined (ACE_HAS_AIO_CALLS) */
02094 }

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 2117 of file WIN32_Asynch_IO.cpp.

References ACE_WIN32_Asynch_Operation::cancel.

02118 {
02119   return ACE_WIN32_Asynch_Operation::cancel ();
02120 }

int ACE_WIN32_Asynch_Accept::open ACE_Handler   handler,
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 (<handle> == ACE_INVALID_HANDLE), <ACE_Handler::handle> will be called on the <handler> to get the correct handle.

Reimplemented from ACE_WIN32_Asynch_Operation.

Definition at line 2105 of file WIN32_Asynch_IO.cpp.

References ACE_WIN32_Asynch_Operation::open.

02109 {
02110   return ACE_WIN32_Asynch_Operation::open (handler,
02111                                            handle,
02112                                            completion_key,
02113                                            proactor);
02114 }

ACE_Proactor * ACE_WIN32_Asynch_Accept::proactor void    const [virtual]
 

Return the underlying proactor.

Reimplemented from ACE_WIN32_Asynch_Operation.

Definition at line 2123 of file WIN32_Asynch_IO.cpp.

References ACE_WIN32_Asynch_Operation::proactor.

02124 {
02125   return ACE_WIN32_Asynch_Operation::proactor ();
02126 }


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 12:59:26 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002