mirror of
https://gitee.com/TarsCloud/TarsCpp.git
synced 2024-12-22 22:16:38 +08:00
fix dns bug, if dns not be resolved then resolved when connect every time
This commit is contained in:
parent
57da604c10
commit
e21ab4fcf2
2
servant/libservant/CommunicatorEpoll.cpp
Normal file → Executable file
2
servant/libservant/CommunicatorEpoll.cpp
Normal file → Executable file
@ -446,7 +446,7 @@ void CommunicatorEpoll::pushAsyncThreadQueue(ReqMessage * msg)
|
||||
|
||||
void CommunicatorEpoll::run()
|
||||
{
|
||||
TLOGDEBUG("CommunicatorEpoll::run id:"<<syscall(SYS_gettid)<<endl);
|
||||
// TLOGDEBUG("CommunicatorEpoll::run id:"<<syscall(SYS_gettid)<<endl);
|
||||
|
||||
ServantProxyThreadData * pSptd = ServantProxyThreadData::getData();
|
||||
assert(pSptd != NULL);
|
||||
|
55
servant/libservant/EndpointInfo.cpp
Normal file → Executable file
55
servant/libservant/EndpointInfo.cpp
Normal file → Executable file
@ -30,6 +30,7 @@ EndpointInfo::EndpointInfo()
|
||||
, _weighttype(0)
|
||||
, _authType(0)
|
||||
, _isIPv6(false)
|
||||
, _addressSucc(false)
|
||||
{
|
||||
_setDivision.clear();
|
||||
memset(&_addr,0,sizeof(_addr));
|
||||
@ -45,24 +46,37 @@ EndpointInfo::EndpointInfo(const string& host, uint16_t port, EndpointInfo::ETyp
|
||||
, _weight(weight)
|
||||
, _weighttype(weighttype)
|
||||
, _authType(authType)
|
||||
, _addressSucc(false)
|
||||
{
|
||||
_isIPv6 = TC_Socket::addressIsIPv6(host);
|
||||
if(_weighttype == 0)
|
||||
{
|
||||
_weight = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(_weight == -1)
|
||||
{
|
||||
_weight = 100;
|
||||
}
|
||||
|
||||
_weight = (_weight > 100 ? 100 : _weight);
|
||||
}
|
||||
|
||||
_cmpDesc = createCompareDesc();
|
||||
|
||||
_desc = createDesc();
|
||||
|
||||
parseAddress();
|
||||
}
|
||||
|
||||
void EndpointInfo::parseAddress()
|
||||
{
|
||||
if(_addressSucc)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
if(_weighttype == 0)
|
||||
{
|
||||
_weight = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(_weight == -1)
|
||||
{
|
||||
_weight = 100;
|
||||
}
|
||||
|
||||
_weight = (_weight > 100 ? 100 : _weight);
|
||||
}
|
||||
|
||||
if (_isIPv6)
|
||||
{
|
||||
NetworkUtil::getAddress(_host, _port, _addr.in6);
|
||||
@ -72,13 +86,11 @@ EndpointInfo::EndpointInfo(const string& host, uint16_t port, EndpointInfo::ETyp
|
||||
NetworkUtil::getAddress(_host, _port, _addr.in);
|
||||
}
|
||||
|
||||
_cmpDesc = createCompareDesc();
|
||||
|
||||
_desc = createDesc();
|
||||
_addressSucc = true;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
TLOGERROR("[ERROR:getAddress fail:" << _host << ":" << _port << "]" << endl);
|
||||
TLOGERROR("EndpointInfo::parseAddress fail:" << _host << ":" << _port << "]" << endl);
|
||||
}
|
||||
}
|
||||
|
||||
@ -148,13 +160,16 @@ uint16_t EndpointInfo::port() const
|
||||
return _port;
|
||||
}
|
||||
|
||||
const struct sockaddr_in& EndpointInfo::addr() const
|
||||
const struct sockaddr_in& EndpointInfo::addr()
|
||||
{
|
||||
parseAddress();
|
||||
return _addr.in;
|
||||
}
|
||||
|
||||
const struct sockaddr * EndpointInfo::addrPtr() const
|
||||
const struct sockaddr * EndpointInfo::addrPtr()
|
||||
{
|
||||
parseAddress();
|
||||
|
||||
return _isIPv6 ? (struct sockaddr *)&_addr.in6 : (struct sockaddr *)&_addr.in;
|
||||
}
|
||||
|
||||
|
13
servant/servant/EndpointInfo.h
Normal file → Executable file
13
servant/servant/EndpointInfo.h
Normal file → Executable file
@ -120,14 +120,14 @@ public:
|
||||
*
|
||||
* @return const struct sockaddr_in&
|
||||
*/
|
||||
const struct sockaddr_in& addr() const;
|
||||
const struct sockaddr_in& addr() ;
|
||||
|
||||
/**
|
||||
* Get ipv4 or ipv6 struct sockaddr
|
||||
*
|
||||
* @return const struct sockaddr *
|
||||
*/
|
||||
const struct sockaddr * addrPtr() const;
|
||||
const struct sockaddr * addrPtr();
|
||||
|
||||
/**
|
||||
* 返回端口类型
|
||||
@ -201,6 +201,10 @@ protected:
|
||||
*/
|
||||
string createCompareDesc();
|
||||
|
||||
/**
|
||||
* 解析域名
|
||||
*/
|
||||
void parseAddress();
|
||||
private:
|
||||
/**
|
||||
* 地址IP
|
||||
@ -271,6 +275,11 @@ private:
|
||||
* _host is IPv6 or not
|
||||
*/
|
||||
bool _isIPv6;
|
||||
|
||||
/**
|
||||
* 解析域名成功
|
||||
*/
|
||||
bool _addressSucc;
|
||||
};
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user