@@ -65,6 +65,8 @@ void TIGER_API::PushSocket::connect()
6565
6666 try
6767 {
68+ socket_state_ = SocketState::CONNECTING;
69+
6870 boost::asio::ip::tcp::resolver resolver (*io_service_);
6971 boost::asio::ip::tcp::resolver::query query (utility::conversions::to_utf8string (client_config_.socket_url ),
7072 utility::conversions::to_utf8string (client_config_.socket_port ));
@@ -78,12 +80,11 @@ void TIGER_API::PushSocket::connect()
7880
7981 socket_->lowest_layer ().async_connect (*rit,
8082 boost::bind (&PushSocket::handle_connect, this , boost::asio::placeholders::error, ++rit));
81-
82- socket_state_ = SocketState::CONNECTING;
8383 }
8484 catch (const boost::system::system_error& e)
8585 {
8686 LOG (ERROR) << e.what ();
87+ // dns解析失败/异常连接状态修改为:DISCONNECTED
8788 socket_state_ = SocketState::DISCONNECTED;
8889 }
8990}
@@ -275,10 +276,6 @@ void TIGER_API::PushSocket::auto_reconnect()
275276 {
276277 LOG (ERROR) << " reconnection timer error: " << error.message ();
277278 socket_state_ = SocketState::DISCONNECTED;
278- if (reconnect_timer_)
279- {
280- reconnect_timer_->cancel ();
281- }
282279 }
283280 });
284281}
@@ -346,7 +343,7 @@ void TIGER_API::PushSocket::handle_handshake(const boost::system::error_code& er
346343 }
347344 else
348345 {
349- LOG (ERROR) << " Handshake Failed : " << error;
346+ LOG (ERROR) << " [handshake failed] : " << error;
350347 // 握手失败关闭会话
351348 dispatch_inner_error_callback (error.message ());
352349 close_session ();
@@ -381,8 +378,7 @@ void TIGER_API::PushSocket::handle_read_head(const boost::system::error_code& er
381378 close_session ();
382379 }
383380 else
384- {
385-
381+ {
386382#if 1
387383 // 循环打印每个字节的二进制值
388384 for (size_t i = 0 ; i < bytes_transferred; ++i)
@@ -417,6 +413,10 @@ void TIGER_API::PushSocket::handle_read_body(const boost::system::error_code& er
417413 LOG (ERROR) << " [read body failed]: " << error;
418414 dispatch_inner_error_callback (error.message ());
419415 close_session ();
416+ if (recv_buff)
417+ {
418+ recv_buff_pool_->ordered_free (recv_buff, page_num);
419+ }
420420 return ;
421421 }
422422
@@ -426,6 +426,10 @@ void TIGER_API::PushSocket::handle_read_body(const boost::system::error_code& er
426426 if (!response_pb_object->ParseFromArray (recv_buff, frame_len))
427427 {
428428 close_session ();
429+ if (recv_buff)
430+ {
431+ recv_buff_pool_->ordered_free (recv_buff, page_num);
432+ }
429433 return ;
430434 }
431435#if 1
@@ -475,6 +479,10 @@ void TIGER_API::PushSocket::handle_timer(const boost::system::error_code& error)
475479 }
476480 else if (socket_state_ == SocketState::DISCONNECTED)
477481 {
482+ if (reconnect_timer_)
483+ {
484+ reconnect_timer_->cancel ();
485+ }
478486 auto_reconnect ();
479487 }
480488
0 commit comments