Merge pull request #2011 from taosdata/hotfix/closeTcpSocket
tune the TCP socket code
This commit is contained in:
commit
0c21072851
|
@ -468,7 +468,7 @@ static void taosFreeFdObj(SFdObj *pFdObj) {
|
||||||
|
|
||||||
pFdObj->signature = NULL;
|
pFdObj->signature = NULL;
|
||||||
epoll_ctl(pThreadObj->pollFd, EPOLL_CTL_DEL, pFdObj->fd, NULL);
|
epoll_ctl(pThreadObj->pollFd, EPOLL_CTL_DEL, pFdObj->fd, NULL);
|
||||||
taosCloseTcpSocket(pFdObj->fd);
|
taosCloseSocket(pFdObj->fd);
|
||||||
|
|
||||||
pThreadObj->numOfFds--;
|
pThreadObj->numOfFds--;
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,6 @@ int taosOpenUdpSocket(uint32_t localIp, uint16_t localPort);
|
||||||
int taosOpenTcpClientSocket(uint32_t ip, uint16_t port, uint32_t localIp);
|
int taosOpenTcpClientSocket(uint32_t ip, uint16_t port, uint32_t localIp);
|
||||||
int taosOpenTcpServerSocket(uint32_t ip, uint16_t port);
|
int taosOpenTcpServerSocket(uint32_t ip, uint16_t port);
|
||||||
int taosKeepTcpAlive(int sockFd);
|
int taosKeepTcpAlive(int sockFd);
|
||||||
void taosCloseTcpSocket(int sockFd);
|
|
||||||
|
|
||||||
int taosGetFqdn(char *);
|
int taosGetFqdn(char *);
|
||||||
uint32_t taosGetIpFromFqdn(const char *);
|
uint32_t taosGetIpFromFqdn(const char *);
|
||||||
|
|
|
@ -305,20 +305,11 @@ int taosOpenTcpClientSocket(uint32_t destIp, uint16_t destPort, uint32_t clientI
|
||||||
sockFd = -1;
|
sockFd = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
taosKeepTcpAlive(sockFd);
|
||||||
|
|
||||||
return 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 taosKeepTcpAlive(int sockFd) {
|
||||||
int alive = 1;
|
int alive = 1;
|
||||||
if (taosSetSockOpt(sockFd, SOL_SOCKET, SO_KEEPALIVE, (void *)&alive, sizeof(alive)) < 0) {
|
if (taosSetSockOpt(sockFd, SOL_SOCKET, SO_KEEPALIVE, (void *)&alive, sizeof(alive)) < 0) {
|
||||||
|
@ -355,6 +346,15 @@ int taosKeepTcpAlive(int sockFd) {
|
||||||
return -1;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue