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"
17 JAWS_Asynch_IO::send ( ACE_HANDLE handle
18 , ACE_Message_Block
*mb
19 , JAWS_Event_Completer
*completer
23 JAWS_EC_AH_Adapter
*jecaha
;
24 jecaha
= JAWS_EC_AH_Adapter::make (completer
);
26 ACE_Asynch_Write_Stream asynch_write_stream
;
29 || asynch_write_stream
.open (*jecaha
, handle
) == -1
30 || asynch_write_stream
.write (*mb
, mb
->length (), act
) == -1)
33 JAWS_Event_Result
io_result ( 0
34 , JAWS_Event_Result::JE_ERROR
35 , JAWS_Event_Result::JE_SEND_FAIL
39 completer
->output_complete (io_result
, act
);
45 JAWS_Asynch_IO::recv ( ACE_HANDLE handle
46 , ACE_Message_Block
*mb
47 , JAWS_Event_Completer
*completer
51 JAWS_EC_AH_Adapter
*jecaha
;
52 jecaha
= JAWS_EC_AH_Adapter::make (completer
);
54 ACE_Asynch_Read_Stream asynch_read_stream
;
57 || asynch_read_stream
.open (*jecaha
, handle
) == -1
58 || asynch_read_stream
.read (*mb
, mb
->space (), act
) == -1)
61 JAWS_Event_Result
io_result ( 0
62 , JAWS_Event_Result::JE_ERROR
63 , JAWS_Event_Result::JE_RECV_FAIL
67 completer
->output_complete (io_result
, act
);
73 JAWS_Asynch_IO::transmit ( ACE_HANDLE handle
75 , JAWS_Event_Completer
*completer
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;
86 new ACE_Asynch_Transmit_File::Header_And_Trailer ( header
92 ACE_Asynch_Transmit_File asynch_transmit_file
;
94 if (source
== ACE_INVALID_HANDLE
96 || header_and_trailer
== 0
97 || asynch_transmit_file
.open (*jecaha
, handle
) == -1
98 || asynch_transmit_file
.transmit_file ( source
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
116 completer
->output_complete (io_result
, act
);
122 JAWS_EC_AH_Adapter::make (JAWS_Event_Completer
*completer
)
124 return new JAWS_EC_AH_Adapter (completer
);
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
);
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
);
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
);
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
;
201 status
= JAWS_Event_Result::JE_ERROR
;
202 reason
= reason_fail
;
205 JAWS_Event_Result
io_result (bytes
, status
, reason
);
210 #else /* EMULATE AIO WITH REACTOR */
212 #include "jaws3/Reactive_IO.h"
215 JAWS_Asynch_IO::send ( ACE_HANDLE handle
216 , ACE_Message_Block
*mb
217 , JAWS_Event_Completer
*completer
221 JAWS_Reactive_IO::instance ()->send (handle
, mb
, completer
, act
);
226 JAWS_Asynch_IO::recv ( ACE_HANDLE handle
227 , ACE_Message_Block
*mb
228 , JAWS_Event_Completer
*completer
232 JAWS_Reactive_IO::instance ()->recv (handle
, mb
, completer
, act
);
237 JAWS_Asynch_IO::transmit ( ACE_HANDLE handle
239 , JAWS_Event_Completer
*completer
241 , ACE_Message_Block
*header
242 , ACE_Message_Block
*trailer
245 JAWS_Reactive_IO::instance ()->transmit ( handle
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"
263 JAWS_Asynch_IO::send ( ACE_HANDLE handle
264 , ACE_Message_Block
*mb
265 , JAWS_Event_Completer
*completer
266 , const ACE_Time_Value
&tv
270 JAWS_Reactive_IO::instance ()->send (handle
, mb
, completer
, tv
, act
);
275 JAWS_Asynch_IO::recv ( ACE_HANDLE handle
276 , ACE_Message_Block
*mb
277 , JAWS_Event_Completer
*completer
278 , const ACE_Time_Value
&tv
282 JAWS_Reactive_IO::instance ()->recv (handle
, mb
, completer
, tv
, act
);
287 JAWS_Asynch_IO::transmit ( ACE_HANDLE handle
289 , JAWS_Event_Completer
*completer
290 , const ACE_Time_Value
&tv
292 , ACE_Message_Block
*header
293 , ACE_Message_Block
*trailer
296 JAWS_Reactive_IO::instance ()->transmit ( handle