提交 18b82010 编写于 作者: W wolf 提交者: youngowlf

Fix bug: if receive buffer overflow and on_msg returns false (which means using receive buffer),

 st_socket will call on_msg again and again (asynchronously) for the same msg until receive buffer becomes available.
上级 8081a77f
......@@ -19,8 +19,8 @@
#ifndef ST_ASIO_WRAPPER_H_
#define ST_ASIO_WRAPPER_H_
#define ST_ASIO_WRAPPER_VER 10101 //[x]xyyzz -> [x]x.[y]y.[z]z
#define ST_ASIO_WRAPPER_VERSION "1.1.1"
#define ST_ASIO_WRAPPER_VER 10102 //[x]xyyzz -> [x]x.[y]y.[z]z
#define ST_ASIO_WRAPPER_VERSION "1.1.2"
#ifdef _MSC_VER
#if _MSC_VER >= 1600
......
......@@ -345,35 +345,32 @@ protected:
//call this in recv_handler (in subclasses) only
void dispatch_msg()
{
bool overflow = false;
#ifndef ST_ASIO_FORCE_TO_USE_MSG_RECV_BUFFER
if (!temp_msg_buffer.empty())
{
#ifndef ST_ASIO_FORCE_TO_USE_MSG_RECV_BUFFER
if (!suspend_dispatch_msg_ && !posting)
if (suspend_dispatch_msg_ || posting)
overflow = true;
else
{
out_container_type temp_2_msg_buffer;
BOOST_AUTO(begin_time, statistic::local_time());
for (BOOST_AUTO(iter, temp_msg_buffer.begin()); iter != temp_msg_buffer.end();)
if (on_msg(*iter))
temp_msg_buffer.erase(iter++);
else
temp_2_msg_buffer.splice(temp_2_msg_buffer.end(), temp_msg_buffer, iter++);
++iter;
BOOST_AUTO(time_duration, statistic::local_time() - begin_time);
stat.handle_time_1_sum += time_duration;
stat.recv_idle_sum += time_duration;
if (!temp_2_msg_buffer.empty())
{
boost::unique_lock<boost::shared_mutex> lock(recv_msg_buffer_mutex);
if (splice_helper(recv_msg_buffer, temp_2_msg_buffer))
do_dispatch_msg(false);
}
temp_msg_buffer.splice(temp_msg_buffer.begin(), temp_2_msg_buffer);
}
#else
boost::unique_lock<boost::shared_mutex> lock(recv_msg_buffer_mutex);
if (splice_helper(recv_msg_buffer, temp_msg_buffer))
do_dispatch_msg(false);
}
#endif
if (!overflow)
{
boost::unique_lock<boost::shared_mutex> lock(recv_msg_buffer_mutex);
recv_msg_buffer.splice(recv_msg_buffer.end(), temp_msg_buffer);
overflow = recv_msg_buffer.size() > ST_ASIO_MAX_MSG_NUM;
do_dispatch_msg(false);
}
if (!overflow)
......
......@@ -37,13 +37,19 @@
* Send more msgs in one async_write call.
* Fix annotations.
*
* 2016.9.4 version 1.1.2
* Renamed proxy_buffer to auto_buffer.
* Added a new replaceable buffer shared_buffer.
* Fix bug: if receive buffer overflow and on_msg() returns false (which means using receive buffer),
* st_socket will call on_msg() again and again (asynchronously) for the same msg until receive buffer becomes available.
*
*/
#ifndef ST_ASIO_WRAPPER_H_
#define ST_ASIO_WRAPPER_H_
#define ST_ASIO_WRAPPER_VER 10101 //[x]xyyzz -> [x]x.[y]y.[z]z
#define ST_ASIO_WRAPPER_VERSION "1.1.1"
#define ST_ASIO_WRAPPER_VER 10102 //[x]xyyzz -> [x]x.[y]y.[z]z
#define ST_ASIO_WRAPPER_VERSION "1.1.2"
#ifdef _MSC_VER
static_assert(_MSC_VER >= 1600, "st_asio_wrapper must be compiled with Visual C++ 10.0 or higher.");
......
......@@ -343,35 +343,32 @@ protected:
//call this in recv_handler (in subclasses) only
void dispatch_msg()
{
auto overflow = false;
#ifndef ST_ASIO_FORCE_TO_USE_MSG_RECV_BUFFER
if (!temp_msg_buffer.empty())
{
#ifndef ST_ASIO_FORCE_TO_USE_MSG_RECV_BUFFER
if (!suspend_dispatch_msg_ && !posting)
if (suspend_dispatch_msg_ || posting)
overflow = true;
else
{
out_container_type temp_2_msg_buffer;
auto begin_time = statistic::local_time();
for (auto iter = std::begin(temp_msg_buffer); iter != std::end(temp_msg_buffer);)
if (on_msg(*iter))
temp_msg_buffer.erase(iter++);
else
temp_2_msg_buffer.splice(std::end(temp_2_msg_buffer), temp_msg_buffer, iter++);
++iter;
auto time_duration = statistic::local_time() - begin_time;
stat.handle_time_1_sum += time_duration;
stat.recv_idle_sum += time_duration;
if (!temp_2_msg_buffer.empty())
{
boost::unique_lock<boost::shared_mutex> lock(recv_msg_buffer_mutex);
if (splice_helper(recv_msg_buffer, temp_2_msg_buffer))
do_dispatch_msg(false);
}
temp_msg_buffer.splice(std::begin(temp_msg_buffer), temp_2_msg_buffer);
}
#else
boost::unique_lock<boost::shared_mutex> lock(recv_msg_buffer_mutex);
if (splice_helper(recv_msg_buffer, temp_msg_buffer))
do_dispatch_msg(false);
}
#endif
if (!overflow)
{
boost::unique_lock<boost::shared_mutex> lock(recv_msg_buffer_mutex);
recv_msg_buffer.splice(std::end(recv_msg_buffer), temp_msg_buffer);
overflow = recv_msg_buffer.size() > ST_ASIO_MAX_MSG_NUM;
do_dispatch_msg(false);
}
if (!overflow)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册