acelyc111 commented on code in PR #1811:
URL: 
https://github.com/apache/incubator-pegasus/pull/1811#discussion_r1436280678


##########
src/runtime/rpc/rpc_host_port.cpp:
##########
@@ -86,6 +87,34 @@ host_port::host_port(rpc_address addr)
     _type = addr.type();
 }
 
+bool host_port::from_string(const std::string s)
+{
+    auto pos = s.find_last_of(':');
+    if (pos == std::string::npos) {
+        return false;
+    }
+    _host = s.substr(0, pos);
+    std::string port = s.substr(pos + 1);
+
+    if (!internal::buf2unsigned(port, _port) || _port > UINT16_MAX) {
+        return false;
+    }
+
+    struct addrinfo hints;
+    memset(&hints, 0, sizeof(hints));
+    hints.ai_family = AF_INET;
+    hints.ai_socktype = SOCK_STREAM;
+    AddrInfo result;
+    auto err_code = GetAddrInfo(_host, hints, &result);
+

Review Comment:
   ```suggestion
   ```



##########
src/utils/test/json_helper_test.cpp:
##########
@@ -505,4 +506,14 @@ TEST(json_helper, upgrade_downgrade)
     ASSERT_EQ(n2.c, o.c);
 }
 
+TEST(json_helper, host_port_encode_decode)
+{
+    dsn::host_port hp("localhost", 8888);
+    dsn::blob bb = dsn::json::json_forwarder<decltype(hp)>::encode(hp);
+    dsn::host_port hp2;
+    dsn::json::json_forwarder<decltype(hp)>::decode(bb, hp2);

Review Comment:
   ```suggestion
       dsn::json::json_forwarder<dsn::host_port>::decode(bb, hp2);
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to