diff options
author | bulatman <bulatman@yandex-team.ru> | 2022-02-10 16:45:50 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:50 +0300 |
commit | 2f6ca198245aeffd5e2d82b65927c2465b68b4f5 (patch) | |
tree | 9142afc54d335ea52910662635b898e79e192e49 /library/cpp/coroutine/engine/helper.cpp | |
parent | 6560e4993b14d193f8c879e33a3de5e5eba6e21d (diff) | |
download | ydb-2f6ca198245aeffd5e2d82b65927c2465b68b4f5.tar.gz |
Restoring authorship annotation for <bulatman@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/coroutine/engine/helper.cpp')
-rw-r--r-- | library/cpp/coroutine/engine/helper.cpp | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/library/cpp/coroutine/engine/helper.cpp b/library/cpp/coroutine/engine/helper.cpp index c3e36bffb6..bffe208dc8 100644 --- a/library/cpp/coroutine/engine/helper.cpp +++ b/library/cpp/coroutine/engine/helper.cpp @@ -1,37 +1,37 @@ -#include "helper.h" - -#include "impl.h" -#include "network.h" - -namespace NCoro { - - bool TryConnect(const TString& host, ui16 port, TDuration timeout) { - bool connected = false; - - auto f = [&connected, &host, port, timeout](TCont* c) { - TSocketHolder socket; - TNetworkAddress address(host, port); - connected = (0 == NCoro::ConnectT(c, socket, address, timeout)); - }; - - TContExecutor e(128 * 1024); - e.Create(f, "try_connect"); - e.Execute(); - return connected; - } - - bool WaitUntilConnectable(const TString& host, ui16 port, TDuration timeout) { - const TInstant deadline = timeout.ToDeadLine(); - - for (size_t i = 1; Now() < deadline; ++i) { - const TDuration waitTime = TDuration::MilliSeconds(100) * i * i; - SleepUntil(Min(Now() + waitTime, deadline)); - - if (TryConnect(host, port, waitTime)) { - return true; - } - } - - return false; - } -} +#include "helper.h" + +#include "impl.h" +#include "network.h" + +namespace NCoro { + + bool TryConnect(const TString& host, ui16 port, TDuration timeout) { + bool connected = false; + + auto f = [&connected, &host, port, timeout](TCont* c) { + TSocketHolder socket; + TNetworkAddress address(host, port); + connected = (0 == NCoro::ConnectT(c, socket, address, timeout)); + }; + + TContExecutor e(128 * 1024); + e.Create(f, "try_connect"); + e.Execute(); + return connected; + } + + bool WaitUntilConnectable(const TString& host, ui16 port, TDuration timeout) { + const TInstant deadline = timeout.ToDeadLine(); + + for (size_t i = 1; Now() < deadline; ++i) { + const TDuration waitTime = TDuration::MilliSeconds(100) * i * i; + SleepUntil(Min(Now() + waitTime, deadline)); + + if (TryConnect(host, port, waitTime)) { + return true; + } + } + + return false; + } +} |