修改websdk,同时支持新版和旧版接口
This commit is contained in:
parent
1a9a1cabcc
commit
73f6dbc9f3
|
@ -21,49 +21,52 @@ static void HGAPI CrashFunc(HGPointer crashAddr, HGPointer param)
|
||||||
HGBase_MakeCrashFile(logPath);
|
HGBase_MakeCrashFile(logPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void HGAPI ThreadFunc(HGThread thread, HGPointer param)
|
static void HGAPI ThreadFuncV1(HGThread thread, HGPointer param)
|
||||||
|
{
|
||||||
|
(void)thread;
|
||||||
|
HGMsgPump msgPump = (HGMsgPump)param;
|
||||||
|
|
||||||
|
HGChar cfgPath[256];
|
||||||
|
HGBase_GetConfigPath(cfgPath, 256);
|
||||||
|
HGChar cfgName[256];
|
||||||
|
sprintf(cfgName, "%s%s", cfgPath, "config.ini");
|
||||||
|
|
||||||
|
ver_1::ManagerV1 manager(msgPump);
|
||||||
|
ver_1::HttpServer httpServer(msgPump, &manager);
|
||||||
|
ver_1::SockIoServer sockIoServer(msgPump, &manager);
|
||||||
|
|
||||||
|
if (httpServer.Open(18999))
|
||||||
|
{
|
||||||
|
if (sockIoServer.Open(28999))
|
||||||
|
{
|
||||||
|
HGBase_RunMsgPump(msgPump, ver_1::HGMsgPumpCallback, NULL);
|
||||||
|
sockIoServer.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
httpServer.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void HGAPI ThreadFuncV2(HGThread thread, HGPointer param)
|
||||||
{
|
{
|
||||||
(void)thread;
|
(void)thread;
|
||||||
HGMsgPump msgPump = (HGMsgPump)param;
|
HGMsgPump msgPump = (HGMsgPump)param;
|
||||||
|
|
||||||
HGChar cfgPath[256];
|
HGChar cfgPath[256];
|
||||||
HGBase_GetConfigPath(cfgPath, 256);
|
HGBase_GetConfigPath(cfgPath, 256);
|
||||||
|
|
||||||
HGChar cfgName[256];
|
HGChar cfgName[256];
|
||||||
sprintf(cfgName, "%s%s", cfgPath, "config.ini");
|
sprintf(cfgName, "%s%s", cfgPath, "config2.ini");
|
||||||
HGInt verNum = 2;
|
|
||||||
HGBase_GetProfileInt(cfgName, "version", "verNum", 2, &verNum);
|
|
||||||
if (1 == verNum) // 使用V1版本接口
|
|
||||||
{
|
|
||||||
ver_1::ManagerV1 manager(msgPump);
|
|
||||||
ver_1::HttpServer httpServer(msgPump, &manager);
|
|
||||||
ver_1::SockIoServer sockIoServer(msgPump, &manager);
|
|
||||||
|
|
||||||
if (httpServer.Open(18999))
|
ver_2::ManagerV2 manager(msgPump);
|
||||||
{
|
ver_2::WSServer wsServer(msgPump, &manager);
|
||||||
if (sockIoServer.Open(28999))
|
|
||||||
{
|
|
||||||
HGBase_RunMsgPump(msgPump, ver_1::HGMsgPumpCallback, NULL);
|
|
||||||
sockIoServer.Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
httpServer.Close();
|
HGInt port = 38999;
|
||||||
}
|
HGBase_GetProfileInt(cfgName, "connect", "port", 38999, &port);
|
||||||
}
|
if (wsServer.Open(port))
|
||||||
else // 使用V2版本接口
|
{
|
||||||
{
|
HGBase_RunMsgPump(msgPump, ver_2::HGMsgPumpCallback, NULL);
|
||||||
ver_2::ManagerV2 manager(msgPump);
|
wsServer.Close();
|
||||||
ver_2::WSServer wsServer(msgPump, &manager);
|
}
|
||||||
|
|
||||||
sprintf(cfgName, "%s%s", cfgPath, "config2.ini");
|
|
||||||
HGInt port = 38999;
|
|
||||||
HGBase_GetProfileInt(cfgName, "connect", "port", 38999, &port);
|
|
||||||
if (wsServer.Open(port))
|
|
||||||
{
|
|
||||||
HGBase_RunMsgPump(msgPump, ver_2::HGMsgPumpCallback, NULL);
|
|
||||||
wsServer.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(HG_CMP_MSC)
|
#if defined(HG_CMP_MSC)
|
||||||
|
@ -114,10 +117,16 @@ int main()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
curl_global_init(CURL_GLOBAL_ALL);
|
curl_global_init(CURL_GLOBAL_ALL);
|
||||||
HGMsgPump msgPump = NULL;
|
|
||||||
HGBase_CreateMsgPump(&msgPump);
|
HGMsgPump msgPumpV1 = NULL;
|
||||||
HGThread thread = NULL;
|
HGBase_CreateMsgPump(&msgPumpV1);
|
||||||
HGBase_OpenThread(ThreadFunc, msgPump, &thread);
|
HGThread threadV1 = NULL;
|
||||||
|
HGBase_OpenThread(ThreadFuncV1, msgPumpV1, &threadV1);
|
||||||
|
|
||||||
|
HGMsgPump msgPumpV2 = NULL;
|
||||||
|
HGBase_CreateMsgPump(&msgPumpV2);
|
||||||
|
HGThread threadV2 = NULL;
|
||||||
|
HGBase_OpenThread(ThreadFuncV2, msgPumpV2, &threadV2);
|
||||||
|
|
||||||
#if defined(HG_CMP_MSC)
|
#if defined(HG_CMP_MSC)
|
||||||
WNDCLASSA wc = { 0 };
|
WNDCLASSA wc = { 0 };
|
||||||
|
@ -157,10 +166,15 @@ int main()
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
HGBase_CloseThread(thread);
|
HGBase_CloseThread(threadV2);
|
||||||
thread = NULL;
|
threadV2 = NULL;
|
||||||
HGBase_DestroyMsgPump(msgPump);
|
HGBase_DestroyMsgPump(msgPumpV2);
|
||||||
msgPump = NULL;
|
msgPumpV2 = NULL;
|
||||||
|
HGBase_CloseThread(threadV1);
|
||||||
|
threadV1 = NULL;
|
||||||
|
HGBase_DestroyMsgPump(msgPumpV1);
|
||||||
|
msgPumpV1 = NULL;
|
||||||
|
|
||||||
curl_global_cleanup();
|
curl_global_cleanup();
|
||||||
|
|
||||||
#if defined(HG_CMP_MSC)
|
#if defined(HG_CMP_MSC)
|
||||||
|
|
Loading…
Reference in New Issue