Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / apps / JAWS3 / jaws3 / Synch_IO.cpp
blobfcf74484bd73b0394293156c0e0f49c039c86670
1 #include "ace/ACE.h"
3 #ifndef JAWS_BUILD_DLL
4 #define JAWS_BUILD_DLL
5 #endif
7 #include "jaws3/Jaws_IO.h"
8 #include "jaws3/Synch_IO.h"
9 #include "jaws3/Event_Completer.h"
11 static JAWS_Event_Result
12 JAWS_synch_send ( ACE_HANDLE handle
13 , ACE_Message_Block *mb
14 , const ACE_Time_Value *tv = 0
17 JAWS_Event_Result io_result;
19 ssize_t result = ACE::send_n (handle, mb->rd_ptr (), mb->length (), tv);
20 if (result < 0)
22 if (errno == ETIME)
24 JAWS_Event_Result tmp_io_result ( 0
25 , JAWS_Event_Result::JE_ERROR
26 , JAWS_Event_Result::JE_SEND_TIMEOUT
28 io_result = tmp_io_result;
30 else
32 JAWS_Event_Result tmp_io_result ( 0
33 , JAWS_Event_Result::JE_ERROR
34 , JAWS_Event_Result::JE_SEND_FAIL
36 io_result = tmp_io_result;
39 else if ((size_t) result < mb->length ())
41 if (result > 0)
42 mb->rd_ptr (result);
44 JAWS_Event_Result tmp_io_result ( result
45 , JAWS_Event_Result::JE_ERROR
46 , JAWS_Event_Result::JE_SEND_SHORT
48 io_result = tmp_io_result;
50 else
52 if (result > 0)
53 mb->rd_ptr (result);
55 JAWS_Event_Result tmp_io_result ( result
56 , JAWS_Event_Result::JE_OK
57 , JAWS_Event_Result::JE_SEND_OK
59 io_result = tmp_io_result;
62 return io_result;
65 void
66 JAWS_Synch_IO::send ( ACE_HANDLE handle
67 , ACE_Message_Block *mb
68 , JAWS_Event_Completer *completer
69 , const ACE_Time_Value &tv
70 , void *act
73 JAWS_Event_Result io_result;
74 const ACE_Time_Value *tvp = 0;
76 if (ACE_Time_Value::zero < tv)
77 tvp = &tv;
79 io_result = JAWS_synch_send (handle, mb, tvp);
81 if (completer)
82 completer->output_complete (io_result, act);
86 void
87 JAWS_Synch_IO::send ( ACE_HANDLE handle
88 , ACE_Message_Block *mb
89 , JAWS_Event_Completer *completer
90 , void *act
93 this->send (handle, mb, completer, ACE_Time_Value::zero, act);
97 void
98 JAWS_Synch_IO::recv ( ACE_HANDLE handle
99 , ACE_Message_Block *mb
100 , JAWS_Event_Completer *completer
101 , const ACE_Time_Value &tv
102 , void *act
105 JAWS_Event_Result io_result;
106 const ACE_Time_Value *tvp = 0;
108 if (ACE_Time_Value::zero < tv)
109 tvp = &tv;
111 ssize_t result = ACE::recv (handle, mb->wr_ptr (), mb->space (), tvp);
112 if (result < 0)
114 JAWS_Event_Result tmp_io_result ( 0
115 , JAWS_Event_Result::JE_ERROR
116 , JAWS_Event_Result::JE_RECV_FAIL
118 io_result = tmp_io_result;
120 else
122 if (result > 0)
123 mb->wr_ptr (result);
125 JAWS_Event_Result tmp_io_result ( result
126 , JAWS_Event_Result::JE_OK
127 , JAWS_Event_Result::JE_RECV_OK
129 io_result = tmp_io_result;
132 if (completer)
133 completer->input_complete (io_result, act);
137 void
138 JAWS_Synch_IO::recv ( ACE_HANDLE handle
139 , ACE_Message_Block *mb
140 , JAWS_Event_Completer *completer
141 , void *act
144 this->recv (handle, mb, completer, ACE_Time_Value::zero, act);
148 void
149 JAWS_Synch_IO::transmit ( ACE_HANDLE handle
150 , ACE_HANDLE source
151 , JAWS_Event_Completer *completer
152 , const ACE_Time_Value &tv
153 , void *act
154 , ACE_Message_Block *header
155 , ACE_Message_Block *trailer
158 JAWS_Event_Result io_result;
159 const ACE_Time_Value *tvp = 0;
161 if (ACE_Time_Value::zero < tv)
162 tvp = &tv;
164 size_t bytes = 0;
166 if (header)
168 io_result = JAWS_synch_send (handle, header, tvp);
169 bytes += io_result.bytes ();
170 if (io_result.status () != JAWS_Event_Result::JE_OK)
172 if (completer)
173 completer->input_complete (io_result, act);
175 return;
179 ACE_Message_Block buf (8 * 1024);
180 ssize_t len = 0;
181 while ((len = ACE::recv (source, buf.wr_ptr (), buf.space (), tvp)) >= 0)
183 if (len == 0)
184 break;
186 buf.wr_ptr (len);
187 io_result = JAWS_synch_send (handle, & buf);
188 bytes += io_result.bytes ();
189 if (io_result.status () != JAWS_Event_Result::JE_OK)
191 JAWS_Event_Result tmp_io_result ( bytes
192 , JAWS_Event_Result::JE_ERROR
193 , JAWS_Event_Result::JE_SEND_SHORT
196 if (completer)
197 completer->input_complete (tmp_io_result, act);
199 return;
202 buf.crunch ();
205 if (trailer)
207 io_result = JAWS_synch_send (handle, trailer, tvp);
208 bytes += io_result.bytes ();
209 if (io_result.status () != JAWS_Event_Result::JE_OK)
211 JAWS_Event_Result tmp_io_result ( bytes
212 , JAWS_Event_Result::JE_ERROR
213 , JAWS_Event_Result::JE_SEND_SHORT
216 if (completer)
217 completer->input_complete (tmp_io_result, act);
219 return;
223 if (len == 0)
225 JAWS_Event_Result tmp_io_result ( bytes
226 , JAWS_Event_Result::JE_OK
227 , JAWS_Event_Result::JE_SEND_OK
229 io_result = tmp_io_result;
231 else
233 JAWS_Event_Result tmp_io_result ( bytes
234 , JAWS_Event_Result::JE_ERROR
235 , JAWS_Event_Result::JE_SEND_SHORT
237 io_result = tmp_io_result;
240 if (completer)
241 completer->input_complete (io_result, act);
245 void
246 JAWS_Synch_IO::transmit ( ACE_HANDLE handle
247 , ACE_HANDLE source
248 , JAWS_Event_Completer *completer
249 , void *act
250 , ACE_Message_Block *header
251 , ACE_Message_Block *trailer
254 this->transmit ( handle
255 , source
256 , completer
257 , ACE_Time_Value::zero
258 , act
259 , header
260 , trailer