3 //=============================================================================
5 * @file Proactor_Impl.h
7 * @author Alexander Babu Arulanthu <alex@cs.wustl.edu>
8 * @author Alexander Libman <alibman@ihug.com.au>
10 //=============================================================================
12 #ifndef ACE_PROACTOR_IMPL_H
13 #define ACE_PROACTOR_IMPL_H
14 #include /**/ "ace/pre.h"
16 #include /**/ "ace/config-all.h"
18 #if defined (ACE_HAS_WIN32_OVERLAPPED_IO) || defined (ACE_HAS_AIO_CALLS)
19 // This only works on standard Win32 platforms and on Unix platforms supporting
22 #include "ace/Asynch_IO.h"
23 #include "ace/Reactor.h"
24 #include "ace/Countdown_Time.h"
26 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
29 * @class ACE_Proactor_Impl
31 * @brief A manager for asynchronous event demultiplexing. This class
32 * is the base class for all the concrete implementation
35 * See the Proactor pattern description at
36 * http://www.dre.vanderbilt.edu/~schmidt/PDF/proactor.pdf for more
39 class ACE_Export ACE_Proactor_Impl
: public ACE_Event_Handler
42 /// Virtual destruction.
43 virtual ~ACE_Proactor_Impl ();
45 /// Close the IO completion port.
46 virtual int close () = 0;
48 /// This method adds the @a handle to the I/O completion port. This
49 /// function is a no-op function for Unix systems.
50 virtual int register_handle (ACE_HANDLE handle
,
51 const void *completion_key
) = 0;
54 * Dispatch a single set of events. If @a wait_time elapses before
55 * any events occur, return 0. Return 1 on success i.e., when a
56 * completion is dispatched, non-zero (-1) on errors and errno is
59 virtual int handle_events (ACE_Time_Value
&wait_time
) = 0;
62 * Block indefinitely until at least one event is dispatched.
63 * Dispatch a single set of events. If <wait_time> elapses before
64 * any events occur, return 0. Return 1 on success i.e., when a
65 * completion is dispatched, non-zero (-1) on errors and errno is
68 virtual int handle_events () = 0;
70 /// Add wakeup dispatch threads (reinit).
71 virtual int wake_up_dispatch_threads () = 0;
73 /// Close all dispatch threads.
74 virtual int close_dispatch_threads (int wait
) = 0;
76 /// Get number of thread used as a parameter to CreatIoCompletionPort.
77 virtual size_t number_of_threads () const = 0;
79 /// Set number of thread used as a parameter to CreatIoCompletionPort.
80 virtual void number_of_threads (size_t threads
) = 0;
82 /// Get the event handle.
83 virtual ACE_HANDLE
get_handle () const = 0;
86 // = Factory methods for the operations
88 // Note that the user does not have to use or know about these
91 /// Create the correct implementation class for doing Asynch_Read_Stream.
92 virtual ACE_Asynch_Read_Stream_Impl
*create_asynch_read_stream () = 0;
94 /// Create the correct implementation class for doing Asynch_Write_Stream.
95 virtual ACE_Asynch_Write_Stream_Impl
*create_asynch_write_stream () = 0;
97 /// Create the correct implementation class for doing Asynch_Read_File.
98 virtual ACE_Asynch_Read_File_Impl
*create_asynch_read_file () = 0;
100 /// Create the correct implementation class for doing Asynch_Write_File.
101 virtual ACE_Asynch_Write_File_Impl
*create_asynch_write_file () = 0;
103 /// Create the correct implementation class for doing Asynch_Accept.
104 virtual ACE_Asynch_Accept_Impl
*create_asynch_accept () = 0;
106 /// Create the correct implementation class for doing Asynch_Connect.
107 virtual ACE_Asynch_Connect_Impl
*create_asynch_connect () = 0;
109 /// Create the correct implementation class for doing Asynch_Transmit_File.
110 virtual ACE_Asynch_Transmit_File_Impl
*create_asynch_transmit_file () = 0;
112 /// Create the correct implementation class for doing
113 /// Asynch_Read_Dgram.
114 virtual ACE_Asynch_Read_Dgram_Impl
*create_asynch_read_dgram () = 0;
116 /// Create the correct implementation class for doing
117 /// Asynch_Write_Dgram.
118 virtual ACE_Asynch_Write_Dgram_Impl
*create_asynch_write_dgram () = 0;
121 // = Factory methods for the results
123 // Note that the user does not have to use or know about these
124 // methods unless they want to "fake" results.
126 /// Create the correct implementation class for ACE_Asynch_Read_Stream::Result class.
127 virtual ACE_Asynch_Read_Stream_Result_Impl
*
128 create_asynch_read_stream_result (const ACE_Handler::Proxy_Ptr
&handler_proxy
,
130 ACE_Message_Block
&message_block
,
131 size_t bytes_to_read
,
133 ACE_HANDLE event
= ACE_INVALID_HANDLE
,
135 int signal_number
= ACE_SIGRTMIN
) = 0;
137 /// Create the correct implementation class for ACE_Asynch_Write_Stream::Result.
138 virtual ACE_Asynch_Write_Stream_Result_Impl
*
139 create_asynch_write_stream_result (const ACE_Handler::Proxy_Ptr
&handler_proxy
,
141 ACE_Message_Block
&message_block
,
142 size_t bytes_to_write
,
144 ACE_HANDLE event
= ACE_INVALID_HANDLE
,
146 int signal_number
= ACE_SIGRTMIN
) = 0;
148 /// Create the correct implementation class for ACE_Asynch_Read_File::Result.
149 virtual ACE_Asynch_Read_File_Result_Impl
*
150 create_asynch_read_file_result (const ACE_Handler::Proxy_Ptr
&handler_proxy
,
152 ACE_Message_Block
&message_block
,
153 size_t bytes_to_read
,
157 ACE_HANDLE event
= ACE_INVALID_HANDLE
,
159 int signal_number
= ACE_SIGRTMIN
) = 0;
161 /// Create the correct implementation class for ACE_Asynch_Write_File::Result.
162 virtual ACE_Asynch_Write_File_Result_Impl
*
163 create_asynch_write_file_result (const ACE_Handler::Proxy_Ptr
&handler
,
165 ACE_Message_Block
&message_block
,
166 size_t bytes_to_write
,
170 ACE_HANDLE event
= ACE_INVALID_HANDLE
,
172 int signal_number
= ACE_SIGRTMIN
) = 0;
174 /// Create the correct implementation class for ACE_Asynch_Read_Dgram::Result.
175 virtual ACE_Asynch_Read_Dgram_Result_Impl
*
176 create_asynch_read_dgram_result (const ACE_Handler::Proxy_Ptr
&handler_proxy
,
178 ACE_Message_Block
*message_block
,
179 size_t bytes_to_read
,
183 ACE_HANDLE event
= ACE_INVALID_HANDLE
,
185 int signal_number
= ACE_SIGRTMIN
) = 0;
187 /// Create the correct implementation class for ACE_Asynch_Write_Dgram::Result.
188 virtual ACE_Asynch_Write_Dgram_Result_Impl
*
189 create_asynch_write_dgram_result (const ACE_Handler::Proxy_Ptr
&handler_proxy
,
191 ACE_Message_Block
*message_block
,
192 size_t bytes_to_write
,
195 ACE_HANDLE event
= ACE_INVALID_HANDLE
,
197 int signal_number
= ACE_SIGRTMIN
) = 0;
199 /// Create the correct implementation class for ACE_Asynch_Accept::Result.
200 virtual ACE_Asynch_Accept_Result_Impl
*
201 create_asynch_accept_result (const ACE_Handler::Proxy_Ptr
&handler_proxy
,
202 ACE_HANDLE listen_handle
,
203 ACE_HANDLE accept_handle
,
204 ACE_Message_Block
&message_block
,
205 size_t bytes_to_read
,
207 ACE_HANDLE event
= ACE_INVALID_HANDLE
,
209 int signal_number
= ACE_SIGRTMIN
) = 0;
211 /// Create the correct implementation class for ACE_Asynch_Connect::Result.
212 virtual ACE_Asynch_Connect_Result_Impl
*
213 create_asynch_connect_result (const ACE_Handler::Proxy_Ptr
&handler_proxy
,
214 ACE_HANDLE connect_handle
,
216 ACE_HANDLE event
= ACE_INVALID_HANDLE
,
218 int signal_number
= ACE_SIGRTMIN
) = 0;
220 /// Create the correct implementation class for ACE_Asynch_Transmit_File::Result.
221 virtual ACE_Asynch_Transmit_File_Result_Impl
*
222 create_asynch_transmit_file_result (const ACE_Handler::Proxy_Ptr
&handler_proxy
,
225 ACE_Asynch_Transmit_File::Header_And_Trailer
*header_and_trailer
,
226 size_t bytes_to_write
,
229 size_t bytes_per_send
,
232 ACE_HANDLE event
= ACE_INVALID_HANDLE
,
234 int signal_number
= ACE_SIGRTMIN
) = 0;
237 * Create the correct implementation object for the Timer
238 * result. POSIX_SIG_Proactor will create a Timer object with a
239 * meaningful signal number, if you leave the signal number as 0.
241 virtual ACE_Asynch_Result_Impl
*
242 create_asynch_timer (const ACE_Handler::Proxy_Ptr
&handler_proxy
,
244 const ACE_Time_Value
&tv
,
245 ACE_HANDLE event
= ACE_INVALID_HANDLE
,
247 int signal_number
= 0) = 0;
250 * Post @a how_many completions to the completion port so that all
251 * threads can wake up. This is used in conjunction with the
254 virtual int post_wakeup_completions (int how_many
) = 0;
257 ACE_END_VERSIONED_NAMESPACE_DECL
259 #endif /* ACE_HAS_WIN32_OVERLAPPED_IO || ACE_HAS_AIO_CALLS */
260 #include /**/ "ace/post.h"
261 #endif /* ACE_PROACTOR_IMPL_H */