diff options
author | monster <monster@ydb.tech> | 2022-07-07 14:41:37 +0300 |
---|---|---|
committer | monster <monster@ydb.tech> | 2022-07-07 14:41:37 +0300 |
commit | 06e5c21a835c0e923506c4ff27929f34e00761c2 (patch) | |
tree | 75efcbc6854ef9bd476eb8bf00cc5c900da436a2 /library/cpp/netliba/v6/net_test.cpp | |
parent | 03f024c4412e3aa613bb543cf1660176320ba8f4 (diff) | |
download | ydb-06e5c21a835c0e923506c4ff27929f34e00761c2.tar.gz |
fix ya.make
Diffstat (limited to 'library/cpp/netliba/v6/net_test.cpp')
-rw-r--r-- | library/cpp/netliba/v6/net_test.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/library/cpp/netliba/v6/net_test.cpp b/library/cpp/netliba/v6/net_test.cpp new file mode 100644 index 0000000000..63fd7c4067 --- /dev/null +++ b/library/cpp/netliba/v6/net_test.cpp @@ -0,0 +1,50 @@ +#include "stdafx.h" +#include "net_test.h" +#include "udp_address.h" + +#ifndef _win_ +#include <errno.h> +#endif + +namespace NNetliba { + TAtomic ActivePortTestersCount; + + const float PING_DELAY = 0.5f; + + TPortUnreachableTester::TPortUnreachableTester() + : TimePassed(0) + , ConnectOk(false) + + { + s.Open(0); + if (s.IsValid()) { + AtomicAdd(ActivePortTestersCount, 1); + } + } + + void TPortUnreachableTester::Connect(const TUdpAddress& addr) { + Y_ASSERT(IsValid()); + sockaddr_in6 toAddress; + GetWinsockAddr(&toAddress, addr); + ConnectOk = s.Connect(toAddress); + TimePassed = 0; + } + + TPortUnreachableTester::~TPortUnreachableTester() { + if (s.IsValid()) + AtomicAdd(ActivePortTestersCount, -1); + } + + bool TPortUnreachableTester::Test(float deltaT) { + if (!ConnectOk) + return false; + if (s.IsHostUnreachable()) + return false; + TimePassed += deltaT; + if (TimePassed > PING_DELAY) { + TimePassed = 0; + s.SendEmptyPacket(); + } + return true; + } +} |