[ 
https://issues.apache.org/jira/browse/GEODE-9327?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17494303#comment-17494303
 ] 

ASF GitHub Bot commented on GEODE-9327:
---------------------------------------

gaussianrecurrence commented on a change in pull request #815:
URL: https://github.com/apache/geode-native/pull/815#discussion_r809574260



##########
File path: cppcache/src/Utils.cpp
##########
@@ -81,43 +83,36 @@ void Utils::parseEndpointString(const char* endpoints, 
std::string& host,
   port = atoi(endpointsStr.c_str());
 }
 
-std::string Utils::convertHostToCanonicalForm(const char* endpoints) {
-  if (endpoints == nullptr) return nullptr;
-  std::string hostString("");
-  uint16_t port = 0;
-  std::string endpointsStr(endpoints);
-  std::string endpointsStr1(endpoints);
-  // Parse this string to get all hostnames and port numbers.
-  std::string endpoint;
-  std::string::size_type length = endpointsStr.size();
-  std::string::size_type pos = 0;
-  ACE_TCHAR hostName[256];
-  pos = endpointsStr.find(':', 0);
-  if (pos != std::string::npos) {
-    endpoint = endpointsStr.substr(0, pos);
-    pos += 1;  // skip ':'
-    length -= (pos);
-    endpointsStr = endpointsStr.substr(pos, length);
-  } else {
-    hostString = "";
-    return "";
+std::string Utils::convertHostToCanonicalForm(const std::string& endpoints) {
+  using boost::asio::io_service;
+  using boost::asio::ip::tcp;
+
+  if (endpoints.empty()) {
+    return {};
   }
-  hostString = endpoint;
-  port = std::stoi(endpointsStr);
-  if (hostString == "localhost") {
-    auto hostname = boost::asio::ip::host_name();
-    if (auto host = ::gethostbyname(hostname.c_str())) {
-      return std::string{host->h_name} + ':' + std::to_string(port);
-    }
-  } else {
-    pos = endpointsStr1.find('.', 0);
-    if (pos != std::string::npos) {
-      ACE_INET_Addr addr(endpoints);
-      addr.get_host_name(hostName, 256);
-      return std::string(hostName) + ":" + std::to_string(port);
-    }
+
+  auto pos = endpoints.rfind(':');
+  if (pos == std::string::npos) {
+    return {};
   }
-  return endpoints;
+
+  auto hostname = endpoints.substr(0, pos);
+  auto port = endpoints.substr(pos);
+
+  if (hostname == "localhost") {
+    hostname = boost::asio::ip::host_name();
+  }
+
+  io_service svc;
+  boost::system::error_code ec;
+  tcp::resolver resolver{svc};
+  auto results = resolver.resolve(hostname, ec);
+
+  if (!ec) {
+    hostname = results->host_name();
+  }
+
+  return hostname + port;

Review comment:
       When re-checking this code I made myself this question. Thing is port is 
already containing the semicolon as of the way the endpoint is split. However, 
I'll change it so port does not contain the semicolon in order to make the code 
more readable.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@geode.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Remove all remaining references to ACE networking
> -------------------------------------------------
>
>                 Key: GEODE-9327
>                 URL: https://issues.apache.org/jira/browse/GEODE-9327
>             Project: Geode
>          Issue Type: Improvement
>          Components: native client
>            Reporter: Mario Salazar de Torres
>            Assignee: Mario Salazar de Torres
>            Priority: Major
>              Labels: obliterate-ace, pull-request-available
>
> *AS A* native client contributor
> *I WANT TO* remove all remaining references to ACE networking
> *SO THAT* eventually we can get rid of ACE library
>  



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to