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

Method TryAcquirePort

library/cpp/testing/common/network.cpp:197–213  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

195
196 private:
197 THolder<NTesting::IPort> TryAcquirePort(ui16 port) const {
198 auto lock = MakeHolder<TFileLock>(TString(SyncDir_ / ::ToString(port)));
199 if (!lock->TryAcquire()) {
200 return nullptr;
201 }
202
203 TInet6StreamSocket sock;
204 Y_VERIFY_SYSERROR(INVALID_SOCKET != static_cast<SOCKET>(sock));
205
206 TSockAddrInet6 addr("::", port);
207 if (sock.Bind(&addr) != 0) {
208 lock->Release();
209 Y_ABORT_UNLESS(EADDRINUSE == LastSystemError(), "unexpected error: %d, port: %d", LastSystemError(), port);
210 return nullptr;
211 }
212 return MakeHolder<TPortGuard>(port, std::move(lock));
213 }
214
215 private:
216 TFsPath SyncDir_;

Callers

nothing calls this directly

Calls 6

LastSystemErrorFunction · 0.85
ToStringFunction · 0.50
moveFunction · 0.50
TryAcquireMethod · 0.45
BindMethod · 0.45
ReleaseMethod · 0.45

Tested by

no test coverage detected