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

Method GetFreePort

library/cpp/testing/common/network.cpp:133–153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

131 }
132
133 NTesting::TPortHolder GetFreePort() const {
134 ui16 salt = RandomNumber<ui16>();
135 for (ui16 attempt = 0; attempt < TotalCount_; ++attempt) {
136 ui16 probe = (salt + attempt) % TotalCount_;
137 for (auto [left, right] : Ranges_) {
138 if (probe >= right - left)
139 probe -= right - left;
140 else {
141 probe += left;
142 break;
143 }
144 }
145
146 auto port = TryAcquirePort(probe);
147 if (port) {
148 return NTesting::TPortHolder{std::move(port)};
149 }
150 }
151
152 Y_ABORT("Cannot get free port!");
153 }
154
155 TVector<NTesting::TPortHolder> GetFreePortsRange(size_t count) const {
156 Y_ABORT_UNLESS(count > 0);

Callers 1

GetFreePortFunction · 0.80

Calls 1

moveFunction · 0.50

Tested by

no test coverage detected