diff --git a/servant/libservant/CommunicatorEpoll.cpp b/servant/libservant/CommunicatorEpoll.cpp old mode 100644 new mode 100755 index b8b6bed..6a694cd --- a/servant/libservant/CommunicatorEpoll.cpp +++ b/servant/libservant/CommunicatorEpoll.cpp @@ -446,7 +446,7 @@ void CommunicatorEpoll::pushAsyncThreadQueue(ReqMessage * msg) void CommunicatorEpoll::run() { - TLOGDEBUG("CommunicatorEpoll::run id:"< 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; } diff --git a/servant/servant/EndpointInfo.h b/servant/servant/EndpointInfo.h old mode 100644 new mode 100755 index f0fc869..28e3246 --- a/servant/servant/EndpointInfo.h +++ b/servant/servant/EndpointInfo.h @@ -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; }; ///////////////////////////////////////////////////////////////////////////// }