diff --git a/include/ascs/ext/unpacker.h b/include/ascs/ext/unpacker.h index 46e3c3297ea7a002a1d7c295154dc66c1db05d3a..ad5fdcf5b8754c95c057c62ab16682a8da118af8 100644 --- a/include/ascs/ext/unpacker.h +++ b/include/ascs/ext/unpacker.h @@ -197,7 +197,13 @@ public: { if (0 == step) //the head been received { - assert(!raw_buff.empty()); + assert(raw_buff.empty() && ASCS_HEAD_LEN == bytes_transferred); + + auto cur_msg_len = ASCS_HEAD_N2H(head) - ASCS_HEAD_LEN; + if (cur_msg_len > ASCS_MSG_BUFFER_SIZE - ASCS_HEAD_LEN) //invalid msg, stop reading + return false; + + raw_buff.assign(cur_msg_len); assert(!raw_buff.empty()); step = 1; } else if (1 == step) //the body been received @@ -211,7 +217,7 @@ public: step = 0; } - return -1 != step; + return true; } //a return value of 0 indicates that the read operation is complete. a non-zero value indicates the maximum number @@ -224,16 +230,7 @@ public: if (0 == step) //want the head { assert(raw_buff.empty()); - - if (bytes_transferred < ASCS_HEAD_LEN) - return asio::detail::default_max_transfer_size; - - assert(ASCS_HEAD_LEN == bytes_transferred); - auto cur_msg_len = ASCS_HEAD_N2H(head) - ASCS_HEAD_LEN; - if (cur_msg_len > ASCS_MSG_BUFFER_SIZE - ASCS_HEAD_LEN) //invalid msg, stop reading - step = -1; - else - raw_buff.assign(cur_msg_len); + return asio::detail::default_max_transfer_size; } else if (1 == step) //want the body { diff --git a/include/ascs/service_pump.h b/include/ascs/service_pump.h index 0ba8a0aa0bd7520abee14c7694a4c497cf90d827..f9efeaef8f6f81040a55b236e93ff917eeeb6c3a 100644 --- a/include/ascs/service_pump.h +++ b/include/ascs/service_pump.h @@ -175,14 +175,14 @@ protected: virtual bool on_exception(const std::exception& e) { unified_out::error_out("service pump exception: %s.", e.what()); - return true; //continue this io_service::run, if needed, rewrite this to decide whether to continue or not + return true; //continue this asio::io_service::run, if needed, rewrite this to decide whether to continue or not } size_t run(asio::error_code& ec) { while (true) { - try {return io_service::run(ec);} + try {return asio::io_service::run(ec);} catch (const std::exception& e) {if (!on_exception(e)) return 0;} } }