Sfoglia il codice sorgente

继续优化调试服务端崩溃的问题

zhangyang 5 anni fa
parent
commit
63b4baad08

+ 2 - 2
lewaimai_pos_windows_server/helper/CAliyunMNS.cpp

@@ -81,13 +81,13 @@ std::string CAliyunMNS::getMessage()
     catch(MNSServerException& me)
     catch(MNSServerException& me)
     {
     {
         cout << "Request Failed: " << me.GetErrorCode().c_str() << endl;
         cout << "Request Failed: " << me.GetErrorCode().c_str() << endl;
-        //LOG_DEBUG("Request Failed: " << me.GetErrorCode().c_str());
+        LOG_INFO("Request Failed: " << me.GetErrorCode().c_str());
         return "error!";
         return "error!";
     }
     }
     catch(MNSExceptionBase& mb)
     catch(MNSExceptionBase& mb)
     {
     {
         cout << "Request Failed: " << mb.ToString().c_str() << endl;
         cout << "Request Failed: " << mb.ToString().c_str() << endl;
-        //LOG_DEBUG("Request Failed: " << mb.ToString().c_str());
+        LOG_INFO("Request Failed: " << mb.ToString().c_str());
         return "error!";
         return "error!";
     }
     }
 }
 }

+ 3 - 1
lewaimai_pos_windows_server/main.cpp

@@ -25,8 +25,10 @@ int main()
 	catch (std::exception& e)
 	catch (std::exception& e)
 	{
 	{
 		std::cerr << "Exception: " << e.what() << "\n";
 		std::cerr << "Exception: " << e.what() << "\n";
-		LOG_INFO("Exception: " << e.what());
+		LOG_ERROR("Exception: " << e.what());
 	}
 	}
 
 
+	LOG_ERROR("ready to exit program");
+
 	return 0;
 	return 0;
 }
 }

+ 27 - 4
lewaimai_pos_windows_server/network/CServer.cpp

@@ -10,12 +10,15 @@ CServer::CServer()
 
 
 CServer::~CServer()
 CServer::~CServer()
 {
 {
+	LOG_ERROR("start ~CServer");
 	delete acceptor_;
 	delete acceptor_;
 
 
 	if (m_db != NULL)
 	if (m_db != NULL)
 	{
 	{
 		sqlite3_close(m_db);
 		sqlite3_close(m_db);
 	}
 	}
+
+	LOG_ERROR("end ~CServer");
 }
 }
 
 
 void CServer::Init()
 void CServer::Init()
@@ -62,8 +65,19 @@ void CServer::Init()
 		t.detach();
 		t.detach();
 	}
 	}
 
 
-	//开始异步执行
-	io_context_.run();
+	LOG_ERROR("ready to run");
+
+	try
+	{
+		//开始异步执行
+		io_context_.run();
+	}
+	catch (std::exception& e)
+	{
+		LOG_ERROR("io_context Exception: " << e.what());
+	}
+
+	LOG_ERROR("stop run");
 }
 }
 
 
 void CServer::InitSqlLite()
 void CServer::InitSqlLite()
@@ -282,12 +296,15 @@ void CServer::start_accept()
 void CServer::handle_accept(CClientSession* new_session,
 void CServer::handle_accept(CClientSession* new_session,
 	const boost::system::error_code& error)
 	const boost::system::error_code& error)
 {
 {
+	//LOG_INFO("new client, handle_accept!");
+
 	if (!error)
 	if (!error)
 	{
 	{
 		new_session->start();
 		new_session->start();
 	}
 	}
 	else
 	else
 	{
 	{
+		LOG_ERROR("handle_accept error");
 		delete new_session;
 		delete new_session;
 	}
 	}
 
 
@@ -311,6 +328,8 @@ void CServer::BindUsername(std::string username, CClientSession* session)
 	m_clients_map[username] = session;
 	m_clients_map[username] = session;
 
 
 	m_map_mutex.unlock();
 	m_map_mutex.unlock();
+
+	LOG_INFO("绑定新客户端成功,当前客户端数量:" << m_clients_map.size());
 }
 }
 
 
 void CServer::DeleteClient(std::string username)
 void CServer::DeleteClient(std::string username)
@@ -323,6 +342,8 @@ void CServer::DeleteClient(std::string username)
 	}
 	}
 
 
 	m_map_mutex.unlock();
 	m_map_mutex.unlock();
+
+	LOG_INFO("删除客户端成功,当前客户端数量:" << m_clients_map.size());
 }
 }
 
 
 /*
 /*
@@ -349,13 +370,15 @@ void CServer::ReceiveMNSMessage()
             continue;
             continue;
         }
         }
 
 
+		//LOG_INFO("new msn message:" << message.c_str());
+
         //获取到了新的消息,开始进行处理
         //获取到了新的消息,开始进行处理
         rapidjson::Document document;
         rapidjson::Document document;
         document.Parse(message.c_str());
         document.Parse(message.c_str());
         if(!document.IsObject())
         if(!document.IsObject())
         {
         {
-            LOG_ERROR("message 非法!");
-			LOG_ERROR("get new message:" << message.c_str());
+            LOG_INFO("message 非法!");
+			LOG_INFO("get new message:" << message.c_str());
             continue;
             continue;
         }
         }