From de8c9fc46fe0d13a1d060822b9cc8cdf991bdbb2 Mon Sep 17 00:00:00 2001 From: Jeff Tao Date: Sat, 20 Jun 2020 08:47:41 +0000 Subject: [PATCH] close UDP thread --- src/rpc/src/rpcTcp.c | 2 +- src/rpc/src/rpcUdp.c | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/rpc/src/rpcTcp.c b/src/rpc/src/rpcTcp.c index 674d560952..5d156492c7 100644 --- a/src/rpc/src/rpcTcp.c +++ b/src/rpc/src/rpcTcp.c @@ -437,7 +437,7 @@ static void *taosProcessTcpData(void *param) { while (1) { int fdNum = epoll_wait(pThreadObj->pollFd, events, maxEvents, -1); if (pThreadObj->stop) { - tTrace("%s, tcp thread get stop event, exiting...", pThreadObj->label); + tTrace("%s TCP thread get stop event, exiting...", pThreadObj->label); break; } if (fdNum < 0) continue; diff --git a/src/rpc/src/rpcUdp.c b/src/rpc/src/rpcUdp.c index 279cf7ed49..41446f87fb 100644 --- a/src/rpc/src/rpcUdp.c +++ b/src/rpc/src/rpcUdp.c @@ -142,16 +142,15 @@ void taosCleanUpUdpConnection(void *handle) { pConn = pSet->udpConn + i; pConn->signature = NULL; - // shutdown to signal the thread to exit - if ( pConn->fd >=0) shutdown(pConn->fd, SHUT_RD); + if (pConn->fd >=0) shutdown(pConn->fd, SHUT_RDWR); + if (pConn->fd >=0) taosCloseSocket(pConn->fd); } for (int i = 0; i < pSet->threads; ++i) { pConn = pSet->udpConn + i; if (pConn->thread) pthread_join(pConn->thread, NULL); - if (pConn->fd >=0) taosCloseSocket(pConn->fd); tfree(pConn->buffer); - tTrace("UDP chandle:%p is closed", pConn); + tTrace("%s UDP thread is closed, inedx:%d", pConn->label, i); } tfree(pSet); @@ -185,15 +184,15 @@ static void *taosRecvUdpData(void *param) { while (1) { dataLen = recvfrom(pConn->fd, pConn->buffer, RPC_MAX_UDP_SIZE, 0, (struct sockaddr *)&sourceAdd, &addLen); - if(dataLen == 0) { - tTrace("data length is 0, socket was closed, exiting"); + if(dataLen <= 0) { + tTrace("%s UDP socket was closed, exiting", pConn->label); break; } port = ntohs(sourceAdd.sin_port); if (dataLen < sizeof(SRpcHead)) { - tError("%s recvfrom failed, reason:%s\n", pConn->label, strerror(errno)); + tError("%s recvfrom failed(%s)", pConn->label, strerror(errno)); continue; }