Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / apps / JAWS3 / jaws3 / Asynch_IO.cpp
blob8b894bae75aba8ef0a5da7b8c58013326ebf7f87
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);
121 JAWS_EC_AH_Adapter *
122 JAWS_EC_AH_Adapter::make (JAWS_Event_Completer *completer)
124 return new JAWS_EC_AH_Adapter (completer);
127 void
128 JAWS_EC_AH_Adapter
129 ::handle_read_stream (const ACE_Asynch_Read_Stream::Result &result)
131 JAWS_Event_Result io_result;
133 io_result = this->make_io_result ( result
134 , JAWS_Event_Result::JE_RECV_OK
135 , JAWS_Event_Result::JE_RECV_FAIL
137 // More useful diagnostics not implemented yet.
139 void *act = const_cast<void *> (result.act ());
141 this->completer_->input_complete (io_result, act);
142 delete this;
145 void
146 JAWS_EC_AH_Adapter
147 ::handle_write_stream (const ACE_Asynch_Write_Stream::Result &result)
149 JAWS_Event_Result io_result;
151 io_result = this->make_io_result ( result
152 , JAWS_Event_Result::JE_SEND_OK
153 , JAWS_Event_Result::JE_SEND_FAIL
155 // More useful diagnostics not implemented yet.
157 void *act = const_cast<void *> (result.act ());
159 this->completer_->output_complete (io_result, act);
160 delete this;
163 void
164 JAWS_EC_AH_Adapter
165 ::handle_transmit_file (const ACE_Asynch_Transmit_File::Result &result)
167 JAWS_Event_Result io_result;
169 io_result = this->make_io_result ( result
170 , JAWS_Event_Result::JE_TRANSMIT_OK
171 , JAWS_Event_Result::JE_TRANSMIT_FAIL
173 // More useful diagnostics not implemented yet.
174 // Watch out for files not opened in overlapped IO mode.
176 void *act = const_cast<void *> (result.act ());
178 this->completer_->output_complete (io_result, act);
179 delete this;
182 JAWS_Event_Result
183 JAWS_EC_AH_Adapter
184 ::make_io_result ( const ACE_Asynch_Result &result
185 , JAWS_Event_Result::JE_REASON reason_ok
186 , JAWS_Event_Result::JE_REASON reason_fail
189 size_t bytes = result.bytes_transferred ();
191 JAWS_Event_Result::JE_STATUS status;
192 JAWS_Event_Result::JE_REASON reason;
194 if (result.success ())
196 status = JAWS_Event_Result::JE_OK;
197 reason = reason_ok;
199 else
201 status = JAWS_Event_Result::JE_ERROR;
202 reason = reason_fail;
205 JAWS_Event_Result io_result (bytes, status, reason);
207 return io_result;
210 #else /* EMULATE AIO WITH REACTOR */
212 #include "jaws3/Reactive_IO.h"
214 void
215 JAWS_Asynch_IO::send ( ACE_HANDLE handle
216 , ACE_Message_Block *mb
217 , JAWS_Event_Completer *completer
218 , void *act
221 JAWS_Reactive_IO::instance ()->send (handle, mb, completer, act);
225 void
226 JAWS_Asynch_IO::recv ( ACE_HANDLE handle
227 , ACE_Message_Block *mb
228 , JAWS_Event_Completer *completer
229 , void *act
232 JAWS_Reactive_IO::instance ()->recv (handle, mb, completer, act);
236 void
237 JAWS_Asynch_IO::transmit ( ACE_HANDLE handle
238 , ACE_HANDLE source
239 , JAWS_Event_Completer *completer
240 , void *act
241 , ACE_Message_Block *header
242 , ACE_Message_Block *trailer
245 JAWS_Reactive_IO::instance ()->transmit ( handle
246 , source
247 , completer
248 , act
249 , header
250 , trailer
254 #endif /* ACE_HAS_AIO_CALLS || ACE_HAS_WIN32_OVERLAPPED_IO */
256 // For now, we will simulate timed Asynch IO with timed Reactive IO.
257 // In the future, we will implement the timed Asynch IO with timers
258 // and Asynch IO cancelation.
260 #include "jaws3/Reactive_IO.h"
262 void
263 JAWS_Asynch_IO::send ( ACE_HANDLE handle
264 , ACE_Message_Block *mb
265 , JAWS_Event_Completer *completer
266 , const ACE_Time_Value &tv
267 , void *act
270 JAWS_Reactive_IO::instance ()->send (handle, mb, completer, tv, act);
274 void
275 JAWS_Asynch_IO::recv ( ACE_HANDLE handle
276 , ACE_Message_Block *mb
277 , JAWS_Event_Completer *completer
278 , const ACE_Time_Value &tv
279 , void *act
282 JAWS_Reactive_IO::instance ()->recv (handle, mb, completer, tv, act);
286 void
287 JAWS_Asynch_IO::transmit ( ACE_HANDLE handle
288 , ACE_HANDLE source
289 , JAWS_Event_Completer *completer
290 , const ACE_Time_Value &tv
291 , void *act
292 , ACE_Message_Block *header
293 , ACE_Message_Block *trailer
296 JAWS_Reactive_IO::instance ()->transmit ( handle
297 , source
298 , completer
299 , tv
300 , act
301 , header
302 , trailer