Skip to content

Commit 190362f

Browse files
committed
Merge branch 'dev_tcp_client_chengxin' into 'feature_tcp_client'
【FIX】定时任务cancel需要处理错误或者捕获异常 See merge request server/openapi/openapi-cpp-sdk!28
2 parents 100d3a3 + e716672 commit 190362f

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

src/push_socket/push_socket.cpp

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,12 @@ void TIGER_API::PushSocket::disconnect()
9393
{
9494
if (keep_alive_timer_)
9595
{
96-
keep_alive_timer_->cancel();
96+
boost::system::error_code ec;
97+
keep_alive_timer_->cancel(ec);
98+
if (ec)
99+
{
100+
LOG(ERROR) << ec;
101+
}
97102
}
98103
close_session();
99104
}
@@ -171,10 +176,7 @@ unsigned int TIGER_API::PushSocket::get_next_id()
171176

172177
void TIGER_API::PushSocket::close_session()
173178
{
174-
if (reconnect_timer_)
175-
{
176-
reconnect_timer_->cancel();
177-
}
179+
cancel_reconnect_timer();
178180

179181
LOG(INFO) << "close socket";
180182
socket_state_ = SocketState::DISCONNECTED;
@@ -280,6 +282,19 @@ void TIGER_API::PushSocket::auto_reconnect()
280282
});
281283
}
282284

285+
void TIGER_API::PushSocket::cancel_reconnect_timer()
286+
{
287+
if (reconnect_timer_)
288+
{
289+
boost::system::error_code ec;
290+
reconnect_timer_->cancel(ec);
291+
if (ec)
292+
{
293+
LOG(ERROR) << ec;
294+
}
295+
}
296+
}
297+
283298
void TIGER_API::PushSocket::handle_connect(const boost::system::error_code& error, boost::asio::ip::tcp::resolver::iterator endpoint_iterator)
284299
{
285300
try
@@ -479,10 +494,7 @@ void TIGER_API::PushSocket::handle_timer(const boost::system::error_code& error)
479494
}
480495
else if (socket_state_ == SocketState::DISCONNECTED)
481496
{
482-
if (reconnect_timer_)
483-
{
484-
reconnect_timer_->cancel();
485-
}
497+
cancel_reconnect_timer();
486498
auto_reconnect();
487499
}
488500

0 commit comments

Comments
 (0)