| 1236 | } |
| 1237 | |
| 1238 | void OnReadSome(const TErrorCode& ec, size_t amount, IHandlingContext& ctx) { |
| 1239 | while (1) { |
| 1240 | if (ec || !amount) { |
| 1241 | OnError(); |
| 1242 | return; |
| 1243 | } |
| 1244 | |
| 1245 | try { |
| 1246 | const char* buff = Buff_.Get(); |
| 1247 | size_t leftBytes = amount; |
| 1248 | do { |
| 1249 | size_t useBytes = Msg_.LoadFrom(buff, leftBytes); |
| 1250 | leftBytes -= useBytes; |
| 1251 | buff += useBytes; |
| 1252 | if (Msg_.IsComplete()) { |
| 1253 | OnReceiveMessage(); |
| 1254 | } |
| 1255 | } while (leftBytes); |
| 1256 | |
| 1257 | if (amount == BuffSize_) { |
| 1258 | //try decrease system calls, - re-run ReadSome if has full filled buffer |
| 1259 | TErrorCode ecR; |
| 1260 | amount = AS_->ReadSome(Buff_.Get(), BuffSize_, ecR); |
| 1261 | if (!ecR) { |
| 1262 | continue; |
| 1263 | } |
| 1264 | if (ecR.Value() == EAGAIN || ecR.Value() == EWOULDBLOCK) { |
| 1265 | ctx.ContinueUseHandler(); |
| 1266 | } else { |
| 1267 | OnError(); |
| 1268 | } |
| 1269 | } else { |
| 1270 | ctx.ContinueUseHandler(); |
| 1271 | } |
| 1272 | } catch (...) { |
| 1273 | DBGOUT("exc. " << CurrentExceptionMessage()); |
| 1274 | OnError(); |
| 1275 | } |
| 1276 | return; |
| 1277 | } |
| 1278 | } |
| 1279 | |
| 1280 | void OnReceiveMessage() { |
| 1281 | DBGOUT("OnReceiveMessage()"); |
nothing calls this directly
no test coverage detected