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

Method GetFreePortsRange

library/cpp/testing/common/network.cpp:155–183  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

153 }
154
155 TVector<NTesting::TPortHolder> GetFreePortsRange(size_t count) const {
156 Y_ABORT_UNLESS(count > 0);
157 TVector<NTesting::TPortHolder> ports(Reserve(count));
158 for (size_t i = 0; i < Retries; ++i) {
159 for (auto[left, right] : Ranges_) {
160 if (right - left < count) {
161 continue;
162 }
163 ui16 start = left + RandomNumber<ui16>((right - left) / 2);
164 if (right - start < count) {
165 continue;
166 }
167 for (ui16 probe = start; probe < right; ++probe) {
168 auto port = TryAcquirePort(probe);
169 if (port) {
170 ports.emplace_back(std::move(port));
171 } else {
172 ports.clear();
173 }
174 if (ports.size() == count) {
175 return ports;
176 }
177 }
178 // Can't find required number of ports without gap in the current range
179 ports.clear();
180 }
181 }
182 Y_ABORT("Cannot get range of %zu ports!", count);
183 }
184
185 NTesting::TPortHolder GetPort(ui16 port) const {
186 if (port && DisableRandomPorts_) {

Callers 1

GetFreePortsRangeFunction · 0.80

Calls 5

ReserveFunction · 0.85
moveFunction · 0.50
emplace_backMethod · 0.45
clearMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected