Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
19517077
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
19517077
编写于
1月 26, 2022
作者:
dengyihao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
stop cli/srv gracefully
上级
d6e8a0ed
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
64 addition
and
11 deletion
+64
-11
source/libs/transport/src/transCli.c
source/libs/transport/src/transCli.c
+1
-0
source/libs/transport/src/transSrv.c
source/libs/transport/src/transSrv.c
+44
-8
source/libs/transport/test/transUT.cc
source/libs/transport/test/transUT.cc
+19
-3
未找到文件。
source/libs/transport/src/transCli.c
浏览文件 @
19517077
...
...
@@ -526,6 +526,7 @@ static void destroyThrdObj(SCliThrdObj* pThrd) {
if
(
pThrd
==
NULL
)
{
return
;
}
uv_stop
(
pThrd
->
loop
);
pthread_join
(
pThrd
->
thread
,
NULL
);
pthread_mutex_destroy
(
&
pThrd
->
msgMtx
);
free
(
pThrd
->
cliAsync
);
...
...
source/libs/transport/src/transSrv.c
浏览文件 @
19517077
...
...
@@ -70,6 +70,7 @@ typedef struct SServerObj {
uv_pipe_t
**
pipe
;
uint32_t
ip
;
uint32_t
port
;
uv_async_t
*
pAcceptAsync
;
// just to quit from from accept thread
}
SServerObj
;
static
const
char
*
notify
=
"a"
;
...
...
@@ -88,9 +89,11 @@ static void uvOnPipeWriteCb(uv_write_t* req, int status);
static
void
uvOnAcceptCb
(
uv_stream_t
*
stream
,
int
status
);
static
void
uvOnConnectionCb
(
uv_stream_t
*
q
,
ssize_t
nread
,
const
uv_buf_t
*
buf
);
static
void
uvWorkerAsyncCb
(
uv_async_t
*
handle
);
static
void
uvAcceptAsyncCb
(
uv_async_t
*
handle
);
static
void
uvPrepareSendData
(
SSrvMsg
*
msg
,
uv_buf_t
*
wb
);
static
void
uvStartSendResp
(
SSrvMsg
*
msg
);
static
void
destroySmsg
(
SSrvMsg
*
smsg
);
// check whether already read complete packet
static
bool
readComplete
(
SConnBuffer
*
buf
);
...
...
@@ -389,7 +392,13 @@ void uvWorkerAsyncCb(uv_async_t* handle) {
tError
(
"except occurred, continue"
);
continue
;
}
if
(
msg
->
pConn
==
NULL
)
{
//
free
(
msg
);
uv_stop
(
pThrd
->
loop
);
}
else
{
uvStartSendResp
(
msg
);
}
// uv_buf_t wb;
// uvPrepareSendData(msg, &wb);
// uv_timer_stop(conn->pTimer);
...
...
@@ -397,6 +406,10 @@ void uvWorkerAsyncCb(uv_async_t* handle) {
// uv_write(conn->pWriter, (uv_stream_t*)conn->pTcp, &wb, 1, uvOnWriteCb);
}
}
static
void
uvAcceptAsyncCb
(
uv_async_t
*
async
)
{
SServerObj
*
srv
=
async
->
data
;
uv_stop
(
srv
->
loop
);
}
void
uvOnAcceptCb
(
uv_stream_t
*
stream
,
int
status
)
{
if
(
status
==
-
1
)
{
...
...
@@ -517,8 +530,12 @@ static bool addHandleToAcceptloop(void* arg) {
return
false
;
}
struct
sockaddr_in
bind_addr
;
// register an async here to quit server gracefully
srv
->
pAcceptAsync
=
calloc
(
1
,
sizeof
(
uv_async_t
));
uv_async_init
(
srv
->
loop
,
srv
->
pAcceptAsync
,
uvAcceptAsyncCb
);
srv
->
pAcceptAsync
->
data
=
srv
;
struct
sockaddr_in
bind_addr
;
uv_ip4_addr
(
"0.0.0.0"
,
srv
->
port
,
&
bind_addr
);
if
((
err
=
uv_tcp_bind
(
&
srv
->
server
,
(
const
struct
sockaddr
*
)
&
bind_addr
,
0
))
!=
0
)
{
tError
(
"failed to bind: %s"
,
uv_err_name
(
err
));
...
...
@@ -646,24 +663,43 @@ void destroyWorkThrd(SWorkThrdObj* pThrd) {
if
(
pThrd
==
NULL
)
{
return
;
}
uv_stop
(
pThrd
->
loop
);
pthread_join
(
pThrd
->
thread
,
NULL
);
// free(srv->pipe[i]);
free
(
pThrd
->
loop
);
pthread_mutex_destroy
(
&
pThrd
->
msgMtx
);
free
(
pThrd
->
workerAsync
);
free
(
pThrd
);
}
void
sendQuitToWorkThrd
(
SWorkThrdObj
*
pThrd
)
{
SSrvMsg
*
srvMsg
=
calloc
(
1
,
sizeof
(
SSrvMsg
));
pthread_mutex_lock
(
&
pThrd
->
msgMtx
);
QUEUE_PUSH
(
&
pThrd
->
msg
,
&
srvMsg
->
q
);
pthread_mutex_unlock
(
&
pThrd
->
msgMtx
);
tDebug
(
"send quit msg to work thread"
);
uv_async_send
(
pThrd
->
workerAsync
);
}
void
taosCloseServer
(
void
*
arg
)
{
// impl later
SServerObj
*
srv
=
arg
;
for
(
int
i
=
0
;
i
<
srv
->
numOfThreads
;
i
++
)
{
sendQuitToWorkThrd
(
srv
->
pThreadObj
[
i
]);
destroyWorkThrd
(
srv
->
pThreadObj
[
i
]);
}
uv_stop
(
srv
->
loop
);
tDebug
(
"send quit msg to accept thread"
);
uv_async_send
(
srv
->
pAcceptAsync
);
pthread_join
(
srv
->
thread
,
NULL
);
free
(
srv
->
pThreadObj
);
free
(
srv
->
pAcceptAsync
);
free
(
srv
->
loop
);
for
(
int
i
=
0
;
i
<
srv
->
numOfThreads
;
i
++
)
{
free
(
srv
->
pipe
[
i
]);
}
free
(
srv
->
pipe
);
free
(
srv
->
pThreadObj
);
pthread_join
(
srv
->
thread
,
NULL
);
free
(
srv
);
}
...
...
source/libs/transport/test/transUT.cc
浏览文件 @
19517077
...
...
@@ -29,7 +29,7 @@ class TransObj {
memset
(
&
rpcInit
,
0
,
sizeof
(
rpcInit
));
rpcInit
.
localPort
=
0
;
rpcInit
.
label
=
(
char
*
)
label
;
rpcInit
.
numOfThreads
=
1
;
rpcInit
.
numOfThreads
=
5
;
rpcInit
.
cfp
=
NULL
;
rpcInit
.
sessions
=
100
;
rpcInit
.
idleTime
=
100
;
...
...
@@ -37,12 +37,22 @@ class TransObj {
rpcInit
.
secret
=
(
char
*
)
secret
;
rpcInit
.
ckey
=
(
char
*
)
ckey
;
rpcInit
.
spi
=
1
;
}
bool
startCli
()
{
trans
=
NULL
;
rpcInit
.
connType
=
TAOS_CONN_CLIENT
;
trans
=
rpcOpen
(
&
rpcInit
);
return
trans
!=
NULL
?
true
:
false
;
}
bool
startSrv
()
{
trans
=
NULL
;
rpcInit
.
connType
=
TAOS_CONN_SERVER
;
trans
=
rpcOpen
(
&
rpcInit
);
return
trans
!=
NULL
?
true
:
false
;
}
bool
stop
()
{
rpcClose
(
trans
);
trans
=
NULL
;
return
true
;
}
...
...
@@ -63,4 +73,10 @@ class TransEnv : public ::testing::Test {
TransObj
*
tr
=
NULL
;
};
TEST_F
(
TransEnv
,
test_start_stop
)
{
assert
(
tr
->
stop
());
}
TEST_F
(
TransEnv
,
test_start_stop
)
{
assert
(
tr
->
startCli
());
assert
(
tr
->
stop
());
assert
(
tr
->
startSrv
());
assert
(
tr
->
stop
());
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录