tune the TCP socket code

This commit is contained in:
Jeff Tao 2020-05-23 06:02:01 +00:00
parent f398488aac
commit 5f635bd3f7
3 changed files with 12 additions and 13 deletions

View File

@ -468,7 +468,7 @@ static void taosFreeFdObj(SFdObj *pFdObj) {
pFdObj->signature = NULL;
epoll_ctl(pThreadObj->pollFd, EPOLL_CTL_DEL, pFdObj->fd, NULL);
taosCloseTcpSocket(pFdObj->fd);
taosCloseSocket(pFdObj->fd);
pThreadObj->numOfFds--;

View File

@ -31,7 +31,6 @@ int taosOpenUdpSocket(uint32_t localIp, uint16_t localPort);
int taosOpenTcpClientSocket(uint32_t ip, uint16_t port, uint32_t localIp);
int taosOpenTcpServerSocket(uint32_t ip, uint16_t port);
int taosKeepTcpAlive(int sockFd);
void taosCloseTcpSocket(int sockFd);
int taosGetFqdn(char *);
uint32_t taosGetIpFromFqdn(const char *);

View File

@ -305,20 +305,11 @@ int taosOpenTcpClientSocket(uint32_t destIp, uint16_t destPort, uint32_t clientI
sockFd = -1;
}
taosKeepTcpAlive(sockFd);
return sockFd;
}
void taosCloseTcpSocket(int sockFd) {
struct linger linger;
linger.l_onoff = 1;
linger.l_linger = 0;
if (taosSetSockOpt(sockFd, SOL_SOCKET, SO_LINGER, (void *)&linger, sizeof(linger)) < 0) {
uError("setsockopt SO_LINGER failed: %d (%s)", errno, strerror(errno));
}
taosCloseSocket(sockFd);
}
int taosKeepTcpAlive(int sockFd) {
int alive = 1;
if (taosSetSockOpt(sockFd, SOL_SOCKET, SO_KEEPALIVE, (void *)&alive, sizeof(alive)) < 0) {
@ -355,6 +346,15 @@ int taosKeepTcpAlive(int sockFd) {
return -1;
}
struct linger linger = {0};
linger.l_onoff = 1;
//linger.l_linger = 0;
if (taosSetSockOpt(sockFd, SOL_SOCKET, SO_LINGER, (void *)&linger, sizeof(linger)) < 0) {
uError("setsockopt SO_LINGER failed: %d (%s)", errno, strerror(errno));
close(sockFd);
return -1;
}
return 0;
}