Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
f8785125
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
f8785125
编写于
9月 14, 2020
作者:
R
root
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-1291]
上级
dfa681df
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
37 addition
and
33 deletion
+37
-33
src/plugins/http/inc/httpContext.h
src/plugins/http/inc/httpContext.h
+1
-1
src/plugins/http/inc/httpInt.h
src/plugins/http/inc/httpInt.h
+3
-3
src/plugins/http/src/httpContext.c
src/plugins/http/src/httpContext.c
+6
-3
src/plugins/http/src/httpParser.c
src/plugins/http/src/httpParser.c
+22
-23
src/plugins/http/src/httpServer.c
src/plugins/http/src/httpServer.c
+5
-3
未找到文件。
src/plugins/http/inc/httpContext.h
浏览文件 @
f8785125
...
...
@@ -25,7 +25,7 @@ const char *httpContextStateStr(HttpContextState state);
HttpContext
*
httpCreateContext
(
int32_t
fd
);
bool
httpInitContext
(
HttpContext
*
pContext
);
HttpContext
*
httpGetContext
(
void
*
pContext
);
void
httpReleaseContext
(
HttpContext
*
pContext
);
void
httpReleaseContext
(
HttpContext
*
pContext
,
bool
clearRes
);
void
httpCloseContextByServer
(
HttpContext
*
pContext
);
void
httpCloseContextByApp
(
HttpContext
*
pContext
);
void
httpNotifyContextClose
(
HttpContext
*
pContext
);
...
...
src/plugins/http/inc/httpInt.h
浏览文件 @
f8785125
...
...
@@ -32,9 +32,9 @@
#define HTTP_MAX_BUFFER_SIZE 1024*1024*8
#define HTTP_LABEL_SIZE 8
#define HTTP_MAX_EVENTS 10
#define HTTP_BUFFER_INIT
8192
#define HTTP_BUFFER_SIZE 8
192000
#define HTTP_STEP_SIZE
1024
//http message get process step by step
#define HTTP_BUFFER_INIT
4096
#define HTTP_BUFFER_SIZE 8
388608
#define HTTP_STEP_SIZE
4096
//http message get process step by step
#define HTTP_METHOD_SCANNER_SIZE 7 //http method fp size
#define TSDB_CODE_HTTP_GC_TARGET_SIZE 512
#define HTTP_WRITE_RETRY_TIMES 500
...
...
src/plugins/http/src/httpContext.c
浏览文件 @
f8785125
...
...
@@ -145,14 +145,17 @@ HttpContext *httpGetContext(void *ptr) {
return
NULL
;
}
void
httpReleaseContext
(
HttpContext
*
pContext
)
{
void
httpReleaseContext
(
HttpContext
*
pContext
,
bool
clearRes
)
{
int32_t
refCount
=
atomic_sub_fetch_32
(
&
pContext
->
refCount
,
1
);
if
(
refCount
<
0
)
{
httpError
(
"context:%p, is already released, refCount:%d"
,
pContext
,
refCount
);
return
;
}
httpClearParser
(
pContext
->
parser
);
if
(
clearRes
)
{
httpClearParser
(
pContext
->
parser
);
}
HttpContext
**
ppContext
=
pContext
->
ppContext
;
httpTrace
(
"context:%p, is released, data:%p refCount:%d"
,
pContext
,
ppContext
,
refCount
);
...
...
@@ -211,7 +214,7 @@ void httpCloseContextByApp(HttpContext *pContext) {
httpContextStateStr
(
pContext
->
state
),
pContext
->
state
);
}
httpReleaseContext
(
pContext
);
httpReleaseContext
(
pContext
,
true
);
}
void
httpCloseContextByServer
(
HttpContext
*
pContext
)
{
...
...
src/plugins/http/src/httpParser.c
浏览文件 @
f8785125
...
...
@@ -110,11 +110,11 @@ static void httpCleanupString(HttpString *str) {
static
int32_t
httpAppendString
(
HttpString
*
str
,
const
char
*
s
,
int32_t
len
)
{
if
(
str
->
size
==
0
)
{
str
->
pos
=
0
;
str
->
size
=
32
;
str
->
size
=
64
;
str
->
str
=
malloc
(
str
->
size
);
}
else
if
(
str
->
pos
+
len
+
1
>=
str
->
size
)
{
str
->
size
+=
len
;
str
->
size
*=
10
;
str
->
size
*=
4
;
str
->
str
=
realloc
(
str
->
str
,
str
->
size
);
}
else
{
}
...
...
@@ -153,17 +153,10 @@ static int32_t httpOnRequestLine(HttpParser *pParser, char *method, char *target
for
(
int32_t
i
=
0
;
i
<
HTTP_MAX_URL
;
i
++
)
{
char
*
pSeek
=
strchr
(
pStart
,
'/'
);
if
(
pSeek
==
NULL
)
{
pParser
->
path
[
i
].
str
=
strdup
(
pStart
);
pParser
->
path
[
i
].
size
=
strlen
(
pStart
);
pParser
->
path
[
i
].
pos
=
pParser
->
path
[
i
].
size
;
httpAppendString
(
pParser
->
path
+
i
,
pStart
,
strlen
(
pStart
));
break
;
}
else
{
int32_t
len
=
(
int32_t
)(
pSeek
-
pStart
);
pParser
->
path
[
i
].
str
=
malloc
(
len
+
1
);
memcpy
(
pParser
->
path
[
i
].
str
,
pStart
,
len
);
pParser
->
path
[
i
].
str
[
len
]
=
0
;
pParser
->
path
[
i
].
size
=
len
;
pParser
->
path
[
i
].
pos
=
len
;
httpAppendString
(
pParser
->
path
+
i
,
pStart
,
(
int32_t
)(
pSeek
-
pStart
));
}
pStart
=
pSeek
+
1
;
}
...
...
@@ -336,23 +329,29 @@ static int32_t httpOnBody(HttpParser *parser, const char *chunk, int32_t len) {
HttpString
*
buf
=
&
parser
->
body
;
if
(
parser
->
parseCode
!=
TSDB_CODE_SUCCESS
)
return
-
1
;
if
(
buf
->
size
<=
0
)
{
buf
->
size
=
MIN
(
len
+
2
,
HTTP_BUFFER_SIZE
);
buf
->
str
=
malloc
(
buf
->
size
);
}
int32_t
newSize
=
buf
->
pos
+
len
+
1
;
if
(
newSize
>=
buf
->
size
)
{
if
(
buf
->
size
>=
HTTP_BUFFER_SIZE
)
{
httpError
(
"context:%p, fd:%d, failed parse body, exceeding buffer size %d"
,
pContext
,
pContext
->
fd
,
buf
->
size
);
httpOnError
(
parser
,
0
,
TSDB_CODE_HTTP_REQUSET_TOO_BIG
);
return
-
1
;
}
else
{
newSize
=
MAX
(
newSize
,
32
);
newSize
*=
10
;
newSize
=
MIN
(
newSize
,
HTTP_BUFFER_SIZE
);
buf
->
str
=
realloc
(
buf
->
str
,
newSize
);
if
(
buf
->
str
==
NULL
)
{
httpError
(
"context:%p, fd:%d, failed parse body, realloc %d failed"
,
pContext
,
pContext
->
fd
,
newSize
);
httpOnError
(
parser
,
0
,
TSDB_CODE_HTTP_NO_ENOUGH_MEMORY
);
return
-
1
;
}
buf
->
size
=
newSize
;
}
newSize
=
MAX
(
newSize
,
HTTP_BUFFER_INIT
);
newSize
*=
4
;
newSize
=
MIN
(
newSize
,
HTTP_BUFFER_SIZE
);
buf
->
str
=
realloc
(
buf
->
str
,
newSize
);
buf
->
size
=
newSize
;
if
(
buf
->
str
==
NULL
)
{
httpError
(
"context:%p, fd:%d, failed parse body, realloc %d failed"
,
pContext
,
pContext
->
fd
,
buf
->
size
);
httpOnError
(
parser
,
0
,
TSDB_CODE_HTTP_NO_ENOUGH_MEMORY
);
return
-
1
;
}
}
...
...
@@ -389,7 +388,7 @@ static int32_t httpPushStack(HttpParser *parser, HTTP_PARSER_STATE state) {
stack
->
size
=
32
;
stack
->
stacks
=
malloc
(
stack
->
size
*
sizeof
(
int8_t
));
}
else
if
(
stack
->
pos
+
1
>
stack
->
size
)
{
stack
->
size
*=
10
;
stack
->
size
*=
2
;
stack
->
stacks
=
realloc
(
stack
->
stacks
,
stack
->
size
*
sizeof
(
int8_t
));
}
else
{
}
...
...
src/plugins/http/src/httpServer.c
浏览文件 @
f8785125
...
...
@@ -132,7 +132,7 @@ static void httpProcessHttpData(void *param) {
if
(
!
httpAlterContextState
(
pContext
,
HTTP_CONTEXT_STATE_READY
,
HTTP_CONTEXT_STATE_READY
))
{
httpDebug
(
"context:%p, fd:%d, state:%s, not in ready state, ignore read events"
,
pContext
,
pContext
->
fd
,
httpContextStateStr
(
pContext
->
state
));
httpReleaseContext
(
pContext
);
httpReleaseContext
(
pContext
,
true
);
continue
;
}
...
...
@@ -145,6 +145,8 @@ static void httpProcessHttpData(void *param) {
if
(
httpReadData
(
pContext
))
{
(
*
(
pThread
->
processData
))(
pContext
);
atomic_fetch_add_32
(
&
pServer
->
requestNum
,
1
);
}
else
{
httpReleaseContext
(
pContext
,
false
);
}
}
}
...
...
@@ -226,7 +228,7 @@ static void *httpAcceptHttpConnection(void *arg) {
httpError
(
"context:%p, fd:%d, ip:%s, thread:%s, failed to add http fd for epoll, error:%s"
,
pContext
,
connFd
,
pContext
->
ipstr
,
pThread
->
label
,
strerror
(
errno
));
taosClose
(
pContext
->
fd
);
httpReleaseContext
(
pContext
);
httpReleaseContext
(
pContext
,
true
);
continue
;
}
...
...
@@ -314,7 +316,7 @@ static bool httpReadData(HttpContext *pContext) {
int32_t
nread
=
(
int32_t
)
taosReadSocket
(
pContext
->
fd
,
buf
,
sizeof
(
buf
));
if
(
nread
>
0
)
{
buf
[
nread
]
=
'\0'
;
httpTrace
(
"context:%p, fd:%d, nread:%d
content:%s"
,
pContext
,
pContext
->
fd
,
nread
,
buf
);
httpTrace
(
"context:%p, fd:%d, nread:%d
"
,
pContext
,
pContext
->
fd
,
nread
);
int32_t
ok
=
httpParseBuf
(
pParser
,
buf
,
nread
);
if
(
ok
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录