Browse Source

处理 websocket 登录时异步回调问题

zzj 6 năm trước cách đây
mục cha
commit
be91fa8d4c
2 tập tin đã thay đổi với 10 bổ sung4 xóa
  1. 7 0
      main.cpp
  2. 3 4
      websocket/wsClient.cpp

+ 7 - 0
main.cpp

@@ -70,6 +70,11 @@ struct Init_Setting
             exit(0);
         }
 
+		{
+			std::vector<char> b(1024*1024);
+			usleep(1000*1000);
+		}
+
 		CYaSetting::Init_sys_setting();
         sit_list::instance()->load_from_db();
         card_list::instance()->init_card_from_db();
@@ -97,7 +102,9 @@ struct Init_Setting
         dp.PoolSize=DBSetting.PoolSize;
 		init_three_rates(dp);
 
+
         log_info("Init_Setting::init  Success. \n" );
+
     }
 
 	void init_three_rates(const db_para& dbs)

+ 3 - 4
websocket/wsClient.cpp

@@ -96,8 +96,6 @@ namespace YA
 
 	void wsClient::login()
 	{
-		char szError[512] = { 0 };
-
 		if ( !IsConnected() )
 		{
 			__LastError = "please connect server before login!";
@@ -121,7 +119,6 @@ namespace YA
 
 		std::this_thread::sleep_for( std::chrono::milliseconds( _LOGIN_SLEEP_TIME_ ) );
 		
-		int nRet = 0;
 		YA::_JS_LOGIN_ Login;
 		Login.user_name = JSON_VALUE_USERNAME;
 		Login.user_password = JSON_VALUE_PASSWORD;
@@ -130,8 +127,10 @@ namespace YA
 		strLogin += "\n";
 		sio::socket::ptr skt_ptr;
 		skt_ptr = __wsclient.socket();
-		skt_ptr->emit( JSON_CMD_VALUE_USER, strLogin, [&]( sio::message::list const& msglist )
+		skt_ptr->emit( JSON_CMD_VALUE_USER, strLogin, [this]( sio::message::list const& msglist )
 		{
+		    int nRet = 0;
+		    char szError[512] = { 0 };
 			sio::message::ptr msg_ptr = msglist[0];
 			nRet = ( int ) msg_ptr->get_map()["code"]->get_int();
 			if ( 0 == nRet )