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

WIN32_Proactor.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    WIN32_Proactor.h
00006  *
00007  *  $Id: WIN32_Proactor.h,v 1.1.1.4 2003/02/21 18:36:32 chad Exp $
00008  *
00009  *  @author Irfan Pyarali (irfan@cs.wustl.edu)
00010  *  @author Tim Harrison (harrison@cs.wustl.edu)
00011  *  @author Alexander Babu Arulanthu <alex@cs.wustl.edu>
00012  *  @author Roger Tragin <r.tragin@computer.org>
00013  *  @author Alexander Libman <alibman@ihug.com.au>
00014  */
00015 //=============================================================================
00016 
00017 #ifndef ACE_WIN32_PROACTOR_H
00018 #define ACE_WIN32_PROACTOR_H
00019 #include "ace/pre.h"
00020 
00021 #include "ace/config-all.h"
00022 
00023 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00024 #pragma once
00025 #endif /* ACE_LACKS_PRAGMA_ONCE */
00026 
00027 #if (defined (ACE_WIN32) && !defined (ACE_HAS_WINCE))
00028 // WIN32 implementation of the Proactor.
00029 
00030 #include "ace/OS.h"
00031 #include "ace/WIN32_Asynch_IO.h"
00032 #include "ace/Event_Handler.h"
00033 
00034 #include "ace/Proactor_Impl.h"
00035 #include "ace/Asynch_Pseudo_Task.h"
00036 
00037 // Forward declarations.
00038 class ACE_WIN32_Asynch_Result;
00039 class ACE_WIN32_Proactor_Timer_Handler;
00040 
00041 /**
00042  * @class ACE_WIN32_Proactor
00043  *
00044  * @brief A manager for asynchronous event demultiplexing on Win32.
00045  *
00046  * See the Proactor pattern description at
00047  * http://www.cs.wustl.edu/~schmidt/PDF/proactor.pdf for more
00048  * details.
00049  */
00050 class ACE_Export ACE_WIN32_Proactor : public ACE_Proactor_Impl
00051 {
00052   friend class ACE_WIN32_Asynch_Connect;
00053 
00054 public:
00055   /// A do nothing constructor.
00056   ACE_WIN32_Proactor (size_t number_of_threads = 0,
00057                       int used_with_reactor_event_loop = 0);
00058 
00059   /// Virtual destruction.
00060   virtual ~ACE_WIN32_Proactor (void);
00061 
00062   /// Close the IO completion port.
00063   virtual int close (void);
00064 
00065   /// This method adds the <handle> to the I/O completion port. This
00066   /// function is a no-op function for Unix systems.
00067   virtual int register_handle (ACE_HANDLE handle,
00068                                const void *completion_key);
00069 
00070   /**
00071    * Dispatch a single set of events.  If <wait_time> elapses before
00072    * any events occur, return 0.  Return 1 on success i.e., when a
00073    * completion is dispatched, non-zero (-1) on errors and errno is
00074    * set accordingly.
00075    */
00076   virtual int handle_events (ACE_Time_Value &wait_time);
00077 
00078   /**
00079    * Block indefinitely until at least one event is dispatched.
00080    * Dispatch a single set of events.  If <wait_time> elapses before
00081    * any events occur, return 0.  Return 1 on success i.e., when a
00082    * completion is dispatched, non-zero (-1) on errors and errno is
00083    * set accordingly.
00084    */
00085   virtual int handle_events (void);
00086 
00087   /**
00088    * Post a result to the completion port of the Proactor.  If errors
00089    * occur, the result will be deleted by this method.  If successful,
00090    * the result will be deleted by the Proactor when the result is
00091    * removed from the completion port.  Therefore, the result should
00092    * have been dynamically allocated and should be orphaned by the
00093    * user once this method is called.
00094    */
00095   virtual int post_completion (ACE_WIN32_Asynch_Result *result);
00096 
00097   /// Add wakeup dispatch threads (reinit).
00098   int wake_up_dispatch_threads (void);
00099 
00100   /// Close all dispatch threads.
00101   int close_dispatch_threads (int wait);
00102 
00103   /// Get number of thread used as a parameter to CreatIoCompletionPort.
00104   size_t number_of_threads (void) const;
00105 
00106   /// Set number of thread used as a parameter to CreatIoCompletionPort.
00107   void number_of_threads (size_t threads);
00108 
00109   /// Get the event handle.
00110   virtual ACE_HANDLE get_handle (void) const;
00111 
00112   virtual ACE_Asynch_Read_Stream_Impl *create_asynch_read_stream (void);
00113   virtual ACE_Asynch_Write_Stream_Impl *create_asynch_write_stream (void);
00114   virtual ACE_Asynch_Read_File_Impl *create_asynch_read_file (void);
00115   virtual ACE_Asynch_Write_File_Impl *create_asynch_write_file (void);
00116   virtual ACE_Asynch_Read_Dgram_Impl *create_asynch_read_dgram (void);
00117   virtual ACE_Asynch_Write_Dgram_Impl *create_asynch_write_dgram (void);
00118   virtual ACE_Asynch_Accept_Impl *create_asynch_accept (void);
00119   virtual ACE_Asynch_Connect_Impl *create_asynch_connect (void);
00120   virtual ACE_Asynch_Transmit_File_Impl *create_asynch_transmit_file (void);
00121 
00122   // Methods used to create Asynch_IO_Result objects. We create the right
00123   // objects here in these methods.
00124 
00125   virtual ACE_Asynch_Read_Stream_Result_Impl *create_asynch_read_stream_result (ACE_Handler &handler,
00126                                                                                 ACE_HANDLE handle,
00127                                                                                 ACE_Message_Block &message_block,
00128                                                                                 size_t bytes_to_read,
00129                                                                                 const void* act,
00130                                                                                 ACE_HANDLE event,
00131                                                                                 int priority,
00132                                                                                 int signal_number = 0);
00133 
00134   virtual ACE_Asynch_Write_Stream_Result_Impl *create_asynch_write_stream_result (ACE_Handler &handler,
00135                                                                                   ACE_HANDLE handle,
00136                                                                                   ACE_Message_Block &message_block,
00137                                                                                   size_t bytes_to_write,
00138                                                                                   const void* act,
00139                                                                                   ACE_HANDLE event,
00140                                                                                   int priority,
00141                                                                                   int signal_number = 0);
00142 
00143   virtual ACE_Asynch_Read_File_Result_Impl *create_asynch_read_file_result (ACE_Handler &handler,
00144                                                                             ACE_HANDLE handle,
00145                                                                             ACE_Message_Block &message_block,
00146                                                                             size_t bytes_to_read,
00147                                                                             const void* act,
00148                                                                             u_long offset,
00149                                                                             u_long offset_high,
00150                                                                             ACE_HANDLE event,
00151                                                                             int priority,
00152                                                                             int signal_number = 0);
00153 
00154   virtual ACE_Asynch_Write_File_Result_Impl *create_asynch_write_file_result (ACE_Handler &handler,
00155                                                                               ACE_HANDLE handle,
00156                                                                               ACE_Message_Block &message_block,
00157                                                                               size_t bytes_to_write,
00158                                                                               const void* act,
00159                                                                               u_long offset,
00160                                                                               u_long offset_high,
00161                                                                               ACE_HANDLE event,
00162                                                                               int priority,
00163                                                                               int signal_number = 0);
00164 
00165   /// Create the correct implementation class for ACE_Asynch_Read_Dgram::Result.
00166   virtual ACE_Asynch_Read_Dgram_Result_Impl *create_asynch_read_dgram_result (ACE_Handler &handler,
00167                                                                               ACE_HANDLE handle,
00168                                                                               ACE_Message_Block *message_block,
00169                                                                               size_t bytes_to_read,
00170                                                                               int flags,
00171                                                                               int protocol_family,
00172                                                                               const void* act,
00173                                                                               ACE_HANDLE event,
00174                                                                               int priority,
00175                                                                               int signal_number = 0);
00176 
00177   /// Create the correct implementation class for ACE_Asynch_Write_Dgram::Result.
00178   virtual ACE_Asynch_Write_Dgram_Result_Impl *create_asynch_write_dgram_result (ACE_Handler &handler,
00179                                                                                 ACE_HANDLE handle,
00180                                                                                 ACE_Message_Block *message_block,
00181                                                                                 size_t bytes_to_write,
00182                                                                                 int flags,
00183                                                                                 const void* act,
00184                                                                                 ACE_HANDLE event,
00185                                                                                 int priority,
00186                                                                                 int signal_number = 0);
00187 
00188   virtual ACE_Asynch_Accept_Result_Impl *create_asynch_accept_result (ACE_Handler &handler,
00189                                                                       ACE_HANDLE listen_handle,
00190                                                                       ACE_HANDLE accept_handle,
00191                                                                       ACE_Message_Block &message_block,
00192                                                                       size_t bytes_to_read,
00193                                                                       const void* act,
00194                                                                       ACE_HANDLE event,
00195                                                                       int priority,
00196                                                                       int signal_number = 0);
00197 
00198   virtual ACE_Asynch_Connect_Result_Impl *create_asynch_connect_result (ACE_Handler & handler,
00199                                                                         ACE_HANDLE connect_handle,
00200                                                                         const void *act,
00201                                                                         ACE_HANDLE event,
00202                                                                         int priority,
00203                                                                         int signal_number = 0);
00204 
00205 
00206   virtual ACE_Asynch_Transmit_File_Result_Impl *create_asynch_transmit_file_result (ACE_Handler &handler,
00207                                                                                     ACE_HANDLE socket,
00208                                                                                     ACE_HANDLE file,
00209                                                                                     ACE_Asynch_Transmit_File::Header_And_Trailer *header_and_trailer,
00210                                                                                     size_t bytes_to_write,
00211                                                                                     u_long offset,
00212                                                                                     u_long offset_high,
00213                                                                                     size_t bytes_per_send,
00214                                                                                     u_long flags,
00215                                                                                     const void *act,
00216                                                                                     ACE_HANDLE event,
00217                                                                                     int priority,
00218                                                                                     int signal_number = 0);
00219 
00220   /// Create a timer result object which can be used with the Timer
00221   /// mechanism of the Proactor.
00222   virtual ACE_Asynch_Result_Impl *create_asynch_timer (ACE_Handler &handler,
00223                                                        const void *act,
00224                                                        const ACE_Time_Value &tv,
00225                                                        ACE_HANDLE event,
00226                                                        int priority,
00227                                                        int signal_number = 0);
00228 
00229 protected:
00230   /// Task to process pseudo-asynchronous operations
00231   ACE_Asynch_Pseudo_Task & get_asynch_pseudo_task (void);
00232 
00233   /// Called when object is signaled by OS (either via UNIX signals or
00234   /// when a Win32 object becomes signaled).
00235   virtual int handle_signal (int signum, siginfo_t * = 0, ucontext_t * = 0);
00236 
00237   /// Called when object is removed from the ACE_Reactor.
00238   virtual int handle_close (ACE_HANDLE handle,
00239                             ACE_Reactor_Mask close_mask);
00240 
00241   /**
00242    * Dispatch a single set of events.  If <milli_seconds> elapses
00243    * before any events occur, return 0. Return 1 if a completion is
00244    * dispatched. Return -1 on errors.
00245    */
00246   virtual int handle_events (unsigned long milli_seconds);
00247 
00248   /// Protect against structured exceptions caused by user code when
00249   /// dispatching handles.
00250   void application_specific_code (ACE_WIN32_Asynch_Result *asynch_result,
00251                                   size_t bytes_transferred,
00252                                   const void *completion_key,
00253                                   u_long error);
00254 
00255   /**
00256    * Post <how_many> completions to the completion port so that all
00257    * threads can wake up. This is used in conjunction with the
00258    * <run_event_loop>.
00259    */
00260   virtual int post_wakeup_completions (int how_many);
00261 
00262   /// Handle for the completion port. Unix doesnt have completion
00263   /// ports.
00264   ACE_HANDLE completion_port_;
00265 
00266   /// This number is passed to the <CreatIOCompletionPort> system
00267   /// call.
00268   DWORD number_of_threads_;
00269 
00270   /// This event is used in conjunction with Reactor when we try to
00271   /// integrate the event loops of Reactor and the Proactor.
00272   ACE_Auto_Event event_;
00273 
00274   /// Flag that indicates whether we are used in conjunction with
00275   /// Reactor.
00276   int used_with_reactor_event_loop_;
00277 
00278   /// Handler to handle the wakeups. This works in conjunction with the
00279   /// <ACE_Proactor::run_event_loop>.
00280   ACE_Handler wakeup_handler_;
00281 
00282   /// Pseudo-task for asynch connect ( NT/2000)
00283   /// In future should removed in XP with ConnectEx support
00284   ACE_Asynch_Pseudo_Task pseudo_task_;
00285 };
00286 
00287 /**
00288  * @class ACE_WIN32_Asynch_Timer
00289  *
00290  * @brief This class is posted to the completion port when a timer
00291  * expires. When the complete method of this object is
00292  * called, the <handler>'s handle_timeout method will be
00293  * called.
00294  */
00295 class ACE_Export ACE_WIN32_Asynch_Timer : public ACE_WIN32_Asynch_Result
00296 {
00297 
00298   /// The factory method for this class is with the POSIX_Proactor
00299   /// class.
00300   friend class ACE_WIN32_Proactor;
00301 
00302 protected:
00303   /// Constructor.
00304   ACE_WIN32_Asynch_Timer (ACE_Handler &handler,
00305                           const void *act,
00306                           const ACE_Time_Value &tv,
00307                           ACE_HANDLE event = ACE_INVALID_HANDLE,
00308                           int priority = 0,
00309                           int signal_number = 0);
00310 
00311   /// This method calls the <handler>'s handle_timeout method.
00312   virtual void complete (size_t bytes_transferred,
00313                          int success,
00314                          const void *completion_key,
00315                          u_long error = 0);
00316 
00317   /// Time value requested by caller
00318   ACE_Time_Value time_;
00319 };
00320 
00321 #endif /* ACE_WIN32 */
00322 #include "ace/post.h"
00323 #endif /* ACE_PROACTOR_H */

Generated on Mon Jun 16 11:22:12 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002