add debug trace
This commit is contained in:
parent
a0804f191a
commit
44fed912b3
|
@ -123,11 +123,13 @@ static void clientHandleResp(SCliConn* conn) {
|
||||||
rpcMsg.code = pHead->code;
|
rpcMsg.code = pHead->code;
|
||||||
rpcMsg.msgType = pHead->msgType;
|
rpcMsg.msgType = pHead->msgType;
|
||||||
rpcMsg.ahandle = pCtx->ahandle;
|
rpcMsg.ahandle = pCtx->ahandle;
|
||||||
|
|
||||||
|
tDebug("client conn %p %s received from %s:%d", conn, TMSG_INFO(pHead->msgType), pMsg->ctx->ip, pMsg->ctx->port);
|
||||||
if (pCtx->pSem == NULL) {
|
if (pCtx->pSem == NULL) {
|
||||||
tDebug("client conn %p handle resp, ", conn);
|
tTrace("client conn(sync) %p handle resp", conn);
|
||||||
(pRpc->cfp)(pRpc->parent, &rpcMsg, NULL);
|
(pRpc->cfp)(pRpc->parent, &rpcMsg, NULL);
|
||||||
} else {
|
} else {
|
||||||
tDebug("client conn(sync) %p handle resp", conn);
|
tTrace("client conn(sync) %p handle resp", conn);
|
||||||
memcpy((char*)pCtx->pRsp, (char*)&rpcMsg, sizeof(rpcMsg));
|
memcpy((char*)pCtx->pRsp, (char*)&rpcMsg, sizeof(rpcMsg));
|
||||||
tsem_post(pCtx->pSem);
|
tsem_post(pCtx->pSem);
|
||||||
}
|
}
|
||||||
|
@ -370,7 +372,7 @@ static void clientWrite(SCliConn* pConn) {
|
||||||
pHead->msgLen = (int32_t)htonl((uint32_t)msgLen);
|
pHead->msgLen = (int32_t)htonl((uint32_t)msgLen);
|
||||||
|
|
||||||
uv_buf_t wb = uv_buf_init((char*)pHead, msgLen);
|
uv_buf_t wb = uv_buf_init((char*)pHead, msgLen);
|
||||||
tDebug("client conn %p data write out, msgType : %s, len: %d", pConn, TMSG_INFO(pHead->msgType), msgLen);
|
tDebug("conn %p %s is send to %s:%d", pConn, TMSG_INFO(pHead->msgType), pCliMsg->ctx->ip, pCliMsg->ctx->port);
|
||||||
uv_write(pConn->writeReq, (uv_stream_t*)pConn->stream, &wb, 1, clientWriteCb);
|
uv_write(pConn->writeReq, (uv_stream_t*)pConn->stream, &wb, 1, clientWriteCb);
|
||||||
}
|
}
|
||||||
static void clientConnCb(uv_connect_t* req, int status) {
|
static void clientConnCb(uv_connect_t* req, int status) {
|
||||||
|
|
|
@ -33,7 +33,7 @@ typedef struct SSrvConn {
|
||||||
void* hostThrd;
|
void* hostThrd;
|
||||||
void* pSrvMsg;
|
void* pSrvMsg;
|
||||||
|
|
||||||
struct sockaddr peername;
|
struct sockaddr_in addr;
|
||||||
|
|
||||||
// SRpcMsg sendMsg;
|
// SRpcMsg sendMsg;
|
||||||
// del later
|
// del later
|
||||||
|
@ -236,14 +236,6 @@ static void uvHandleReq(SSrvConn* pConn) {
|
||||||
assert(transIsReq(pHead->msgType));
|
assert(transIsReq(pHead->msgType));
|
||||||
|
|
||||||
SRpcInfo* pRpc = (SRpcInfo*)p->shandle;
|
SRpcInfo* pRpc = (SRpcInfo*)p->shandle;
|
||||||
// auth here
|
|
||||||
// auth should not do in rpc thread
|
|
||||||
|
|
||||||
// int8_t code = uvAuthMsg(pConn, (char*)pHead, p->msgLen);
|
|
||||||
// if (code != 0) {
|
|
||||||
// terrno = code;
|
|
||||||
// return;
|
|
||||||
//}
|
|
||||||
pHead->code = htonl(pHead->code);
|
pHead->code = htonl(pHead->code);
|
||||||
|
|
||||||
int32_t dlen = 0;
|
int32_t dlen = 0;
|
||||||
|
@ -266,7 +258,8 @@ static void uvHandleReq(SSrvConn* pConn) {
|
||||||
|
|
||||||
transClearBuffer(&pConn->readBuf);
|
transClearBuffer(&pConn->readBuf);
|
||||||
pConn->ref++;
|
pConn->ref++;
|
||||||
tDebug("%s received on %p", TMSG_INFO(rpcMsg.msgType), pConn);
|
tDebug("%p %s received from %s:%d", pConn, TMSG_INFO(rpcMsg.msgType), inet_ntoa(pConn->addr.sin_addr),
|
||||||
|
ntohs(pConn->addr.sin_port));
|
||||||
(*(pRpc->cfp))(pRpc->parent, &rpcMsg, NULL);
|
(*(pRpc->cfp))(pRpc->parent, &rpcMsg, NULL);
|
||||||
// uv_timer_start(pConn->pTimer, uvHandleActivityTimeout, pRpc->idleTime * 10000, 0);
|
// uv_timer_start(pConn->pTimer, uvHandleActivityTimeout, pRpc->idleTime * 10000, 0);
|
||||||
// auth
|
// auth
|
||||||
|
@ -279,12 +272,12 @@ void uvOnReadCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf) {
|
||||||
SConnBuffer* pBuf = &conn->readBuf;
|
SConnBuffer* pBuf = &conn->readBuf;
|
||||||
if (nread > 0) {
|
if (nread > 0) {
|
||||||
pBuf->len += nread;
|
pBuf->len += nread;
|
||||||
tDebug("conn %p read summary, total read: %d, current read: %d", conn, pBuf->len, (int)nread);
|
tTrace("conn %p read summary, total read: %d, current read: %d", conn, pBuf->len, (int)nread);
|
||||||
if (readComplete(pBuf)) {
|
if (readComplete(pBuf)) {
|
||||||
tDebug("conn %p alread read complete packet", conn);
|
tTrace("conn %p alread read complete packet", conn);
|
||||||
uvHandleReq(conn);
|
uvHandleReq(conn);
|
||||||
} else {
|
} else {
|
||||||
tDebug("conn %p read partial packet, continue to read", conn);
|
tTrace("conn %p read partial packet, continue to read", conn);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -338,7 +331,8 @@ static void uvOnPipeWriteCb(uv_write_t* req, int status) {
|
||||||
static void uvPrepareSendData(SSrvMsg* smsg, uv_buf_t* wb) {
|
static void uvPrepareSendData(SSrvMsg* smsg, uv_buf_t* wb) {
|
||||||
// impl later;
|
// impl later;
|
||||||
tDebug("conn %p prepare to send resp", smsg->pConn);
|
tDebug("conn %p prepare to send resp", smsg->pConn);
|
||||||
SRpcMsg* pMsg = &smsg->msg;
|
SRpcMsg* pMsg = &smsg->msg;
|
||||||
|
SSrvConn* pConn = smsg->pConn;
|
||||||
if (pMsg->pCont == 0) {
|
if (pMsg->pCont == 0) {
|
||||||
pMsg->pCont = (void*)rpcMallocCont(0);
|
pMsg->pCont = (void*)rpcMallocCont(0);
|
||||||
pMsg->contLen = 0;
|
pMsg->contLen = 0;
|
||||||
|
@ -351,6 +345,9 @@ static void uvPrepareSendData(SSrvMsg* smsg, uv_buf_t* wb) {
|
||||||
if (transCompressMsg(msg, len, NULL)) {
|
if (transCompressMsg(msg, len, NULL)) {
|
||||||
// impl later
|
// impl later
|
||||||
}
|
}
|
||||||
|
tDebug("%p start to send %s to %s:%d", pConn, TMSG_INFO(pHead->msgType), inet_ntoa(pConn->addr.sin_addr),
|
||||||
|
ntohs(pConn->addr.sin_port));
|
||||||
|
|
||||||
pHead->msgLen = htonl(len);
|
pHead->msgLen = htonl(len);
|
||||||
wb->base = msg;
|
wb->base = msg;
|
||||||
wb->len = len;
|
wb->len = len;
|
||||||
|
@ -490,8 +487,8 @@ void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) {
|
||||||
uv_os_fd_t fd;
|
uv_os_fd_t fd;
|
||||||
uv_fileno((const uv_handle_t*)pConn->pTcp, &fd);
|
uv_fileno((const uv_handle_t*)pConn->pTcp, &fd);
|
||||||
tDebug("conn %p created, fd: %d", pConn, fd);
|
tDebug("conn %p created, fd: %d", pConn, fd);
|
||||||
int namelen = sizeof(pConn->peername);
|
int addrlen = sizeof(pConn->addr);
|
||||||
if (0 != uv_tcp_getpeername(pConn->pTcp, &pConn->peername, &namelen)) {
|
if (0 != uv_tcp_getpeername(pConn->pTcp, (struct sockaddr*)&pConn->addr, &addrlen)) {
|
||||||
tError("failed to get peer name");
|
tError("failed to get peer name");
|
||||||
destroyConn(pConn, true);
|
destroyConn(pConn, true);
|
||||||
} else {
|
} else {
|
||||||
|
@ -732,18 +729,18 @@ void rpcSendResponse(const SRpcMsg* pMsg) {
|
||||||
// QUEUE_PUSH(&pThrd->msg, &srvMsg->q);
|
// QUEUE_PUSH(&pThrd->msg, &srvMsg->q);
|
||||||
// pthread_mutex_unlock(&pThrd->msgMtx);
|
// pthread_mutex_unlock(&pThrd->msgMtx);
|
||||||
|
|
||||||
tDebug("conn %p start to send resp", pConn);
|
tTrace("conn %p start to send resp", pConn);
|
||||||
transSendAsync(pThrd->asyncPool, &srvMsg->q);
|
transSendAsync(pThrd->asyncPool, &srvMsg->q);
|
||||||
// uv_async_send(pThrd->workerAsync);
|
// uv_async_send(pThrd->workerAsync);
|
||||||
}
|
}
|
||||||
|
|
||||||
int rpcGetConnInfo(void* thandle, SRpcConnInfo* pInfo) {
|
int rpcGetConnInfo(void* thandle, SRpcConnInfo* pInfo) {
|
||||||
SSrvConn* pConn = thandle;
|
SSrvConn* pConn = thandle;
|
||||||
struct sockaddr* pPeerName = &pConn->peername;
|
// struct sockaddr* pPeerName = &pConn->peername;
|
||||||
|
|
||||||
struct sockaddr_in caddr = *(struct sockaddr_in*)(pPeerName);
|
struct sockaddr_in addr = pConn->addr;
|
||||||
pInfo->clientIp = (uint32_t)(caddr.sin_addr.s_addr);
|
pInfo->clientIp = (uint32_t)(addr.sin_addr.s_addr);
|
||||||
pInfo->clientPort = ntohs(caddr.sin_port);
|
pInfo->clientPort = ntohs(addr.sin_port);
|
||||||
|
|
||||||
tstrncpy(pInfo->user, pConn->user, sizeof(pInfo->user));
|
tstrncpy(pInfo->user, pConn->user, sizeof(pInfo->user));
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue