Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
35c7506d
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,发现更多精彩内容 >>
提交
35c7506d
编写于
4月 10, 2021
作者:
Y
yihaoDeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
reset tcp
上级
35d220c8
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
12 addition
and
143 deletion
+12
-143
src/rpc/src/rpcTcp.c
src/rpc/src/rpcTcp.c
+12
-143
未找到文件。
src/rpc/src/rpcTcp.c
浏览文件 @
35c7506d
...
...
@@ -21,13 +21,6 @@
#include "rpcLog.h"
#include "rpcHead.h"
#include "rpcTcp.h"
#include "tlist.h"
typedef
struct
SConnItem
{
SOCKET
fd
;
uint32_t
ip
;
uint16_t
port
;
}
SConnItem
;
typedef
struct
SFdObj
{
void
*
signature
;
...
...
@@ -45,12 +38,6 @@ typedef struct SThreadObj {
pthread_t
thread
;
SFdObj
*
pHead
;
pthread_mutex_t
mutex
;
// receive the notify from dispatch thread
int
notifyReceiveFd
;
int
notifySendFd
;
SList
*
connQueue
;
uint32_t
ip
;
bool
stop
;
EpollFd
pollFd
;
...
...
@@ -82,7 +69,6 @@ typedef struct {
}
SServerObj
;
static
void
*
taosProcessTcpData
(
void
*
param
);
static
void
*
taosProcessServerTcpData
(
void
*
param
);
static
SFdObj
*
taosMallocFdObj
(
SThreadObj
*
pThreadObj
,
SOCKET
fd
);
static
void
taosFreeFdObj
(
SFdObj
*
pFdObj
);
static
void
taosReportBrokenLink
(
SFdObj
*
pFdObj
);
...
...
@@ -138,7 +124,6 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread
tstrncpy
(
pThreadObj
->
label
,
label
,
sizeof
(
pThreadObj
->
label
));
pThreadObj
->
shandle
=
shandle
;
pThreadObj
->
stop
=
false
;
pThreadObj
->
connQueue
=
tdListNew
(
sizeof
(
SConnItem
));
}
// initialize mutex, thread, fd which may fail
...
...
@@ -157,25 +142,7 @@ void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThread
break
;
}
int
fds
[
2
];
if
(
pipe
(
fds
))
{
tError
(
"%s failed to create pipe"
,
label
);
code
=
-
1
;
break
;
}
pThreadObj
->
notifyReceiveFd
=
fds
[
0
];
pThreadObj
->
notifySendFd
=
fds
[
1
];
struct
epoll_event
event
;
event
.
events
=
EPOLLIN
|
EPOLLRDHUP
;
event
.
data
.
fd
=
pThreadObj
->
notifyReceiveFd
;
if
(
epoll_ctl
(
pThreadObj
->
pollFd
,
EPOLL_CTL_ADD
,
pThreadObj
->
notifyReceiveFd
,
&
event
)
<
0
)
{
tError
(
"%s failed to create pipe"
,
label
);
code
=
-
1
;
break
;
}
code
=
pthread_create
(
&
(
pThreadObj
->
thread
),
&
thattr
,
taosProcessServerTcpData
,
(
void
*
)(
pThreadObj
));
code
=
pthread_create
(
&
(
pThreadObj
->
thread
),
&
thattr
,
taosProcessTcpData
,
(
void
*
)(
pThreadObj
));
if
(
code
!=
0
)
{
tError
(
"%s failed to create TCP process data thread(%s)"
,
label
,
strerror
(
errno
));
break
;
...
...
@@ -308,12 +275,17 @@ static void *taosAcceptTcpConnection(void *arg) {
// pick up the thread to handle this connection
pThreadObj
=
pServerObj
->
pThreadObj
[
threadId
];
pthread_mutex_lock
(
&
(
pThreadObj
->
mutex
));
SConnItem
item
=
{.
fd
=
connFd
,
.
ip
=
caddr
.
sin_addr
.
s_addr
,
.
port
=
htons
(
caddr
.
sin_port
)};
tdListAppend
(
pThreadObj
->
connQueue
,
&
item
);
pthread_mutex_unlock
(
&
(
pThreadObj
->
mutex
));
write
(
pThreadObj
->
notifySendFd
,
""
,
1
);
SFdObj
*
pFdObj
=
taosMallocFdObj
(
pThreadObj
,
connFd
);
if
(
pFdObj
)
{
pFdObj
->
ip
=
caddr
.
sin_addr
.
s_addr
;
pFdObj
->
port
=
htons
(
caddr
.
sin_port
);
tDebug
(
"%s new TCP connection from %s:%hu, fd:%d FD:%p numOfFds:%d"
,
pServerObj
->
label
,
taosInetNtoa
(
caddr
.
sin_addr
),
pFdObj
->
port
,
connFd
,
pFdObj
,
pThreadObj
->
numOfFds
);
}
else
{
taosCloseSocket
(
connFd
);
tError
(
"%s failed to malloc FdObj(%s) for connection from:%s:%hu"
,
pServerObj
->
label
,
strerror
(
errno
),
taosInetNtoa
(
caddr
.
sin_addr
),
htons
(
caddr
.
sin_port
));
}
// pick up next thread for next connection
threadId
++
;
...
...
@@ -619,109 +591,6 @@ static void *taosProcessTcpData(void *param) {
return
NULL
;
}
static
void
*
taosProcessServerTcpData
(
void
*
param
)
{
SThreadObj
*
pThreadObj
=
param
;
SFdObj
*
pFdObj
;
struct
epoll_event
events
[
maxEvents
];
SRecvInfo
recvInfo
;
char
bb
[
1
];
#ifdef __APPLE__
taos_block_sigalrm
();
#endif // __APPLE__
while
(
1
)
{
int
fdNum
=
epoll_wait
(
pThreadObj
->
pollFd
,
events
,
maxEvents
,
TAOS_EPOLL_WAIT_TIME
);
if
(
pThreadObj
->
stop
)
{
tDebug
(
"%s TCP thread get stop event, exiting..."
,
pThreadObj
->
label
);
break
;
}
if
(
fdNum
<
0
)
continue
;
for
(
int
i
=
0
;
i
<
fdNum
;
++
i
)
{
if
(
events
[
i
].
data
.
fd
==
pThreadObj
->
notifyReceiveFd
)
{
if
(
events
[
i
].
events
&
EPOLLIN
)
{
read
(
pThreadObj
->
notifyReceiveFd
,
bb
,
1
);
pthread_mutex_lock
(
&
(
pThreadObj
->
mutex
));
SListNode
*
head
=
tdListPopHead
(
pThreadObj
->
connQueue
);
pthread_mutex_unlock
(
&
(
pThreadObj
->
mutex
));
SConnItem
item
=
{
0
};
tdListNodeGetData
(
pThreadObj
->
connQueue
,
head
,
&
item
);
tfree
(
head
);
// register fd on epoll
SFdObj
*
pFdObj
=
taosMallocFdObj
(
pThreadObj
,
item
.
fd
);
if
(
pFdObj
)
{
pFdObj
->
ip
=
item
.
ip
;
pFdObj
->
port
=
item
.
port
;
tDebug
(
"%s new TCP connection from %u:%hu, fd:%d FD:%p numOfFds:%d"
,
pThreadObj
->
label
,
pFdObj
->
ip
,
pFdObj
->
port
,
item
.
fd
,
pFdObj
,
pThreadObj
->
numOfFds
);
}
else
{
taosCloseSocket
(
item
.
fd
);
tError
(
"%s failed to malloc FdObj(%s) for connection from:%u:%hu"
,
pThreadObj
->
label
,
strerror
(
errno
),
pFdObj
->
ip
,
pFdObj
->
port
);
}
}
continue
;
}
pFdObj
=
events
[
i
].
data
.
ptr
;
if
(
events
[
i
].
events
&
EPOLLERR
)
{
tDebug
(
"%s %p FD:%p epoll errors"
,
pThreadObj
->
label
,
pFdObj
->
thandle
,
pFdObj
);
taosReportBrokenLink
(
pFdObj
);
continue
;
}
if
(
events
[
i
].
events
&
EPOLLRDHUP
)
{
tDebug
(
"%s %p FD:%p RD hang up"
,
pThreadObj
->
label
,
pFdObj
->
thandle
,
pFdObj
);
taosReportBrokenLink
(
pFdObj
);
continue
;
}
if
(
events
[
i
].
events
&
EPOLLHUP
)
{
tDebug
(
"%s %p FD:%p hang up"
,
pThreadObj
->
label
,
pFdObj
->
thandle
,
pFdObj
);
taosReportBrokenLink
(
pFdObj
);
continue
;
}
if
(
taosReadTcpData
(
pFdObj
,
&
recvInfo
)
<
0
)
{
shutdown
(
pFdObj
->
fd
,
SHUT_WR
);
continue
;
}
pFdObj
->
thandle
=
(
*
(
pThreadObj
->
processData
))(
&
recvInfo
);
if
(
pFdObj
->
thandle
==
NULL
)
taosFreeFdObj
(
pFdObj
);
}
if
(
pThreadObj
->
stop
)
break
;
}
if
(
pThreadObj
->
connQueue
)
{
pThreadObj
->
connQueue
=
tdListFree
(
pThreadObj
->
connQueue
);
}
// close pipe
close
(
pThreadObj
->
notifySendFd
);
close
(
pThreadObj
->
notifyReceiveFd
);
if
(
pThreadObj
->
pollFd
>=
0
)
{
EpollClose
(
pThreadObj
->
pollFd
);
pThreadObj
->
pollFd
=
-
1
;
}
while
(
pThreadObj
->
pHead
)
{
SFdObj
*
pFdObj
=
pThreadObj
->
pHead
;
pThreadObj
->
pHead
=
pFdObj
->
next
;
taosReportBrokenLink
(
pFdObj
);
}
pthread_mutex_destroy
(
&
(
pThreadObj
->
mutex
));
tDebug
(
"%s TCP thread exits ..."
,
pThreadObj
->
label
);
tfree
(
pThreadObj
);
return
NULL
;
}
static
SFdObj
*
taosMallocFdObj
(
SThreadObj
*
pThreadObj
,
SOCKET
fd
)
{
struct
epoll_event
event
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录