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

rearrange the code to make it more readable

上级 37b55ef1
...@@ -59,7 +59,8 @@ typedef struct { ...@@ -59,7 +59,8 @@ typedef struct {
int16_t index; int16_t index;
int16_t numOfIps; int16_t numOfIps;
uint16_t port; uint16_t port;
char ipStr[TSDB_MAX_MPEERS][40]; uint32_t ip[TSDB_MAX_MPEERS];
char ipStr[TSDB_MAX_MPEERS][TSDB_IPv4ADDR_LEN];
} SRpcIpSet; } SRpcIpSet;
void *rpcOpen(SRpcInit *pRpc); void *rpcOpen(SRpcInit *pRpc);
......
...@@ -13,23 +13,20 @@ ...@@ -13,23 +13,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef TDENGINE_TSCCACHE_H #ifndef TDENGINE_CONN_CACHE_H
#define TDENGINE_TSCCACHE_H #define TDENGINE_CONN_CACHE_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
void *taosOpenConnCache(int maxSessions, void (*cleanFp)(void *), void *tmrCtrl, int64_t keepTimer); void *taosOpenConnCache(int maxSessions, void (*cleanFp)(void *), void *tmrCtrl, int64_t keepTimer);
void taosCloseConnCache(void *handle);
void taosCloseConnCache(void *handle); void taosAddConnIntoCache(void *handle, void *data, uint32_t ip, uint16_t port, char *user);
void *taosAddConnIntoCache(void *handle, void *data, uint32_t ip, uint16_t port, char *user);
void *taosGetConnFromCache(void *handle, uint32_t ip, uint16_t port, char *user); void *taosGetConnFromCache(void *handle, uint32_t ip, uint16_t port, char *user);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif // TDENGINE_TSCACHE_H #endif // TDENGINE_CONN_CACHE_H
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#include "ttime.h" #include "ttime.h"
#include "ttimer.h" #include "ttimer.h"
#include "tutil.h" #include "tutil.h"
#include "tcache.h" #include "tconncache.h"
typedef struct _c_hash_t { typedef struct _c_hash_t {
uint32_t ip; uint32_t ip;
...@@ -64,7 +64,6 @@ int taosHashConn(void *handle, uint32_t ip, uint16_t port, char *user) { ...@@ -64,7 +64,6 @@ int taosHashConn(void *handle, uint32_t ip, uint16_t port, char *user) {
} }
void taosRemoveExpiredNodes(SConnCache *pObj, SConnHash *pNode, int hash, uint64_t time) { void taosRemoveExpiredNodes(SConnCache *pObj, SConnHash *pNode, int hash, uint64_t time) {
if (pNode == NULL) return;
if (time < pObj->keepTimer + pNode->time) return; if (time < pObj->keepTimer + pNode->time) return;
SConnHash *pPrev = pNode->prev, *pNext; SConnHash *pPrev = pNode->prev, *pNext;
...@@ -86,7 +85,7 @@ void taosRemoveExpiredNodes(SConnCache *pObj, SConnHash *pNode, int hash, uint64 ...@@ -86,7 +85,7 @@ void taosRemoveExpiredNodes(SConnCache *pObj, SConnHash *pNode, int hash, uint64
pObj->connHashList[hash] = NULL; pObj->connHashList[hash] = NULL;
} }
void *taosAddConnIntoCache(void *handle, void *data, uint32_t ip, uint16_t port, char *user) { void taosAddConnIntoCache(void *handle, void *data, uint32_t ip, uint16_t port, char *user) {
int hash; int hash;
SConnHash * pNode; SConnHash * pNode;
SConnCache *pObj; SConnCache *pObj;
...@@ -94,12 +93,8 @@ void *taosAddConnIntoCache(void *handle, void *data, uint32_t ip, uint16_t port, ...@@ -94,12 +93,8 @@ void *taosAddConnIntoCache(void *handle, void *data, uint32_t ip, uint16_t port,
uint64_t time = taosGetTimestampMs(); uint64_t time = taosGetTimestampMs();
pObj = (SConnCache *)handle; pObj = (SConnCache *)handle;
if (pObj == NULL || pObj->maxSessions == 0) return NULL; assert(pObj);
assert(data);
if (data == NULL) {
tscTrace("data:%p ip:%p:%d not valid, not added in cache", data, ip, port);
return NULL;
}
hash = taosHashConn(pObj, ip, port, user); hash = taosHashConn(pObj, ip, port, user);
pNode = (SConnHash *)taosMemPoolMalloc(pObj->connHashMemPool); pNode = (SConnHash *)taosMemPoolMalloc(pObj->connHashMemPool);
...@@ -123,7 +118,7 @@ void *taosAddConnIntoCache(void *handle, void *data, uint32_t ip, uint16_t port, ...@@ -123,7 +118,7 @@ void *taosAddConnIntoCache(void *handle, void *data, uint32_t ip, uint16_t port,
tscTrace("%p ip:0x%x:%hu:%d:%p added, connections in cache:%d", data, ip, port, hash, pNode, pObj->count[hash]); tscTrace("%p ip:0x%x:%hu:%d:%p added, connections in cache:%d", data, ip, port, hash, pNode, pObj->count[hash]);
return pObj; return;
} }
void taosCleanConnCache(void *handle, void *tmrId) { void taosCleanConnCache(void *handle, void *tmrId) {
...@@ -155,7 +150,7 @@ void *taosGetConnFromCache(void *handle, uint32_t ip, uint16_t port, char *user) ...@@ -155,7 +150,7 @@ void *taosGetConnFromCache(void *handle, uint32_t ip, uint16_t port, char *user)
void * pData = NULL; void * pData = NULL;
pObj = (SConnCache *)handle; pObj = (SConnCache *)handle;
if (pObj == NULL || pObj->maxSessions == 0) return NULL; assert(pObj);
uint64_t time = taosGetTimestampMs(); uint64_t time = taosGetTimestampMs();
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册