MCPcopy Create free account
hub / github.com/ml-explore/mlx / parse_address

Function parse_address

mlx/distributed/utils.cpp:16–35  ·  view source on GitHub ↗

* Parse a sockaddr from an ip and port provided as strings. */

Source from the content-addressed store, hash-verified

14 * Parse a sockaddr from an ip and port provided as strings.
15 */
16address_t parse_address(const std::string& ip, const std::string& port) {
17 struct addrinfo hints, *res;
18 std::memset(&hints, 0, sizeof(hints));
19 hints.ai_family = AF_UNSPEC;
20 hints.ai_socktype = SOCK_STREAM;
21
22 int status = getaddrinfo(ip.c_str(), port.c_str(), &hints, &res);
23 if (status != 0) {
24 std::ostringstream msg;
25 msg << "Can't parse address " << ip << ":" << port;
26 throw std::runtime_error(msg.str());
27 }
28
29 address_t result;
30 memcpy(&result.addr, res->ai_addr, res->ai_addrlen);
31 result.len = res->ai_addrlen;
32 freeaddrinfo(res);
33
34 return result;
35}
36
37/**
38 * Parse a sockaddr provided as an <ip>:<port> string.

Callers

nothing calls this directly

Calls 3

findMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected