1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
|
// $Id: Synch_IO.cpp 85419 2009-05-22 10:52:11Z johnnyw $
#include "ace/ACE.h"
#ifndef JAWS_BUILD_DLL
#define JAWS_BUILD_DLL
#endif
#include "jaws3/Jaws_IO.h"
#include "jaws3/Synch_IO.h"
#include "jaws3/Event_Completer.h"
static JAWS_Event_Result
JAWS_synch_send ( ACE_HANDLE handle
, ACE_Message_Block *mb
, const ACE_Time_Value *tv = 0
)
{
JAWS_Event_Result io_result;
ssize_t result = ACE::send_n (handle, mb->rd_ptr (), mb->length (), tv);
if (result < 0)
{
if (errno == ETIME)
{
JAWS_Event_Result tmp_io_result ( 0
, JAWS_Event_Result::JE_ERROR
, JAWS_Event_Result::JE_SEND_TIMEOUT
);
io_result = tmp_io_result;
}
else
{
JAWS_Event_Result tmp_io_result ( 0
, JAWS_Event_Result::JE_ERROR
, JAWS_Event_Result::JE_SEND_FAIL
);
io_result = tmp_io_result;
}
}
else if ((size_t) result < mb->length ())
{
if (result > 0)
mb->rd_ptr (result);
JAWS_Event_Result tmp_io_result ( result
, JAWS_Event_Result::JE_ERROR
, JAWS_Event_Result::JE_SEND_SHORT
);
io_result = tmp_io_result;
}
else
{
if (result > 0)
mb->rd_ptr (result);
JAWS_Event_Result tmp_io_result ( result
, JAWS_Event_Result::JE_OK
, JAWS_Event_Result::JE_SEND_OK
);
io_result = tmp_io_result;
}
return io_result;
}
void
JAWS_Synch_IO::send ( ACE_HANDLE handle
, ACE_Message_Block *mb
, JAWS_Event_Completer *completer
, const ACE_Time_Value &tv
, void *act
)
{
JAWS_Event_Result io_result;
const ACE_Time_Value *tvp = 0;
if (ACE_Time_Value::zero < tv)
tvp = &tv;
io_result = JAWS_synch_send (handle, mb, tvp);
if (completer)
completer->output_complete (io_result, act);
}
void
JAWS_Synch_IO::send ( ACE_HANDLE handle
, ACE_Message_Block *mb
, JAWS_Event_Completer *completer
, void *act
)
{
this->send (handle, mb, completer, ACE_Time_Value::zero, act);
}
void
JAWS_Synch_IO::recv ( ACE_HANDLE handle
, ACE_Message_Block *mb
, JAWS_Event_Completer *completer
, const ACE_Time_Value &tv
, void *act
)
{
JAWS_Event_Result io_result;
const ACE_Time_Value *tvp = 0;
if (ACE_Time_Value::zero < tv)
tvp = &tv;
ssize_t result = ACE::recv (handle, mb->wr_ptr (), mb->space (), tvp);
if (result < 0)
{
JAWS_Event_Result tmp_io_result ( 0
, JAWS_Event_Result::JE_ERROR
, JAWS_Event_Result::JE_RECV_FAIL
);
io_result = tmp_io_result;
}
else
{
if (result > 0)
mb->wr_ptr (result);
JAWS_Event_Result tmp_io_result ( result
, JAWS_Event_Result::JE_OK
, JAWS_Event_Result::JE_RECV_OK
);
io_result = tmp_io_result;
}
if (completer)
completer->input_complete (io_result, act);
}
void
JAWS_Synch_IO::recv ( ACE_HANDLE handle
, ACE_Message_Block *mb
, JAWS_Event_Completer *completer
, void *act
)
{
this->recv (handle, mb, completer, ACE_Time_Value::zero, act);
}
void
JAWS_Synch_IO::transmit ( ACE_HANDLE handle
, ACE_HANDLE source
, JAWS_Event_Completer *completer
, const ACE_Time_Value &tv
, void *act
, ACE_Message_Block *header
, ACE_Message_Block *trailer
)
{
JAWS_Event_Result io_result;
const ACE_Time_Value *tvp = 0;
if (ACE_Time_Value::zero < tv)
tvp = &tv;
size_t bytes = 0;
if (header)
{
io_result = JAWS_synch_send (handle, header, tvp);
bytes += io_result.bytes ();
if (io_result.status () != JAWS_Event_Result::JE_OK)
{
if (completer)
completer->input_complete (io_result, act);
return;
}
}
ACE_Message_Block buf (8 * 1024);
ssize_t len = 0;
while ((len = ACE::recv (source, buf.wr_ptr (), buf.space (), tvp)) >= 0)
{
if (len == 0)
break;
buf.wr_ptr (len);
io_result = JAWS_synch_send (handle, & buf);
bytes += io_result.bytes ();
if (io_result.status () != JAWS_Event_Result::JE_OK)
{
JAWS_Event_Result tmp_io_result ( bytes
, JAWS_Event_Result::JE_ERROR
, JAWS_Event_Result::JE_SEND_SHORT
);
if (completer)
completer->input_complete (tmp_io_result, act);
return;
}
buf.crunch ();
}
if (trailer)
{
io_result = JAWS_synch_send (handle, trailer, tvp);
bytes += io_result.bytes ();
if (io_result.status () != JAWS_Event_Result::JE_OK)
{
JAWS_Event_Result tmp_io_result ( bytes
, JAWS_Event_Result::JE_ERROR
, JAWS_Event_Result::JE_SEND_SHORT
);
if (completer)
completer->input_complete (tmp_io_result, act);
return;
}
}
if (len == 0)
{
JAWS_Event_Result tmp_io_result ( bytes
, JAWS_Event_Result::JE_OK
, JAWS_Event_Result::JE_SEND_OK
);
io_result = tmp_io_result;
}
else
{
JAWS_Event_Result tmp_io_result ( bytes
, JAWS_Event_Result::JE_ERROR
, JAWS_Event_Result::JE_SEND_SHORT
);
io_result = tmp_io_result;
}
if (completer)
completer->input_complete (io_result, act);
}
void
JAWS_Synch_IO::transmit ( ACE_HANDLE handle
, ACE_HANDLE source
, JAWS_Event_Completer *completer
, void *act
, ACE_Message_Block *header
, ACE_Message_Block *trailer
)
{
this->transmit ( handle
, source
, completer
, ACE_Time_Value::zero
, act
, header
, trailer
);
}
|