00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file POSIX_CB_Proactor.h 00006 * 00007 * POSIX_CB_Proactor.h,v 4.16 2006/01/08 19:30:13 jwillemsen Exp 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) && !defined(__Lynx__) && !defined (__FreeBSD__) 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 #if defined(AIX) || defined(sun) || defined(__APPLE__) || defined (ACE_VXWORKS) 00031 typedef union sigval sigval_t; 00032 #endif 00033 00034 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00035 00036 /** 00037 * @class ACE_POSIX_CB_Proactor 00038 * 00039 * @brief Implementation of Callback-based Proactor 00040 * }; 00041 */ 00042 class ACE_Export ACE_POSIX_CB_Proactor : public ACE_POSIX_AIOCB_Proactor 00043 { 00044 00045 public: 00046 virtual Proactor_Type get_impl_type (void); 00047 00048 /// Destructor. 00049 virtual ~ACE_POSIX_CB_Proactor (void); 00050 00051 /// Constructor defines max number asynchronous operations that can 00052 /// be started at the same time. 00053 ACE_POSIX_CB_Proactor (size_t max_aio_operations = ACE_AIO_DEFAULT_SIZE); 00054 00055 // This only public so the "extern C" completion function can see it 00056 // when needed. 00057 static void aio_completion_func (sigval_t cb_data); 00058 00059 protected: 00060 00061 /** 00062 * Dispatch a single set of events. If <wait_time> elapses before 00063 * any events occur, return 0. Return 1 on success i.e., when a 00064 * completion is dispatched, non-zero (-1) on errors and errno is 00065 * set accordingly. 00066 */ 00067 virtual int handle_events (ACE_Time_Value &wait_time); 00068 00069 /** 00070 * Block indefinitely until at least one event is dispatched. 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 (void); 00077 00078 /// Find free slot to store result and aiocb pointer 00079 virtual ssize_t allocate_aio_slot (ACE_POSIX_Asynch_Result *result); 00080 00081 /// Notify queue of "post_completed" ACE_POSIX_Asynch_Results 00082 /// called from post_completion method 00083 virtual int notify_completion (int sig_num); 00084 00085 /** 00086 * Dispatch a single set of events. If <milli_seconds> elapses 00087 * before any events occur, return 0. Return 1 if a completion is 00088 * dispatched. Return -1 on errors. 00089 */ 00090 int handle_events_i (u_long milli_seconds); 00091 00092 /// semaphore variable to notify 00093 /// used to wait the first AIO start 00094 ACE_SYNCH_SEMAPHORE sema_; 00095 }; 00096 00097 ACE_END_VERSIONED_NAMESPACE_DECL 00098 00099 #endif /* ACE_HAS_AIO_CALLS && !__Lynx__ && !__FreeBSD__ */ 00100 #endif /* ACE_POSIX_CB_PROACTOR_H*/