00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file POSIX_CB_Proactor.h 00006 * 00007 * $Id: POSIX_CB_Proactor.h 76858 2007-02-02 07:53:52Z olli $ 00008 * 00009 * @author Alexander Libman <alibman@ihug.com.au> 00010 */ 00011 //============================================================================= 00012 00013 #ifndef ACE_POSIX_CB_PROACTOR_H 00014 #define ACE_POSIX_CB_PROACTOR_H 00015 00016 #include /**/ "ace/config-all.h" 00017 00018 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00019 # pragma once 00020 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00021 00022 #if defined (ACE_HAS_AIO_CALLS) 00023 00024 #include "ace/Synch_Traits.h" 00025 #include "ace/Thread_Semaphore.h" 00026 #include "ace/Null_Semaphore.h" 00027 00028 #include "ace/POSIX_Proactor.h" 00029 00030 00031 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00032 00033 /** 00034 * @class ACE_POSIX_CB_Proactor 00035 * 00036 * @brief Implementation of Callback-based Proactor 00037 * }; 00038 */ 00039 class ACE_Export ACE_POSIX_CB_Proactor : public ACE_POSIX_AIOCB_Proactor 00040 { 00041 00042 public: 00043 virtual Proactor_Type get_impl_type (void); 00044 00045 /// Destructor. 00046 virtual ~ACE_POSIX_CB_Proactor (void); 00047 00048 /// Constructor defines max number asynchronous operations that can 00049 /// be started at the same time. 00050 ACE_POSIX_CB_Proactor (size_t max_aio_operations = ACE_AIO_DEFAULT_SIZE); 00051 00052 // This only public so the "extern C" completion function can see it 00053 // when needed. 00054 static void aio_completion_func (sigval cb_data); 00055 00056 protected: 00057 00058 /** 00059 * Dispatch a single set of events. If <wait_time> elapses before 00060 * any events occur, return 0. Return 1 on success i.e., when a 00061 * completion is dispatched, non-zero (-1) on errors and errno is 00062 * set accordingly. 00063 */ 00064 virtual int handle_events (ACE_Time_Value &wait_time); 00065 00066 /** 00067 * Block indefinitely until at least one event is dispatched. 00068 * Dispatch a single set of events. If <wait_time> elapses before 00069 * any events occur, return 0. Return 1 on success i.e., when a 00070 * completion is dispatched, non-zero (-1) on errors and errno is 00071 * set accordingly. 00072 */ 00073 virtual int handle_events (void); 00074 00075 /// Find free slot to store result and aiocb pointer 00076 virtual ssize_t allocate_aio_slot (ACE_POSIX_Asynch_Result *result); 00077 00078 /// Notify queue of "post_completed" ACE_POSIX_Asynch_Results 00079 /// called from post_completion method 00080 virtual int notify_completion (int sig_num); 00081 00082 /** 00083 * Dispatch a single set of events. If @a milli_seconds elapses 00084 * before any events occur, return 0. Return 1 if a completion is 00085 * dispatched. Return -1 on errors. 00086 */ 00087 int handle_events_i (u_long milli_seconds); 00088 00089 /// Semaphore variable to notify 00090 /// used to wait the first AIO start 00091 ACE_SYNCH_SEMAPHORE sema_; 00092 }; 00093 00094 ACE_END_VERSIONED_NAMESPACE_DECL 00095 00096 #endif /* ACE_HAS_AIO_CALLS */ 00097 #endif /* ACE_POSIX_CB_PROACTOR_H*/