From 4402e599bdd807ef4da6d354edea9a975b10c194 Mon Sep 17 00:00:00 2001 From: jtao1735 Date: Mon, 4 May 2020 01:38:12 +0000 Subject: [PATCH] minor changes on UDP --- src/rpc/src/rpcMain.c | 2 +- src/rpc/src/rpcUdp.c | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/rpc/src/rpcMain.c b/src/rpc/src/rpcMain.c index 2e8c4bbc30..36d74189f5 100644 --- a/src/rpc/src/rpcMain.c +++ b/src/rpc/src/rpcMain.c @@ -793,7 +793,7 @@ static SRpcConn *rpcProcessMsgHead(SRpcInfo *pRpc, SRecvInfo *pRecv) { sid = pConn->sid; pConn->chandle = pRecv->chandle; - if (pRecv->port) pConn->peerPort = pRecv->port; + if (pConn->peerPort == 0) pConn->peerPort = pRecv->port; if (pHead->port) pConn->peerPort = htons(pHead->port); terrno = rpcCheckAuthentication(pConn, (char *)pHead, pRecv->msgLen); diff --git a/src/rpc/src/rpcUdp.c b/src/rpc/src/rpcUdp.c index 4a5fc7ba27..8d5721a437 100644 --- a/src/rpc/src/rpcUdp.c +++ b/src/rpc/src/rpcUdp.c @@ -127,7 +127,7 @@ void *taosInitUdpConnection(uint32_t ip, uint16_t port, char *label, int threads unsigned int addrlen = sizeof(sin); if (getsockname(pConn->fd, (struct sockaddr *)&sin, &addrlen) == 0 && sin.sin_family == AF_INET && addrlen == sizeof(sin)) { - pConn->localPort = (int16_t)ntohs(sin.sin_port); + pConn->localPort = (uint16_t)ntohs(sin.sin_port); } strcpy(pConn->label, label); @@ -198,8 +198,7 @@ void *taosOpenUdpConnection(void *shandle, void *thandle, uint32_t ip, uint16_t SUdpConn *pConn = pSet->udpConn + pSet->index; pConn->port = port; - tTrace("%s UDP connection is setup, ip:%x:%hu, local:%x:%d", pConn->label, ip, port, pSet->ip, - ntohs((uint16_t)pConn->localPort)); + tTrace("%s UDP connection is setup, ip:%x:%hu, local:%x:%d", pConn->label, ip, port, pSet->ip, pConn->localPort); return pConn; } @@ -219,16 +218,14 @@ static void *taosRecvUdpData(void *param) { while (1) { dataLen = recvfrom(pConn->fd, pConn->buffer, RPC_MAX_UDP_SIZE, 0, (struct sockaddr *)&sourceAdd, &addLen); - tTrace("%s msg is recv from 0x%x:%hu len:%d", pConn->label, sourceAdd.sin_addr.s_addr, ntohs(sourceAdd.sin_port), - dataLen); + port = ntohs(sourceAdd.sin_port); + tTrace("%s msg is recv from 0x%x:%hu len:%d", pConn->label, sourceAdd.sin_addr.s_addr, port, dataLen); if (dataLen < sizeof(SRpcHead)) { tError("%s recvfrom failed, reason:%s\n", pConn->label, strerror(errno)); continue; } - port = ntohs(sourceAdd.sin_port); - int processedLen = 0, leftLen = 0; int msgLen = 0; int count = 0; -- GitLab