Skip to content

Commit 8c4ef87

Browse files
committed
delete:APIHelp_Distributed_IsMode function
modify:APIHelp_Distributed_RandomAddr support loadbalance mode selection
1 parent 3a175a0 commit 8c4ef87

File tree

5 files changed

+47
-76
lines changed

5 files changed

+47
-76
lines changed

XEngine_Source/StorageModule_APIHelp/APIHelp_Define.h

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,6 @@ extern "C" DWORD StorageHelp_GetLastError(int* pInt_SysError = NULL);
2323
/* 分布式函数 */
2424
/************************************************************************/
2525
/********************************************************************
26-
函数名称:APIHelp_Distributed_IsMode
27-
函数功能:判断负载模式是否为指定模式
28-
参数.一:pStl_ListMode
29-
In/Out:In
30-
类型:STL容器指针
31-
可空:N
32-
意思:输入支持的模式列表
33-
参数.二:nMode
34-
In/Out:In
35-
类型:整数型
36-
可空:N
37-
意思:输入要判断的模式
38-
返回值
39-
类型:逻辑型
40-
意思:是否成功
41-
备注:
42-
*********************************************************************/
43-
extern "C" BOOL APIHelp_Distributed_IsMode(list<int>*pStl_ListMode, int nMode);
44-
/********************************************************************
4526
函数名称:APIHelp_Distributed_RandomAddr
4627
函数功能:随机选择一个负载的重定向服务器地址
4728
参数.一:pStl_ListAddr
@@ -54,12 +35,17 @@ extern "C" BOOL APIHelp_Distributed_IsMode(list<int>*pStl_ListMode, int nMode);
5435
类型:字符指针
5536
可空:N
5637
意思:输出获取到的负载地址
38+
参数.三:nMode
39+
In/Out:Out
40+
类型:整数型
41+
可空:N
42+
意思:负载模式
5743
返回值
5844
类型:逻辑型
5945
意思:是否成功
6046
备注:
6147
*********************************************************************/
62-
extern "C" BOOL APIHelp_Distributed_RandomAddr(list<string>* pStl_ListAddr, TCHAR* ptszAddr);
48+
extern "C" BOOL APIHelp_Distributed_RandomAddr(list<string>* pStl_ListAddr, TCHAR* ptszAddr, int nMode);
6349
/********************************************************************
6450
函数名称:APIHelp_Distributed_FileList
6551
函数功能:解析所有解析到的内容并且打包成指定结构

XEngine_Source/StorageModule_APIHelp/APIHelp_Distributed/APIHelp_Distributed.cpp

Lines changed: 38 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -23,40 +23,6 @@ CAPIHelp_Distributed::~CAPIHelp_Distributed()
2323
// 公有函数
2424
//////////////////////////////////////////////////////////////////////////
2525
/********************************************************************
26-
函数名称:APIHelp_Distributed_IsMode
27-
函数功能:判断负载模式是否为指定模式
28-
参数.一:pStl_ListMode
29-
In/Out:In
30-
类型:STL容器指针
31-
可空:N
32-
意思:输入支持的模式列表
33-
参数.二:nMode
34-
In/Out:In
35-
类型:整数型
36-
可空:N
37-
意思:输入要判断的模式
38-
返回值
39-
类型:逻辑型
40-
意思:是否成功
41-
备注:
42-
*********************************************************************/
43-
BOOL CAPIHelp_Distributed::APIHelp_Distributed_IsMode(list<int>* pStl_ListMode, int nMode)
44-
{
45-
APIHelp_IsErrorOccur = FALSE;
46-
47-
BOOL bFound = FALSE;
48-
list<int>::const_iterator stl_ListIterator = pStl_ListMode->begin();
49-
for (; stl_ListIterator != pStl_ListMode->end(); stl_ListIterator++)
50-
{
51-
if (nMode == *stl_ListIterator)
52-
{
53-
bFound = TRUE;
54-
break;
55-
}
56-
}
57-
return bFound;
58-
}
59-
/********************************************************************
6026
函数名称:APIHelp_Distributed_RandomAddr
6127
函数功能:随机选择一个负载的重定向服务器地址
6228
参数.一:pStl_ListAddr
@@ -69,33 +35,58 @@ BOOL CAPIHelp_Distributed::APIHelp_Distributed_IsMode(list<int>* pStl_ListMode,
6935
类型:字符指针
7036
可空:N
7137
意思:输出获取到的负载地址
38+
参数.三:nMode
39+
In/Out:Out
40+
类型:整数型
41+
可空:N
42+
意思:负载模式
7243
返回值
7344
类型:逻辑型
7445
意思:是否成功
7546
备注:
7647
*********************************************************************/
77-
BOOL CAPIHelp_Distributed::APIHelp_Distributed_RandomAddr(list<string>* pStl_ListAddr, TCHAR* ptszAddr)
48+
BOOL CAPIHelp_Distributed::APIHelp_Distributed_RandomAddr(list<string>* pStl_ListAddr, TCHAR* ptszAddr, int nMode)
7849
{
7950
APIHelp_IsErrorOccur = FALSE;
8051

81-
BOOL bFound = FALSE;
82-
XNETHANDLE xhToken = 0;
83-
84-
BaseLib_OperatorHandle_Create(&xhToken, 0, pStl_ListAddr->size(), FALSE);
85-
if (xhToken == pStl_ListAddr->size())
52+
if (!pStl_ListAddr->empty())
8653
{
87-
xhToken--;
54+
APIHelp_IsErrorOccur = TRUE;
55+
APIHelp_dwErrorCode = ERROR_STORAGE_MODULE_APIHELP_PARAMENT;
56+
return FALSE;
8857
}
89-
list<string>::const_iterator stl_ListIterator = pStl_ListAddr->begin();
90-
for (XNETHANDLE i = 0; stl_ListIterator != pStl_ListAddr->end(); stl_ListIterator++, i++)
58+
59+
BOOL bFound = FALSE;
60+
if (0 == nMode)
9161
{
92-
if (xhToken == i)
62+
XNETHANDLE xhToken = 0;
63+
BaseLib_OperatorHandle_Create(&xhToken, 0, pStl_ListAddr->size(), FALSE);
64+
if (xhToken == pStl_ListAddr->size())
9365
{
94-
bFound = TRUE;
95-
_tcscpy(ptszAddr, stl_ListIterator->c_str());
96-
break;
66+
xhToken--;
67+
}
68+
list<string>::const_iterator stl_ListIterator = pStl_ListAddr->begin();
69+
for (XNETHANDLE i = 0; stl_ListIterator != pStl_ListAddr->end(); stl_ListIterator++, i++)
70+
{
71+
if (xhToken == i)
72+
{
73+
bFound = TRUE;
74+
_tcscpy(ptszAddr, stl_ListIterator->c_str());
75+
break;
76+
}
9777
}
9878
}
79+
else if (1 == nMode)
80+
{
81+
bFound = TRUE;
82+
_tcscpy(ptszAddr, pStl_ListAddr->front().c_str());
83+
}
84+
else if (2 == nMode)
85+
{
86+
87+
bFound = TRUE;
88+
_tcscpy(ptszAddr, pStl_ListAddr->back().c_str());
89+
}
9990
return bFound;
10091
}
10192
/********************************************************************

XEngine_Source/StorageModule_APIHelp/APIHelp_Distributed/APIHelp_Distributed.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ class CAPIHelp_Distributed
1818
CAPIHelp_Distributed();
1919
~CAPIHelp_Distributed();
2020
public:
21-
BOOL APIHelp_Distributed_IsMode(list<int>* pStl_ListMode, int nMode);
22-
BOOL APIHelp_Distributed_RandomAddr(list<string>* pStl_ListAddr, TCHAR* ptszAddr);
21+
BOOL APIHelp_Distributed_RandomAddr(list<string>* pStl_ListAddr, TCHAR* ptszAddr, int nMode);
2322
BOOL APIHelp_Distributed_FileList(list<APIHELP_LBFILEINFO>* pStl_ListParse, XSTORAGECORE_DBFILE*** pppSt_ListPacket, int* pInt_ListCount);
2423
BOOL APIHelp_Distributed_DLStorage(LPCTSTR lpszMsgBuffer, list<XENGINE_STORAGEBUCKET>* pStl_ListBucket, XENGINE_STORAGEBUCKET* pSt_StorageBucket);
2524
BOOL APIHelp_Distributed_UPStorage(list<XENGINE_STORAGEBUCKET>* pStl_ListBucket, XENGINE_STORAGEBUCKET* pSt_StorageBucket);

XEngine_Source/StorageModule_APIHelp/StorageModule_APIHelp.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ LIBRARY
33
EXPORTS
44
StorageHelp_GetLastError
55

6-
APIHelp_Distributed_IsMode
76
APIHelp_Distributed_RandomAddr
87
APIHelp_Distributed_FileList
98
APIHelp_Distributed_DLStorage

XEngine_Source/StorageModule_APIHelp/pch.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,9 @@ extern "C" DWORD StorageHelp_GetLastError(int* pInt_SysError)
3131
/************************************************************************/
3232
/* */
3333
/************************************************************************/
34-
extern "C" BOOL APIHelp_Distributed_IsMode(list<int>*pStl_ListMode, int nMode)
34+
extern "C" BOOL APIHelp_Distributed_RandomAddr(list<string>*pStl_ListAddr, TCHAR * ptszAddr, int nMode)
3535
{
36-
return m_APIDistributed.APIHelp_Distributed_IsMode(pStl_ListMode, nMode);
37-
}
38-
extern "C" BOOL APIHelp_Distributed_RandomAddr(list<string>*pStl_ListAddr, TCHAR * ptszAddr)
39-
{
40-
return m_APIDistributed.APIHelp_Distributed_RandomAddr(pStl_ListAddr, ptszAddr);
36+
return m_APIDistributed.APIHelp_Distributed_RandomAddr(pStl_ListAddr, ptszAddr, nMode);
4137
}
4238
extern "C" BOOL APIHelp_Distributed_FileList(list<APIHELP_LBFILEINFO>*pStl_ListParse, XSTORAGECORE_DBFILE * **pppSt_ListPacket, int* pInt_ListCount)
4339
{

0 commit comments

Comments
 (0)