Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
3b147dd5
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
3b147dd5
编写于
3月 18, 2022
作者:
dengyihao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
handle except
上级
3cc9979a
变更
10
显示空白变更内容
内联
并排
Showing
10 changed file
with
226 addition
and
82 deletion
+226
-82
include/libs/transport/trpc.h
include/libs/transport/trpc.h
+20
-12
source/libs/transport/inc/transComm.h
source/libs/transport/inc/transComm.h
+24
-13
source/libs/transport/inc/transportInt.h
source/libs/transport/inc/transportInt.h
+0
-3
source/libs/transport/src/.transCli.c.swn
source/libs/transport/src/.transCli.c.swn
+0
-0
source/libs/transport/src/trans.c
source/libs/transport/src/trans.c
+10
-2
source/libs/transport/src/transCli.c
source/libs/transport/src/transCli.c
+12
-5
source/libs/transport/src/transComm.c
source/libs/transport/src/transComm.c
+54
-2
source/libs/transport/src/transSrv.c
source/libs/transport/src/transSrv.c
+10
-10
source/libs/transport/test/transUT.cc
source/libs/transport/test/transUT.cc
+2
-35
source/libs/transport/test/transportTests.cc
source/libs/transport/test/transportTests.cc
+94
-0
未找到文件。
include/libs/transport/trpc.h
浏览文件 @
3b147dd5
...
...
@@ -70,12 +70,19 @@ typedef struct SRpcInit {
// call back to retrieve the client auth info, for server app only
int
(
*
afp
)(
void
*
parent
,
char
*
tableId
,
char
*
spi
,
char
*
encrypt
,
char
*
secret
,
char
*
ckey
);
// to support Send messages multiple times on a link
void
*
(
*
mfp
)(
void
*
parent
,
tmsg_t
msgType
);
void
*
parent
;
}
SRpcInit
;
typedef
struct
{
void
*
val
;
int32_t
len
;
void
(
*
free
)(
void
*
arg
);
}
SRpcCtxVal
;
typedef
struct
{
SHashObj
*
args
;
}
SRpcCtx
;
int32_t
rpcInit
();
void
rpcCleanup
();
void
*
rpcOpen
(
const
SRpcInit
*
pRpc
);
...
...
@@ -84,16 +91,17 @@ void * rpcMallocCont(int contLen);
void
rpcFreeCont
(
void
*
pCont
);
void
*
rpcReallocCont
(
void
*
ptr
,
int
contLen
);
void
rpcSendRequest
(
void
*
thandle
,
const
SEpSet
*
pEpSet
,
SRpcMsg
*
pMsg
,
int64_t
*
rid
);
void
rpcSendRequestWithCtx
(
void
*
thandle
,
const
SEpSet
*
pEpSet
,
SRpcMsg
*
pMsg
,
int64_t
*
rid
,
SRpcCtx
*
ctx
);
void
rpcSendResponse
(
const
SRpcMsg
*
pMsg
);
void
rpcSendRedirectRsp
(
void
*
pConn
,
const
SEpSet
*
pEpSet
);
int
rpcGetConnInfo
(
void
*
thandle
,
SRpcConnInfo
*
pInfo
);
void
rpcSendRecv
(
void
*
shandle
,
SEpSet
*
pEpSet
,
SRpcMsg
*
pReq
,
SRpcMsg
*
pRsp
);
int
rpcReportProgress
(
void
*
pConn
,
char
*
pCont
,
int
contLen
);
void
rpcCancelRequest
(
int64_t
rid
);
void
rpcRegisterBrokenLinkArg
(
SRpcMsg
*
msg
);
// just release client conn to rpc instance, no close sock
void
rpcReleaseHandle
(
void
*
handle
,
int8_t
type
);
void
rpcReleaseHandle
(
void
*
handle
,
int8_t
type
);
//
void
rpcRefHandle
(
void
*
handle
,
int8_t
type
);
void
rpcUnrefHandle
(
void
*
handle
,
int8_t
type
);
...
...
source/libs/transport/inc/transComm.h
浏览文件 @
3b147dd5
...
...
@@ -14,6 +14,10 @@
*/
#ifdef USE_UV
#ifdef __cplusplus
extern
"C"
{
#endif
#include <uv.h>
#include "lz4.h"
#include "os.h"
...
...
@@ -121,6 +125,8 @@ typedef struct {
}
SRpcReqContext
;
typedef
SRpcMsg
STransMsg
;
typedef
SRpcCtx
STransCtx
;
typedef
SRpcCtxVal
STransCtxVal
;
typedef
SRpcInfo
STrans
;
typedef
SRpcConnInfo
STransHandleInfo
;
...
...
@@ -128,15 +134,10 @@ typedef struct {
SEpSet
epSet
;
// ip list provided by app
void
*
ahandle
;
// handle provided by app
tmsg_t
msgType
;
// message type
uint8_t
*
pCont
;
// content provided by app
int32_t
contLen
;
// content length
// int32_t code; // error code
// int16_t numOfTry; // number of try for different servers
// int8_t oldInUse; // server EP inUse passed by app
// int8_t redirect; // flag to indicate redirect
int8_t
connType
;
// connection type cli/srv
int64_t
rid
;
// refId returned by taosAddRef
STransCtx
appCtx
;
//
STransMsg
*
pRsp
;
// for synchronous API
tsem_t
*
pSem
;
// for synchronous API
...
...
@@ -181,7 +182,7 @@ typedef struct {
#pragma pack(pop)
typedef
enum
{
Normal
,
Quit
,
Release
}
STransMsgType
;
typedef
enum
{
ConnNormal
,
ConnAcquire
,
ConnRelease
}
ConnStatus
;
typedef
enum
{
ConnNormal
,
ConnAcquire
,
ConnRelease
,
ConnBroken
}
ConnStatus
;
#define container_of(ptr, type, member) ((type*)((char*)(ptr)-offsetof(type, member)))
#define RPC_RESERVE_SIZE (sizeof(STranConnCtx))
...
...
@@ -259,7 +260,7 @@ void transUnrefCliHandle(void* handle);
void
transReleaseCliHandle
(
void
*
handle
);
void
transReleaseSrvHandle
(
void
*
handle
);
void
transSendRequest
(
void
*
shandle
,
const
char
*
ip
,
uint32_t
port
,
STransMsg
*
pMsg
);
void
transSendRequest
(
void
*
shandle
,
const
char
*
ip
,
uint32_t
port
,
STransMsg
*
pMsg
,
STransCtx
*
pCtx
);
void
transSendRecv
(
void
*
shandle
,
const
char
*
ip
,
uint32_t
port
,
STransMsg
*
pMsg
,
STransMsg
*
pRsp
);
void
transSendResponse
(
const
STransMsg
*
pMsg
);
int
transGetConnInfo
(
void
*
thandle
,
STransHandleInfo
*
pInfo
);
...
...
@@ -270,4 +271,14 @@ void* transInitClient(uint32_t ip, uint32_t port, char* label, int numOfThreads,
void
transCloseClient
(
void
*
arg
);
void
transCloseServer
(
void
*
arg
);
void
transCtxInit
(
STransCtx
*
ctx
);
void
transCtxDestroy
(
STransCtx
*
ctx
);
void
transCtxClear
(
STransCtx
*
ctx
);
void
transCtxMerge
(
STransCtx
*
dst
,
STransCtx
*
src
);
void
*
transCtxDumpVal
(
STransCtx
*
ctx
,
int32_t
key
);
#ifdef __cplusplus
}
#endif
#endif
source/libs/transport/inc/transportInt.h
浏览文件 @
3b147dd5
...
...
@@ -63,9 +63,6 @@ typedef struct {
void
(
*
cfp
)(
void
*
parent
,
SRpcMsg
*
,
SEpSet
*
);
int
(
*
afp
)(
void
*
parent
,
char
*
user
,
char
*
spi
,
char
*
encrypt
,
char
*
secret
,
char
*
ckey
);
bool
(
*
pfp
)(
void
*
parent
,
tmsg_t
msgType
);
void
*
(
*
mfp
)(
void
*
parent
,
tmsg_t
msgType
);
bool
(
*
efp
)(
void
*
parent
,
tmsg_t
msgType
);
int32_t
refCount
;
void
*
parent
;
...
...
source/libs/transport/src/.transCli.c.swn
0 → 100644
浏览文件 @
3b147dd5
文件已添加
source/libs/transport/src/trans.c
浏览文件 @
3b147dd5
...
...
@@ -39,7 +39,6 @@ void* rpcOpen(const SRpcInit* pInit) {
// register callback handle
pRpc
->
cfp
=
pInit
->
cfp
;
pRpc
->
afp
=
pInit
->
afp
;
pRpc
->
mfp
=
pInit
->
mfp
;
if
(
pInit
->
connType
==
TAOS_CONN_SERVER
)
{
pRpc
->
numOfThreads
=
pInit
->
numOfThreads
>
TSDB_MAX_RPC_THREADS
?
TSDB_MAX_RPC_THREADS
:
pInit
->
numOfThreads
;
...
...
@@ -119,7 +118,12 @@ void rpcCancelRequest(int64_t rid) { return; }
void
rpcSendRequest
(
void
*
shandle
,
const
SEpSet
*
pEpSet
,
SRpcMsg
*
pMsg
,
int64_t
*
pRid
)
{
char
*
ip
=
(
char
*
)(
pEpSet
->
eps
[
pEpSet
->
inUse
].
fqdn
);
uint32_t
port
=
pEpSet
->
eps
[
pEpSet
->
inUse
].
port
;
transSendRequest
(
shandle
,
ip
,
port
,
pMsg
);
transSendRequest
(
shandle
,
ip
,
port
,
pMsg
,
NULL
);
}
void
rpcSendRequestWithCtx
(
void
*
shandle
,
const
SEpSet
*
pEpSet
,
SRpcMsg
*
pMsg
,
int64_t
*
pRid
,
SRpcCtx
*
pCtx
)
{
char
*
ip
=
(
char
*
)(
pEpSet
->
eps
[
pEpSet
->
inUse
].
fqdn
);
uint32_t
port
=
pEpSet
->
eps
[
pEpSet
->
inUse
].
port
;
transSendRequest
(
shandle
,
ip
,
port
,
pMsg
,
pCtx
);
}
void
rpcSendRecv
(
void
*
shandle
,
SEpSet
*
pEpSet
,
SRpcMsg
*
pMsg
,
SRpcMsg
*
pRsp
)
{
char
*
ip
=
(
char
*
)(
pEpSet
->
eps
[
pEpSet
->
inUse
].
fqdn
);
...
...
@@ -140,6 +144,10 @@ void rpcUnrefHandle(void* handle, int8_t type) {
(
*
taosUnRefHandle
[
type
])(
handle
);
}
void
rpcRegisterBrokenLinkArg
(
SRpcMsg
*
msg
)
{
//
rpcSendResponse
(
msg
);
}
void
rpcReleaseHandle
(
void
*
handle
,
int8_t
type
)
{
assert
(
type
==
TAOS_CONN_SERVER
||
type
==
TAOS_CONN_CLIENT
);
(
*
transReleaseHandle
[
type
])(
handle
);
...
...
source/libs/transport/src/transCli.c
浏览文件 @
3b147dd5
...
...
@@ -30,6 +30,7 @@ typedef struct SCliConn {
uint64_t
expireTime
;
int
hThrdIdx
;
bool
broken
;
// link broken or not
STransCtx
ctx
;
ConnStatus
status
;
//
int
release
;
// 1: release
...
...
@@ -207,7 +208,7 @@ void cliHandleResp(SCliConn* conn) {
STransConnCtx
*
pCtx
=
pMsg
?
pMsg
->
ctx
:
NULL
;
if
(
pMsg
==
NULL
&&
!
CONN_NO_PERSIST_BY_APP
(
conn
))
{
transMsg
.
ahandle
=
pTransInst
->
mfp
?
(
*
pTransInst
->
mfp
)(
pTransInst
->
parent
,
transMsg
.
msgType
)
:
NULL
;
transMsg
.
ahandle
=
transCtxDumpVal
(
&
conn
->
ctx
,
transMsg
.
msgType
)
;
}
else
{
transMsg
.
ahandle
=
pCtx
?
pCtx
->
ahandle
:
NULL
;
}
...
...
@@ -283,7 +284,7 @@ void cliHandleExcept(SCliConn* pConn) {
transMsg
.
ahandle
=
NULL
;
if
(
pMsg
==
NULL
&&
!
CONN_NO_PERSIST_BY_APP
(
pConn
))
{
transMsg
.
ahandle
=
pTransInst
->
mfp
?
(
*
pTransInst
->
mfp
)(
pTransInst
->
parent
,
transMsg
.
msgType
)
:
NULL
;
transMsg
.
ahandle
=
transCtxDumpVal
(
&
pConn
->
ctx
,
transMsg
.
msgType
)
;
}
else
{
transMsg
.
ahandle
=
pCtx
?
pCtx
->
ahandle
:
NULL
;
}
...
...
@@ -374,6 +375,7 @@ static SCliConn* getConnFromPool(void* pool, char* ip, uint32_t port) {
static
void
addConnToPool
(
void
*
pool
,
SCliConn
*
conn
)
{
char
key
[
128
]
=
{
0
};
transCtxDestroy
(
&
conn
->
ctx
);
tstrncpy
(
key
,
conn
->
ip
,
strlen
(
conn
->
ip
));
tstrncpy
(
key
+
strlen
(
key
),
(
char
*
)(
&
conn
->
port
),
sizeof
(
conn
->
port
));
tTrace
(
"cli conn %p added to conn pool, read buf cap: %d"
,
conn
,
conn
->
readBuf
.
cap
);
...
...
@@ -436,7 +438,6 @@ static SCliConn* cliCreateConn(SCliThrdObj* pThrd) {
conn
->
writeReq
.
data
=
conn
;
conn
->
connReq
.
data
=
conn
;
conn
->
cliMsgs
=
taosArrayInit
(
2
,
sizeof
(
void
*
));
QUEUE_INIT
(
&
conn
->
conn
);
conn
->
hostThrd
=
pThrd
;
conn
->
status
=
ConnNormal
;
...
...
@@ -446,6 +447,7 @@ static SCliConn* cliCreateConn(SCliThrdObj* pThrd) {
}
static
void
cliDestroyConn
(
SCliConn
*
conn
,
bool
clear
)
{
tTrace
(
"%s cli conn %p remove from conn pool"
,
CONN_GET_INST_LABEL
(
conn
),
conn
);
QUEUE_REMOVE
(
&
conn
->
conn
);
if
(
clear
)
{
uv_close
((
uv_handle_t
*
)
conn
->
stream
,
cliDestroy
);
...
...
@@ -455,6 +457,7 @@ static void cliDestroy(uv_handle_t* handle) {
SCliConn
*
conn
=
handle
->
data
;
free
(
conn
->
ip
);
free
(
conn
->
stream
);
transCtxDestroy
(
&
conn
->
ctx
);
taosArrayDestroy
(
conn
->
cliMsgs
);
tTrace
(
"%s cli conn %p destroy successfully"
,
CONN_GET_INST_LABEL
(
conn
),
conn
);
free
(
conn
);
...
...
@@ -630,10 +633,12 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrdObj* pThrd) {
if
(
conn
!=
NULL
)
{
conn
->
hThrdIdx
=
pCtx
->
hThrdIdx
;
transCtxMerge
(
&
conn
->
ctx
,
&
pCtx
->
appCtx
);
if
(
taosArrayGetSize
(
conn
->
cliMsgs
)
>
0
)
{
taosArrayPush
(
conn
->
cliMsgs
,
&
pMsg
);
return
;
}
taosArrayPush
(
conn
->
cliMsgs
,
&
pMsg
);
transDestroyBuffer
(
&
conn
->
readBuf
);
cliSend
(
conn
);
...
...
@@ -825,7 +830,7 @@ void transReleaseCliHandle(void* handle) {
transSendAsync
(
thrd
->
asyncPool
,
&
cmsg
->
q
);
}
void
transSendRequest
(
void
*
shandle
,
const
char
*
ip
,
uint32_t
port
,
STransMsg
*
pMsg
)
{
void
transSendRequest
(
void
*
shandle
,
const
char
*
ip
,
uint32_t
port
,
STransMsg
*
pMsg
,
STransCtx
*
ctx
)
{
STrans
*
pTransInst
=
(
STrans
*
)
shandle
;
int
index
=
CONN_HOST_THREAD_INDEX
((
SCliConn
*
)
pMsg
->
handle
);
if
(
index
==
-
1
)
{
...
...
@@ -835,13 +840,14 @@ void transSendRequest(void* shandle, const char* ip, uint32_t port, STransMsg* p
if
(
transCompressMsg
(
pMsg
->
pCont
,
pMsg
->
contLen
,
&
flen
))
{
// imp later
}
tDebug
(
"send request at thread:%d %p
"
,
index
,
pMsg
);
tDebug
(
"send request at thread:%d %p
, dst: %s:%d"
,
index
,
pMsg
,
ip
,
port
);
STransConnCtx
*
pCtx
=
calloc
(
1
,
sizeof
(
STransConnCtx
));
pCtx
->
ahandle
=
pMsg
->
ahandle
;
pCtx
->
msgType
=
pMsg
->
msgType
;
pCtx
->
ip
=
strdup
(
ip
);
pCtx
->
port
=
port
;
pCtx
->
hThrdIdx
=
index
;
pCtx
->
appCtx
=
*
ctx
;
assert
(
pTransInst
->
connType
==
TAOS_CONN_CLIENT
);
// atomic or not
...
...
@@ -855,6 +861,7 @@ void transSendRequest(void* shandle, const char* ip, uint32_t port, STransMsg* p
SCliThrdObj
*
thrd
=
((
SCliObj
*
)
pTransInst
->
tcphandle
)
->
pThreadObj
[
index
];
transSendAsync
(
thrd
->
asyncPool
,
&
(
cliMsg
->
q
));
}
void
transSendRecv
(
void
*
shandle
,
const
char
*
ip
,
uint32_t
port
,
STransMsg
*
pReq
,
STransMsg
*
pRsp
)
{
STrans
*
pTransInst
=
(
STrans
*
)
shandle
;
int
index
=
CONN_HOST_THREAD_INDEX
(
pReq
->
handle
);
...
...
source/libs/transport/src/transComm.c
浏览文件 @
3b147dd5
...
...
@@ -155,9 +155,9 @@ bool transReadComplete(SConnBuffer* connBuf) {
}
return
false
;
}
int
transPackMsg
(
STransMsgHead
*
msgHead
,
bool
sercured
,
bool
auth
)
{
return
0
;
}
int
transPackMsg
(
STransMsgHead
*
msgHead
,
bool
sercured
,
bool
auth
)
{
return
0
;
}
int
transUnpackMsg
(
STransMsgHead
*
msgHead
)
{
return
0
;
}
int
transUnpackMsg
(
STransMsgHead
*
msgHead
)
{
return
0
;
}
int
transDestroyBuffer
(
SConnBuffer
*
buf
)
{
if
(
buf
->
cap
>
0
)
{
tfree
(
buf
->
buf
);
...
...
@@ -224,4 +224,56 @@ int transSendAsync(SAsyncPool* pool, queue* q) {
return
uv_async_send
(
async
);
}
void
transCtxInit
(
STransCtx
*
ctx
)
{
// init transCtx
ctx
->
args
=
taosHashInit
(
2
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_UINT
),
true
,
HASH_NO_LOCK
);
}
void
transCtxDestroy
(
STransCtx
*
ctx
)
{
if
(
ctx
->
args
==
NULL
)
{
return
;
}
STransCtxVal
*
iter
=
taosHashIterate
(
ctx
->
args
,
NULL
);
while
(
iter
)
{
iter
->
free
(
iter
->
val
);
iter
=
taosHashIterate
(
ctx
->
args
,
iter
);
}
taosHashCleanup
(
ctx
->
args
);
}
void
transCtxMerge
(
STransCtx
*
dst
,
STransCtx
*
src
)
{
if
(
dst
->
args
==
NULL
)
{
dst
->
args
=
src
->
args
;
src
->
args
=
NULL
;
return
;
}
void
*
key
=
NULL
;
size_t
klen
=
0
;
void
*
iter
=
taosHashIterate
(
src
->
args
,
NULL
);
while
(
iter
)
{
STransCtxVal
*
sVal
=
(
STransCtxVal
*
)
iter
;
key
=
taosHashGetKey
(
sVal
,
&
klen
);
STransCtxVal
*
dVal
=
taosHashGet
(
dst
->
args
,
key
,
klen
);
if
(
dVal
)
{
dVal
->
free
(
dVal
->
val
);
}
taosHashPut
(
dst
->
args
,
key
,
klen
,
sVal
,
sizeof
(
*
sVal
));
iter
=
taosHashIterate
(
src
->
args
,
iter
);
}
taosHashCleanup
(
src
->
args
);
}
void
*
transCtxDumpVal
(
STransCtx
*
ctx
,
int32_t
key
)
{
if
(
ctx
->
args
==
NULL
)
{
return
NULL
;
}
STransCtxVal
*
cVal
=
taosHashGet
(
ctx
->
args
,
(
const
void
*
)
&
key
,
sizeof
(
key
));
if
(
cVal
==
NULL
)
{
return
NULL
;
}
char
*
ret
=
calloc
(
1
,
cVal
->
len
);
memcpy
(
ret
,
(
char
*
)
cVal
->
val
,
cVal
->
len
);
return
(
void
*
)
ret
;
}
#endif
source/libs/transport/src/transSrv.c
浏览文件 @
3b147dd5
...
...
@@ -403,16 +403,16 @@ static void uvStartSendResp(SSrvMsg* smsg) {
return
;
}
static
void
uvNotifyLinkBrokenToApp
(
SSrvConn
*
conn
)
{
STrans
*
pTransInst
=
conn
->
pTransInst
;
if
(
pTransInst
->
efp
!=
NULL
&&
(
*
pTransInst
->
efp
)(
NULL
,
conn
->
inType
)
&&
T_REF_VAL_GET
(
conn
)
>=
2
)
{
STransMsg
transMsg
=
{
0
};
transMsg
.
msgType
=
conn
->
inType
;
transMsg
.
code
=
TSDB_CODE_RPC_NETWORK_UNAVAIL
;
// transRefSrvHandle(conn);
(
*
pTransInst
->
cfp
)(
pTransInst
->
parent
,
&
transMsg
,
0
);
}
}
//
static void uvNotifyLinkBrokenToApp(SSrvConn* conn) {
//
STrans* pTransInst = conn->pTransInst;
//
if (pTransInst->efp != NULL && (*pTransInst->efp)(NULL, conn->inType) && T_REF_VAL_GET(conn) >= 2) {
//
STransMsg transMsg = {0};
//
transMsg.msgType = conn->inType;
//
transMsg.code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
//
// transRefSrvHandle(conn);
//
(*pTransInst->cfp)(pTransInst->parent, &transMsg, 0);
//
}
//
}
static
void
destroySmsg
(
SSrvMsg
*
smsg
)
{
if
(
smsg
==
NULL
)
{
return
;
...
...
source/libs/transport/test/transUT.cc
浏览文件 @
3b147dd5
...
...
@@ -86,18 +86,8 @@ class Client {
rpcClose
(
this
->
transCli
);
this
->
transCli
=
NULL
;
}
void
SetPersistFP
(
bool
(
*
pfp
)(
void
*
parent
,
tmsg_t
msgType
))
{
rpcClose
(
this
->
transCli
);
this
->
transCli
=
rpcOpen
(
&
rpcInit_
);
}
void
SetConstructFP
(
void
*
(
*
mfp
)(
void
*
parent
,
tmsg_t
msgType
))
{
rpcClose
(
this
->
transCli
);
rpcInit_
.
mfp
=
mfp
;
this
->
transCli
=
rpcOpen
(
&
rpcInit_
);
}
void
SetPAndMFp
(
bool
(
*
pfp
)(
void
*
parent
,
tmsg_t
msgType
),
void
*
(
*
mfp
)(
void
*
parent
,
tmsg_t
msgType
))
{
rpcClose
(
this
->
transCli
);
rpcInit_
.
mfp
=
mfp
;
this
->
transCli
=
rpcOpen
(
&
rpcInit_
);
}
...
...
@@ -156,10 +146,6 @@ class Server {
rpcClose
(
this
->
transSrv
);
this
->
transSrv
=
NULL
;
}
void
SetExceptFp
(
bool
(
*
efp
)(
void
*
parent
,
tmsg_t
msgType
))
{
this
->
Stop
();
this
->
Start
();
}
void
SetSrvContinueSend
(
void
(
*
cfp
)(
void
*
parent
,
SRpcMsg
*
pMsg
,
SEpSet
*
pEpSet
))
{
this
->
Stop
();
rpcInit_
.
cfp
=
cfp
;
...
...
@@ -252,23 +238,11 @@ class TransObj {
//
srv
->
Stop
();
}
void
SetCliPersistFp
(
bool
(
*
pfp
)(
void
*
parent
,
tmsg_t
msgType
))
{
// do nothing
cli
->
SetPersistFP
(
pfp
);
}
void
SetCliMFp
(
void
*
(
*
mfp
)(
void
*
parent
,
tmsg_t
msgType
))
{
// do nothing
cli
->
SetConstructFP
(
mfp
);
}
void
SetCliMAndPFp
(
bool
(
*
pfp
)(
void
*
parent
,
tmsg_t
msgType
),
void
*
(
*
mfp
)(
void
*
parent
,
tmsg_t
msgType
))
{
// do nothing
cli
->
SetPAndMFp
(
pfp
,
mfp
);
}
// call when link broken, and notify query or fetch stop
void
SetSrvExceptFp
(
bool
(
*
efp
)(
void
*
parent
,
tmsg_t
msgType
))
{
////////
srv
->
SetExceptFp
(
efp
);
}
void
SetSrvContinueSend
(
void
(
*
cfp
)(
void
*
parent
,
SRpcMsg
*
pMsg
,
SEpSet
*
pEpSet
))
{
///////
srv
->
SetSrvContinueSend
(
cfp
);
...
...
@@ -375,22 +349,15 @@ TEST_F(TransEnv, cliReleaseHandle) {
req
.
pCont
=
rpcMallocCont
(
10
);
req
.
contLen
=
10
;
tr
->
cliSendAndRecvNoHandle
(
&
req
,
&
resp
);
// if (i == 5) {
// std::cout << "stop server" << std::endl;
// tr->StopSrv();
//}
// if (i >= 6) {
EXPECT_TRUE
(
resp
.
code
==
0
);
//}
}
//////////////////
}
TEST_F
(
TransEnv
,
cliReleaseHandleExcept
)
{
// tr->SetCliPersistFp(cliPersistHandle);
SRpcMsg
resp
=
{
0
};
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
SRpcMsg
req
=
{.
handle
=
resp
.
handle
};
SRpcMsg
req
=
{.
handle
=
resp
.
handle
,
.
persistHandle
=
1
};
req
.
msgType
=
1
;
req
.
pCont
=
rpcMallocCont
(
10
);
req
.
contLen
=
10
;
...
...
@@ -459,7 +426,7 @@ TEST_F(TransEnv, multiCliPersistHandleExcept) {
// conn broken
}
TEST_F
(
TransEnv
,
queryExcept
)
{
tr
->
SetSrvExceptFp
(
handleExcept
);
//
tr->SetSrvExceptFp(handleExcept);
// query and conn is broken
}
...
...
source/libs/transport/test/transportTests.cc
浏览文件 @
3b147dd5
...
...
@@ -136,4 +136,98 @@ TEST_F(QueueEnv, testIter) {
assert
(
result
.
size
()
==
vals
.
size
());
}
class
TransCtxEnv
:
public
::
testing
::
Test
{
protected:
virtual
void
SetUp
()
{
ctx
=
(
STransCtx
*
)
calloc
(
1
,
sizeof
(
STransCtx
));
transCtxInit
(
ctx
);
// TODO
}
virtual
void
TearDown
()
{
transCtxDestroy
(
ctx
);
// formate
}
STransCtx
*
ctx
;
};
TEST_F
(
TransCtxEnv
,
mergeTest
)
{
int
key
=
1
;
{
STransCtx
*
src
=
(
STransCtx
*
)
calloc
(
1
,
sizeof
(
STransCtx
));
transCtxInit
(
src
);
{
STransCtxVal
val1
=
{.
val
=
NULL
,
.
len
=
0
,
.
free
=
free
};
val1
.
val
=
malloc
(
12
);
val1
.
len
=
12
;
taosHashPut
(
src
->
args
,
&
key
,
sizeof
(
key
),
&
val1
,
sizeof
(
val1
));
key
++
;
}
{
STransCtxVal
val1
=
{.
val
=
NULL
,
.
len
=
0
,
.
free
=
free
};
val1
.
val
=
malloc
(
12
);
val1
.
len
=
12
;
taosHashPut
(
src
->
args
,
&
key
,
sizeof
(
key
),
&
val1
,
sizeof
(
val1
));
key
++
;
}
transCtxMerge
(
ctx
,
src
);
free
(
src
);
}
EXPECT_EQ
(
2
,
taosHashGetSize
(
ctx
->
args
));
{
STransCtx
*
src
=
(
STransCtx
*
)
calloc
(
1
,
sizeof
(
STransCtx
));
transCtxInit
(
src
);
{
STransCtxVal
val1
=
{.
val
=
NULL
,
.
len
=
0
,
.
free
=
free
};
val1
.
val
=
malloc
(
12
);
val1
.
len
=
12
;
taosHashPut
(
src
->
args
,
&
key
,
sizeof
(
key
),
&
val1
,
sizeof
(
val1
));
key
++
;
}
{
STransCtxVal
val1
=
{.
val
=
NULL
,
.
len
=
0
,
.
free
=
free
};
val1
.
val
=
malloc
(
12
);
val1
.
len
=
12
;
taosHashPut
(
src
->
args
,
&
key
,
sizeof
(
key
),
&
val1
,
sizeof
(
val1
));
key
++
;
}
transCtxMerge
(
ctx
,
src
);
free
(
src
);
}
std
::
string
val
(
"Hello"
);
EXPECT_EQ
(
4
,
taosHashGetSize
(
ctx
->
args
));
{
key
=
1
;
STransCtx
*
src
=
(
STransCtx
*
)
calloc
(
1
,
sizeof
(
STransCtx
));
transCtxInit
(
src
);
{
STransCtxVal
val1
=
{.
val
=
NULL
,
.
len
=
0
,
.
free
=
free
};
val1
.
val
=
calloc
(
1
,
11
);
memcpy
(
val1
.
val
,
val
.
c_str
(),
val
.
size
());
val1
.
len
=
11
;
taosHashPut
(
src
->
args
,
&
key
,
sizeof
(
key
),
&
val1
,
sizeof
(
val1
));
key
++
;
}
{
STransCtxVal
val1
=
{.
val
=
NULL
,
.
len
=
0
,
.
free
=
free
};
val1
.
val
=
calloc
(
1
,
11
);
memcpy
(
val1
.
val
,
val
.
c_str
(),
val
.
size
());
val1
.
len
=
11
;
taosHashPut
(
src
->
args
,
&
key
,
sizeof
(
key
),
&
val1
,
sizeof
(
val1
));
key
++
;
}
transCtxMerge
(
ctx
,
src
);
free
(
src
);
}
EXPECT_EQ
(
4
,
taosHashGetSize
(
ctx
->
args
));
char
*
skey
=
(
char
*
)
transCtxDumpVal
(
ctx
,
1
);
EXPECT_EQ
(
0
,
strcmp
(
skey
,
val
.
c_str
()));
free
(
skey
);
skey
=
(
char
*
)
transCtxDumpVal
(
ctx
,
2
);
EXPECT_EQ
(
0
,
strcmp
(
skey
,
val
.
c_str
()));
}
#endif
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录