ACE+TAO-7_0_8
[ACE_TAO.git] / ACE / apps / JAWS3 / jaws3 / Asynch_IO.cpp
blobbc00dc656d48a07c343ddf383b1ee2436e25f6ad
1 #ifndef JAWS_BUILD_DLL
2 #define JAWS_BUILD_DLL
3 #endif /*JAWS_BUILD_DLL*/
5 #include "ace/config-lite.h"
7 #include "jaws3/Jaws_IO.h"
8 #include "jaws3/Asynch_IO.h"
9 #include "jaws3/Event_Completer.h"
10 #include "jaws3/Event_Result.h"
12 #if defined (ACE_HAS_AIO_CALLS) || defined (ACE_HAS_WIN32_OVERLAPPED_IO)
14 #include "jaws3/Asynch_IO_Helpers.h"
16 void
17 JAWS_Asynch_IO::send ( ACE_HANDLE handle
18 , ACE_Message_Block *mb
19 , JAWS_Event_Completer *completer
20 , void *act
23 JAWS_EC_AH_Adapter *jecaha;
24 jecaha = JAWS_EC_AH_Adapter::make (completer);
26 ACE_Asynch_Write_Stream asynch_write_stream;
28 if (jecaha == 0
29 || asynch_write_stream.open (*jecaha, handle) == -1
30 || asynch_write_stream.write (*mb, mb->length (), act) == -1)
32 delete jecaha;
33 JAWS_Event_Result io_result ( 0
34 , JAWS_Event_Result::JE_ERROR
35 , JAWS_Event_Result::JE_SEND_FAIL
38 if (completer)
39 completer->output_complete (io_result, act);
44 void
45 JAWS_Asynch_IO::recv ( ACE_HANDLE handle
46 , ACE_Message_Block *mb
47 , JAWS_Event_Completer *completer
48 , void *act
51 JAWS_EC_AH_Adapter *jecaha;
52 jecaha = JAWS_EC_AH_Adapter::make (completer);
54 ACE_Asynch_Read_Stream asynch_read_stream;
56 if (jecaha == 0
57 || asynch_read_stream.open (*jecaha, handle) == -1
58 || asynch_read_stream.read (*mb, mb->space (), act) == -1)
60 delete jecaha;
61 JAWS_Event_Result io_result ( 0
62 , JAWS_Event_Result::JE_ERROR
63 , JAWS_Event_Result::JE_RECV_FAIL
66 if (completer)
67 completer->output_complete (io_result, act);
72 void
73 JAWS_Asynch_IO::transmit ( ACE_HANDLE handle
74 , ACE_HANDLE source
75 , JAWS_Event_Completer *completer
76 , void *act
77 , ACE_Message_Block *header
78 , ACE_Message_Block *trailer
81 JAWS_EC_AH_Adapter *jecaha;
82 jecaha = JAWS_EC_AH_Adapter::make (completer);
84 ACE_Asynch_Transmit_File::Header_And_Trailer *header_and_trailer = 0;
85 header_and_trailer =
86 new ACE_Asynch_Transmit_File::Header_And_Trailer ( header
87 , header->length ()
88 , trailer
89 , trailer->length ()
92 ACE_Asynch_Transmit_File asynch_transmit_file;
94 if (source == ACE_INVALID_HANDLE
95 || jecaha == 0
96 || header_and_trailer == 0
97 || asynch_transmit_file.open (*jecaha, handle) == -1
98 || asynch_transmit_file.transmit_file ( source
99 , header_and_trailer
105 , act
106 ) == -1)
108 delete jecaha;
109 delete header_and_trailer;
110 JAWS_Event_Result io_result ( 0
111 , JAWS_Event_Result::JE_ERROR
112 , JAWS_Event_Result::JE_TRANSMIT_FAIL
115 if (completer)
116 completer->output_complete (io_result, act);
122 JAWS_EC_AH_Adapter *
123 JAWS_EC_AH_Adapter::make (JAWS_Event_Completer *completer)
125 return new JAWS_EC_AH_Adapter (completer);
128 void
129 JAWS_EC_AH_Adapter
130 ::handle_read_stream (const ACE_Asynch_Read_Stream::Result &result)
132 JAWS_Event_Result io_result;
134 io_result = this->make_io_result ( result
135 , JAWS_Event_Result::JE_RECV_OK
136 , JAWS_Event_Result::JE_RECV_FAIL
138 // More useful diagnostics not implemented yet.
140 void *act = const_cast<void *> (result.act ());
142 this->completer_->input_complete (io_result, act);
143 delete this;
146 void
147 JAWS_EC_AH_Adapter
148 ::handle_write_stream (const ACE_Asynch_Write_Stream::Result &result)
150 JAWS_Event_Result io_result;
152 io_result = this->make_io_result ( result
153 , JAWS_Event_Result::JE_SEND_OK
154 , JAWS_Event_Result::JE_SEND_FAIL
156 // More useful diagnostics not implemented yet.
158 void *act = const_cast<void *> (result.act ());
160 this->completer_->output_complete (io_result, act);
161 delete this;
164 void
165 JAWS_EC_AH_Adapter
166 ::handle_transmit_file (const ACE_Asynch_Transmit_File::Result &result)
168 JAWS_Event_Result io_result;
170 io_result = this->make_io_result ( result
171 , JAWS_Event_Result::JE_TRANSMIT_OK
172 , JAWS_Event_Result::JE_TRANSMIT_FAIL
174 // More useful diagnostics not implemented yet.
175 // Watch out for files not opened in overlapped IO mode.
177 void *act = const_cast<void *> (result.act ());
179 this->completer_->output_complete (io_result, act);
180 delete this;
183 JAWS_Event_Result
184 JAWS_EC_AH_Adapter
185 ::make_io_result ( const ACE_Asynch_Result &result
186 , JAWS_Event_Result::JE_REASON reason_ok
187 , JAWS_Event_Result::JE_REASON reason_fail
190 size_t bytes = result.bytes_transferred ();
192 JAWS_Event_Result::JE_STATUS status;
193 JAWS_Event_Result::JE_REASON reason;
195 if (result.success ())
197 status = JAWS_Event_Result::JE_OK;
198 reason = reason_ok;
200 else
202 status = JAWS_Event_Result::JE_ERROR;
203 reason = reason_fail;
206 JAWS_Event_Result io_result (bytes, status, reason);
208 return io_result;
211 #else /* EMULATE AIO WITH REACTOR */
213 #include "jaws3/Reactive_IO.h"
215 void
216 JAWS_Asynch_IO::send ( ACE_HANDLE handle
217 , ACE_Message_Block *mb
218 , JAWS_Event_Completer *completer
219 , void *act
222 JAWS_Reactive_IO::instance ()->send (handle, mb, completer, act);
226 void
227 JAWS_Asynch_IO::recv ( ACE_HANDLE handle
228 , ACE_Message_Block *mb
229 , JAWS_Event_Completer *completer
230 , void *act
233 JAWS_Reactive_IO::instance ()->recv (handle, mb, completer, act);
237 void
238 JAWS_Asynch_IO::transmit ( ACE_HANDLE handle
239 , ACE_HANDLE source
240 , JAWS_Event_Completer *completer
241 , void *act
242 , ACE_Message_Block *header
243 , ACE_Message_Block *trailer
246 JAWS_Reactive_IO::instance ()->transmit ( handle
247 , source
248 , completer
249 , act
250 , header
251 , trailer
255 #endif /* ACE_HAS_AIO_CALLS || ACE_HAS_WIN32_OVERLAPPED_IO */
257 // For now, we will simulate timed Asynch IO with timed Reactive IO.
258 // In the future, we will implement the timed Asynch IO with timers
259 // and Asynch IO cancelation.
261 #include "jaws3/Reactive_IO.h"
263 void
264 JAWS_Asynch_IO::send ( ACE_HANDLE handle
265 , ACE_Message_Block *mb
266 , JAWS_Event_Completer *completer
267 , const ACE_Time_Value &tv
268 , void *act
271 JAWS_Reactive_IO::instance ()->send (handle, mb, completer, tv, act);
275 void
276 JAWS_Asynch_IO::recv ( ACE_HANDLE handle
277 , ACE_Message_Block *mb
278 , JAWS_Event_Completer *completer
279 , const ACE_Time_Value &tv
280 , void *act
283 JAWS_Reactive_IO::instance ()->recv (handle, mb, completer, tv, act);
287 void
288 JAWS_Asynch_IO::transmit ( ACE_HANDLE handle
289 , ACE_HANDLE source
290 , JAWS_Event_Completer *completer
291 , const ACE_Time_Value &tv
292 , void *act
293 , ACE_Message_Block *header
294 , ACE_Message_Block *trailer
297 JAWS_Reactive_IO::instance ()->transmit ( handle
298 , source
299 , completer
300 , tv
301 , act
302 , header
303 , trailer