MCPcopy Create free account
hub / github.com/catboost/catboost / ParseInetName

Function ParseInetName

library/cpp/netliba/v6/udp_address.cpp:86–174  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

84 }
85
86 static bool ParseInetName(TUdpAddress* pRes, const char* name, int nDefaultPort, EUdpAddressType addressType) {
87 int nPort = nDefaultPort;
88
89 TString host;
90 if (name[0] == '[') {
91 ++name;
92 const char* nameFin = name;
93 for (; *nameFin; ++nameFin) {
94 if (nameFin[0] == ']')
95 break;
96 }
97 host.assign(name, nameFin);
98 Y_ASSERT(IsValidIPv6(host.c_str()));
99 name = *nameFin ? nameFin + 1 : nameFin;
100 if (name[0] == ':') {
101 char* endPtr = nullptr;
102 nPort = strtol(name + 1, &endPtr, 10);
103 if (!endPtr || *endPtr != '\0')
104 return false;
105 }
106 } else {
107 host = name;
108 if (!IsValidIPv6(name)) {
109 size_t nIdx = host.find(':');
110 if (nIdx != (size_t)TString::npos) {
111 const char* pszPort = host.c_str() + nIdx + 1;
112 char* endPtr = nullptr;
113 nPort = strtol(pszPort, &endPtr, 10);
114 if (!endPtr || *endPtr != '\0')
115 return false;
116 host.resize(nIdx);
117 }
118 }
119 }
120
121 addrinfo aiHints;
122 Zero(aiHints);
123 aiHints.ai_family = AF_UNSPEC;
124 aiHints.ai_socktype = SOCK_DGRAM;
125 aiHints.ai_protocol = IPPROTO_UDP;
126
127 // Do not use TMutex here: it has a non-trivial destructor which will be called before
128 // destruction of current thread, if its TThread declared as global/static variable.
129 static TAdaptiveLock cs;
130 TGuard lock(cs);
131
132 addrinfo* aiList = nullptr;
133 for (int attempt = 0; attempt < 1000; ++attempt) {
134 int rv = getaddrinfo(host.c_str(), "1313", &aiHints, &aiList);
135 if (rv == 0)
136 break;
137 if (aiList) {
138 freeaddrinfo(aiList);
139 }
140 if (rv != EAI_AGAIN) {
141 return false;
142 }
143 usleep(100 * 1000);

Callers 1

CreateAddressFunction · 0.70

Calls 8

ZeroFunction · 0.85
usleepFunction · 0.85
IsValidIPv6Function · 0.70
GetUdpAddressFunction · 0.70
assignMethod · 0.45
c_strMethod · 0.45
findMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected