Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
25a4625e
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看板
提交
25a4625e
编写于
2月 22, 2020
作者:
陶建辉(Jeff)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support both TCP and UDP simultaneously for both server and client
上级
db1e1e54
变更
11
展开全部
显示空白变更内容
内联
并排
Showing
11 changed file
with
603 addition
and
993 deletion
+603
-993
src/inc/trpc.h
src/inc/trpc.h
+2
-12
src/rpc/inc/rpcClient.h
src/rpc/inc/rpcClient.h
+1
-1
src/rpc/inc/rpcHead.h
src/rpc/inc/rpcHead.h
+21
-3
src/rpc/inc/rpcServer.h
src/rpc/inc/rpcServer.h
+1
-1
src/rpc/inc/rpcUdp.h
src/rpc/inc/rpcUdp.h
+2
-3
src/rpc/src/rpcClient.c
src/rpc/src/rpcClient.c
+153
-150
src/rpc/src/rpcMain.c
src/rpc/src/rpcMain.c
+119
-104
src/rpc/src/rpcServer.c
src/rpc/src/rpcServer.c
+150
-137
src/rpc/src/rpcUdp.c
src/rpc/src/rpcUdp.c
+150
-570
src/rpc/test/rclient.c
src/rpc/test/rclient.c
+2
-6
src/rpc/test/rserver.c
src/rpc/test/rserver.c
+2
-6
未找到文件。
src/inc/trpc.h
浏览文件 @
25a4625e
...
@@ -23,18 +23,8 @@ extern "C" {
...
@@ -23,18 +23,8 @@ extern "C" {
#include <stdint.h>
#include <stdint.h>
#include "taosdef.h"
#include "taosdef.h"
#define TAOS_CONN_UDPS 0
#define TAOS_CONN_SERVER 0
#define TAOS_CONN_UDPC 1
#define TAOS_CONN_CLIENT 1
#define TAOS_CONN_TCPS 2
#define TAOS_CONN_TCPC 3
#define TAOS_CONN_HTTPS 4
#define TAOS_CONN_HTTPC 5
#define TAOS_SOCKET_TYPE_NAME_TCP "tcp"
#define TAOS_SOCKET_TYPE_NAME_UDP "udp"
#define TAOS_CONN_SOCKET_TYPE_S() ((strcasecmp(tsSocketType, TAOS_SOCKET_TYPE_NAME_UDP) == 0)? TAOS_CONN_UDPS:TAOS_CONN_TCPS)
#define TAOS_CONN_SOCKET_TYPE_C() ((strcasecmp(tsSocketType, TAOS_SOCKET_TYPE_NAME_UDP) == 0)? TAOS_CONN_UDPC:TAOS_CONN_TCPC)
extern
int
tsRpcHeadSize
;
extern
int
tsRpcHeadSize
;
...
...
src/rpc/inc/rpcClient.h
浏览文件 @
25a4625e
...
@@ -26,7 +26,7 @@ void *taosInitTcpClient(char *ip, uint16_t port, char *label, int num, void *fp,
...
@@ -26,7 +26,7 @@ void *taosInitTcpClient(char *ip, uint16_t port, char *label, int num, void *fp,
void
taosCleanUpTcpClient
(
void
*
chandle
);
void
taosCleanUpTcpClient
(
void
*
chandle
);
void
*
taosOpenTcpClientConnection
(
void
*
shandle
,
void
*
thandle
,
char
*
ip
,
uint16_t
port
);
void
*
taosOpenTcpClientConnection
(
void
*
shandle
,
void
*
thandle
,
char
*
ip
,
uint16_t
port
);
void
taosCloseTcpClientConnection
(
void
*
chandle
);
void
taosCloseTcpClientConnection
(
void
*
chandle
);
int
taosSendTcpClientData
(
uint32_t
ip
,
uint16_t
port
,
char
*
data
,
int
len
,
void
*
chandle
);
int
taosSendTcpClientData
(
uint32_t
ip
,
uint16_t
port
,
void
*
data
,
int
len
,
void
*
chandle
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
src/rpc/inc/rpcHead.h
浏览文件 @
25a4625e
...
@@ -20,12 +20,29 @@
...
@@ -20,12 +20,29 @@
extern
"C"
{
extern
"C"
{
#endif
#endif
#define RPC_CONN_UDPS 0
#define RPC_CONN_UDPC 1
#define RPC_CONN_TCPS 2
#define RPC_CONN_TCPC 3
#define RPC_CONN_TCP 2
typedef
struct
{
void
*
msg
;
int
msgLen
;
uint32_t
ip
;
uint16_t
port
;
int
connType
;
void
*
shandle
;
void
*
thandle
;
void
*
chandle
;
}
SRecvInfo
;
#pragma pack(push, 1)
#pragma pack(push, 1)
typedef
struct
{
typedef
struct
{
char
version
:
4
;
// RPC version
char
version
:
4
;
// RPC version
char
comp
:
4
;
// compression algorithm, 0:no compression 1:lz4
char
comp
:
4
;
// compression algorithm, 0:no compression 1:lz4
char
tcp
:
2
;
// tcp flag
char
resflag
:
2
;
// reserved bits
char
spi
:
3
;
// security parameter index
char
spi
:
3
;
// security parameter index
char
encrypt
:
3
;
// encrypt algorithm, 0: no encryption
char
encrypt
:
3
;
// encrypt algorithm, 0: no encryption
uint16_t
tranId
;
// transcation ID
uint16_t
tranId
;
// transcation ID
...
@@ -33,12 +50,12 @@ typedef struct {
...
@@ -33,12 +50,12 @@ typedef struct {
uint32_t
sourceId
;
// source ID, an index for connection list
uint32_t
sourceId
;
// source ID, an index for connection list
uint32_t
destId
;
// destination ID, an index for connection list
uint32_t
destId
;
// destination ID, an index for connection list
uint32_t
destIp
;
// destination IP address, for NAT scenario
uint32_t
destIp
;
// destination IP address, for NAT scenario
char
user
[
TSDB_UNI_LEN
];
char
user
[
TSDB_UNI_LEN
];
// user ID
uint16_t
port
;
// for UDP only, port may be changed
uint16_t
port
;
// for UDP only, port may be changed
char
empty
[
1
];
// reserved
char
empty
[
1
];
// reserved
uint8_t
msgType
;
// message type
uint8_t
msgType
;
// message type
int32_t
msgLen
;
// message length including the header iteslf
int32_t
msgLen
;
// message length including the header iteslf
int32_t
code
;
int32_t
code
;
// code in response message
uint8_t
content
[
0
];
// message body starts from here
uint8_t
content
[
0
];
// message body starts from here
}
SRpcHead
;
}
SRpcHead
;
...
@@ -54,6 +71,7 @@ typedef struct {
...
@@ -54,6 +71,7 @@ typedef struct {
#pragma pack(pop)
#pragma pack(pop)
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
...
...
src/rpc/inc/rpcServer.h
浏览文件 @
25a4625e
...
@@ -25,7 +25,7 @@ extern "C" {
...
@@ -25,7 +25,7 @@ extern "C" {
void
*
taosInitTcpServer
(
char
*
ip
,
uint16_t
port
,
char
*
label
,
int
numOfThreads
,
void
*
fp
,
void
*
shandle
);
void
*
taosInitTcpServer
(
char
*
ip
,
uint16_t
port
,
char
*
label
,
int
numOfThreads
,
void
*
fp
,
void
*
shandle
);
void
taosCleanUpTcpServer
(
void
*
param
);
void
taosCleanUpTcpServer
(
void
*
param
);
void
taosCloseTcpServerConnection
(
void
*
param
);
void
taosCloseTcpServerConnection
(
void
*
param
);
int
taosSendTcpServerData
(
uint32_t
ip
,
uint16_t
port
,
char
*
data
,
int
len
,
void
*
chandle
);
int
taosSendTcpServerData
(
uint32_t
ip
,
uint16_t
port
,
void
*
data
,
int
len
,
void
*
chandle
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
src/rpc/inc/rpcUdp.h
浏览文件 @
25a4625e
...
@@ -22,10 +22,9 @@ extern "C" {
...
@@ -22,10 +22,9 @@ extern "C" {
#include "taosdef.h"
#include "taosdef.h"
void
*
taosInitUdpServer
(
char
*
ip
,
uint16_t
port
,
char
*
label
,
int
,
void
*
fp
,
void
*
shandle
);
void
*
taosInitUdpConnection
(
char
*
ip
,
uint16_t
port
,
char
*
label
,
int
,
void
*
fp
,
void
*
shandle
);
void
*
taosInitUdpClient
(
char
*
ip
,
uint16_t
port
,
char
*
label
,
int
,
void
*
fp
,
void
*
shandle
);
void
taosCleanUpUdpConnection
(
void
*
handle
);
void
taosCleanUpUdpConnection
(
void
*
handle
);
int
taosSendUdpData
(
uint32_t
ip
,
uint16_t
port
,
char
*
data
,
int
dataLen
,
void
*
chandle
);
int
taosSendUdpData
(
uint32_t
ip
,
uint16_t
port
,
void
*
data
,
int
dataLen
,
void
*
chandle
);
void
*
taosOpenUdpConnection
(
void
*
shandle
,
void
*
thandle
,
char
*
ip
,
uint16_t
port
);
void
*
taosOpenUdpConnection
(
void
*
shandle
,
void
*
thandle
,
char
*
ip
,
uint16_t
port
);
void
taosFreeMsgHdr
(
void
*
hdr
);
void
taosFreeMsgHdr
(
void
*
hdr
);
...
...
src/rpc/src/rpcClient.c
浏览文件 @
25a4625e
...
@@ -45,16 +45,143 @@ typedef struct _tcp_client {
...
@@ -45,16 +45,143 @@ typedef struct _tcp_client {
int
numOfFds
;
int
numOfFds
;
char
label
[
12
];
char
label
[
12
];
char
ipstr
[
20
];
char
ipstr
[
20
];
void
*
shandle
;
// handle passed by upper layer during server initialization
void
*
shandle
;
// handle passed by upper layer during server initialization
void
*
(
*
processData
)(
char
*
data
,
int
dataLen
,
unsigned
int
ip
,
uint16_t
port
,
void
*
shandle
,
void
*
thandle
,
void
*
(
*
processData
)(
SRecvInfo
*
pRecv
);
void
*
chandle
);
// char buffer[128000];
}
STcpClient
;
}
STcpClient
;
#define maxTcpEvents 100
#define maxTcpEvents 100
static
void
taosCleanUpTcpFdObj
(
STcpFd
*
pFdObj
);
static
void
*
taosReadTcpData
(
void
*
param
);
void
*
taosInitTcpClient
(
char
*
ip
,
uint16_t
port
,
char
*
label
,
int
num
,
void
*
fp
,
void
*
shandle
)
{
STcpClient
*
pTcp
;
pthread_attr_t
thattr
;
pTcp
=
(
STcpClient
*
)
malloc
(
sizeof
(
STcpClient
));
memset
(
pTcp
,
0
,
sizeof
(
STcpClient
));
strcpy
(
pTcp
->
label
,
label
);
strcpy
(
pTcp
->
ipstr
,
ip
);
pTcp
->
shandle
=
shandle
;
if
(
pthread_mutex_init
(
&
(
pTcp
->
mutex
),
NULL
)
<
0
)
{
tError
(
"%s failed to init TCP mutex, reason:%s"
,
label
,
strerror
(
errno
));
return
NULL
;
}
if
(
pthread_cond_init
(
&
(
pTcp
->
fdReady
),
NULL
)
!=
0
)
{
tError
(
"%s init TCP condition variable failed, reason:%s
\n
"
,
label
,
strerror
(
errno
));
return
NULL
;
}
pTcp
->
pollFd
=
epoll_create
(
10
);
// size does not matter
if
(
pTcp
->
pollFd
<
0
)
{
tError
(
"%s failed to create TCP epoll"
,
label
);
return
NULL
;
}
pTcp
->
processData
=
fp
;
pthread_attr_init
(
&
thattr
);
pthread_attr_setdetachstate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
if
(
pthread_create
(
&
(
pTcp
->
thread
),
&
thattr
,
taosReadTcpData
,
(
void
*
)(
pTcp
))
!=
0
)
{
tError
(
"%s failed to create TCP read data thread, reason:%s"
,
label
,
strerror
(
errno
));
return
NULL
;
}
tTrace
(
"%s TCP client is initialized, ip:%s port:%hu"
,
label
,
ip
,
port
);
return
pTcp
;
}
void
taosCleanUpTcpClient
(
void
*
chandle
)
{
STcpClient
*
pTcp
=
(
STcpClient
*
)
chandle
;
if
(
pTcp
==
NULL
)
return
;
while
(
pTcp
->
pHead
)
{
taosCleanUpTcpFdObj
(
pTcp
->
pHead
);
pTcp
->
pHead
=
pTcp
->
pHead
->
next
;
}
close
(
pTcp
->
pollFd
);
pthread_cancel
(
pTcp
->
thread
);
pthread_join
(
pTcp
->
thread
,
NULL
);
// tTrace (":%s, all connections are cleaned up", pTcp->label);
tfree
(
pTcp
);
}
void
*
taosOpenTcpClientConnection
(
void
*
shandle
,
void
*
thandle
,
char
*
ip
,
uint16_t
port
)
{
STcpClient
*
pTcp
=
(
STcpClient
*
)
shandle
;
STcpFd
*
pFdObj
;
struct
epoll_event
event
;
struct
in_addr
destIp
;
int
fd
;
fd
=
taosOpenTcpClientSocket
(
ip
,
port
,
pTcp
->
ipstr
);
if
(
fd
<=
0
)
return
NULL
;
pFdObj
=
(
STcpFd
*
)
malloc
(
sizeof
(
STcpFd
));
if
(
pFdObj
==
NULL
)
{
tError
(
"%s no enough resource to allocate TCP FD IDs"
,
pTcp
->
label
);
tclose
(
fd
);
return
NULL
;
}
memset
(
pFdObj
,
0
,
sizeof
(
STcpFd
));
pFdObj
->
fd
=
fd
;
strcpy
(
pFdObj
->
ipstr
,
ip
);
inet_aton
(
ip
,
&
destIp
);
pFdObj
->
ip
=
destIp
.
s_addr
;
pFdObj
->
port
=
port
;
pFdObj
->
pTcp
=
pTcp
;
pFdObj
->
thandle
=
thandle
;
pFdObj
->
signature
=
pFdObj
;
event
.
events
=
EPOLLIN
|
EPOLLPRI
|
EPOLLWAKEUP
;
event
.
data
.
ptr
=
pFdObj
;
if
(
epoll_ctl
(
pTcp
->
pollFd
,
EPOLL_CTL_ADD
,
fd
,
&
event
)
<
0
)
{
tError
(
"%s failed to add TCP FD for epoll, error:%s"
,
pTcp
->
label
,
strerror
(
errno
));
tfree
(
pFdObj
);
tclose
(
fd
);
return
NULL
;
}
// notify the data process, add into the FdObj list
pthread_mutex_lock
(
&
(
pTcp
->
mutex
));
pFdObj
->
next
=
pTcp
->
pHead
;
if
(
pTcp
->
pHead
)
(
pTcp
->
pHead
)
->
prev
=
pFdObj
;
pTcp
->
pHead
=
pFdObj
;
pTcp
->
numOfFds
++
;
pthread_cond_signal
(
&
pTcp
->
fdReady
);
pthread_mutex_unlock
(
&
(
pTcp
->
mutex
));
tTrace
(
"%s TCP connection to %s:%hu is created, FD:%p numOfFds:%d"
,
pTcp
->
label
,
ip
,
port
,
pFdObj
,
pTcp
->
numOfFds
);
return
pFdObj
;
}
void
taosCloseTcpClientConnection
(
void
*
chandle
)
{
STcpFd
*
pFdObj
=
(
STcpFd
*
)
chandle
;
if
(
pFdObj
==
NULL
)
return
;
taosCleanUpTcpFdObj
(
pFdObj
);
}
int
taosSendTcpClientData
(
uint32_t
ip
,
uint16_t
port
,
void
*
data
,
int
len
,
void
*
chandle
)
{
STcpFd
*
pFdObj
=
(
STcpFd
*
)
chandle
;
if
(
chandle
==
NULL
)
return
-
1
;
return
(
int
)
send
(
pFdObj
->
fd
,
data
,
(
size_t
)
len
,
0
);
}
static
void
taosCleanUpTcpFdObj
(
STcpFd
*
pFdObj
)
{
static
void
taosCleanUpTcpFdObj
(
STcpFd
*
pFdObj
)
{
STcpClient
*
pTcp
;
STcpClient
*
pTcp
;
SRecvInfo
recvInfo
;
if
(
pFdObj
==
NULL
)
return
;
if
(
pFdObj
==
NULL
)
return
;
if
(
pFdObj
->
signature
!=
pFdObj
)
return
;
if
(
pFdObj
->
signature
!=
pFdObj
)
return
;
...
@@ -75,8 +202,6 @@ static void taosCleanUpTcpFdObj(STcpFd *pFdObj) {
...
@@ -75,8 +202,6 @@ static void taosCleanUpTcpFdObj(STcpFd *pFdObj) {
if
(
pTcp
->
numOfFds
<
0
)
if
(
pTcp
->
numOfFds
<
0
)
tError
(
"%s number of TCP FDs shall never be negative, FD:%p"
,
pTcp
->
label
,
pFdObj
);
tError
(
"%s number of TCP FDs shall never be negative, FD:%p"
,
pTcp
->
label
,
pFdObj
);
// remove from the FdObject list
if
(
pFdObj
->
prev
)
{
if
(
pFdObj
->
prev
)
{
(
pFdObj
->
prev
)
->
next
=
pFdObj
->
next
;
(
pFdObj
->
prev
)
->
next
=
pFdObj
->
next
;
}
else
{
}
else
{
...
@@ -89,40 +214,28 @@ static void taosCleanUpTcpFdObj(STcpFd *pFdObj) {
...
@@ -89,40 +214,28 @@ static void taosCleanUpTcpFdObj(STcpFd *pFdObj) {
pthread_mutex_unlock
(
&
pTcp
->
mutex
);
pthread_mutex_unlock
(
&
pTcp
->
mutex
);
// notify the upper layer to clean the associated context
recvInfo
.
msg
=
NULL
;
if
(
pFdObj
->
thandle
)
(
*
(
pTcp
->
processData
))(
NULL
,
0
,
0
,
0
,
pTcp
->
shandle
,
pFdObj
->
thandle
,
NULL
);
recvInfo
.
msgLen
=
0
;
recvInfo
.
ip
=
0
;
recvInfo
.
port
=
0
;
recvInfo
.
shandle
=
pTcp
->
shandle
;
recvInfo
.
thandle
=
pFdObj
->
thandle
;;
recvInfo
.
chandle
=
NULL
;
recvInfo
.
connType
=
RPC_CONN_TCP
;
if
(
pFdObj
->
thandle
)
(
*
(
pTcp
->
processData
))(
&
recvInfo
);
tTrace
(
"%s TCP is cleaned up, FD:%p numOfFds:%d"
,
pTcp
->
label
,
pFdObj
,
pTcp
->
numOfFds
);
tTrace
(
"%s TCP is cleaned up, FD:%p numOfFds:%d"
,
pTcp
->
label
,
pFdObj
,
pTcp
->
numOfFds
);
memset
(
pFdObj
,
0
,
sizeof
(
STcpFd
));
memset
(
pFdObj
,
0
,
sizeof
(
STcpFd
));
tfree
(
pFdObj
);
tfree
(
pFdObj
);
}
}
void
taosCleanUpTcpClient
(
void
*
chandle
)
{
STcpClient
*
pTcp
=
(
STcpClient
*
)
chandle
;
if
(
pTcp
==
NULL
)
return
;
while
(
pTcp
->
pHead
)
{
taosCleanUpTcpFdObj
(
pTcp
->
pHead
);
pTcp
->
pHead
=
pTcp
->
pHead
->
next
;
}
close
(
pTcp
->
pollFd
);
pthread_cancel
(
pTcp
->
thread
);
pthread_join
(
pTcp
->
thread
,
NULL
);
// tTrace (":%s, all connections are cleaned up", pTcp->label);
tfree
(
pTcp
);
}
static
void
*
taosReadTcpData
(
void
*
param
)
{
static
void
*
taosReadTcpData
(
void
*
param
)
{
STcpClient
*
pTcp
=
(
STcpClient
*
)
param
;
STcpClient
*
pTcp
=
(
STcpClient
*
)
param
;
int
i
,
fdNum
;
int
i
,
fdNum
;
STcpFd
*
pFdObj
;
STcpFd
*
pFdObj
;
struct
epoll_event
events
[
maxTcpEvents
];
struct
epoll_event
events
[
maxTcpEvents
];
SRecvInfo
recvInfo
;
while
(
1
)
{
while
(
1
)
{
pthread_mutex_lock
(
&
pTcp
->
mutex
);
pthread_mutex_lock
(
&
pTcp
->
mutex
);
...
@@ -186,132 +299,22 @@ static void *taosReadTcpData(void *param) {
...
@@ -186,132 +299,22 @@ static void *taosReadTcpData(void *param) {
continue
;
continue
;
}
}
pFdObj
->
thandle
=
recvInfo
.
msg
=
buffer
;
(
*
(
pTcp
->
processData
))(
buffer
,
dataLen
,
pFdObj
->
ip
,
pFdObj
->
port
,
pTcp
->
shandle
,
pFdObj
->
thandle
,
pFdObj
);
recvInfo
.
msgLen
=
dataLen
;
recvInfo
.
ip
=
pFdObj
->
ip
;
if
(
pFdObj
->
thandle
==
NULL
)
taosCleanUpTcpFdObj
(
pFdObj
);
recvInfo
.
port
=
pFdObj
->
port
;
}
recvInfo
.
shandle
=
pTcp
->
shandle
;
}
recvInfo
.
thandle
=
pFdObj
->
thandle
;;
recvInfo
.
chandle
=
pFdObj
;
return
NULL
;
recvInfo
.
connType
=
RPC_CONN_TCP
;
}
void
*
taosInitTcpClient
(
char
*
ip
,
uint16_t
port
,
char
*
label
,
int
num
,
void
*
fp
,
void
*
shandle
)
{
STcpClient
*
pTcp
;
pthread_attr_t
thattr
;
pTcp
=
(
STcpClient
*
)
malloc
(
sizeof
(
STcpClient
));
memset
(
pTcp
,
0
,
sizeof
(
STcpClient
));
strcpy
(
pTcp
->
label
,
label
);
strcpy
(
pTcp
->
ipstr
,
ip
);
pTcp
->
shandle
=
shandle
;
if
(
pthread_mutex_init
(
&
(
pTcp
->
mutex
),
NULL
)
<
0
)
{
tError
(
"%s failed to init TCP mutex, reason:%s"
,
label
,
strerror
(
errno
));
return
NULL
;
}
if
(
pthread_cond_init
(
&
(
pTcp
->
fdReady
),
NULL
)
!=
0
)
{
tError
(
"%s init TCP condition variable failed, reason:%s
\n
"
,
label
,
strerror
(
errno
));
return
NULL
;
}
pTcp
->
pollFd
=
epoll_create
(
10
);
// size does not matter
if
(
pTcp
->
pollFd
<
0
)
{
tError
(
"%s failed to create TCP epoll"
,
label
);
return
NULL
;
}
pTcp
->
processData
=
fp
;
pthread_attr_init
(
&
thattr
);
pthread_attr_setdetachstate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
if
(
pthread_create
(
&
(
pTcp
->
thread
),
&
thattr
,
taosReadTcpData
,
(
void
*
)(
pTcp
))
!=
0
)
{
tError
(
"%s failed to create TCP read data thread, reason:%s"
,
label
,
strerror
(
errno
));
return
NULL
;
}
tTrace
(
"%s TCP client is initialized, ip:%s port:%hu"
,
label
,
ip
,
port
);
return
pTcp
;
}
void
taosCloseTcpClientConnection
(
void
*
chandle
)
{
STcpFd
*
pFdObj
=
(
STcpFd
*
)
chandle
;
if
(
pFdObj
==
NULL
)
return
;
taosCleanUpTcpFdObj
(
pFdObj
);
pFdObj
->
thandle
=
(
*
(
pTcp
->
processData
))(
&
recvInfo
);
}
void
*
taosOpenTcpClientConnection
(
void
*
shandle
,
void
*
thandle
,
char
*
ip
,
uint16_t
port
)
{
if
(
pFdObj
->
thandle
==
NULL
)
taosCleanUpTcpFdObj
(
pFdObj
);
STcpClient
*
pTcp
=
(
STcpClient
*
)
shandle
;
STcpFd
*
pFdObj
;
struct
epoll_event
event
;
struct
in_addr
destIp
;
int
fd
;
/*
if ( (strcmp(ip, "127.0.0.1") == 0 ) || (strcmp(ip, "localhost") == 0 ) ) {
fd = taosOpenUDClientSocket(ip, port);
} else {
fd = taosOpenTcpClientSocket(ip, port, pTcp->ipstr);
}
}
*/
fd
=
taosOpenTcpClientSocket
(
ip
,
port
,
pTcp
->
ipstr
);
if
(
fd
<=
0
)
return
NULL
;
pFdObj
=
(
STcpFd
*
)
malloc
(
sizeof
(
STcpFd
));
if
(
pFdObj
==
NULL
)
{
tError
(
"%s no enough resource to allocate TCP FD IDs"
,
pTcp
->
label
);
tclose
(
fd
);
return
NULL
;
}
}
memset
(
pFdObj
,
0
,
sizeof
(
STcpFd
));
pFdObj
->
fd
=
fd
;
strcpy
(
pFdObj
->
ipstr
,
ip
);
inet_aton
(
ip
,
&
destIp
);
pFdObj
->
ip
=
destIp
.
s_addr
;
pFdObj
->
port
=
port
;
pFdObj
->
pTcp
=
pTcp
;
pFdObj
->
thandle
=
thandle
;
pFdObj
->
signature
=
pFdObj
;
event
.
events
=
EPOLLIN
|
EPOLLPRI
|
EPOLLWAKEUP
;
event
.
data
.
ptr
=
pFdObj
;
if
(
epoll_ctl
(
pTcp
->
pollFd
,
EPOLL_CTL_ADD
,
fd
,
&
event
)
<
0
)
{
tError
(
"%s failed to add TCP FD for epoll, error:%s"
,
pTcp
->
label
,
strerror
(
errno
));
tfree
(
pFdObj
);
tclose
(
fd
);
return
NULL
;
return
NULL
;
}
// notify the data process, add into the FdObj list
pthread_mutex_lock
(
&
(
pTcp
->
mutex
));
pFdObj
->
next
=
pTcp
->
pHead
;
if
(
pTcp
->
pHead
)
(
pTcp
->
pHead
)
->
prev
=
pFdObj
;
pTcp
->
pHead
=
pFdObj
;
pTcp
->
numOfFds
++
;
pthread_cond_signal
(
&
pTcp
->
fdReady
);
pthread_mutex_unlock
(
&
(
pTcp
->
mutex
));
tTrace
(
"%s TCP connection to %s:%hu is created, FD:%p numOfFds:%d"
,
pTcp
->
label
,
ip
,
port
,
pFdObj
,
pTcp
->
numOfFds
);
return
pFdObj
;
}
}
int
taosSendTcpClientData
(
uint32_t
ip
,
uint16_t
port
,
char
*
data
,
int
len
,
void
*
chandle
)
{
STcpFd
*
pFdObj
=
(
STcpFd
*
)
chandle
;
if
(
chandle
==
NULL
)
return
-
1
;
return
(
int
)
send
(
pFdObj
->
fd
,
data
,
(
size_t
)
len
,
0
);
}
src/rpc/src/rpcMain.c
浏览文件 @
25a4625e
...
@@ -62,7 +62,8 @@ typedef struct {
...
@@ -62,7 +62,8 @@ typedef struct {
void
*
idPool
;
// handle to ID pool
void
*
idPool
;
// handle to ID pool
void
*
tmrCtrl
;
// handle to timer
void
*
tmrCtrl
;
// handle to timer
void
*
hash
;
// handle returned by hash utility
void
*
hash
;
// handle returned by hash utility
void
*
shandle
;
// returned handle from lower layer during initialization
void
*
tcphandle
;
// returned handle from TCP initialization
void
*
udphandle
;
// returned handle from UDP initialization
void
*
pCache
;
// connection cache
void
*
pCache
;
// connection cache
pthread_mutex_t
mutex
;
pthread_mutex_t
mutex
;
struct
_RpcConn
*
connList
;
// connection list
struct
_RpcConn
*
connList
;
// connection list
...
@@ -79,6 +80,7 @@ typedef struct {
...
@@ -79,6 +80,7 @@ typedef struct {
int16_t
numOfTry
;
// number of try for different servers
int16_t
numOfTry
;
// number of try for different servers
int8_t
oldIndex
;
// server IP index passed by app
int8_t
oldIndex
;
// server IP index passed by app
int8_t
redirect
;
// flag to indicate redirect
int8_t
redirect
;
// flag to indicate redirect
int8_t
connType
;
// connection type
char
msg
[
0
];
// RpcHead starts from here
char
msg
[
0
];
// RpcHead starts from here
}
SRpcReqContext
;
}
SRpcReqContext
;
...
@@ -113,6 +115,7 @@ typedef struct _RpcConn {
...
@@ -113,6 +115,7 @@ typedef struct _RpcConn {
char
*
pReqMsg
;
// request message including header
char
*
pReqMsg
;
// request message including header
int
reqMsgLen
;
// request message length
int
reqMsgLen
;
// request message length
SRpcInfo
*
pRpc
;
// the associated SRpcInfo
SRpcInfo
*
pRpc
;
// the associated SRpcInfo
int
connType
;
// connection type
SRpcReqContext
*
pContext
;
// request context
SRpcReqContext
*
pContext
;
// request context
}
SRpcConn
;
}
SRpcConn
;
...
@@ -122,9 +125,16 @@ int tsRpcProgressTime = 10; // milliseocnds
...
@@ -122,9 +125,16 @@ int tsRpcProgressTime = 10; // milliseocnds
int
tsRpcMaxRetry
;
int
tsRpcMaxRetry
;
int
tsRpcHeadSize
;
int
tsRpcHeadSize
;
// server:0 client:1 tcp:2 udp:0
#define RPC_CONN_UDPS 0
#define RPC_CONN_UDPC 1
#define RPC_CONN_TCPS 2
#define RPC_CONN_TCPC 3
#define RPC_CONN_TCP 2
void
*
(
*
taosInitConn
[])(
char
*
ip
,
uint16_t
port
,
char
*
label
,
int
threads
,
void
*
fp
,
void
*
shandle
)
=
{
void
*
(
*
taosInitConn
[])(
char
*
ip
,
uint16_t
port
,
char
*
label
,
int
threads
,
void
*
fp
,
void
*
shandle
)
=
{
taosInitUdp
Server
,
taosInitUdp
Connection
,
taosInitUdpC
lient
,
taosInitUdpC
onnection
,
taosInitTcpServer
,
taosInitTcpServer
,
taosInitTcpClient
taosInitTcpClient
};
};
...
@@ -136,7 +146,7 @@ void (*taosCleanUpConn[])(void *thandle) = {
...
@@ -136,7 +146,7 @@ void (*taosCleanUpConn[])(void *thandle) = {
taosCleanUpTcpClient
taosCleanUpTcpClient
};
};
int
(
*
taosSendData
[])(
uint32_t
ip
,
uint16_t
port
,
char
*
data
,
int
len
,
void
*
chandle
)
=
{
int
(
*
taosSendData
[])(
uint32_t
ip
,
uint16_t
port
,
void
*
data
,
int
len
,
void
*
chandle
)
=
{
taosSendUdpData
,
taosSendUdpData
,
taosSendUdpData
,
taosSendUdpData
,
taosSendTcpServerData
,
taosSendTcpServerData
,
...
@@ -157,19 +167,19 @@ void (*taosCloseConn[])(void *chandle) = {
...
@@ -157,19 +167,19 @@ void (*taosCloseConn[])(void *chandle) = {
taosCloseTcpClientConnection
taosCloseTcpClientConnection
};
};
static
SRpcConn
*
rpcOpenConn
(
SRpcInfo
*
pRpc
,
char
*
peerIpStr
,
uint16_t
peerPort
);
static
SRpcConn
*
rpcOpenConn
(
SRpcInfo
*
pRpc
,
char
*
peerIpStr
,
uint16_t
peerPort
,
int8_t
connType
);
static
void
rpcCloseConn
(
void
*
thandle
);
static
void
rpcCloseConn
(
void
*
thandle
);
static
SRpcConn
*
rpcSetConnToServer
(
SRpc
Info
*
pRpc
,
SRpcIpSet
ipSe
t
);
static
SRpcConn
*
rpcSetConnToServer
(
SRpc
ReqContext
*
pContex
t
);
static
SRpcConn
*
rpcAllocateClientConn
(
SRpcInfo
*
pRpc
);
static
SRpcConn
*
rpcAllocateClientConn
(
SRpcInfo
*
pRpc
);
static
SRpcConn
*
rpcAllocateServerConn
(
SRpcInfo
*
pRpc
,
char
*
user
,
char
*
hashstr
);
static
SRpcConn
*
rpcAllocateServerConn
(
SRpcInfo
*
pRpc
,
char
*
user
,
char
*
hashstr
);
static
SRpcConn
*
rpcGetConnObj
(
SRpcInfo
*
pRpc
,
int
sid
,
char
*
user
,
char
*
hashstr
);
static
SRpcConn
*
rpcGetConnObj
(
SRpcInfo
*
pRpc
,
int
sid
,
char
*
user
,
char
*
hashstr
);
static
void
rpcSendReqToServer
(
SRpcInfo
*
pRpc
,
SRpcReqContext
*
pContext
);
static
void
rpcSendReqToServer
(
SRpcInfo
*
pRpc
,
SRpcReqContext
*
pContext
);
static
void
rpcSendQuickRsp
(
SRpcConn
*
pConn
,
int32_t
code
);
static
void
rpcSendQuickRsp
(
SRpcConn
*
pConn
,
int32_t
code
);
static
void
rpcSendErrorMsgToPeer
(
SR
pcInfo
*
pRpc
,
char
*
pMsg
,
int32_t
code
,
uint32_t
ip
,
uint16_t
port
,
void
*
chandl
e
);
static
void
rpcSendErrorMsgToPeer
(
SR
ecvInfo
*
pRecv
,
int32_t
cod
e
);
static
void
rpcSendMsgToPeer
(
SRpcConn
*
pConn
,
void
*
data
,
int
dataLen
);
static
void
rpcSendMsgToPeer
(
SRpcConn
*
pConn
,
void
*
data
,
int
dataLen
);
static
void
*
rpcProcessMsgFromPeer
(
void
*
msg
,
int
msgLen
,
uint32_t
ip
,
uint16_t
port
,
void
*
shandle
,
void
*
thandle
,
void
*
chandle
);
static
void
*
rpcProcessMsgFromPeer
(
SRecvInfo
*
pRecv
);
static
void
rpcProcessIncomingMsg
(
SRpcConn
*
pConn
,
SRpcHead
*
pHead
);
static
void
rpcProcessIncomingMsg
(
SRpcConn
*
pConn
,
SRpcHead
*
pHead
);
static
void
rpcProcessConnError
(
void
*
param
,
void
*
id
);
static
void
rpcProcessConnError
(
void
*
param
,
void
*
id
);
static
void
rpcProcessRetryTimer
(
void
*
,
void
*
);
static
void
rpcProcessRetryTimer
(
void
*
,
void
*
);
...
@@ -194,7 +204,8 @@ void *rpcOpen(SRpcInit *pInit) {
...
@@ -194,7 +204,8 @@ void *rpcOpen(SRpcInit *pInit) {
if
(
pInit
->
label
)
strcpy
(
pRpc
->
label
,
pInit
->
label
);
if
(
pInit
->
label
)
strcpy
(
pRpc
->
label
,
pInit
->
label
);
pRpc
->
connType
=
pInit
->
connType
;
pRpc
->
connType
=
pInit
->
connType
;
pRpc
->
idleTime
=
pInit
->
idleTime
;
pRpc
->
idleTime
=
pInit
->
idleTime
;
pRpc
->
numOfThreads
=
pInit
->
numOfThreads
>
TSDB_MAX_RPC_THREADS
?
TSDB_MAX_RPC_THREADS
:
pInit
->
numOfThreads
;
// pRpc->numOfThreads = pInit->numOfThreads>TSDB_MAX_RPC_THREADS ? TSDB_MAX_RPC_THREADS:pInit->numOfThreads;
pRpc
->
numOfThreads
=
1
;
if
(
pInit
->
localIp
)
strcpy
(
pRpc
->
localIp
,
pInit
->
localIp
);
if
(
pInit
->
localIp
)
strcpy
(
pRpc
->
localIp
,
pInit
->
localIp
);
pRpc
->
localPort
=
pInit
->
localPort
;
pRpc
->
localPort
=
pInit
->
localPort
;
pRpc
->
afp
=
pInit
->
afp
;
pRpc
->
afp
=
pInit
->
afp
;
...
@@ -207,9 +218,12 @@ void *rpcOpen(SRpcInit *pInit) {
...
@@ -207,9 +218,12 @@ void *rpcOpen(SRpcInit *pInit) {
pRpc
->
cfp
=
pInit
->
cfp
;
pRpc
->
cfp
=
pInit
->
cfp
;
pRpc
->
afp
=
pInit
->
afp
;
pRpc
->
afp
=
pInit
->
afp
;
pRpc
->
shandle
=
(
*
taosInitConn
[
pRpc
->
connType
])(
pRpc
->
localIp
,
pRpc
->
localPort
,
pRpc
->
label
,
pRpc
->
tcphandle
=
(
*
taosInitConn
[
pRpc
->
connType
|
RPC_CONN_TCP
])(
pRpc
->
localIp
,
pRpc
->
localPort
,
pRpc
->
label
,
pRpc
->
numOfThreads
,
rpcProcessMsgFromPeer
,
pRpc
);
pRpc
->
udphandle
=
(
*
taosInitConn
[
pRpc
->
connType
])(
pRpc
->
localIp
,
pRpc
->
localPort
,
pRpc
->
label
,
pRpc
->
numOfThreads
,
rpcProcessMsgFromPeer
,
pRpc
);
pRpc
->
numOfThreads
,
rpcProcessMsgFromPeer
,
pRpc
);
if
(
pRpc
->
shandle
==
NULL
)
{
if
(
pRpc
->
tcphandle
==
NULL
||
pRpc
->
udphandle
==
NULL
)
{
tError
(
"%s failed to init network, %s:%d"
,
pRpc
->
label
,
pRpc
->
localIp
,
pRpc
->
localPort
);
tError
(
"%s failed to init network, %s:%d"
,
pRpc
->
label
,
pRpc
->
localIp
,
pRpc
->
localPort
);
rpcClose
(
pRpc
);
rpcClose
(
pRpc
);
return
NULL
;
return
NULL
;
...
@@ -237,19 +251,21 @@ void *rpcOpen(SRpcInit *pInit) {
...
@@ -237,19 +251,21 @@ void *rpcOpen(SRpcInit *pInit) {
return
NULL
;
return
NULL
;
}
}
if
(
pRpc
->
connType
==
TAOS_CONN_SERVER
)
{
pRpc
->
hash
=
taosInitStrHash
(
pRpc
->
sessions
,
sizeof
(
pRpc
),
taosHashString
);
pRpc
->
hash
=
taosInitStrHash
(
pRpc
->
sessions
,
sizeof
(
pRpc
),
taosHashString
);
if
(
pRpc
->
hash
==
NULL
)
{
if
(
pRpc
->
hash
==
NULL
)
{
tError
(
"%s failed to init string hash"
,
pRpc
->
label
);
tError
(
"%s failed to init string hash"
,
pRpc
->
label
);
rpcClose
(
pRpc
);
rpcClose
(
pRpc
);
return
NULL
;
return
NULL
;
}
}
}
else
{
pRpc
->
pCache
=
rpcOpenConnCache
(
pRpc
->
sessions
,
rpcCloseConn
,
pRpc
->
tmrCtrl
,
tsShellActivityTimer
*
1000
);
pRpc
->
pCache
=
rpcOpenConnCache
(
pRpc
->
sessions
,
rpcCloseConn
,
pRpc
->
tmrCtrl
,
tsShellActivityTimer
*
1000
);
if
(
pRpc
->
pCache
==
NULL
)
{
if
(
pRpc
->
pCache
==
NULL
)
{
tError
(
"%s failed to init connection cache"
,
pRpc
->
label
);
tError
(
"%s failed to init connection cache"
,
pRpc
->
label
);
rpcClose
(
pRpc
);
rpcClose
(
pRpc
);
return
NULL
;
return
NULL
;
}
}
}
pthread_mutex_init
(
&
pRpc
->
mutex
,
NULL
);
pthread_mutex_init
(
&
pRpc
->
mutex
,
NULL
);
...
@@ -261,7 +277,8 @@ void *rpcOpen(SRpcInit *pInit) {
...
@@ -261,7 +277,8 @@ void *rpcOpen(SRpcInit *pInit) {
void
rpcClose
(
void
*
param
)
{
void
rpcClose
(
void
*
param
)
{
SRpcInfo
*
pRpc
=
(
SRpcInfo
*
)
param
;
SRpcInfo
*
pRpc
=
(
SRpcInfo
*
)
param
;
(
*
taosCleanUpConn
[
pRpc
->
connType
])(
pRpc
->
shandle
);
(
*
taosCleanUpConn
[
pRpc
->
connType
|
RPC_CONN_TCP
])(
pRpc
->
tcphandle
);
(
*
taosCleanUpConn
[
pRpc
->
connType
])(
pRpc
->
udphandle
);
for
(
int
i
=
0
;
i
<
pRpc
->
sessions
;
++
i
)
{
for
(
int
i
=
0
;
i
<
pRpc
->
sessions
;
++
i
)
{
if
(
pRpc
->
connList
[
i
].
user
[
0
])
{
if
(
pRpc
->
connList
[
i
].
user
[
0
])
{
...
@@ -313,6 +330,16 @@ void rpcSendRequest(void *shandle, SRpcIpSet *pIpSet, char type, void *pCont, in
...
@@ -313,6 +330,16 @@ void rpcSendRequest(void *shandle, SRpcIpSet *pIpSet, char type, void *pCont, in
pContext
->
msgType
=
type
;
pContext
->
msgType
=
type
;
pContext
->
oldIndex
=
pIpSet
->
index
;
pContext
->
oldIndex
=
pIpSet
->
index
;
pContext
->
connType
=
RPC_CONN_UDPC
;
if
(
contLen
>
16000
)
pContext
->
connType
=
RPC_CONN_TCPC
;
// connection type is application specific.
// for TDengine, all the query, show commands shall have TCP connection
if
(
type
==
TSDB_MSG_TYPE_DNODE_QUERY
||
type
==
TSDB_MSG_TYPE_DNODE_RETRIEVE
||
type
==
TSDB_MSG_TYPE_STABLE_META
||
type
==
TSDB_MSG_TYPE_MULTI_TABLE_META
||
type
==
TSDB_MSG_TYPE_SHOW
)
pContext
->
connType
=
RPC_CONN_TCPC
;
rpcSendReqToServer
(
pRpc
,
pContext
);
rpcSendReqToServer
(
pRpc
,
pContext
);
return
;
return
;
...
@@ -346,7 +373,6 @@ void rpcSendResponse(void *handle, int32_t code, void *pCont, int contLen) {
...
@@ -346,7 +373,6 @@ void rpcSendResponse(void *handle, int32_t code, void *pCont, int contLen) {
pHead
->
version
=
1
;
pHead
->
version
=
1
;
pHead
->
msgType
=
pConn
->
inType
+
1
;
pHead
->
msgType
=
pConn
->
inType
+
1
;
pHead
->
spi
=
0
;
pHead
->
spi
=
0
;
pHead
->
tcp
=
0
;
pHead
->
encrypt
=
0
;
pHead
->
encrypt
=
0
;
pHead
->
tranId
=
pConn
->
inTranId
;
pHead
->
tranId
=
pConn
->
inTranId
;
pHead
->
sourceId
=
pConn
->
ownId
;
pHead
->
sourceId
=
pConn
->
ownId
;
...
@@ -388,7 +414,6 @@ void rpcSendRedirectRsp(void *thandle, SRpcIpSet *pIpSet) {
...
@@ -388,7 +414,6 @@ void rpcSendRedirectRsp(void *thandle, SRpcIpSet *pIpSet) {
void
rpcGetConnInfo
(
void
*
thandle
,
SRpcConnInfo
*
pInfo
)
{
void
rpcGetConnInfo
(
void
*
thandle
,
SRpcConnInfo
*
pInfo
)
{
SRpcConn
*
pConn
=
(
SRpcConn
*
)
thandle
;
SRpcConn
*
pConn
=
(
SRpcConn
*
)
thandle
;
SRpcInfo
*
pRpc
=
pConn
->
pRpc
;
pInfo
->
clientIp
=
pConn
->
peerIp
;
pInfo
->
clientIp
=
pConn
->
peerIp
;
pInfo
->
clientPort
=
pConn
->
peerPort
;
pInfo
->
clientPort
=
pConn
->
peerPort
;
...
@@ -396,7 +421,7 @@ void rpcGetConnInfo(void *thandle, SRpcConnInfo *pInfo) {
...
@@ -396,7 +421,7 @@ void rpcGetConnInfo(void *thandle, SRpcConnInfo *pInfo) {
strcpy
(
pInfo
->
user
,
pConn
->
user
);
strcpy
(
pInfo
->
user
,
pConn
->
user
);
}
}
static
SRpcConn
*
rpcOpenConn
(
SRpcInfo
*
pRpc
,
char
*
peerIpStr
,
uint16_t
peerPort
)
{
static
SRpcConn
*
rpcOpenConn
(
SRpcInfo
*
pRpc
,
char
*
peerIpStr
,
uint16_t
peerPort
,
int8_t
connType
)
{
SRpcConn
*
pConn
;
SRpcConn
*
pConn
;
pConn
=
rpcAllocateClientConn
(
pRpc
);
pConn
=
rpcAllocateClientConn
(
pRpc
);
...
@@ -406,12 +431,14 @@ static SRpcConn *rpcOpenConn(SRpcInfo *pRpc, char *peerIpStr, uint16_t peerPort)
...
@@ -406,12 +431,14 @@ static SRpcConn *rpcOpenConn(SRpcInfo *pRpc, char *peerIpStr, uint16_t peerPort)
pConn
->
peerIp
=
inet_addr
(
peerIpStr
);
pConn
->
peerIp
=
inet_addr
(
peerIpStr
);
pConn
->
peerPort
=
peerPort
;
pConn
->
peerPort
=
peerPort
;
strcpy
(
pConn
->
user
,
pRpc
->
user
);
strcpy
(
pConn
->
user
,
pRpc
->
user
);
pConn
->
connType
=
connType
;
if
(
taosOpenConn
[
pRpc
->
connType
])
{
if
(
taosOpenConn
[
connType
])
{
pConn
->
chandle
=
(
*
taosOpenConn
[
pRpc
->
connType
])(
pRpc
->
shandle
,
pConn
,
pConn
->
peerIpstr
,
pConn
->
peerPort
);
void
*
shandle
=
(
connType
&
RPC_CONN_TCP
)
?
pRpc
->
tcphandle
:
pRpc
->
udphandle
;
pConn
->
chandle
=
(
*
taosOpenConn
[
connType
])(
shandle
,
pConn
,
pConn
->
peerIpstr
,
pConn
->
peerPort
);
if
(
pConn
->
chandle
)
{
if
(
pConn
->
chandle
)
{
tTrace
(
"%s %p, rpc connection is set up, sid:%d id:%s ip:%s:%hu
localPort
:%d"
,
pRpc
->
label
,
tTrace
(
"%s %p, rpc connection is set up, sid:%d id:%s ip:%s:%hu
connType
:%d"
,
pRpc
->
label
,
pConn
,
pConn
->
sid
,
pRpc
->
user
,
pConn
->
peerIpstr
,
pConn
->
peerPort
,
pConn
->
localPort
);
pConn
,
pConn
->
sid
,
pRpc
->
user
,
pConn
->
peerIpstr
,
pConn
->
peerPort
,
pConn
->
connType
);
}
else
{
}
else
{
tError
(
"%s %p, failed to set up connection to ip:%s:%hu"
,
pRpc
->
label
,
pConn
,
tError
(
"%s %p, failed to set up connection to ip:%s:%hu"
,
pRpc
->
label
,
pConn
,
pConn
->
peerIpstr
,
pConn
->
peerPort
);
pConn
->
peerIpstr
,
pConn
->
peerPort
);
...
@@ -433,14 +460,14 @@ static void rpcCloseConn(void *thandle) {
...
@@ -433,14 +460,14 @@ static void rpcCloseConn(void *thandle) {
if
(
pConn
->
user
[
0
])
{
if
(
pConn
->
user
[
0
])
{
pConn
->
user
[
0
]
=
0
;
pConn
->
user
[
0
]
=
0
;
if
(
taosCloseConn
[
p
Rpc
->
connType
])
(
*
taosCloseConn
[
pRpc
->
connType
])(
pConn
->
chandle
);
if
(
taosCloseConn
[
p
Conn
->
connType
])
(
*
taosCloseConn
[
pConn
->
connType
])(
pConn
->
chandle
);
taosTmrStopA
(
&
pConn
->
pTimer
);
taosTmrStopA
(
&
pConn
->
pTimer
);
taosTmrStopA
(
&
pConn
->
pIdleTimer
);
taosTmrStopA
(
&
pConn
->
pIdleTimer
);
if
(
pRpc
->
connType
==
TAOS_CONN_
UDPS
||
pRpc
->
connType
==
TAOS_CONN_TCPS
)
{
if
(
pRpc
->
connType
==
TAOS_CONN_
SERVER
)
{
char
hashstr
[
40
]
=
{
0
};
char
hashstr
[
40
]
=
{
0
};
sprintf
(
hashstr
,
"%x:%x:%x
"
,
pConn
->
peerIp
,
pConn
->
peerUid
,
pConn
->
peerId
);
sprintf
(
hashstr
,
"%x:%x:%x
:%d"
,
pConn
->
peerIp
,
pConn
->
peerUid
,
pConn
->
peerId
,
pConn
->
connType
);
taosDeleteStrHash
(
pRpc
->
hash
,
hashstr
);
taosDeleteStrHash
(
pRpc
->
hash
,
hashstr
);
rpcFreeOutMsg
(
pConn
->
pRspMsg
);
// it may have a response msg saved, but not request msg
rpcFreeOutMsg
(
pConn
->
pRspMsg
);
// it may have a response msg saved, but not request msg
pConn
->
pRspMsg
=
NULL
;
pConn
->
pRspMsg
=
NULL
;
...
@@ -540,15 +567,17 @@ static SRpcConn *rpcGetConnObj(SRpcInfo *pRpc, int sid, char *user, char *hashst
...
@@ -540,15 +567,17 @@ static SRpcConn *rpcGetConnObj(SRpcInfo *pRpc, int sid, char *user, char *hashst
return
pConn
;
return
pConn
;
}
}
SRpcConn
*
rpcSetConnToServer
(
SRpc
Info
*
pRpc
,
SRpcIpSet
ipSe
t
)
{
SRpcConn
*
rpcSetConnToServer
(
SRpc
ReqContext
*
pContex
t
)
{
SRpcConn
*
pConn
;
SRpcConn
*
pConn
;
SRpcInfo
*
pRpc
=
pContext
->
pRpc
;
SRpcIpSet
*
pIpSet
=
&
pContext
->
ipSet
;
pConn
=
rpcGetConnFromCache
(
pRpc
->
pCache
,
ipSet
.
ip
[
ipSet
.
index
],
ipSet
.
port
,
pRpc
->
user
);
pConn
=
rpcGetConnFromCache
(
pRpc
->
pCache
,
pIpSet
->
ip
[
pIpSet
->
index
],
pIpSet
->
port
,
pRpc
->
user
);
if
(
pConn
==
NULL
)
{
if
(
pConn
==
NULL
)
{
char
ipstr
[
20
]
=
{
0
};
char
ipstr
[
20
]
=
{
0
};
tinet_ntoa
(
ipstr
,
ipSet
.
ip
[
ipSet
.
index
]);
tinet_ntoa
(
ipstr
,
pIpSet
->
ip
[
pIpSet
->
index
]);
pConn
=
rpcOpenConn
(
pRpc
,
ipstr
,
ipSet
.
port
);
pConn
=
rpcOpenConn
(
pRpc
,
ipstr
,
pIpSet
->
port
,
pContext
->
connType
);
pConn
->
destIp
=
ipSet
.
ip
[
ipSet
.
index
];
if
(
pConn
)
pConn
->
destIp
=
pIpSet
->
ip
[
pIpSet
->
index
];
}
}
return
pConn
;
return
pConn
;
...
@@ -618,7 +647,7 @@ static int rpcProcessRspHead(SRpcConn *pConn, SRpcHead *pHead) {
...
@@ -618,7 +647,7 @@ static int rpcProcessRspHead(SRpcConn *pConn, SRpcHead *pHead) {
taosTmrStopA
(
&
pConn
->
pTimer
);
taosTmrStopA
(
&
pConn
->
pTimer
);
pConn
->
retry
=
0
;
pConn
->
retry
=
0
;
if
(
*
pHead
->
content
==
TSDB_CODE_ACTION_IN_PROGRESS
||
pHead
->
tcp
)
{
if
(
*
pHead
->
content
==
TSDB_CODE_ACTION_IN_PROGRESS
)
{
if
(
pConn
->
tretry
<=
tsRpcMaxRetry
)
{
if
(
pConn
->
tretry
<=
tsRpcMaxRetry
)
{
pConn
->
tretry
++
;
pConn
->
tretry
++
;
tTrace
(
"%s %p, peer is still processing the transaction"
,
pRpc
->
label
,
pConn
);
tTrace
(
"%s %p, peer is still processing the transaction"
,
pRpc
->
label
,
pConn
);
...
@@ -638,13 +667,12 @@ static int rpcProcessRspHead(SRpcConn *pConn, SRpcHead *pHead) {
...
@@ -638,13 +667,12 @@ static int rpcProcessRspHead(SRpcConn *pConn, SRpcHead *pHead) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
rpcProcessHead
(
SRpcInfo
*
pRpc
,
SRpcConn
**
ppConn
,
void
*
data
,
int
dataLen
,
uint32_t
ip
)
{
static
SRpcConn
*
rpcProcessHead
(
SRpcInfo
*
pRpc
,
SRecvInfo
*
pRecv
)
{
int32_t
sid
,
code
=
0
;
int32_t
sid
;
SRpcConn
*
pConn
=
NULL
;
SRpcConn
*
pConn
=
NULL
;
char
hashstr
[
40
]
=
{
0
};
char
hashstr
[
40
]
=
{
0
};
*
ppConn
=
NULL
;
SRpcHead
*
pHead
=
(
SRpcHead
*
)
pRecv
->
msg
;
SRpcHead
*
pHead
=
(
SRpcHead
*
)
data
;
sid
=
htonl
(
pHead
->
destId
);
sid
=
htonl
(
pHead
->
destId
);
pHead
->
code
=
htonl
(
pHead
->
code
);
pHead
->
code
=
htonl
(
pHead
->
code
);
...
@@ -652,50 +680,54 @@ static int32_t rpcProcessHead(SRpcInfo *pRpc, SRpcConn **ppConn, void *data, int
...
@@ -652,50 +680,54 @@ static int32_t rpcProcessHead(SRpcInfo *pRpc, SRpcConn **ppConn, void *data, int
if
(
pHead
->
msgType
>=
TSDB_MSG_TYPE_MAX
||
pHead
->
msgType
<=
0
)
{
if
(
pHead
->
msgType
>=
TSDB_MSG_TYPE_MAX
||
pHead
->
msgType
<=
0
)
{
tTrace
(
"%s sid:%d, invalid message type:%d"
,
pRpc
->
label
,
sid
,
pHead
->
msgType
);
tTrace
(
"%s sid:%d, invalid message type:%d"
,
pRpc
->
label
,
sid
,
pHead
->
msgType
);
return
TSDB_CODE_INVALID_MSG_TYPE
;
terrno
=
TSDB_CODE_INVALID_MSG_TYPE
;
return
NULL
;
}
}
if
(
data
Len
!=
pHead
->
msgLen
)
{
if
(
pRecv
->
msg
Len
!=
pHead
->
msgLen
)
{
tTrace
(
"%s sid:%d, %s has invalid length, dataLen:%d, msgLen:%d"
,
pRpc
->
label
,
sid
,
tTrace
(
"%s sid:%d, %s has invalid length, dataLen:%d, msgLen:%d"
,
pRpc
->
label
,
sid
,
taosMsg
[
pHead
->
msgType
],
data
Len
,
pHead
->
msgLen
);
taosMsg
[
pHead
->
msgType
],
pRecv
->
msg
Len
,
pHead
->
msgLen
);
return
TSDB_CODE_INVALID_MSG_LEN
;
terrno
=
TSDB_CODE_INVALID_MSG_LEN
;
return
NULL
;
}
}
if
(
sid
<
0
||
sid
>=
pRpc
->
sessions
)
{
if
(
sid
<
0
||
sid
>=
pRpc
->
sessions
)
{
tTrace
(
"%s sid:%d, sid is out of range, max sid:%d, %s discarded"
,
pRpc
->
label
,
sid
,
tTrace
(
"%s sid:%d, sid is out of range, max sid:%d, %s discarded"
,
pRpc
->
label
,
sid
,
pRpc
->
sessions
,
taosMsg
[
pHead
->
msgType
]);
pRpc
->
sessions
,
taosMsg
[
pHead
->
msgType
]);
return
TSDB_CODE_INVALID_SESSION_ID
;
terrno
=
TSDB_CODE_INVALID_SESSION_ID
;
return
NULL
;
}
}
if
(
sid
==
0
)
sprintf
(
hashstr
,
"%x:%x:%x
"
,
ip
,
pHead
->
uid
,
pHead
->
sourceId
);
if
(
sid
==
0
)
sprintf
(
hashstr
,
"%x:%x:%x
:%d"
,
pRecv
->
ip
,
pHead
->
uid
,
pHead
->
sourceId
,
pRecv
->
connType
);
pConn
=
rpcGetConnObj
(
pRpc
,
sid
,
pHead
->
user
,
hashstr
);
pConn
=
rpcGetConnObj
(
pRpc
,
sid
,
pHead
->
user
,
hashstr
);
if
(
pConn
==
NULL
)
return
terrno
;
if
(
pConn
==
NULL
)
return
NULL
;
*
ppConn
=
pConn
;
sid
=
pConn
->
sid
;
sid
=
pConn
->
sid
;
if
(
pHead
->
uid
)
pConn
->
peerUid
=
pHead
->
uid
;
pConn
->
chandle
=
pRecv
->
chandle
;
if
(
pConn
->
peerIp
!=
pRecv
->
ip
)
{
if
(
pHead
->
tcp
)
{
pConn
->
peerIp
=
pRecv
->
ip
;
tTrace
(
"%s %p, content will be transfered via TCP"
,
pRpc
->
label
,
pConn
)
;
char
ipstr
[
20
]
=
{
0
}
;
if
(
pConn
->
outType
)
taosTmrReset
(
rpcProcessRetryTimer
,
tsRpcTimer
,
pConn
,
pRpc
->
tmrCtrl
,
&
pConn
->
pTimer
);
tinet_ntoa
(
ipstr
,
pRecv
->
ip
);
return
TSDB_CODE_ALREADY_PROCESSED
;
strcpy
(
pConn
->
peerIpstr
,
ipstr
)
;
}
}
code
=
rpcCheckAuthentication
(
pConn
,
(
char
*
)
pHead
,
dataLen
);
if
(
pRecv
->
port
)
pConn
->
peerPort
=
pRecv
->
port
;
if
(
code
!=
0
)
return
code
;
if
(
pHead
->
port
)
pConn
->
peerPort
=
pHead
->
port
;
if
(
pHead
->
uid
)
pConn
->
peerUid
=
pHead
->
uid
;
terrno
=
rpcCheckAuthentication
(
pConn
,
(
char
*
)
pHead
,
pRecv
->
msgLen
);
if
(
terrno
!=
0
)
return
pConn
;
if
(
pHead
->
msgType
!=
TSDB_MSG_TYPE_REG
&&
pHead
->
encrypt
)
{
if
(
pHead
->
msgType
!=
TSDB_MSG_TYPE_REG
&&
pHead
->
encrypt
)
{
// decrypt here
// decrypt here
}
}
if
(
rpcIsReq
(
pHead
->
msgType
)
)
{
if
(
rpcIsReq
(
pHead
->
msgType
)
)
{
code
=
rpcProcessReqHead
(
pConn
,
pHead
);
terrno
=
rpcProcessReqHead
(
pConn
,
pHead
);
pConn
->
connType
=
pRecv
->
connType
;
}
else
{
}
else
{
code
=
rpcProcessRspHead
(
pConn
,
pHead
);
terrno
=
rpcProcessRspHead
(
pConn
,
pHead
);
}
}
return
code
;
return
pConn
;
}
}
static
void
rpcProcessBrokenLink
(
SRpcConn
*
pConn
)
{
static
void
rpcProcessBrokenLink
(
SRpcConn
*
pConn
)
{
...
@@ -713,45 +745,31 @@ static void rpcProcessBrokenLink(SRpcConn *pConn) {
...
@@ -713,45 +745,31 @@ static void rpcProcessBrokenLink(SRpcConn *pConn) {
rpcCloseConn
(
pConn
);
rpcCloseConn
(
pConn
);
}
}
static
void
*
rpcProcessMsgFromPeer
(
void
*
msg
,
int
msgLen
,
uint32_t
ip
,
uint16_t
port
,
void
*
shandle
,
void
*
thandle
,
void
*
chandle
)
{
static
void
*
rpcProcessMsgFromPeer
(
SRecvInfo
*
pRecv
)
{
SRpcHead
*
pHead
=
(
SRpcHead
*
)
msg
;
SRpcHead
*
pHead
=
(
SRpcHead
*
)
pRecv
->
msg
;
SRpcInfo
*
pRpc
=
(
SRpcInfo
*
)
shandle
;
SRpcInfo
*
pRpc
=
(
SRpcInfo
*
)
pRecv
->
shandle
;
SRpcConn
*
pConn
=
(
SRpcConn
*
)
thandle
;
SRpcConn
*
pConn
=
(
SRpcConn
*
)
pRecv
->
thandle
;
int32_t
code
=
0
;
int32_t
code
=
0
;
tDump
(
msg
,
msgLen
);
tDump
(
pRecv
->
msg
,
pRecv
->
msgLen
);
if
(
ip
==
0
&&
pConn
)
{
// underlying UDP layer does not know it is server or client
pRecv
->
connType
=
pRecv
->
connType
|
pRpc
->
connType
;
if
(
pRecv
->
ip
==
0
&&
pConn
)
{
rpcProcessBrokenLink
(
pConn
);
rpcProcessBrokenLink
(
pConn
);
tfree
(
msg
);
tfree
(
pRecv
->
msg
);
return
NULL
;
return
NULL
;
}
}
pthread_mutex_lock
(
&
pRpc
->
mutex
);
pthread_mutex_lock
(
&
pRpc
->
mutex
);
pConn
=
rpcProcessHead
(
pRpc
,
pRecv
);
code
=
rpcProcessHead
(
pRpc
,
&
pConn
,
msg
,
msgLen
,
ip
);
if
(
pConn
)
{
// update connection info
pConn
->
chandle
=
chandle
;
if
(
pConn
->
peerIp
!=
ip
)
{
pConn
->
peerIp
=
ip
;
char
ipstr
[
20
]
=
{
0
};
tinet_ntoa
(
ipstr
,
ip
);
strcpy
(
pConn
->
peerIpstr
,
ipstr
);
}
if
(
port
)
pConn
->
peerPort
=
port
;
if
(
pHead
->
port
)
// port maybe changed by the peer
pConn
->
peerPort
=
pHead
->
port
;
}
pthread_mutex_unlock
(
&
pRpc
->
mutex
);
pthread_mutex_unlock
(
&
pRpc
->
mutex
);
if
(
pHead
->
msgType
<
TSDB_MSG_TYPE_HEARTBEAT
||
(
rpcDebugFlag
&
16
))
{
if
(
pHead
->
msgType
<
TSDB_MSG_TYPE_HEARTBEAT
||
(
rpcDebugFlag
&
16
))
{
tTrace
(
"%s %p, %s received from 0x%x:%hu, parse code:%x len:%d source:0x%08x dest:0x%08x tranId:%d"
,
tTrace
(
"%s %p, %s received from 0x%x:%hu, parse code:%x len:%d source:0x%08x dest:0x%08x tranId:%d"
,
pRpc
->
label
,
pConn
,
taosMsg
[
pHead
->
msgType
],
ip
,
port
,
code
,
pRpc
->
label
,
pConn
,
taosMsg
[
pHead
->
msgType
],
pRecv
->
ip
,
pRecv
->
port
,
code
,
msgLen
,
pHead
->
sourceId
,
pHead
->
destId
,
pHead
->
tranId
);
pRecv
->
msgLen
,
pHead
->
sourceId
,
pHead
->
destId
,
pHead
->
tranId
);
}
}
if
(
pConn
&&
pRpc
->
idleTime
)
{
if
(
pConn
&&
pRpc
->
idleTime
)
{
...
@@ -761,7 +779,7 @@ static void *rpcProcessMsgFromPeer(void *msg, int msgLen, uint32_t ip, uint16_t
...
@@ -761,7 +779,7 @@ static void *rpcProcessMsgFromPeer(void *msg, int msgLen, uint32_t ip, uint16_t
if
(
code
!=
TSDB_CODE_ALREADY_PROCESSED
)
{
if
(
code
!=
TSDB_CODE_ALREADY_PROCESSED
)
{
if
(
code
!=
0
)
{
// parsing error
if
(
code
!=
0
)
{
// parsing error
if
(
rpcIsReq
(
pHead
->
msgType
)
)
{
if
(
rpcIsReq
(
pHead
->
msgType
)
)
{
rpcSendErrorMsgToPeer
(
pR
pc
,
msg
,
code
,
ip
,
port
,
chandl
e
);
rpcSendErrorMsgToPeer
(
pR
ecv
,
cod
e
);
tTrace
(
"%s %p, %s is sent with error code:%x"
,
pRpc
->
label
,
pConn
,
taosMsg
[
pHead
->
msgType
+
1
],
code
);
tTrace
(
"%s %p, %s is sent with error code:%x"
,
pRpc
->
label
,
pConn
,
taosMsg
[
pHead
->
msgType
+
1
],
code
);
}
}
}
else
{
// parsing OK
}
else
{
// parsing OK
...
@@ -769,7 +787,7 @@ static void *rpcProcessMsgFromPeer(void *msg, int msgLen, uint32_t ip, uint16_t
...
@@ -769,7 +787,7 @@ static void *rpcProcessMsgFromPeer(void *msg, int msgLen, uint32_t ip, uint16_t
}
}
}
}
if
(
code
!=
0
)
free
(
msg
);
if
(
code
!=
0
)
free
(
pRecv
->
msg
);
return
pConn
;
return
pConn
;
}
}
...
@@ -816,7 +834,6 @@ static void rpcSendQuickRsp(SRpcConn *pConn, int32_t code) {
...
@@ -816,7 +834,6 @@ static void rpcSendQuickRsp(SRpcConn *pConn, int32_t code) {
pHead
->
version
=
1
;
pHead
->
version
=
1
;
pHead
->
msgType
=
pConn
->
inType
+
1
;
pHead
->
msgType
=
pConn
->
inType
+
1
;
pHead
->
spi
=
0
;
pHead
->
spi
=
0
;
pHead
->
tcp
=
0
;
pHead
->
encrypt
=
0
;
pHead
->
encrypt
=
0
;
pHead
->
tranId
=
pConn
->
inTranId
;
pHead
->
tranId
=
pConn
->
inTranId
;
pHead
->
sourceId
=
pConn
->
ownId
;
pHead
->
sourceId
=
pConn
->
ownId
;
...
@@ -828,19 +845,18 @@ static void rpcSendQuickRsp(SRpcConn *pConn, int32_t code) {
...
@@ -828,19 +845,18 @@ static void rpcSendQuickRsp(SRpcConn *pConn, int32_t code) {
rpcSendMsgToPeer
(
pConn
,
msg
,
0
);
rpcSendMsgToPeer
(
pConn
,
msg
,
0
);
}
}
static
void
rpcSendErrorMsgToPeer
(
SR
pcInfo
*
pRpc
,
char
*
pMsg
,
int32_t
code
,
uint32_t
ip
,
uint16_t
port
,
void
*
chandl
e
)
{
static
void
rpcSendErrorMsgToPeer
(
SR
ecvInfo
*
pRecv
,
int32_t
cod
e
)
{
SRpcHead
*
pRecvHead
,
*
pReplyHead
;
SRpcHead
*
pRecvHead
,
*
pReplyHead
;
char
msg
[
sizeof
(
SRpcHead
)
+
sizeof
(
SRpcDigest
)
+
sizeof
(
uint32_t
)
];
char
msg
[
sizeof
(
SRpcHead
)
+
sizeof
(
SRpcDigest
)
+
sizeof
(
uint32_t
)
];
uint32_t
timeStamp
;
uint32_t
timeStamp
;
int
msgLen
;
int
msgLen
;
pRecvHead
=
(
SRpcHead
*
)
p
M
sg
;
pRecvHead
=
(
SRpcHead
*
)
p
Recv
->
m
sg
;
pReplyHead
=
(
SRpcHead
*
)
msg
;
pReplyHead
=
(
SRpcHead
*
)
msg
;
memset
(
msg
,
0
,
sizeof
(
SRpcHead
));
memset
(
msg
,
0
,
sizeof
(
SRpcHead
));
pReplyHead
->
version
=
pRecvHead
->
version
;
pReplyHead
->
version
=
pRecvHead
->
version
;
pReplyHead
->
msgType
=
(
char
)(
pRecvHead
->
msgType
+
1
);
pReplyHead
->
msgType
=
(
char
)(
pRecvHead
->
msgType
+
1
);
pReplyHead
->
tcp
=
0
;
pReplyHead
->
spi
=
0
;
pReplyHead
->
spi
=
0
;
pReplyHead
->
encrypt
=
0
;
pReplyHead
->
encrypt
=
0
;
pReplyHead
->
tranId
=
pRecvHead
->
tranId
;
pReplyHead
->
tranId
=
pRecvHead
->
tranId
;
...
@@ -860,7 +876,7 @@ static void rpcSendErrorMsgToPeer(SRpcInfo *pRpc, char *pMsg, int32_t code, uint
...
@@ -860,7 +876,7 @@ static void rpcSendErrorMsgToPeer(SRpcInfo *pRpc, char *pMsg, int32_t code, uint
}
}
pReplyHead
->
msgLen
=
(
int32_t
)
htonl
((
uint32_t
)
msgLen
);
pReplyHead
->
msgLen
=
(
int32_t
)
htonl
((
uint32_t
)
msgLen
);
(
*
taosSendData
[
pR
pc
->
connType
])(
ip
,
port
,
msg
,
msgLen
,
chandle
);
(
*
taosSendData
[
pR
ecv
->
connType
])(
pRecv
->
ip
,
pRecv
->
port
,
msg
,
msgLen
,
pRecv
->
chandle
);
return
;
return
;
}
}
...
@@ -872,7 +888,7 @@ static void rpcSendReqToServer(SRpcInfo *pRpc, SRpcReqContext *pContext) {
...
@@ -872,7 +888,7 @@ static void rpcSendReqToServer(SRpcInfo *pRpc, SRpcReqContext *pContext) {
char
msgType
=
pContext
->
msgType
;
char
msgType
=
pContext
->
msgType
;
pContext
->
numOfTry
++
;
pContext
->
numOfTry
++
;
SRpcConn
*
pConn
=
rpcSetConnToServer
(
p
Rpc
,
pContext
->
ipSe
t
);
SRpcConn
*
pConn
=
rpcSetConnToServer
(
p
Contex
t
);
if
(
pConn
==
NULL
)
{
if
(
pConn
==
NULL
)
{
pContext
->
code
=
terrno
;
pContext
->
code
=
terrno
;
taosTmrStart
(
rpcProcessConnError
,
0
,
pContext
,
pRpc
->
tmrCtrl
);
taosTmrStart
(
rpcProcessConnError
,
0
,
pContext
,
pRpc
->
tmrCtrl
);
...
@@ -884,7 +900,6 @@ static void rpcSendReqToServer(SRpcInfo *pRpc, SRpcReqContext *pContext) {
...
@@ -884,7 +900,6 @@ static void rpcSendReqToServer(SRpcInfo *pRpc, SRpcReqContext *pContext) {
// set the message header
// set the message header
pHead
->
version
=
1
;
pHead
->
version
=
1
;
pHead
->
msgType
=
msgType
;
pHead
->
msgType
=
msgType
;
pHead
->
tcp
=
0
;
pHead
->
encrypt
=
0
;
pHead
->
encrypt
=
0
;
pConn
->
tranId
++
;
pConn
->
tranId
++
;
if
(
pConn
->
tranId
==
0
)
pConn
->
tranId
++
;
if
(
pConn
->
tranId
==
0
)
pConn
->
tranId
++
;
...
@@ -928,7 +943,7 @@ static void rpcSendMsgToPeer(SRpcConn *pConn, void *msg, int msgLen) {
...
@@ -928,7 +943,7 @@ static void rpcSendMsgToPeer(SRpcConn *pConn, void *msg, int msgLen) {
(
uint8_t
)
pHead
->
content
[
0
],
msgLen
,
pHead
->
sourceId
,
pHead
->
destId
,
pHead
->
tranId
);
(
uint8_t
)
pHead
->
content
[
0
],
msgLen
,
pHead
->
sourceId
,
pHead
->
destId
,
pHead
->
tranId
);
}
}
writtenLen
=
(
*
taosSendData
[
p
Rpc
->
connType
])(
pConn
->
peerIp
,
pConn
->
peerPort
,
(
char
*
)
pHead
,
msgLen
,
pConn
->
chandle
);
writtenLen
=
(
*
taosSendData
[
p
Conn
->
connType
])(
pConn
->
peerIp
,
pConn
->
peerPort
,
pHead
,
msgLen
,
pConn
->
chandle
);
if
(
writtenLen
!=
msgLen
)
{
if
(
writtenLen
!=
msgLen
)
{
tError
(
"%s %p, failed to send, dataLen:%d writtenLen:%d, reason:%s"
,
pRpc
->
label
,
pConn
,
tError
(
"%s %p, failed to send, dataLen:%d writtenLen:%d, reason:%s"
,
pRpc
->
label
,
pConn
,
...
...
src/rpc/src/rpcServer.c
浏览文件 @
25a4625e
...
@@ -46,10 +46,8 @@ typedef struct _thread_obj {
...
@@ -46,10 +46,8 @@ typedef struct _thread_obj {
int
numOfFds
;
int
numOfFds
;
int
threadId
;
int
threadId
;
char
label
[
12
];
char
label
[
12
];
// char buffer[128000]; // buffer to receive data
void
*
shandle
;
// handle passed by upper layer during server initialization
void
*
shandle
;
// handle passed by upper layer during server initialization
void
*
(
*
processData
)(
char
*
data
,
int
dataLen
,
unsigned
int
ip
,
uint16_t
port
,
void
*
shandle
,
void
*
thandle
,
void
*
(
*
processData
)(
SRecvInfo
*
pPacket
);
void
*
chandle
);
}
SThreadObj
;
}
SThreadObj
;
typedef
struct
{
typedef
struct
{
...
@@ -62,59 +60,81 @@ typedef struct {
...
@@ -62,59 +60,81 @@ typedef struct {
pthread_t
thread
;
pthread_t
thread
;
}
SServerObj
;
}
SServerObj
;
static
void
taosCleanUpFdObj
(
SFdObj
*
pFdObj
)
{
static
void
taosCleanUpFdObj
(
SFdObj
*
pFdObj
);
static
void
taosProcessTcpData
(
void
*
param
);
static
void
taosAcceptTcpConnection
(
void
*
arg
);
void
*
taosInitTcpServer
(
char
*
ip
,
uint16_t
port
,
char
*
label
,
int
numOfThreads
,
void
*
fp
,
void
*
shandle
)
{
int
i
;
SServerObj
*
pServerObj
;
pthread_attr_t
thattr
;
SThreadObj
*
pThreadObj
;
SThreadObj
*
pThreadObj
;
if
(
pFdObj
==
NULL
)
return
;
pServerObj
=
(
SServerObj
*
)
malloc
(
sizeof
(
SServerObj
));
if
(
pFdObj
->
signature
!=
pFdObj
)
return
;
strcpy
(
pServerObj
->
ip
,
ip
);
pServerObj
->
port
=
port
;
strcpy
(
pServerObj
->
label
,
label
);
pServerObj
->
numOfThreads
=
numOfThreads
;
p
ThreadObj
=
pFdObj
->
pThreadObj
;
p
ServerObj
->
pThreadObj
=
(
SThreadObj
*
)
malloc
(
sizeof
(
SThreadObj
)
*
(
size_t
)
numOfThreads
)
;
if
(
pThreadObj
==
NULL
)
{
if
(
p
ServerObj
->
p
ThreadObj
==
NULL
)
{
tError
(
"
FdObj double clean up!!!"
);
tError
(
"
TCP:%s no enough memory"
,
label
);
return
;
return
NULL
;
}
}
memset
(
pServerObj
->
pThreadObj
,
0
,
sizeof
(
SThreadObj
)
*
(
size_t
)
numOfThreads
);
epoll_ctl
(
pThreadObj
->
pollFd
,
EPOLL_CTL_DEL
,
pFdObj
->
fd
,
NULL
);
pThreadObj
=
pServerObj
->
pThreadObj
;
close
(
pFdObj
->
fd
);
for
(
i
=
0
;
i
<
numOfThreads
;
++
i
)
{
pThreadObj
->
processData
=
fp
;
pthread_mutex_lock
(
&
pThreadObj
->
threadMutex
);
strcpy
(
pThreadObj
->
label
,
label
);
pThreadObj
->
shandle
=
shandle
;
pThreadObj
->
numOfFds
--
;
if
(
pThreadObj
->
numOfFds
<
0
)
tError
(
"%s TCP thread:%d, number of FDs shall never be negative"
,
pThreadObj
->
label
,
pThreadObj
->
threadId
);
// remove from the FdObject list
if
(
pFdObj
->
prev
)
{
if
(
pthread_mutex_init
(
&
(
pThreadObj
->
threadMutex
),
NULL
)
<
0
)
{
(
pFdObj
->
prev
)
->
next
=
pFdObj
->
next
;
tError
(
"%s failed to init TCP process data mutex, reason:%s"
,
label
,
strerror
(
errno
));
}
else
{
return
NULL
;
pThreadObj
->
pHead
=
pFdObj
->
next
;
}
}
if
(
pFdObj
->
next
)
{
if
(
pthread_cond_init
(
&
(
pThreadObj
->
fdReady
),
NULL
)
!=
0
)
{
(
pFdObj
->
next
)
->
prev
=
pFdObj
->
prev
;
tError
(
"%s init TCP condition variable failed, reason:%s
\n
"
,
label
,
strerror
(
errno
));
return
NULL
;
}
}
pthread_mutex_unlock
(
&
pThreadObj
->
threadMutex
);
pThreadObj
->
pollFd
=
epoll_create
(
10
);
// size does not matter
if
(
pThreadObj
->
pollFd
<
0
)
{
// notify the upper layer, so it will clean the associated context
tError
(
"%s failed to create TCP epoll"
,
label
);
if
(
pFdObj
->
thandle
)
(
*
(
pThreadObj
->
processData
))(
NULL
,
0
,
0
,
0
,
pThreadObj
->
shandle
,
pFdObj
->
thandle
,
NULL
);
return
NULL
;
}
tTrace
(
"%s TCP thread:%d, FD:%p is cleaned up, numOfFds:%d"
,
pThreadObj
->
label
,
pThreadObj
->
threadId
,
pFdObj
,
pThreadObj
->
numOfFds
);
memset
(
pFdObj
,
0
,
sizeof
(
SFdObj
));
pthread_attr_init
(
&
thattr
);
pthread_attr_setdetachstate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
if
(
pthread_create
(
&
(
pThreadObj
->
thread
),
&
thattr
,
(
void
*
)
taosProcessTcpData
,
(
void
*
)(
pThreadObj
))
!=
0
)
{
tError
(
"%s failed to create TCP process data thread, reason:%s"
,
label
,
strerror
(
errno
));
return
NULL
;
}
tfree
(
pFdObj
);
pThreadObj
->
threadId
=
i
;
}
pThreadObj
++
;
}
void
taosCloseTcpServerConnection
(
void
*
chandle
)
{
pthread_attr_init
(
&
thattr
);
SFdObj
*
pFdObj
=
(
SFdObj
*
)
chandle
;
pthread_attr_setdetachstate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
if
(
pthread_create
(
&
(
pServerObj
->
thread
),
&
thattr
,
(
void
*
)
taosAcceptTcpConnection
,
(
void
*
)(
pServerObj
))
!=
0
)
{
tError
(
"%s failed to create TCP accept thread, reason:%s"
,
label
,
strerror
(
errno
));
return
NULL
;
}
if
(
pFdObj
==
NULL
)
return
;
/*
if ( pthread_create(&(pServerObj->thread), &thattr,
(void*)taosAcceptUDConnection, (void *)(pServerObj)) != 0 ) {
tError("%s failed to create UD accept thread, reason:%s", label,
strerror(errno));
return NULL;
}
*/
pthread_attr_destroy
(
&
thattr
);
tTrace
(
"%s TCP server is initialized, ip:%s port:%hu numOfThreads:%d"
,
label
,
ip
,
port
,
numOfThreads
);
taosCleanUpFdObj
(
pFdObj
)
;
return
(
void
*
)
pServerObj
;
}
}
void
taosCleanUpTcpServer
(
void
*
handle
)
{
void
taosCleanUpTcpServer
(
void
*
handle
)
{
...
@@ -148,6 +168,22 @@ void taosCleanUpTcpServer(void *handle) {
...
@@ -148,6 +168,22 @@ void taosCleanUpTcpServer(void *handle) {
tfree
(
pServerObj
);
tfree
(
pServerObj
);
}
}
void
taosCloseTcpServerConnection
(
void
*
chandle
)
{
SFdObj
*
pFdObj
=
(
SFdObj
*
)
chandle
;
if
(
pFdObj
==
NULL
)
return
;
taosCleanUpFdObj
(
pFdObj
);
}
int
taosSendTcpServerData
(
uint32_t
ip
,
uint16_t
port
,
void
*
data
,
int
len
,
void
*
chandle
)
{
SFdObj
*
pFdObj
=
(
SFdObj
*
)
chandle
;
if
(
chandle
==
NULL
)
return
-
1
;
return
(
int
)
send
(
pFdObj
->
fd
,
data
,
(
size_t
)
len
,
0
);
}
#define maxEvents 10
#define maxEvents 10
static
void
taosProcessTcpData
(
void
*
param
)
{
static
void
taosProcessTcpData
(
void
*
param
)
{
...
@@ -155,7 +191,7 @@ static void taosProcessTcpData(void *param) {
...
@@ -155,7 +191,7 @@ static void taosProcessTcpData(void *param) {
int
i
,
fdNum
;
int
i
,
fdNum
;
SFdObj
*
pFdObj
;
SFdObj
*
pFdObj
;
struct
epoll_event
events
[
maxEvents
];
struct
epoll_event
events
[
maxEvents
];
SRecvInfo
recvInfo
;
pThreadObj
=
(
SThreadObj
*
)
param
;
pThreadObj
=
(
SThreadObj
*
)
param
;
while
(
1
)
{
while
(
1
)
{
...
@@ -209,15 +245,22 @@ static void taosProcessTcpData(void *param) {
...
@@ -209,15 +245,22 @@ static void taosProcessTcpData(void *param) {
continue
;
continue
;
}
}
pFdObj
->
thandle
=
(
*
(
pThreadObj
->
processData
))(
buffer
,
dataLen
,
pFdObj
->
ip
,
pFdObj
->
port
,
recvInfo
.
msg
=
buffer
;
pThreadObj
->
shandle
,
pFdObj
->
thandle
,
pFdObj
);
recvInfo
.
msgLen
=
dataLen
;
recvInfo
.
ip
=
pFdObj
->
ip
;
recvInfo
.
port
=
pFdObj
->
port
;
recvInfo
.
shandle
=
pThreadObj
->
shandle
;
recvInfo
.
thandle
=
pFdObj
->
thandle
;;
recvInfo
.
chandle
=
pFdObj
;
recvInfo
.
connType
=
RPC_CONN_TCP
;
pFdObj
->
thandle
=
(
*
(
pThreadObj
->
processData
))(
&
recvInfo
);
if
(
pFdObj
->
thandle
==
NULL
)
taosCleanUpFdObj
(
pFdObj
);
if
(
pFdObj
->
thandle
==
NULL
)
taosCleanUpFdObj
(
pFdObj
);
}
}
}
}
}
}
void
taosAcceptTcpConnection
(
void
*
arg
)
{
static
void
taosAcceptTcpConnection
(
void
*
arg
)
{
int
connFd
=
-
1
;
int
connFd
=
-
1
;
struct
sockaddr_in
clientAddr
;
struct
sockaddr_in
clientAddr
;
int
sockFd
;
int
sockFd
;
...
@@ -280,16 +323,11 @@ void taosAcceptTcpConnection(void *arg) {
...
@@ -280,16 +323,11 @@ void taosAcceptTcpConnection(void *arg) {
// notify the data process, add into the FdObj list
// notify the data process, add into the FdObj list
pthread_mutex_lock
(
&
(
pThreadObj
->
threadMutex
));
pthread_mutex_lock
(
&
(
pThreadObj
->
threadMutex
));
pFdObj
->
next
=
pThreadObj
->
pHead
;
pFdObj
->
next
=
pThreadObj
->
pHead
;
if
(
pThreadObj
->
pHead
)
(
pThreadObj
->
pHead
)
->
prev
=
pFdObj
;
if
(
pThreadObj
->
pHead
)
(
pThreadObj
->
pHead
)
->
prev
=
pFdObj
;
pThreadObj
->
pHead
=
pFdObj
;
pThreadObj
->
pHead
=
pFdObj
;
pThreadObj
->
numOfFds
++
;
pThreadObj
->
numOfFds
++
;
pthread_cond_signal
(
&
pThreadObj
->
fdReady
);
pthread_cond_signal
(
&
pThreadObj
->
fdReady
);
pthread_mutex_unlock
(
&
(
pThreadObj
->
threadMutex
));
pthread_mutex_unlock
(
&
(
pThreadObj
->
threadMutex
));
tTrace
(
"%s TCP thread:%d, a new connection from %s:%hu, FD:%p, numOfFds:%d"
,
pServerObj
->
label
,
tTrace
(
"%s TCP thread:%d, a new connection from %s:%hu, FD:%p, numOfFds:%d"
,
pServerObj
->
label
,
...
@@ -301,7 +339,65 @@ void taosAcceptTcpConnection(void *arg) {
...
@@ -301,7 +339,65 @@ void taosAcceptTcpConnection(void *arg) {
}
}
}
}
void
taosAcceptUDConnection
(
void
*
arg
)
{
static
void
taosCleanUpFdObj
(
SFdObj
*
pFdObj
)
{
SThreadObj
*
pThreadObj
;
if
(
pFdObj
==
NULL
)
return
;
if
(
pFdObj
->
signature
!=
pFdObj
)
return
;
pThreadObj
=
pFdObj
->
pThreadObj
;
if
(
pThreadObj
==
NULL
)
{
tError
(
"FdObj double clean up!!!"
);
return
;
}
epoll_ctl
(
pThreadObj
->
pollFd
,
EPOLL_CTL_DEL
,
pFdObj
->
fd
,
NULL
);
close
(
pFdObj
->
fd
);
pthread_mutex_lock
(
&
pThreadObj
->
threadMutex
);
pThreadObj
->
numOfFds
--
;
if
(
pThreadObj
->
numOfFds
<
0
)
tError
(
"%s TCP thread:%d, number of FDs shall never be negative"
,
pThreadObj
->
label
,
pThreadObj
->
threadId
);
// remove from the FdObject list
if
(
pFdObj
->
prev
)
{
(
pFdObj
->
prev
)
->
next
=
pFdObj
->
next
;
}
else
{
pThreadObj
->
pHead
=
pFdObj
->
next
;
}
if
(
pFdObj
->
next
)
{
(
pFdObj
->
next
)
->
prev
=
pFdObj
->
prev
;
}
pthread_mutex_unlock
(
&
pThreadObj
->
threadMutex
);
// notify the upper layer, so it will clean the associated context
SRecvInfo
recvInfo
;
recvInfo
.
msg
=
NULL
;
recvInfo
.
msgLen
=
0
;
recvInfo
.
ip
=
0
;
recvInfo
.
port
=
0
;
recvInfo
.
shandle
=
pThreadObj
->
shandle
;
recvInfo
.
thandle
=
pFdObj
->
thandle
;;
recvInfo
.
chandle
=
NULL
;
recvInfo
.
connType
=
RPC_CONN_TCP
;
if
(
pFdObj
->
thandle
)
(
*
(
pThreadObj
->
processData
))(
&
recvInfo
);
tTrace
(
"%s TCP thread:%d, FD:%p is cleaned up, numOfFds:%d"
,
pThreadObj
->
label
,
pThreadObj
->
threadId
,
pFdObj
,
pThreadObj
->
numOfFds
);
memset
(
pFdObj
,
0
,
sizeof
(
SFdObj
));
tfree
(
pFdObj
);
}
#if 0
static void taosAcceptUDConnection(void *arg) {
int connFd = -1;
int connFd = -1;
int sockFd;
int sockFd;
int threadId = 0;
int threadId = 0;
...
@@ -353,16 +449,11 @@ void taosAcceptUDConnection(void *arg) {
...
@@ -353,16 +449,11 @@ void taosAcceptUDConnection(void *arg) {
// notify the data process, add into the FdObj list
// notify the data process, add into the FdObj list
pthread_mutex_lock(&(pThreadObj->threadMutex));
pthread_mutex_lock(&(pThreadObj->threadMutex));
pFdObj->next = pThreadObj->pHead;
pFdObj->next = pThreadObj->pHead;
if (pThreadObj->pHead) (pThreadObj->pHead)->prev = pFdObj;
if (pThreadObj->pHead) (pThreadObj->pHead)->prev = pFdObj;
pThreadObj->pHead = pFdObj;
pThreadObj->pHead = pFdObj;
pThreadObj->numOfFds++;
pThreadObj->numOfFds++;
pthread_cond_signal(&pThreadObj->fdReady);
pthread_cond_signal(&pThreadObj->fdReady);
pthread_mutex_unlock(&(pThreadObj->threadMutex));
pthread_mutex_unlock(&(pThreadObj->threadMutex));
tTrace("%s UD thread:%d, a new connection, numOfFds:%d", pServerObj->label, pThreadObj->threadId,
tTrace("%s UD thread:%d, a new connection, numOfFds:%d", pServerObj->label, pThreadObj->threadId,
...
@@ -373,79 +464,7 @@ void taosAcceptUDConnection(void *arg) {
...
@@ -373,79 +464,7 @@ void taosAcceptUDConnection(void *arg) {
threadId = threadId % pServerObj->numOfThreads;
threadId = threadId % pServerObj->numOfThreads;
}
}
}
}
#endif
void
*
taosInitTcpServer
(
char
*
ip
,
uint16_t
port
,
char
*
label
,
int
numOfThreads
,
void
*
fp
,
void
*
shandle
)
{
int
i
;
SServerObj
*
pServerObj
;
pthread_attr_t
thattr
;
SThreadObj
*
pThreadObj
;
pServerObj
=
(
SServerObj
*
)
malloc
(
sizeof
(
SServerObj
));
strcpy
(
pServerObj
->
ip
,
ip
);
pServerObj
->
port
=
port
;
strcpy
(
pServerObj
->
label
,
label
);
pServerObj
->
numOfThreads
=
numOfThreads
;
pServerObj
->
pThreadObj
=
(
SThreadObj
*
)
malloc
(
sizeof
(
SThreadObj
)
*
(
size_t
)
numOfThreads
);
if
(
pServerObj
->
pThreadObj
==
NULL
)
{
tError
(
"TCP:%s no enough memory"
,
label
);
return
NULL
;
}
memset
(
pServerObj
->
pThreadObj
,
0
,
sizeof
(
SThreadObj
)
*
(
size_t
)
numOfThreads
);
pThreadObj
=
pServerObj
->
pThreadObj
;
for
(
i
=
0
;
i
<
numOfThreads
;
++
i
)
{
pThreadObj
->
processData
=
fp
;
strcpy
(
pThreadObj
->
label
,
label
);
pThreadObj
->
shandle
=
shandle
;
if
(
pthread_mutex_init
(
&
(
pThreadObj
->
threadMutex
),
NULL
)
<
0
)
{
tError
(
"%s failed to init TCP process data mutex, reason:%s"
,
label
,
strerror
(
errno
));
return
NULL
;
}
if
(
pthread_cond_init
(
&
(
pThreadObj
->
fdReady
),
NULL
)
!=
0
)
{
tError
(
"%s init TCP condition variable failed, reason:%s
\n
"
,
label
,
strerror
(
errno
));
return
NULL
;
}
pThreadObj
->
pollFd
=
epoll_create
(
10
);
// size does not matter
if
(
pThreadObj
->
pollFd
<
0
)
{
tError
(
"%s failed to create TCP epoll"
,
label
);
return
NULL
;
}
pthread_attr_init
(
&
thattr
);
pthread_attr_setdetachstate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
if
(
pthread_create
(
&
(
pThreadObj
->
thread
),
&
thattr
,
(
void
*
)
taosProcessTcpData
,
(
void
*
)(
pThreadObj
))
!=
0
)
{
tError
(
"%s failed to create TCP process data thread, reason:%s"
,
label
,
strerror
(
errno
));
return
NULL
;
}
pThreadObj
->
threadId
=
i
;
pThreadObj
++
;
}
pthread_attr_init
(
&
thattr
);
pthread_attr_setdetachstate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
if
(
pthread_create
(
&
(
pServerObj
->
thread
),
&
thattr
,
(
void
*
)
taosAcceptTcpConnection
,
(
void
*
)(
pServerObj
))
!=
0
)
{
tError
(
"%s failed to create TCP accept thread, reason:%s"
,
label
,
strerror
(
errno
));
return
NULL
;
}
/*
if ( pthread_create(&(pServerObj->thread), &thattr,
(void*)taosAcceptUDConnection, (void *)(pServerObj)) != 0 ) {
tError("%s failed to create UD accept thread, reason:%s", label,
strerror(errno));
return NULL;
}
*/
pthread_attr_destroy
(
&
thattr
);
tTrace
(
"%s TCP server is initialized, ip:%s port:%hu numOfThreads:%d"
,
label
,
ip
,
port
,
numOfThreads
);
return
(
void
*
)
pServerObj
;
}
#if 0
#if 0
void taosListTcpConnection(void *handle, char *buffer) {
void taosListTcpConnection(void *handle, char *buffer) {
...
@@ -489,10 +508,4 @@ void taosListTcpConnection(void *handle, char *buffer) {
...
@@ -489,10 +508,4 @@ void taosListTcpConnection(void *handle, char *buffer) {
}
}
#endif
#endif
int
taosSendTcpServerData
(
uint32_t
ip
,
uint16_t
port
,
char
*
data
,
int
len
,
void
*
chandle
)
{
SFdObj
*
pFdObj
=
(
SFdObj
*
)
chandle
;
if
(
chandle
==
NULL
)
return
-
1
;
return
(
int
)
send
(
pFdObj
->
fd
,
data
,
(
size_t
)
len
,
0
);
}
src/rpc/src/rpcUdp.c
浏览文件 @
25a4625e
此差异已折叠。
点击以展开。
src/rpc/test/rclient.c
浏览文件 @
25a4625e
...
@@ -85,7 +85,6 @@ int main(int argc, char *argv[]) {
...
@@ -85,7 +85,6 @@ int main(int argc, char *argv[]) {
int
msgSize
=
128
;
int
msgSize
=
128
;
int
numOfReqs
=
0
;
int
numOfReqs
=
0
;
int
appThreads
=
1
;
int
appThreads
=
1
;
char
socketType
[
20
]
=
"udp"
;
char
serverIp
[
40
]
=
"127.0.0.1"
;
char
serverIp
[
40
]
=
"127.0.0.1"
;
struct
timeval
systemTime
;
struct
timeval
systemTime
;
int64_t
startTime
,
endTime
;
int64_t
startTime
,
endTime
;
...
@@ -113,9 +112,7 @@ int main(int argc, char *argv[]) {
...
@@ -113,9 +112,7 @@ int main(int argc, char *argv[]) {
rpcInit
.
ckey
=
"key"
;
rpcInit
.
ckey
=
"key"
;
for
(
int
i
=
1
;
i
<
argc
;
++
i
)
{
for
(
int
i
=
1
;
i
<
argc
;
++
i
)
{
if
(
strcmp
(
argv
[
i
],
"-c"
)
==
0
&&
i
<
argc
-
1
)
{
if
(
strcmp
(
argv
[
i
],
"-p"
)
==
0
&&
i
<
argc
-
1
)
{
strcpy
(
socketType
,
argv
[
++
i
]);
}
else
if
(
strcmp
(
argv
[
i
],
"-p"
)
==
0
&&
i
<
argc
-
1
)
{
ipSet
.
port
=
atoi
(
argv
[
++
i
]);
ipSet
.
port
=
atoi
(
argv
[
++
i
]);
}
else
if
(
strcmp
(
argv
[
i
],
"-i"
)
==
0
&&
i
<
argc
-
1
)
{
}
else
if
(
strcmp
(
argv
[
i
],
"-i"
)
==
0
&&
i
<
argc
-
1
)
{
ipSet
.
ip
[
0
]
=
inet_addr
(
argv
[
++
i
]);
ipSet
.
ip
[
0
]
=
inet_addr
(
argv
[
++
i
]);
...
@@ -138,7 +135,6 @@ int main(int argc, char *argv[]) {
...
@@ -138,7 +135,6 @@ int main(int argc, char *argv[]) {
}
else
if
(
strcmp
(
argv
[
i
],
"-d"
)
==
0
&&
i
<
argc
-
1
)
{
}
else
if
(
strcmp
(
argv
[
i
],
"-d"
)
==
0
&&
i
<
argc
-
1
)
{
}
else
{
}
else
{
printf
(
"
\n
usage: %s [options]
\n
"
,
argv
[
0
]);
printf
(
"
\n
usage: %s [options]
\n
"
,
argv
[
0
]);
printf
(
" [-c ctype]: connection type:udp or tpc, default is:%s
\n
"
,
socketType
);
printf
(
" [-i ip]: first server IP address, default is:%s
\n
"
,
serverIp
);
printf
(
" [-i ip]: first server IP address, default is:%s
\n
"
,
serverIp
);
printf
(
" [-p port]: server port number, default is:%d
\n
"
,
ipSet
.
port
);
printf
(
" [-p port]: server port number, default is:%d
\n
"
,
ipSet
.
port
);
printf
(
" [-t threads]: number of rpc threads, default is:%d
\n
"
,
rpcInit
.
numOfThreads
);
printf
(
" [-t threads]: number of rpc threads, default is:%d
\n
"
,
rpcInit
.
numOfThreads
);
...
@@ -154,7 +150,7 @@ int main(int argc, char *argv[]) {
...
@@ -154,7 +150,7 @@ int main(int argc, char *argv[]) {
}
}
}
}
rpcInit
.
connType
=
strcasecmp
(
socketType
,
"udp"
)
==
0
?
TAOS_CONN_UDPC
:
TAOS_CONN_TCPC
;
rpcInit
.
connType
=
TAOS_CONN_CLIENT
;
taosInitLog
(
"client.log"
,
100000
,
10
);
taosInitLog
(
"client.log"
,
100000
,
10
);
void
*
pRpc
=
rpcOpen
(
&
rpcInit
);
void
*
pRpc
=
rpcOpen
(
&
rpcInit
);
...
...
src/rpc/test/rserver.c
浏览文件 @
25a4625e
...
@@ -60,7 +60,6 @@ void processRequestMsg(char type, void *pCont, int contLen, void *thandle, int32
...
@@ -60,7 +60,6 @@ void processRequestMsg(char type, void *pCont, int contLen, void *thandle, int32
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
{
SRpcInit
rpcInit
;
SRpcInit
rpcInit
;
char
socketType
[
20
]
=
"udp"
;
char
dataName
[
20
]
=
"server.data"
;
char
dataName
[
20
]
=
"server.data"
;
memset
(
&
rpcInit
,
0
,
sizeof
(
rpcInit
));
memset
(
&
rpcInit
,
0
,
sizeof
(
rpcInit
));
...
@@ -73,9 +72,7 @@ int main(int argc, char *argv[]) {
...
@@ -73,9 +72,7 @@ int main(int argc, char *argv[]) {
rpcInit
.
idleTime
=
2000
;
rpcInit
.
idleTime
=
2000
;
for
(
int
i
=
1
;
i
<
argc
;
++
i
)
{
for
(
int
i
=
1
;
i
<
argc
;
++
i
)
{
if
(
strcmp
(
argv
[
i
],
"-c"
)
==
0
&&
i
<
argc
-
1
)
{
if
(
strcmp
(
argv
[
i
],
"-p"
)
==
0
&&
i
<
argc
-
1
)
{
strcpy
(
socketType
,
argv
[
++
i
]);
}
else
if
(
strcmp
(
argv
[
i
],
"-p"
)
==
0
&&
i
<
argc
-
1
)
{
rpcInit
.
localPort
=
atoi
(
argv
[
++
i
]);
rpcInit
.
localPort
=
atoi
(
argv
[
++
i
]);
}
else
if
(
strcmp
(
argv
[
i
],
"-i"
)
==
0
&&
i
<
argc
-
1
)
{
}
else
if
(
strcmp
(
argv
[
i
],
"-i"
)
==
0
&&
i
<
argc
-
1
)
{
strcpy
(
rpcInit
.
localIp
,
argv
[
++
i
]);
strcpy
(
rpcInit
.
localIp
,
argv
[
++
i
]);
...
@@ -93,7 +90,6 @@ int main(int argc, char *argv[]) {
...
@@ -93,7 +90,6 @@ int main(int argc, char *argv[]) {
rpcDebugFlag
=
atoi
(
argv
[
++
i
]);
rpcDebugFlag
=
atoi
(
argv
[
++
i
]);
}
else
{
}
else
{
printf
(
"
\n
usage: %s [options]
\n
"
,
argv
[
0
]);
printf
(
"
\n
usage: %s [options]
\n
"
,
argv
[
0
]);
printf
(
" [-c ctype]: connection type:udp or tcp, default is:%s
\n
"
,
socketType
);
printf
(
" [-i ip]: server IP address, default is:%s
\n
"
,
rpcInit
.
localIp
);
printf
(
" [-i ip]: server IP address, default is:%s
\n
"
,
rpcInit
.
localIp
);
printf
(
" [-p port]: server port number, default is:%d
\n
"
,
rpcInit
.
localPort
);
printf
(
" [-p port]: server port number, default is:%d
\n
"
,
rpcInit
.
localPort
);
printf
(
" [-t threads]: number of threads, default is:%d
\n
"
,
rpcInit
.
numOfThreads
);
printf
(
" [-t threads]: number of threads, default is:%d
\n
"
,
rpcInit
.
numOfThreads
);
...
@@ -107,7 +103,7 @@ int main(int argc, char *argv[]) {
...
@@ -107,7 +103,7 @@ int main(int argc, char *argv[]) {
}
}
}
}
rpcInit
.
connType
=
strcasecmp
(
socketType
,
"udp"
)
==
0
?
TAOS_CONN_UDPS
:
TAOS_CONN_TCPS
;
rpcInit
.
connType
=
TAOS_CONN_SERVER
;
taosInitLog
(
"server.log"
,
100000
,
10
);
taosInitLog
(
"server.log"
,
100000
,
10
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录