Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
90f38515
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
90f38515
编写于
7月 27, 2022
作者:
dengyihao
提交者:
GitHub
7月 27, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #15446 from taosdata/rpc/optBuf
refactor: opt rpc
上级
e2cf1e45
ea2c6f68
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
92 addition
and
53 deletion
+92
-53
source/libs/transport/inc/transComm.h
source/libs/transport/inc/transComm.h
+4
-2
source/libs/transport/src/thttp.c
source/libs/transport/src/thttp.c
+4
-2
source/libs/transport/src/transCli.c
source/libs/transport/src/transCli.c
+6
-4
source/libs/transport/src/transComm.c
source/libs/transport/src/transComm.c
+73
-42
source/libs/transport/src/transSvr.c
source/libs/transport/src/transSvr.c
+5
-3
未找到文件。
source/libs/transport/inc/transComm.h
浏览文件 @
90f38515
...
...
@@ -7,8 +7,7 @@
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* FITNESS FOR A PARTICULAR PURPOSE. *
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
...
...
@@ -211,6 +210,7 @@ typedef struct SConnBuffer {
char
*
buf
;
int
len
;
int
cap
;
int
left
;
int
total
;
}
SConnBuffer
;
...
...
@@ -282,6 +282,8 @@ int transClearBuffer(SConnBuffer* buf);
int
transDestroyBuffer
(
SConnBuffer
*
buf
);
int
transAllocBuffer
(
SConnBuffer
*
connBuf
,
uv_buf_t
*
uvBuf
);
bool
transReadComplete
(
SConnBuffer
*
connBuf
);
int
transResetBuffer
(
SConnBuffer
*
connBuf
);
int
transDumpFromBuffer
(
SConnBuffer
*
connBuf
,
char
**
buf
);
int
transSetConnOption
(
uv_tcp_t
*
stream
);
...
...
source/libs/transport/src/thttp.c
浏览文件 @
90f38515
...
...
@@ -17,6 +17,7 @@
#ifdef USE_UV
#include <uv.h>
#endif
// clang-format off
#include "zlib.h"
#include "thttp.h"
#include "taoserror.h"
...
...
@@ -174,7 +175,7 @@ int32_t taosSendHttpReport(const char* server, uint16_t port, char* pCont, int32
#else
int32_t
taosSendHttpReport
(
const
char
*
server
,
uint16_t
port
,
char
*
pCont
,
int32_t
contLen
,
EHttpCompFlag
flag
)
{
int32_t
code
=
-
1
;
int32_t
code
=
-
1
;
TdSocketPtr
pSocket
=
NULL
;
uint32_t
ip
=
taosGetIpv4FromFqdn
(
server
);
...
...
@@ -231,4 +232,5 @@ SEND_OVER:
return
code
;
}
#endif
\ No newline at end of file
// clang-format on
#endif
source/libs/transport/src/transCli.c
浏览文件 @
90f38515
...
...
@@ -323,7 +323,8 @@ void cliHandleResp(SCliConn* conn) {
SCliThrd
*
pThrd
=
conn
->
hostThrd
;
STrans
*
pTransInst
=
pThrd
->
pTransInst
;
STransMsgHead
*
pHead
=
(
STransMsgHead
*
)(
conn
->
readBuf
.
buf
);
STransMsgHead
*
pHead
=
NULL
;
transDumpFromBuffer
(
&
conn
->
readBuf
,
(
char
**
)
&
pHead
);
pHead
->
code
=
htonl
(
pHead
->
code
);
pHead
->
msgLen
=
htonl
(
pHead
->
msgLen
);
...
...
@@ -366,7 +367,6 @@ void cliHandleResp(SCliConn* conn) {
}
}
// buf's mem alread translated to transMsg.pCont
transClearBuffer
(
&
conn
->
readBuf
);
if
(
!
CONN_NO_PERSIST_BY_APP
(
conn
))
{
transMsg
.
info
.
handle
=
(
void
*
)
conn
->
refId
;
tDebug
(
"%s conn %p ref by app"
,
CONN_GET_INST_LABEL
(
conn
),
conn
);
...
...
@@ -636,6 +636,8 @@ static SCliConn* cliCreateConn(SCliThrd* pThrd) {
transReqQueueInit
(
&
conn
->
wreqQueue
);
transQueueInit
(
&
conn
->
cliMsgs
,
NULL
);
transInitBuffer
(
&
conn
->
readBuf
);
QUEUE_INIT
(
&
conn
->
q
);
conn
->
hostThrd
=
pThrd
;
conn
->
status
=
ConnNormal
;
...
...
@@ -651,8 +653,9 @@ static void cliDestroyConn(SCliConn* conn, bool clear) {
QUEUE_REMOVE
(
&
conn
->
q
);
QUEUE_INIT
(
&
conn
->
q
);
transRemoveExHandle
(
transGetRefMgt
(),
conn
->
refId
);
conn
->
refId
=
-
1
;
transDestroyBuffer
(
&
conn
->
readBuf
)
;
conn
->
refId
=
-
1
;
if
(
conn
->
task
!=
NULL
)
transDQCancel
(((
SCliThrd
*
)
conn
->
hostThrd
)
->
timeoutQueue
,
conn
->
task
);
if
(
clear
)
{
...
...
@@ -678,7 +681,6 @@ static void cliDestroy(uv_handle_t* handle) {
tTrace
(
"%s conn %p destroy successfully"
,
CONN_GET_INST_LABEL
(
conn
),
conn
);
transReqQueueClear
(
&
conn
->
wreqQueue
);
transDestroyBuffer
(
&
conn
->
readBuf
);
taosMemoryFree
(
conn
);
}
static
bool
cliHandleNoResp
(
SCliConn
*
conn
)
{
...
...
source/libs/transport/src/transComm.c
浏览文件 @
90f38515
...
...
@@ -16,6 +16,8 @@
#include "transComm.h"
#define BUFFER_CAP 4096
static
TdThreadOnce
transModuleInit
=
PTHREAD_ONCE_INIT
;
static
int32_t
refMgt
;
...
...
@@ -111,12 +113,56 @@ int transGetSockDebugInfo(struct sockaddr* sockname, char* dst) {
return
r
;
}
int
transInitBuffer
(
SConnBuffer
*
buf
)
{
transClearBuffer
(
buf
);
buf
->
cap
=
BUFFER_CAP
;
buf
->
buf
=
taosMemoryCalloc
(
1
,
BUFFER_CAP
);
buf
->
left
=
-
1
;
buf
->
len
=
0
;
buf
->
total
=
0
;
return
0
;
}
int
transDestroyBuffer
(
SConnBuffer
*
buf
)
{
taosMemoryFree
(
buf
->
buf
);
return
0
;
}
int
transClearBuffer
(
SConnBuffer
*
buf
)
{
memset
(
buf
,
0
,
sizeof
(
*
buf
));
buf
->
total
=
-
1
;
SConnBuffer
*
p
=
buf
;
if
(
p
->
cap
>
BUFFER_CAP
)
{
p
->
cap
=
BUFFER_CAP
;
p
->
buf
=
taosMemoryRealloc
(
p
->
buf
,
BUFFER_CAP
);
}
p
->
left
=
-
1
;
p
->
len
=
0
;
p
->
total
=
0
;
return
0
;
}
int
transDumpFromBuffer
(
SConnBuffer
*
connBuf
,
char
**
buf
)
{
SConnBuffer
*
p
=
connBuf
;
if
(
p
->
left
!=
0
)
{
return
-
1
;
}
int
total
=
connBuf
->
total
;
*
buf
=
taosMemoryCalloc
(
1
,
total
);
memcpy
(
*
buf
,
p
->
buf
,
total
);
transResetBuffer
(
connBuf
);
return
total
;
}
int
transResetBuffer
(
SConnBuffer
*
connBuf
)
{
SConnBuffer
*
p
=
connBuf
;
if
(
p
->
total
<=
p
->
len
)
{
int
left
=
p
->
len
-
p
->
total
;
memmove
(
p
->
buf
,
p
->
buf
+
p
->
total
,
left
);
p
->
left
=
-
1
;
p
->
total
=
0
;
p
->
len
=
left
;
}
else
{
p
->
left
=
-
1
;
p
->
total
=
0
;
p
->
len
=
0
;
}
return
0
;
}
int
transAllocBuffer
(
SConnBuffer
*
connBuf
,
uv_buf_t
*
uvBuf
)
{
...
...
@@ -126,54 +172,39 @@ int transAllocBuffer(SConnBuffer* connBuf, uv_buf_t* uvBuf) {
* |<------STransMsgHead------->|<-------------------userdata--------------->|<-----auth data----->|<----user
* info--->|
*/
static
const
int
CAPACITY
=
sizeof
(
STransMsgHead
);
SConnBuffer
*
p
=
connBuf
;
if
(
p
->
cap
==
0
)
{
p
->
buf
=
(
char
*
)
taosMemoryCalloc
(
CAPACITY
,
sizeof
(
char
));
tTrace
(
"internal malloc mem:%p, size:%d"
,
p
->
buf
,
CAPACITY
);
p
->
len
=
0
;
p
->
cap
=
CAPACITY
;
p
->
total
=
-
1
;
uvBuf
->
base
=
p
->
buf
;
uvBuf
->
len
=
CAPACITY
;
}
else
if
(
p
->
total
==
-
1
&&
p
->
len
<
CAPACITY
)
{
uvBuf
->
base
=
p
->
buf
+
p
->
len
;
uvBuf
->
len
=
CAPACITY
-
p
->
len
;
}
else
{
p
->
cap
=
p
->
total
;
p
->
buf
=
taosMemoryRealloc
(
p
->
buf
,
p
->
cap
);
tTrace
(
"internal realloc mem:%p, size:%d"
,
p
->
buf
,
p
->
cap
);
uvBuf
->
base
=
p
->
buf
+
p
->
len
;
uvBuf
->
base
=
p
->
buf
+
p
->
len
;
if
(
p
->
left
==
-
1
)
{
uvBuf
->
len
=
p
->
cap
-
p
->
len
;
}
else
{
if
(
p
->
left
<
p
->
cap
-
p
->
len
)
{
uvBuf
->
len
=
p
->
left
;
}
else
{
p
->
buf
=
taosMemoryRealloc
(
p
->
buf
,
p
->
left
+
p
->
len
);
uvBuf
->
base
=
p
->
buf
+
p
->
len
;
uvBuf
->
len
=
p
->
left
;
}
}
return
0
;
}
// check whether already read complete
bool
transReadComplete
(
SConnBuffer
*
connBuf
)
{
if
(
connBuf
->
total
==
-
1
&&
connBuf
->
len
>=
sizeof
(
STransMsgHead
))
{
STransMsgHead
head
;
memcpy
((
char
*
)
&
head
,
connBuf
->
buf
,
sizeof
(
head
));
int32_t
msgLen
=
(
int32_t
)
htonl
(
head
.
msgLen
);
connBuf
->
total
=
msgLen
;
}
if
(
connBuf
->
len
==
connBuf
->
cap
&&
connBuf
->
total
==
connBuf
->
cap
)
{
return
true
;
}
return
false
;
}
int
transPackMsg
(
STransMsgHead
*
msgHead
,
bool
sercured
,
bool
auth
)
{
return
0
;
}
int
transUnpackMsg
(
STransMsgHead
*
msgHead
)
{
return
0
;
}
int
transDestroyBuffer
(
SConnBuffer
*
buf
)
{
if
(
buf
->
cap
>
0
)
{
taosMemoryFreeClear
(
buf
->
buf
);
SConnBuffer
*
p
=
connBuf
;
if
(
p
->
len
>=
sizeof
(
STransMsgHead
))
{
if
(
p
->
left
==
-
1
)
{
STransMsgHead
head
;
memcpy
((
char
*
)
&
head
,
connBuf
->
buf
,
sizeof
(
head
));
int32_t
msgLen
=
(
int32_t
)
htonl
(
head
.
msgLen
);
p
->
total
=
msgLen
;
}
if
(
p
->
total
>=
p
->
len
)
{
p
->
left
=
p
->
total
-
p
->
len
;
}
else
{
p
->
left
=
0
;
}
}
transClearBuffer
(
buf
);
return
0
;
return
p
->
left
==
0
?
true
:
false
;
}
int
transSetConnOption
(
uv_tcp_t
*
stream
)
{
...
...
source/libs/transport/src/transSvr.c
浏览文件 @
90f38515
...
...
@@ -212,9 +212,10 @@ static void uvHandleActivityTimeout(uv_timer_t* handle) {
}
static
void
uvHandleReq
(
SSvrConn
*
pConn
)
{
SConnBuffer
*
pBuf
=
&
pConn
->
readBuf
;
char
*
msg
=
pBuf
->
buf
;
uint32_t
msgLen
=
pBuf
->
len
;
STransMsgHead
*
msg
=
NULL
;
int
msgLen
=
0
;
msgLen
=
transDumpFromBuffer
(
&
pConn
->
readBuf
,
(
char
**
)
&
msg
);
STransMsgHead
*
pHead
=
(
STransMsgHead
*
)
msg
;
pHead
->
code
=
htonl
(
pHead
->
code
);
...
...
@@ -761,6 +762,7 @@ static SSvrConn* createConn(void* hThrd) {
memset
(
&
pConn
->
regArg
,
0
,
sizeof
(
pConn
->
regArg
));
pConn
->
broken
=
false
;
pConn
->
status
=
ConnNormal
;
transInitBuffer
(
&
pConn
->
readBuf
);
SExHandle
*
exh
=
taosMemoryMalloc
(
sizeof
(
SExHandle
));
exh
->
handle
=
pConn
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录