Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小楼昨夜-听风雨
TDengine
提交
95b157c0
T
TDengine
项目概览
小楼昨夜-听风雨
/
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
95b157c0
编写于
7月 20, 2019
作者:
S
slguan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix the issue #127, Check dead http links and close them
上级
412db1ab
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
22 addition
and
3 deletion
+22
-3
src/modules/http/inc/httpHandle.h
src/modules/http/inc/httpHandle.h
+1
-0
src/modules/http/src/httpServer.c
src/modules/http/src/httpServer.c
+21
-3
未找到文件。
src/modules/http/inc/httpHandle.h
浏览文件 @
95b157c0
...
@@ -140,6 +140,7 @@ typedef struct HttpContext {
...
@@ -140,6 +140,7 @@ typedef struct HttpContext {
void
*
signature
;
void
*
signature
;
int
fd
;
int
fd
;
uint32_t
accessTimes
;
uint32_t
accessTimes
;
uint32_t
lastAccessTime
;
uint8_t
httpVersion
:
1
;
uint8_t
httpVersion
:
1
;
uint8_t
httpChunked
:
1
;
uint8_t
httpChunked
:
1
;
uint8_t
httpKeepAlive
:
2
;
// http1.0 and not keep-alive, close connection immediately
uint8_t
httpKeepAlive
:
2
;
// http1.0 and not keep-alive, close connection immediately
...
...
src/modules/http/src/httpServer.c
浏览文件 @
95b157c0
...
@@ -36,6 +36,7 @@
...
@@ -36,6 +36,7 @@
#include "tlog.h"
#include "tlog.h"
#include "tsocket.h"
#include "tsocket.h"
#include "tutil.h"
#include "tutil.h"
#include "ttime.h"
#include "http.h"
#include "http.h"
#include "httpCode.h"
#include "httpCode.h"
...
@@ -70,6 +71,7 @@ HttpContext *httpCreateContext(HttpServer *pServer) {
...
@@ -70,6 +71,7 @@ HttpContext *httpCreateContext(HttpServer *pServer) {
pContext
->
signature
=
pContext
;
pContext
->
signature
=
pContext
;
pContext
->
httpVersion
=
HTTP_VERSION_10
;
pContext
->
httpVersion
=
HTTP_VERSION_10
;
pContext
->
lastAccessTime
=
taosGetTimestampSec
();
if
(
pthread_mutex_init
(
&
(
pContext
->
mutex
),
NULL
)
<
0
)
{
if
(
pthread_mutex_init
(
&
(
pContext
->
mutex
),
NULL
)
<
0
)
{
httpFreeContext
(
pServer
,
pContext
);
httpFreeContext
(
pServer
,
pContext
);
return
NULL
;
return
NULL
;
...
@@ -140,6 +142,7 @@ void httpCleanUpContext(HttpThread *pThread, HttpContext *pContext) {
...
@@ -140,6 +142,7 @@ void httpCleanUpContext(HttpThread *pThread, HttpContext *pContext) {
bool
httpInitContext
(
HttpContext
*
pContext
)
{
bool
httpInitContext
(
HttpContext
*
pContext
)
{
pContext
->
accessTimes
++
;
pContext
->
accessTimes
++
;
pContext
->
lastAccessTime
=
taosGetTimestampSec
();
pContext
->
httpVersion
=
HTTP_VERSION_10
;
pContext
->
httpVersion
=
HTTP_VERSION_10
;
pContext
->
httpKeepAlive
=
HTTP_KEEPALIVE_NO_INPUT
;
pContext
->
httpKeepAlive
=
HTTP_KEEPALIVE_NO_INPUT
;
pContext
->
httpChunked
=
HTTP_UNCUNKED
;
pContext
->
httpChunked
=
HTTP_UNCUNKED
;
...
@@ -216,12 +219,9 @@ void httpCleanUpConnect(HttpServer *pServer) {
...
@@ -216,12 +219,9 @@ void httpCleanUpConnect(HttpServer *pServer) {
pThread
=
pServer
->
pThreads
+
i
;
pThread
=
pServer
->
pThreads
+
i
;
taosCloseSocket
(
pThread
->
pollFd
);
taosCloseSocket
(
pThread
->
pollFd
);
pthread_mutex_lock
(
&
pThread
->
threadMutex
);
while
(
pThread
->
pHead
)
{
while
(
pThread
->
pHead
)
{
httpCleanUpContext
(
pThread
,
pThread
->
pHead
);
httpCleanUpContext
(
pThread
,
pThread
->
pHead
);
pThread
->
pHead
=
pThread
->
pHead
;
}
}
pthread_mutex_unlock
(
&
pThread
->
threadMutex
);
pthread_cancel
(
pThread
->
thread
);
pthread_cancel
(
pThread
->
thread
);
pthread_join
(
pThread
->
thread
,
NULL
);
pthread_join
(
pThread
->
thread
,
NULL
);
...
@@ -233,6 +233,20 @@ void httpCleanUpConnect(HttpServer *pServer) {
...
@@ -233,6 +233,20 @@ void httpCleanUpConnect(HttpServer *pServer) {
httpTrace
(
"http server:%s is cleaned up"
,
pServer
->
label
);
httpTrace
(
"http server:%s is cleaned up"
,
pServer
->
label
);
}
}
void
httpCloseDeadConnects
(
HttpThread
*
pThread
)
{
int32_t
thresholdSec
=
taosGetTimestampSec
()
-
3600
;
HttpContext
*
pContext
=
(
HttpContext
*
)
pThread
->
pHead
;
while
(
pContext
!=
NULL
&&
pContext
==
pContext
->
signature
)
{
HttpContext
*
pContextNext
=
pContext
->
next
;
if
(
pContext
->
lastAccessTime
<
thresholdSec
)
{
httpPrint
(
"context:%p, fd:%d, ip:%s, lastAccessTime:%d smaller then threshold:%d, so close it"
,
pContext
,
pContext
->
fd
,
pContext
->
ipstr
,
pContext
->
lastAccessTime
,
thresholdSec
);
httpCloseContextByServer
(
pThread
,
pContext
);
}
pContext
=
pContextNext
;
}
}
// read all the data, then just discard it
// read all the data, then just discard it
void
httpReadDirtyData
(
int
fd
)
{
void
httpReadDirtyData
(
int
fd
)
{
char
data
[
1024
]
=
{
0
};
char
data
[
1024
]
=
{
0
};
...
@@ -392,6 +406,7 @@ void httpAcceptHttpConnection(void *arg) {
...
@@ -392,6 +406,7 @@ void httpAcceptHttpConnection(void *arg) {
struct
sockaddr_in
clientAddr
;
struct
sockaddr_in
clientAddr
;
int
sockFd
;
int
sockFd
;
int
threadId
=
0
;
int
threadId
=
0
;
int
connThreshold
=
2
*
tsHttpCacheSessions
/
tsHttpMaxThreads
;
HttpThread
*
pThread
;
HttpThread
*
pThread
;
HttpServer
*
pServer
;
HttpServer
*
pServer
;
HttpContext
*
pContext
;
HttpContext
*
pContext
;
...
@@ -475,6 +490,9 @@ void httpAcceptHttpConnection(void *arg) {
...
@@ -475,6 +490,9 @@ void httpAcceptHttpConnection(void *arg) {
pContext
,
connFd
,
inet_ntoa
(
clientAddr
.
sin_addr
),
htons
(
clientAddr
.
sin_port
),
pThread
->
label
,
pContext
,
connFd
,
inet_ntoa
(
clientAddr
.
sin_addr
),
htons
(
clientAddr
.
sin_port
),
pThread
->
label
,
pThread
->
numOfFds
);
pThread
->
numOfFds
);
if
(
pThread
->
numOfFds
>
connThreshold
)
{
httpCloseDeadConnects
(
pThread
);
}
// pick up next thread for next connection
// pick up next thread for next connection
threadId
++
;
threadId
++
;
threadId
=
threadId
%
pServer
->
numOfThreads
;
threadId
=
threadId
%
pServer
->
numOfThreads
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录