diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/testing/common/network.h | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/testing/common/network.h')
-rw-r--r-- | library/cpp/testing/common/network.h | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/library/cpp/testing/common/network.h b/library/cpp/testing/common/network.h new file mode 100644 index 0000000000..eb4d32f3a1 --- /dev/null +++ b/library/cpp/testing/common/network.h @@ -0,0 +1,52 @@ +#pragma once + +#include <util/generic/ptr.h> +#include <util/generic/vector.h> + +namespace NTesting { + + //@brief network port holder interface + class IPort { + public: + virtual ~IPort() {} + + virtual ui16 Get() = 0; + }; + + class TPortHolder : private THolder<IPort> { + using TBase = THolder<IPort>; + public: + using TBase::TBase; + using TBase::Release; + using TBase::Reset; + + operator ui16() const& { + return (*this)->Get(); + } + + operator ui16() const&& = delete; + }; + + IOutputStream& operator<<(IOutputStream& out, const TPortHolder& port); + + //@brief Get first free port. + [[nodiscard]] TPortHolder GetFreePort(); + + namespace NLegacy { + // Do not use this method, it needs only for TPortManager from unittests. + // Returns continuous sequence of the specified number of ports. + [[nodiscard]] TVector<TPortHolder> GetFreePortsRange(size_t count); + } + + //@brief helper class for inheritance + struct TFreePortOwner { + TFreePortOwner() : Port_(GetFreePort()) {} + + ui16 GetPort() const { + return Port_; + } + + private: + TPortHolder Port_; + }; +} |