This commit is contained in:
yihaoDeng 2022-03-14 16:11:17 +08:00
parent 0deef5aa1e
commit ed788d3991
3 changed files with 47 additions and 45 deletions

View File

@ -147,7 +147,6 @@ typedef struct {
// SEpSet* pSet; // for synchronous API // SEpSet* pSet; // for synchronous API
} STransConnCtx; } STransConnCtx;
#pragma pack(push, 1) #pragma pack(push, 1)
typedef struct { typedef struct {
@ -248,24 +247,21 @@ bool transReadComplete(SConnBuffer* connBuf);
int transSetConnOption(uv_tcp_t* stream); int transSetConnOption(uv_tcp_t* stream);
void transRefSrvHandle(void* handle); void transRefSrvHandle(void* handle);
void transUnrefSrvHandle(void* handle); void transUnrefSrvHandle(void* handle);
void transRefCliHandle(void* handle); void transRefCliHandle(void* handle);
void transUnrefCliHandle(void* handle); void transUnrefCliHandle(void* handle);
void transSendRequest(void* shandle, const char* ip, uint32_t port, STransMsg* pMsg);
void transSendRequest(void *shandle, const char *ip, uint32_t port, STransMsg *pMsg); void transSendRecv(void* shandle, const char* ip, uint32_t port, STransMsg* pMsg, STransMsg* pRsp);
void transSendRecv(void* shandle, const char *ip, uint32_t port, STransMsg *pMsg, STransMsg *pRsp);
void transSendResponse(const STransMsg* pMsg); void transSendResponse(const STransMsg* pMsg);
int transGetConnInfo(void *thandle, STransHandleInfo *pInfo); int transGetConnInfo(void* thandle, STransHandleInfo* pInfo);
void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, void* fp, void* shandle); void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, void* fp, void* shandle);
void* transInitClient(uint32_t ip, uint32_t port, char* label, int numOfThreads, void* fp, void* shandle); void* transInitClient(uint32_t ip, uint32_t port, char* label, int numOfThreads, void* fp, void* shandle);
void transCloseClient(void *arg); void transCloseClient(void* arg);
void transCloseServer(void *arg); void transCloseServer(void* arg);
#endif #endif

View File

@ -135,7 +135,13 @@ static void destroyThrdObj(SCliThrdObj* pThrd);
} \ } \
} while (0); } while (0);
#define CONN_SET_PERSIST_BY_APP(conn) do { if (conn->persist == false) { conn->persist = true; transRefCliHandle(conn);}} while(0) #define CONN_SET_PERSIST_BY_APP(conn) \
do { \
if (conn->persist == false) { \
conn->persist = true; \
transRefCliHandle(conn); \
} \
} while (0)
#define CONN_NO_PERSIST_BY_APP(conn) ((conn)->persist == false) #define CONN_NO_PERSIST_BY_APP(conn) ((conn)->persist == false)
static void* cliWorkThread(void* arg); static void* cliWorkThread(void* arg);
@ -159,13 +165,13 @@ void cliHandleResp(SCliConn* conn) {
rpcMsg.ahandle = NULL; rpcMsg.ahandle = NULL;
SCliMsg* pMsg = conn->data; SCliMsg* pMsg = conn->data;
STransConnCtx *pCtx = pMsg ? pMsg->ctx : NULL; STransConnCtx* pCtx = pMsg ? pMsg->ctx : NULL;
if (pMsg == NULL && !CONN_NO_PERSIST_BY_APP(conn)) { if (pMsg == NULL && !CONN_NO_PERSIST_BY_APP(conn)) {
rpcMsg.ahandle = pTransInst->mfp ? (*pTransInst->mfp)(pTransInst->parent, rpcMsg.msgType) : NULL; rpcMsg.ahandle = pTransInst->mfp ? (*pTransInst->mfp)(pTransInst->parent, rpcMsg.msgType) : NULL;
} else { } else {
rpcMsg.ahandle = pCtx ? pCtx->ahandle : NULL; rpcMsg.ahandle = pCtx ? pCtx->ahandle : NULL;
} }
//if (rpcMsg.ahandle == NULL) { // if (rpcMsg.ahandle == NULL) {
// tDebug("%s cli conn %p handle except", CONN_GET_INST_LABEL(conn), conn); // tDebug("%s cli conn %p handle except", CONN_GET_INST_LABEL(conn), conn);
// return; // return;
//} //}
@ -216,7 +222,7 @@ void cliHandleExcept(SCliConn* pConn) {
STrans* pTransInst = pThrd->pTransInst; STrans* pTransInst = pThrd->pTransInst;
SCliMsg* pMsg = pConn->data; SCliMsg* pMsg = pConn->data;
STransConnCtx *pCtx = pMsg ? pMsg->ctx : NULL; STransConnCtx* pCtx = pMsg ? pMsg->ctx : NULL;
STransMsg rpcMsg = {0}; STransMsg rpcMsg = {0};
rpcMsg.code = TSDB_CODE_RPC_NETWORK_UNAVAIL; rpcMsg.code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
@ -689,9 +695,9 @@ void transUnrefCliHandle(void* handle) {
} }
} }
void transSendRequest(void *shandle, const char *ip, uint32_t port, STransMsg *pMsg) { void transSendRequest(void* shandle, const char* ip, uint32_t port, STransMsg* pMsg) {
STrans* pTransInst = (STrans*)shandle; STrans* pTransInst = (STrans*)shandle;
int index = CONN_HOST_THREAD_INDEX((SCliConn *)pMsg->handle); int index = CONN_HOST_THREAD_INDEX((SCliConn*)pMsg->handle);
if (index == -1) { if (index == -1) {
index = cliRBChoseIdx(pTransInst); index = cliRBChoseIdx(pTransInst);
} }
@ -718,7 +724,7 @@ void transSendRequest(void *shandle, const char *ip, uint32_t port, STransMsg *p
SCliThrdObj* thrd = ((SCliObj*)pTransInst->tcphandle)->pThreadObj[index]; SCliThrdObj* thrd = ((SCliObj*)pTransInst->tcphandle)->pThreadObj[index];
transSendAsync(thrd->asyncPool, &(cliMsg->q)); transSendAsync(thrd->asyncPool, &(cliMsg->q));
} }
void transSendRecv(void* shandle, const char *ip, uint32_t port, STransMsg *pReq, STransMsg *pRsp) { void transSendRecv(void* shandle, const char* ip, uint32_t port, STransMsg* pReq, STransMsg* pRsp) {
STrans* pTransInst = (STrans*)shandle; STrans* pTransInst = (STrans*)shandle;
int index = CONN_HOST_THREAD_INDEX(pReq->handle); int index = CONN_HOST_THREAD_INDEX(pReq->handle);
if (index == -1) { if (index == -1) {

View File

@ -798,7 +798,7 @@ void transSendResponse(const STransMsg* pMsg) {
tTrace("server conn %p start to send resp", pConn); tTrace("server conn %p start to send resp", pConn);
transSendAsync(pThrd->asyncPool, &srvMsg->q); transSendAsync(pThrd->asyncPool, &srvMsg->q);
} }
int transGetConnInfo(void *thandle, STransHandleInfo *pInfo) { int transGetConnInfo(void* thandle, STransHandleInfo* pInfo) {
SSrvConn* pConn = thandle; SSrvConn* pConn = thandle;
struct sockaddr_in addr = pConn->addr; struct sockaddr_in addr = pConn->addr;