提交 a3bb1d5f 编写于 作者: 陶建辉(Jeff)'s avatar 陶建辉(Jeff)

tune the code

上级 e90d241e
...@@ -25,6 +25,7 @@ void taosStopTcpServer(void *param); ...@@ -25,6 +25,7 @@ void taosStopTcpServer(void *param);
void taosCleanUpTcpServer(void *param); void taosCleanUpTcpServer(void *param);
void *taosInitTcpClient(uint32_t ip, uint16_t port, char *label, int num, void *fp, void *shandle); void *taosInitTcpClient(uint32_t ip, uint16_t port, char *label, int num, void *fp, void *shandle);
void taosStopTcpClient(void *chandle);
void taosCleanUpTcpClient(void *chandle); void taosCleanUpTcpClient(void *chandle);
void *taosOpenTcpClientConnection(void *shandle, void *thandle, uint32_t ip, uint16_t port); void *taosOpenTcpClientConnection(void *shandle, void *thandle, uint32_t ip, uint16_t port);
......
...@@ -23,6 +23,7 @@ extern "C" { ...@@ -23,6 +23,7 @@ extern "C" {
#include "taosdef.h" #include "taosdef.h"
void *taosInitUdpConnection(uint32_t ip, uint16_t port, char *label, int, void *fp, void *shandle); void *taosInitUdpConnection(uint32_t ip, uint16_t port, char *label, int, void *fp, void *shandle);
void taosStopUdpConnection(void *handle);
void taosCleanUpUdpConnection(void *handle); void taosCleanUpUdpConnection(void *handle);
int taosSendUdpData(uint32_t ip, uint16_t port, void *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, uint32_t ip, uint16_t port); void *taosOpenUdpConnection(void *shandle, void *thandle, uint32_t ip, uint16_t port);
......
...@@ -147,17 +147,17 @@ void *(*taosInitConn[])(uint32_t ip, uint16_t port, char *label, int threads, vo ...@@ -147,17 +147,17 @@ void *(*taosInitConn[])(uint32_t ip, uint16_t port, char *label, int threads, vo
}; };
void (*taosCleanUpConn[])(void *thandle) = { void (*taosCleanUpConn[])(void *thandle) = {
NULL, taosCleanUpUdpConnection,
NULL, taosCleanUpUdpConnection,
taosCleanUpTcpServer, taosCleanUpTcpServer,
taosCleanUpTcpClient taosCleanUpTcpClient
}; };
void (*taosStopConn[])(void *thandle) = { void (*taosStopConn[])(void *thandle) = {
taosCleanUpUdpConnection, taosStopUdpConnection,
taosCleanUpUdpConnection, taosStopUdpConnection,
taosStopTcpServer, taosStopTcpServer,
NULL taosStopTcpClient,
}; };
int (*taosSendData[])(uint32_t ip, uint16_t port, void *data, int len, void *chandle) = { int (*taosSendData[])(uint32_t ip, uint16_t port, void *data, int len, void *chandle) = {
...@@ -297,11 +297,8 @@ void rpcClose(void *param) { ...@@ -297,11 +297,8 @@ void rpcClose(void *param) {
SRpcInfo *pRpc = (SRpcInfo *)param; SRpcInfo *pRpc = (SRpcInfo *)param;
// stop connection to outside first // stop connection to outside first
if (taosStopConn[pRpc->connType | RPC_CONN_TCP]) (*taosStopConn[pRpc->connType | RPC_CONN_TCP])(pRpc->tcphandle);
(*taosStopConn[pRpc->connType | RPC_CONN_TCP])(pRpc->tcphandle); (*taosStopConn[pRpc->connType])(pRpc->udphandle);
if (taosStopConn[pRpc->connType])
(*taosStopConn[pRpc->connType])(pRpc->udphandle);
// close all connections // close all connections
for (int i = 0; i < pRpc->sessions; ++i) { for (int i = 0; i < pRpc->sessions; ++i) {
...@@ -311,11 +308,8 @@ void rpcClose(void *param) { ...@@ -311,11 +308,8 @@ void rpcClose(void *param) {
} }
// clean up // clean up
if (taosCleanUpConn[pRpc->connType | RPC_CONN_TCP]) (*taosCleanUpConn[pRpc->connType | RPC_CONN_TCP])(pRpc->tcphandle);
(*taosCleanUpConn[pRpc->connType | RPC_CONN_TCP])(pRpc->tcphandle); (*taosCleanUpConn[pRpc->connType])(pRpc->udphandle);
if (taosCleanUpConn[pRpc->connType])
(*taosCleanUpConn[pRpc->connType])(pRpc->udphandle);
tTrace("%s rpc is closed", pRpc->label); tTrace("%s rpc is closed", pRpc->label);
rpcDecRef(pRpc); rpcDecRef(pRpc);
......
...@@ -193,10 +193,11 @@ static void taosStopTcpThread(SThreadObj* pThreadObj) { ...@@ -193,10 +193,11 @@ static void taosStopTcpThread(SThreadObj* pThreadObj) {
void taosStopTcpServer(void *handle) { void taosStopTcpServer(void *handle) {
SServerObj *pServerObj = handle; SServerObj *pServerObj = handle;
tTrace("TCP:%s, stop accept new connections", pServerObj->label);
if (pServerObj == NULL) return; if (pServerObj == NULL) return;
if(pServerObj->fd >=0) shutdown(pServerObj->fd, SHUT_RD); if(pServerObj->fd >=0) shutdown(pServerObj->fd, SHUT_RD);
if(pServerObj->thread) pthread_join(pServerObj->thread, NULL); if(pServerObj->thread) pthread_join(pServerObj->thread, NULL);
tTrace("%s TCP server is stopped", pServerObj->label);
} }
void taosCleanUpTcpServer(void *handle) { void taosCleanUpTcpServer(void *handle) {
...@@ -210,7 +211,7 @@ void taosCleanUpTcpServer(void *handle) { ...@@ -210,7 +211,7 @@ void taosCleanUpTcpServer(void *handle) {
pthread_mutex_destroy(&(pThreadObj->mutex)); pthread_mutex_destroy(&(pThreadObj->mutex));
} }
tTrace("TCP:%s, TCP server is cleaned up", pServerObj->label); tTrace("%s TCP server is cleaned up", pServerObj->label);
tfree(pServerObj->pThreadObj); tfree(pServerObj->pThreadObj);
tfree(pServerObj); tfree(pServerObj);
...@@ -309,12 +310,19 @@ void *taosInitTcpClient(uint32_t ip, uint16_t port, char *label, int num, void * ...@@ -309,12 +310,19 @@ void *taosInitTcpClient(uint32_t ip, uint16_t port, char *label, int num, void *
return pThreadObj; return pThreadObj;
} }
void taosStopTcpClient(void *chandle) {
SThreadObj *pThreadObj = chandle;
if (pThreadObj == NULL) return;
tTrace ("%s TCP client is stopped", pThreadObj->label);
}
void taosCleanUpTcpClient(void *chandle) { void taosCleanUpTcpClient(void *chandle) {
SThreadObj *pThreadObj = chandle; SThreadObj *pThreadObj = chandle;
if (pThreadObj == NULL) return; if (pThreadObj == NULL) return;
taosStopTcpThread(pThreadObj); taosStopTcpThread(pThreadObj);
tTrace ("%s, all connections are cleaned up", pThreadObj->label); tTrace ("%s TCP client is cleaned up", pThreadObj->label);
tfree(pThreadObj); tfree(pThreadObj);
} }
......
...@@ -130,7 +130,7 @@ void *taosInitUdpConnection(uint32_t ip, uint16_t port, char *label, int threads ...@@ -130,7 +130,7 @@ void *taosInitUdpConnection(uint32_t ip, uint16_t port, char *label, int threads
return pSet; return pSet;
} }
void taosCleanUpUdpConnection(void *handle) { void taosStopUdpConnection(void *handle) {
SUdpConnSet *pSet = (SUdpConnSet *)handle; SUdpConnSet *pSet = (SUdpConnSet *)handle;
SUdpConn *pConn; SUdpConn *pConn;
...@@ -146,9 +146,24 @@ void taosCleanUpUdpConnection(void *handle) { ...@@ -146,9 +146,24 @@ void taosCleanUpUdpConnection(void *handle) {
pConn = pSet->udpConn + i; pConn = pSet->udpConn + i;
if (pConn->thread) pthread_join(pConn->thread, NULL); if (pConn->thread) pthread_join(pConn->thread, NULL);
tfree(pConn->buffer); tfree(pConn->buffer);
tTrace("%s UDP thread is closed, inedx:%d", pConn->label, i); // tTrace("%s UDP thread is closed, index:%d", pConn->label, i);
}
tTrace("%s UDP is stopped", pSet->label);
}
void taosCleanUpUdpConnection(void *handle) {
SUdpConnSet *pSet = (SUdpConnSet *)handle;
SUdpConn *pConn;
if (pSet == NULL) return;
for (int i = 0; i < pSet->threads; ++i) {
pConn = pSet->udpConn + i;
if (pConn->fd >=0) taosCloseSocket(pConn->fd);
} }
tTrace("%s UDP is cleaned up", pSet->label);
tfree(pSet); tfree(pSet);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册