POSIX_Proactor.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    POSIX_Proactor.h
00006  *
00007  *  POSIX_Proactor.h,v 4.53 2006/04/27 11:17:55 jwillemsen 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@baltimore.com>
00014  */
00015 //=============================================================================
00016 
00017 #ifndef ACE_POSIX_PROACTOR_H
00018 #define ACE_POSIX_PROACTOR_H
00019 
00020 #include "ace/config-all.h"
00021 
00022 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00023 #pragma once
00024 #endif /* ACE_LACKS_PRAGMA_ONCE */
00025 
00026 #if defined (ACE_HAS_AIO_CALLS)
00027 // POSIX implementation of Proactor depends on the <aio_> family of
00028 // system calls.
00029 
00030 #include "ace/Proactor_Impl.h"
00031 #include "ace/Free_List.h"
00032 #include "ace/Pipe.h"
00033 #include "ace/POSIX_Asynch_IO.h"
00034 #include "ace/Asynch_Pseudo_Task.h"
00035 
00036 #define ACE_AIO_MAX_SIZE     2048
00037 #define ACE_AIO_DEFAULT_SIZE 1024
00038 
00039 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00040 
00041 /**
00042  * @class ACE_POSIX_Proactor
00043  *
00044  * @brief POSIX implementation of the Proactor.
00045  *
00046  * There are two different strategies by which Proactor can get
00047  * to know the completion of <aio> operations. One is based on
00048  * Asynchronous I/O Control Blocks (AIOCB) where a list of
00049  * AIOCBs are stored and completion status of the corresponding
00050  * operations are queried on them. The other one is based on
00051  * POSIX Real Time signals. This class abstracts out the common
00052  * code needed for both the strategies. <ACE_POSIX_AIOCB_Proactor> and
00053  * <ACE_POSIX_SIG_Proactor> specialize this class for each strategy.
00054  */
00055 class ACE_Export ACE_POSIX_Proactor : public ACE_Proactor_Impl
00056 {
00057 public:
00058   enum Proactor_Type
00059   {
00060     /// Base class type
00061     PROACTOR_POSIX  = 0,
00062 
00063     /// Aio_suspend() based
00064     PROACTOR_AIOCB  = 1,
00065 
00066     /// Signals notifications
00067     PROACTOR_SIG    = 2,
00068 
00069     /// SUN specific aiowait()
00070     PROACTOR_SUN    = 3,
00071 
00072     /// Callback notifications
00073     PROACTOR_CB     = 4
00074   };
00075 
00076 
00077   enum SystemType  // open for future extention
00078   {
00079     ACE_OS_UNDEFINED= 0x0000,
00080     ACE_OS_WIN      = 0x0100,          // for future
00081     ACE_OS_WIN_NT   = ACE_OS_WIN | 0x0001,
00082     ACE_OS_WIN_2000 = ACE_OS_WIN | 0x0002,
00083     ACE_OS_SUN      = 0x0200,          // Sun Solaris family
00084     ACE_OS_SUN_55   = ACE_OS_SUN | 0x0001,
00085     ACE_OS_SUN_56   = ACE_OS_SUN | 0x0002,
00086     ACE_OS_SUN_57   = ACE_OS_SUN | 0x0004,
00087     ACE_OS_SUN_58   = ACE_OS_SUN | 0x0008,
00088     ACE_OS_HPUX     = 0x0400,          // HPUX family
00089     ACE_OS_HPUX_11  = ACE_OS_HPUX | 0x0001,
00090     ACE_OS_LINUX    = 0x0800,          // Linux family
00091     ACE_OS_FREEBSD  = 0x1000,          // FreeBSD family
00092     ACE_OS_IRIX     = 0x2000,          // SGI IRIX family
00093     ACE_OS_OPENBSD  = 0x4000           // OpenBSD familty
00094   };
00095 
00096   enum Opcode {
00097     ACE_OPCODE_READ = 1,
00098     ACE_OPCODE_WRITE = 2
00099   };
00100 
00101   virtual Proactor_Type  get_impl_type (void);
00102 
00103   /// Virtual destructor.
00104   virtual ~ACE_POSIX_Proactor (void);
00105 
00106   /// Close down the Proactor.
00107   virtual int close (void);
00108 
00109   /**
00110    * Dispatch a single set of events.  If @a wait_time elapses before
00111    * any events occur, return 0.  Return 1 on success i.e., when a
00112    * completion is dispatched, non-zero (-1) on errors and errno is
00113    * set accordingly.
00114    */
00115   virtual int handle_events (ACE_Time_Value &wait_time) = 0;
00116 
00117   /**
00118    * Block indefinitely until at least one event is dispatched.
00119    * Dispatch a single set of events.Return 1 on success i.e., when a
00120    * completion is dispatched, non-zero (-1) on errors and errno is
00121    * set accordingly.
00122    */
00123   virtual int handle_events (void) = 0;
00124 
00125   /**
00126    * Post a result to the completion port of the Proactor.  If errors
00127    * occur, the result will be deleted by this method.  If successful,
00128    * the result will be deleted by the Proactor when the result is
00129    * removed from the completion port. Therefore, the result should
00130    * have been dynamically allocated and should be orphaned by the
00131    * user once this method is called.
00132    */
00133   virtual int post_completion (ACE_POSIX_Asynch_Result *result) = 0;
00134 
00135   virtual int start_aio (ACE_POSIX_Asynch_Result *result, Opcode op) = 0;
00136 
00137   virtual int cancel_aio (ACE_HANDLE h) = 0;
00138 
00139   /// Task to process pseudo-asynchronous operations
00140   ACE_Asynch_Pseudo_Task &get_asynch_pseudo_task ();
00141 
00142   /// This function is a no-op function for Unix systems. Returns 0.
00143   virtual int register_handle (ACE_HANDLE handle,
00144                                const void *completion_key);
00145 
00146   /// @@ This is a no-op on POSIX platforms. Returns 0.
00147   int wake_up_dispatch_threads (void);
00148 
00149   /// @@ This is a no-op on POSIX platforms. Returns 0.
00150   int close_dispatch_threads (int wait);
00151 
00152   /// @@ This is a no-op on POSIX platforms. Returns 0.
00153   size_t number_of_threads (void) const;
00154   void number_of_threads (size_t threads);
00155 
00156   /// This is a no-op in POSIX. Returns ACE_INVALID_HANDLE.
00157   virtual ACE_HANDLE get_handle (void) const;
00158 
00159   // Methods used to create Asynch IO factory and result objects. We
00160   // create the right objects here in these methods.
00161 
00162   virtual ACE_Asynch_Read_Stream_Impl *create_asynch_read_stream (void);
00163   virtual ACE_Asynch_Read_Stream_Result_Impl *
00164     create_asynch_read_stream_result (const ACE_Handler::Proxy_Ptr &handler_proxy,
00165                                       ACE_HANDLE handle,
00166                                       ACE_Message_Block &message_block,
00167                                       size_t bytes_to_read,
00168                                       const void *act,
00169                                       ACE_HANDLE event = ACE_INVALID_HANDLE,
00170                                       int priority = 0,
00171                                       int signal_number = ACE_SIGRTMIN);
00172 
00173   virtual ACE_Asynch_Write_Stream_Impl *create_asynch_write_stream (void);
00174   virtual ACE_Asynch_Write_Stream_Result_Impl *
00175     create_asynch_write_stream_result (const ACE_Handler::Proxy_Ptr &handler_proxy,
00176                                        ACE_HANDLE handle,
00177                                        ACE_Message_Block &message_block,
00178                                        size_t bytes_to_write,
00179                                        const void *act,
00180                                        ACE_HANDLE event = ACE_INVALID_HANDLE,
00181                                        int priority = 0,
00182                                        int signal_number = ACE_SIGRTMIN);
00183 
00184   virtual ACE_Asynch_Read_File_Impl *create_asynch_read_file (void);
00185   virtual ACE_Asynch_Read_File_Result_Impl *
00186     create_asynch_read_file_result (const ACE_Handler::Proxy_Ptr &handler_proxy,
00187                                     ACE_HANDLE handle,
00188                                     ACE_Message_Block &message_block,
00189                                     size_t bytes_to_read,
00190                                     const void *act,
00191                                     u_long offset,
00192                                     u_long offset_high,
00193                                     ACE_HANDLE event = ACE_INVALID_HANDLE,
00194                                     int priority = 0,
00195                                     int signal_number = ACE_SIGRTMIN);
00196 
00197   virtual ACE_Asynch_Write_File_Impl *create_asynch_write_file (void);
00198   virtual ACE_Asynch_Write_File_Result_Impl *
00199     create_asynch_write_file_result (const ACE_Handler::Proxy_Ptr &handler_proxy,
00200                                      ACE_HANDLE handle,
00201                                      ACE_Message_Block &message_block,
00202                                      size_t bytes_to_write,
00203                                      const void *act,
00204                                      u_long offset,
00205                                      u_long offset_high,
00206                                      ACE_HANDLE event = ACE_INVALID_HANDLE,
00207                                      int priority = 0,
00208                                      int signal_number = ACE_SIGRTMIN);
00209 
00210   virtual ACE_Asynch_Read_Dgram_Impl *create_asynch_read_dgram (void);
00211   virtual ACE_Asynch_Read_Dgram_Result_Impl *
00212     create_asynch_read_dgram_result (const ACE_Handler::Proxy_Ptr &handler_proxy,
00213                                      ACE_HANDLE handle,
00214                                      ACE_Message_Block *message_block,
00215                                      size_t bytes_to_read,
00216                                      int flags,
00217                                      int protocol_family,
00218                                      const void* act,
00219                                      ACE_HANDLE event = ACE_INVALID_HANDLE,
00220                                      int priority = 0,
00221                                      int signal_number = ACE_SIGRTMIN);
00222 
00223   virtual ACE_Asynch_Write_Dgram_Impl *create_asynch_write_dgram (void);
00224   virtual ACE_Asynch_Write_Dgram_Result_Impl *
00225     create_asynch_write_dgram_result (const ACE_Handler::Proxy_Ptr &handler_proxy,
00226                                       ACE_HANDLE handle,
00227                                       ACE_Message_Block *message_block,
00228                                       size_t bytes_to_write,
00229                                       int flags,
00230                                       const void* act,
00231                                       ACE_HANDLE event = ACE_INVALID_HANDLE,
00232                                       int priority = 0,
00233                                       int signal_number = ACE_SIGRTMIN);
00234 
00235   virtual ACE_Asynch_Accept_Impl *create_asynch_accept (void);
00236   virtual ACE_Asynch_Accept_Result_Impl *
00237     create_asynch_accept_result (const ACE_Handler::Proxy_Ptr &handler_proxy,
00238                                  ACE_HANDLE listen_handle,
00239                                  ACE_HANDLE accept_handle,
00240                                  ACE_Message_Block &message_block,
00241                                  size_t bytes_to_read,
00242                                  const void *act,
00243                                  ACE_HANDLE event = ACE_INVALID_HANDLE,
00244                                  int priority = 0,
00245                                  int signal_number = ACE_SIGRTMIN);
00246 
00247   virtual ACE_Asynch_Connect_Impl *create_asynch_connect (void);
00248   virtual ACE_Asynch_Connect_Result_Impl *
00249     create_asynch_connect_result (const ACE_Handler::Proxy_Ptr &handler_proxy,
00250                                   ACE_HANDLE connect_handle,
00251                                   const void *act,
00252                                   ACE_HANDLE event = ACE_INVALID_HANDLE,
00253                                   int priority = 0,
00254                                   int signal_number = ACE_SIGRTMIN);
00255 
00256   virtual ACE_Asynch_Transmit_File_Impl *create_asynch_transmit_file (void);
00257   virtual ACE_Asynch_Transmit_File_Result_Impl *
00258     create_asynch_transmit_file_result (const ACE_Handler::Proxy_Ptr &handler_proxy,
00259                                         ACE_HANDLE socket,
00260                                         ACE_HANDLE file,
00261                                         ACE_Asynch_Transmit_File::Header_And_Trailer *header_and_trailer,
00262                                         size_t bytes_to_write,
00263                                         u_long offset,
00264                                         u_long offset_high,
00265                                         size_t bytes_per_send,
00266                                         u_long flags,
00267                                         const void *act,
00268                                         ACE_HANDLE event = ACE_INVALID_HANDLE,
00269                                         int priority = 0,
00270                                         int signal_number = ACE_SIGRTMIN);
00271 
00272   /// Create a timer result object which can be used with the Timer
00273   /// mechanism of the Proactor.
00274   virtual ACE_Asynch_Result_Impl *
00275     create_asynch_timer (const ACE_Handler::Proxy_Ptr &handler_proxy,
00276                          const void *act,
00277                          const ACE_Time_Value &tv,
00278                          ACE_HANDLE event = ACE_INVALID_HANDLE,
00279                          int priority = 0,
00280                          int signal_number = ACE_SIGRTMIN);
00281 
00282 protected:
00283   /// Constructor.
00284   ACE_POSIX_Proactor (void);
00285 
00286   /**
00287    * Protect against structured exceptions caused by user code when
00288    * dispatching handles. The <completion_key> is not very useful
00289    * compared to <AST> that can be associated each asynchronous
00290    * operation. <completion_key> is implemented right now for the
00291    * POSIX Proators.
00292    */
00293   void application_specific_code (ACE_POSIX_Asynch_Result *asynch_result,
00294                                   size_t bytes_transferred,
00295                                   const void *completion_key,
00296                                   u_long error);
00297 
00298   /**
00299    * Post <how_many> completions to the completion port so that all
00300    * threads can wake up. This is used in conjunction with the
00301    * <run_event_loop>.
00302    */
00303   virtual int post_wakeup_completions (int how_many);
00304 
00305 protected:
00306   /// Handler to handle the wakeups. This works in conjunction with the
00307   /// <ACE_Proactor::run_event_loop>.
00308   ACE_Handler wakeup_handler_;
00309   int os_id_;
00310 
00311 private:
00312   /// Task to process pseudo-asynchronous accept/connect
00313   ACE_Asynch_Pseudo_Task  pseudo_task_;
00314 
00315 };
00316 
00317 // Forward declarations.
00318 class ACE_AIOCB_Notify_Pipe_Manager;
00319 
00320 /**
00321  * @class ACE_POSIX_AIOCB_Proactor
00322  *
00323  * @brief This Proactor makes use of Asynchronous I/O Control Blocks
00324  * (AIOCB) to notify/get the completion status of the <aio_>
00325  * operations issued.
00326  */
00327 class ACE_Export ACE_POSIX_AIOCB_Proactor : public ACE_POSIX_Proactor
00328 {
00329 
00330   /// Handler needs to call application specific code.
00331   friend class ACE_AIOCB_Notify_Pipe_Manager;
00332 
00333   /// This class does the registering of Asynch Operations with the
00334   /// Proactor which is necessary in the AIOCB strategy.
00335   friend class ACE_POSIX_Asynch_Operation;
00336   friend class ACE_POSIX_Asynch_Accept;
00337   friend class ACE_POSIX_Asynch_Connect;
00338 
00339 
00340 public:
00341   /// Constructor defines max number asynchronous operations
00342   /// which can be started at the same time
00343   ACE_POSIX_AIOCB_Proactor (size_t nmaxop = ACE_AIO_DEFAULT_SIZE);
00344 
00345   virtual Proactor_Type  get_impl_type (void);
00346 
00347   /// Destructor.
00348   virtual ~ACE_POSIX_AIOCB_Proactor (void);
00349 
00350   /// Close down the Proactor.
00351   virtual int close (void);
00352 
00353   /**
00354    * Dispatch a single set of events.  If <wait_time> elapses before
00355    * any events occur, return 0.  Return 1 on success i.e., when a
00356    * completion is dispatched, non-zero (-1) on errors and errno is
00357    * set accordingly.
00358    */
00359   virtual int handle_events (ACE_Time_Value &wait_time);
00360 
00361   /**
00362    * Block indefinitely until at least one event is dispatched.
00363    * Dispatch a single set of events.  If <wait_time> elapses before
00364    * any events occur, return 0.  Return 1 on success i.e., when a
00365    * completion is dispatched, non-zero (-1) on errors and errno is
00366    * set accordingly.
00367    */
00368   virtual int handle_events (void);
00369 
00370   /// Post a result to the completion port of the Proactor.
00371   virtual int post_completion (ACE_POSIX_Asynch_Result *result);
00372 
00373   virtual int start_aio (ACE_POSIX_Asynch_Result *result,
00374                          ACE_POSIX_Proactor::Opcode op);
00375 
00376   /**
00377    * This method should be called from
00378    * ACE_POSIX_Asynch_Operation::cancel()
00379    * instead of usual ::aio_cancel.
00380    * For all deferred AIO requests with handle "h"
00381    * it removes its from the lists and notifies user.
00382    * For all running AIO requests with handle "h"
00383    * it calls ::aio_cancel. According to the POSIX standards
00384    * we will receive ECANCELED  for all ::aio_canceled AIO requests
00385    * later on return from ::aio_suspend
00386    */
00387   virtual int cancel_aio (ACE_HANDLE h);
00388 
00389 protected:
00390 
00391   /// Special constructor for ACE_SUN_Proactor
00392   /// and ACE_POSIX_SIG_Proactor
00393   ACE_POSIX_AIOCB_Proactor (size_t nmaxop,
00394                             ACE_POSIX_Proactor::Proactor_Type ptype);
00395 
00396   /// Check AIO for completion, error and result status
00397   /// Return: 1 - AIO completed , 0 - not completed yet
00398   virtual int get_result_status (ACE_POSIX_Asynch_Result *asynch_result,
00399                                  int &error_status,
00400                                  size_t &transfer_count);
00401 
00402   /// Create aiocb list
00403   int create_result_aiocb_list (void);
00404 
00405   /// Call this method from derived class when virtual table is
00406   /// built.
00407   int delete_result_aiocb_list (void);
00408 
00409   /// Call these methods from derived class when virtual table is
00410   /// built.
00411   void create_notify_manager (void);
00412   void delete_notify_manager (void);
00413 
00414   /// Define the maximum number of asynchronous I/O requests
00415   /// for the current OS
00416   void check_max_aio_num (void) ;
00417 
00418   /// To identify requests from Notify_Pipe_Manager
00419   void set_notify_handle (ACE_HANDLE h);
00420 
00421   /**
00422    * Dispatch a single set of events.  If <milli_seconds> elapses
00423    * before any events occur, return 0. Return 1 if a completion
00424    * dispatched. Return -1 on errors.
00425    */
00426   int handle_events_i (u_long milli_seconds);
00427 
00428   /// Start deferred AIO if necessary
00429   int start_deferred_aio (void);
00430 
00431   /// Cancel running or deferred AIO
00432   virtual int cancel_aiocb (ACE_POSIX_Asynch_Result * result);
00433 
00434   /// Extract the results of aio.
00435   ACE_POSIX_Asynch_Result *find_completed_aio (int &error_status,
00436                                                size_t &transfer_count,
00437                                                size_t &index,
00438                                                size_t &count);
00439 
00440   /// Find free slot to store result and aiocb pointer
00441   virtual ssize_t allocate_aio_slot (ACE_POSIX_Asynch_Result *result);
00442 
00443   /// Initiate an aio operation.
00444   virtual int start_aio_i (ACE_POSIX_Asynch_Result *result);
00445 
00446   /// Notify queue of "post_completed" ACE_POSIX_Asynch_Results
00447   /// called from post_completion method
00448   virtual int notify_completion (int sig_num);
00449 
00450   /// Put "post_completed" result into the internal queue
00451   int  putq_result (ACE_POSIX_Asynch_Result *result);
00452 
00453   /// Get "post_completed" result from the internal queue
00454   ACE_POSIX_Asynch_Result * getq_result (void);
00455 
00456   /// Clear the internal results queue
00457   int clear_result_queue (void);
00458 
00459   /// Process the internal results queue
00460   int process_result_queue (void);
00461 
00462 
00463   /// This class takes care of doing <accept> when we use
00464   /// AIO_CONTROL_BLOCKS strategy.
00465   ACE_AIOCB_Notify_Pipe_Manager *aiocb_notify_pipe_manager_;
00466 
00467   /// Use a dynamically allocated array to keep track of all the aio's
00468   /// issued currently.
00469   aiocb **aiocb_list_;
00470   ACE_POSIX_Asynch_Result **result_list_;
00471 
00472   /// To maintain the maximum size of the array (list).
00473   size_t aiocb_list_max_size_;
00474 
00475   /// To maintain the current size of the array (list).
00476   size_t aiocb_list_cur_size_;
00477 
00478   /// Mutex to protect work with lists.
00479   ACE_SYNCH_MUTEX mutex_;
00480 
00481   /// The purpose of this member is only to identify asynchronous request
00482   /// from NotifyManager. We will reserve for it always slot 0
00483   /// in the list of aiocb's to be sure that don't lose notifications.
00484   ACE_HANDLE notify_pipe_read_handle_ ;
00485 
00486   /// Number of ACE_POSIX_Asynch_Result's waiting for start
00487   /// i.e. deferred AIOs
00488   size_t num_deferred_aiocb_ ;
00489 
00490   /// Number active,i.e. running requests
00491   size_t num_started_aio_ ;
00492 
00493   /// Queue which keeps "post_completed" ACE_POSIX_Asynch_Result's
00494   ACE_Unbounded_Queue<ACE_POSIX_Asynch_Result *> result_queue_;
00495 };
00496 
00497 #if defined(ACE_HAS_POSIX_REALTIME_SIGNALS)
00498 /**
00499  * @class ACE_POSIX_SIG_Proactor
00500  *
00501  * @brief This Proactor implementation does completion event detection using
00502  * POSIX Real Time signals. @c sigtimedwait() or @c sigwaitinfo() is
00503  * used to wait for completions.
00504  * The real-time signals that are going to be used with this
00505  * Proactor should be given apriori in the constructor, so that
00506  * those signals can be masked from asynchronous delivery.
00507  */
00508 class ACE_Export ACE_POSIX_SIG_Proactor : public ACE_POSIX_AIOCB_Proactor
00509 {
00510 
00511   /**
00512    * This class does the registering of Asynch Operations with the
00513    * Proactor which is necessary in the SIG strategy, because we need
00514    * to store the signal number.
00515    */
00516   friend class ACE_POSIX_SIG_Asynch_Operation;
00517 
00518 public:
00519   /**
00520    * This constructor masks only the <ACE_SIGRTMIN>
00521    * real-time signal. Only this signal should be used to issue
00522    * asynchronous operations using this Proctor.
00523    */
00524   ACE_POSIX_SIG_Proactor (size_t nmaxop = ACE_AIO_DEFAULT_SIZE);
00525 
00526   virtual Proactor_Type  get_impl_type (void);
00527 
00528   /**
00529    * This constructor should be used to tell the Proactor to mask and
00530    * wait for the real-time signals specified in this set. Only these
00531    * signals should be used by the asynchronous operations when they
00532    * use this Proactor.
00533    */
00534   ACE_POSIX_SIG_Proactor (const sigset_t mask_set,
00535                           size_t nmaxop = ACE_AIO_DEFAULT_SIZE);
00536 
00537   /// Destructor.
00538   virtual ~ACE_POSIX_SIG_Proactor (void);
00539 
00540   /**
00541    * Dispatch a single set of events.  If <wait_time> elapses before
00542    * any events occur, return 0.  Return 1 on success i.e., when a
00543    * completion is dispatched, non-zero (-1) on errors and errno is
00544    * set accordingly.
00545    */
00546   virtual int handle_events (ACE_Time_Value &wait_time);
00547 
00548   /**
00549    * Block indefinitely until at least one event is dispatched.
00550    * Dispatch a single set of events.  If <wait_time> elapses before
00551    * any events occur, return 0.  Return 1 on success i.e., when a
00552    * completion is dispatched, non-zero (-1) on errors and errno is
00553    * set accordingly.
00554    */
00555   virtual int handle_events (void);
00556 
00557   /// Post a result to the completion port of the Proactor.
00558   /// now it is implemented in base ACE_POSIX_AIOCB_Proactor class
00559   ///virtual int post_completion (ACE_POSIX_Asynch_Result *result);
00560 
00561   /**
00562    * If <signal_number> is -1, check with the Proactor and use one of
00563    * the signals that is present in the mask set (i.e., the signals for
00564    * which the Proactor will be waiting) of the Proactor. If there are
00565    * more than one signal, the higher numbered signal will be chosen.
00566    */
00567   virtual ACE_Asynch_Result_Impl *create_asynch_timer
00568     (const ACE_Handler::Proxy_Ptr &handler_proxy,
00569      const void *act,
00570      const ACE_Time_Value &tv,
00571      ACE_HANDLE event = ACE_INVALID_HANDLE,
00572      int priority = 0,
00573      int signal_number = ACE_SIGRTMIN);
00574 
00575 protected:
00576   /// To setup the handler for a real-time signbal.
00577   int setup_signal_handler (int signal_number) const;
00578 
00579   /// Insures that RT_completion_signals_ are blocked in the calling thread.
00580   int block_signals (void) const;
00581 
00582   /**
00583    * Dispatch a single set of events.  @a timeout is a pointer to a
00584    * relative time representing the maximum amount of time to wait for
00585    * an event to occur. If 0, wait indefinitely.
00586    *
00587    * @retval 0  A timeout occurred before any event was detected.
00588    * @retval 1  A completion was dispatched.
00589    * @retval -1 An error occurred; errno contains an error code.
00590    */
00591   virtual int handle_events_i (const ACE_Time_Value *timeout);
00592 
00593   /// Find free slot to store result and aiocb pointer
00594   virtual ssize_t allocate_aio_slot (ACE_POSIX_Asynch_Result *result);
00595 
00596 
00597   /// Notify queue of "post_completed" ACE_POSIX_Asynch_Results
00598   /// called from post_completion method
00599   virtual int notify_completion (int sig_num);
00600 
00601   /**
00602    * These signals are used for completion notification by the
00603    * Proactor. The signals specified while issuing asynchronous
00604    * operations are stored here in this set. These signals are masked
00605    * for a thread when it calls handle_events().
00606    */
00607   sigset_t RT_completion_signals_;
00608 };
00609 
00610 
00611 #endif /* ACE_HAS_POSIX_REALTIME_SIGNALS */
00612 
00613 /**
00614  * @class ACE_POSIX_Asynch_Timer
00615  *
00616  * @brief This class is posted to the completion port when a timer
00617  * expires. When the @c complete() method of this object is
00618  * called, the handler's @c handle_timeout() method will be
00619  * called.
00620  */
00621 class ACE_Export ACE_POSIX_Asynch_Timer : public ACE_POSIX_Asynch_Result
00622 {
00623 
00624   /// The factory method for this class is with the POSIX_Proactor
00625   /// class.
00626   friend class ACE_POSIX_Proactor;
00627 #if defined(ACE_HAS_POSIX_REALTIME_SIGNALS)
00628   friend class ACE_POSIX_SIG_Proactor;
00629 #endif
00630 
00631 protected:
00632   /// Constructor.
00633   ACE_POSIX_Asynch_Timer (const ACE_Handler::Proxy_Ptr &handler_proxy,
00634                           const void *act,
00635                           const ACE_Time_Value &tv,
00636                           ACE_HANDLE event = ACE_INVALID_HANDLE,
00637                           int priority = 0,
00638                           int signal_number = ACE_SIGRTMIN);
00639 
00640   /// Destructor.
00641   virtual ~ACE_POSIX_Asynch_Timer (void) {}
00642 
00643   /// This method calls the handler's handle_timeout method.
00644   virtual void complete (size_t bytes_transferred,
00645                          int success,
00646                          const void *completion_key,
00647                          u_long error = 0);
00648 
00649   /// Time value requested by caller
00650   ACE_Time_Value time_;
00651 };
00652 
00653 ACE_END_VERSIONED_NAMESPACE_DECL
00654 
00655 #if defined (__ACE_INLINE__)
00656 #include "ace/POSIX_Proactor.inl"
00657 #endif /* __ACE_INLINE__ */
00658 
00659 #endif /* ACE_HAS_AIO_CALLS  && ACE_HAS_POSIX_REALTIME_SIGNALS */
00660 #endif /* ACE_POSIX_PROACTOR_H */

Generated on Thu Nov 9 09:41:59 2006 for ACE by doxygen 1.3.6