MCPcopy Create free account
hub / github.com/Tencent/hpc-ops / parse_tcp

Function parse_tcp

src/communicator/protocol.cc:23–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21}
22
23bool parse_tcp(const std::string &url, std::string *ip, int *port) {
24 const std::string kTcpPrefix = "tcp://";
25
26 if (url.compare(0, kTcpPrefix.length(), kTcpPrefix) != 0) {
27 return false;
28 }
29
30 const std::string ip_and_port = url.substr(kTcpPrefix.length());
31
32 auto colon_pos = ip_and_port.find(":");
33 if (colon_pos == std::string::npos) {
34 return false;
35 }
36
37 const std::string sip = ip_and_port.substr(0, colon_pos);
38 const std::string sport = ip_and_port.substr(colon_pos + 1);
39
40 int lport = -1;
41 try {
42 lport = std::stoi(sport);
43 } catch (const std::exception &e) {
44 return false;
45 }
46
47 if (lport < 1 || lport > 65535) {
48 return false;
49 }
50
51 *ip = sip;
52 *port = lport;
53
54 return true;
55}
56
57bool parse_unix(const std::string &url, std::string *file) {
58 const std::string kUnixPrefix = "unix://";

Callers 2

ConnectMethod · 0.85
ListenMethod · 0.85

Calls 1

findMethod · 0.80

Tested by

no test coverage detected