From 8c87d83a56245996d520ea046830aa87e902f009 Mon Sep 17 00:00:00 2001 From: Jeff Tao Date: Tue, 25 Feb 2020 07:39:16 +0800 Subject: [PATCH] fix a write bug, make the connection cache code prettier --- src/rpc/src/rpcMain.c | 6 +++--- src/rpc/test/rserver.c | 11 +++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/rpc/src/rpcMain.c b/src/rpc/src/rpcMain.c index 57d332c55e..05141b0235 100755 --- a/src/rpc/src/rpcMain.c +++ b/src/rpc/src/rpcMain.c @@ -802,7 +802,7 @@ static void *rpcProcessMsgFromPeer(SRecvInfo *pRecv) { pConn = rpcProcessMsgHead(pRpc, pRecv); 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 port:%hu", + tTrace("%s %p, %s received from 0x%x:%hu, parse code:%x len:%d sig:0x%08x:0x%08x:%d", pRpc->label, pConn, taosMsg[pHead->msgType], pRecv->ip, pRecv->port, terrno, pRecv->msgLen, pHead->sourceId, pHead->destId, pHead->tranId, pHead->port); } @@ -969,12 +969,12 @@ static void rpcSendMsgToPeer(SRpcConn *pConn, void *msg, int msgLen) { if ( rpcIsReq(pHead->msgType)) { if (pHead->msgType < TSDB_MSG_TYPE_HEARTBEAT || (rpcDebugFlag & 16)) - tTrace("%s %p, %s is sent to %s:%hu, len:%d source:0x%08x dest:0x%08x tranId:%d", + tTrace("%s %p, %s is sent to %s:%hu, len:%d sig:0x%08x:0x%08x:%d", pRpc->label, pConn, taosMsg[pHead->msgType], pConn->peerIpstr, pConn->peerPort, msgLen, pHead->sourceId, pHead->destId, pHead->tranId); } else { if (pHead->msgType < TSDB_MSG_TYPE_HEARTBEAT || (rpcDebugFlag & 16)) - tTrace( "%s %p, %s is sent to %s:%hu, code:%u len:%d source:0x%08x dest:0x%08x tranId:%d", + tTrace( "%s %p, %s is sent to %s:%hu, code:%u len:%d sig:0x%08x:0x%08x:%d", pRpc->label, pConn, taosMsg[pHead->msgType], pConn->peerIpstr, pConn->peerPort, (uint8_t)pHead->content[0], msgLen, pHead->sourceId, pHead->destId, pHead->tranId); } diff --git a/src/rpc/test/rserver.c b/src/rpc/test/rserver.c index 1b5e1b6ee7..89e3221a41 100644 --- a/src/rpc/test/rserver.c +++ b/src/rpc/test/rserver.c @@ -27,9 +27,12 @@ void processRequestMsg(char type, void *pCont, int contLen, void *thandle, int32 static int num = 0; tTrace("request is received, type:%d, contLen:%d", type, contLen); - if (dataFd >=0) - write(dataFd, pCont, contLen); - + if (dataFd >=0) { + if ( write(dataFd, pCont, contLen) <0 ) { + tPrint("failed to write data file, reason:%s", strerror(errno)); + } + } + if (commit >=2) { ++num; if ( fsync(dataFd) < 0 ) { @@ -117,7 +120,7 @@ int main(int argc, char *argv[]) { tPrint("RPC server is running, ctrl-c to exit"); if (commit) { - dataFd = open(dataName, O_APPEND | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO); + dataFd = open(dataName, O_APPEND | O_CREAT | O_WRONLY, S_IRWXU | S_IRWXG | S_IRWXO); if (dataFd<0) tPrint("failed to open data file, reason:%s", strerror(errno)); } -- GitLab