From 445596011e020dfc637f94fdf5c88f62e306e401 Mon Sep 17 00:00:00 2001 From: afwerar <1296468573@qq.com> Date: Tue, 11 Oct 2022 14:12:11 +0800 Subject: [PATCH] fix: win compile error --- include/os/os.h | 3 +++ source/os/src/osSocket.c | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/os/os.h b/include/os/os.h index 71966061a1..d646ffe4fd 100644 --- a/include/os/os.h +++ b/include/os/os.h @@ -51,6 +51,9 @@ extern "C" { #endif #else +#ifndef __func__ +#define __func__ __FUNCTION__ +#endif #include #include #ifndef TD_USE_WINSOCK diff --git a/source/os/src/osSocket.c b/source/os/src/osSocket.c index c1e02b48aa..bfeef248cd 100644 --- a/source/os/src/osSocket.c +++ b/source/os/src/osSocket.c @@ -267,21 +267,29 @@ int32_t taosSetSockOpt(TdSocketPtr pSocket, int32_t level, int32_t optname, void return -1; } #ifdef WINDOWS +#ifdef TCP_KEEPCNT if (level == SOL_SOCKET && optname == TCP_KEEPCNT) { return 0; } +#endif +#ifdef TCP_KEEPIDLE if (level == SOL_TCP && optname == TCP_KEEPIDLE) { return 0; } +#endif +#ifdef TCP_KEEPINTVL if (level == SOL_TCP && optname == TCP_KEEPINTVL) { return 0; } +#endif +#ifdef TCP_KEEPCNT if (level == SOL_TCP && optname == TCP_KEEPCNT) { return 0; } +#endif return setsockopt(pSocket->fd, level, optname, optval, optlen); #else @@ -601,26 +609,32 @@ int32_t taosKeepTcpAlive(TdSocketPtr pSocket) { #ifndef __APPLE__ // all fails on macosx +#ifdef TCP_KEEPCNT int32_t probes = 3; if (taosSetSockOpt(pSocket, SOL_TCP, TCP_KEEPCNT, (void *)&probes, sizeof(probes)) < 0) { // printf("fd:%d setsockopt SO_KEEPCNT failed: %d (%s)", sockFd, errno, strerror(errno)); taosCloseSocket(&pSocket); return -1; } +#endif +#ifdef TCP_KEEPIDLE int32_t alivetime = 10; if (taosSetSockOpt(pSocket, SOL_TCP, TCP_KEEPIDLE, (void *)&alivetime, sizeof(alivetime)) < 0) { // printf("fd:%d setsockopt SO_KEEPIDLE failed: %d (%s)", sockFd, errno, strerror(errno)); taosCloseSocket(&pSocket); return -1; } +#endif +#ifdef TCP_KEEPINTVL int32_t interval = 3; if (taosSetSockOpt(pSocket, SOL_TCP, TCP_KEEPINTVL, (void *)&interval, sizeof(interval)) < 0) { // printf("fd:%d setsockopt SO_KEEPINTVL failed: %d (%s)", sockFd, errno, strerror(errno)); taosCloseSocket(&pSocket); return -1; } +#endif #endif // __APPLE__ int32_t nodelay = 1;