diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:17 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:17 +0300 |
commit | d3a398281c6fd1d3672036cb2d63f842d2cb28c5 (patch) | |
tree | dd4bd3ca0f36b817e96812825ffaf10d645803f2 /util/network/sock_ut.cpp | |
parent | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (diff) | |
download | ydb-d3a398281c6fd1d3672036cb2d63f842d2cb28c5.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 2 of 2.
Diffstat (limited to 'util/network/sock_ut.cpp')
-rw-r--r-- | util/network/sock_ut.cpp | 274 |
1 files changed, 137 insertions, 137 deletions
diff --git a/util/network/sock_ut.cpp b/util/network/sock_ut.cpp index 9f42f1f1a4..fd8c783747 100644 --- a/util/network/sock_ut.cpp +++ b/util/network/sock_ut.cpp @@ -1,5 +1,5 @@ -#include "sock.h" - +#include "sock.h" + #include <library/cpp/testing/unittest/registar.h> #include <library/cpp/threading/future/legacy_future.h> @@ -7,109 +7,109 @@ Y_UNIT_TEST_SUITE(TSocketTest) { Y_UNIT_TEST(InetDgramTest) { - char buf[256]; - TSockAddrInetDgram servAddr(IpFromString("127.0.0.1"), 0); - TSockAddrInetDgram cliAddr(IpFromString("127.0.0.1"), 0); - TSockAddrInetDgram servFromAddr; - TSockAddrInetDgram cliFromAddr; - TInetDgramSocket cliSock; - TInetDgramSocket servSock; - cliSock.CheckSock(); - servSock.CheckSock(); - - TBaseSocket::Check(cliSock.Bind(&cliAddr)); - TBaseSocket::Check(servSock.Bind(&servAddr)); - - // client - const char reqStr[] = "Hello, world!!!"; - TBaseSocket::Check(cliSock.SendTo(reqStr, sizeof(reqStr), &servAddr)); - - // server - TBaseSocket::Check(servSock.RecvFrom(buf, 256, &servFromAddr)); - UNIT_ASSERT(strcmp(reqStr, buf) == 0); - const char repStr[] = "The World's greatings to you"; - TBaseSocket::Check(servSock.SendTo(repStr, sizeof(repStr), &servFromAddr)); - - // client - TBaseSocket::Check(cliSock.RecvFrom(buf, 256, &cliFromAddr)); - UNIT_ASSERT(strcmp(repStr, buf) == 0); - } - - void RunLocalDgramTest(const char* localServerSockName, const char* localClientSockName) { - char buf[256]; - TSockAddrLocalDgram servAddr(localServerSockName); - TSockAddrLocalDgram cliAddr(localClientSockName); - TSockAddrLocalDgram servFromAddr; - TSockAddrLocalDgram cliFromAddr; - TLocalDgramSocket cliSock; - TLocalDgramSocket servSock; - cliSock.CheckSock(); - servSock.CheckSock(); - - TBaseSocket::Check(cliSock.Bind(&cliAddr), "bind client"); - TBaseSocket::Check(servSock.Bind(&servAddr), "bind server"); - - // client - const char reqStr[] = "Hello, world!!!"; - TBaseSocket::Check(cliSock.SendTo(reqStr, sizeof(reqStr), &servAddr), "send from client"); - - // server - TBaseSocket::Check(servSock.RecvFrom(buf, 256, &servFromAddr), "receive from client"); - UNIT_ASSERT(strcmp(reqStr, buf) == 0); - const char repStr[] = "The World's greatings to you"; - TBaseSocket::Check(servSock.SendTo(repStr, sizeof(repStr), &servFromAddr), "send to client"); - - // client - TBaseSocket::Check(cliSock.RecvFrom(buf, 256, &cliFromAddr), "receive from server"); - UNIT_ASSERT(strcmp(repStr, buf) == 0); - } + char buf[256]; + TSockAddrInetDgram servAddr(IpFromString("127.0.0.1"), 0); + TSockAddrInetDgram cliAddr(IpFromString("127.0.0.1"), 0); + TSockAddrInetDgram servFromAddr; + TSockAddrInetDgram cliFromAddr; + TInetDgramSocket cliSock; + TInetDgramSocket servSock; + cliSock.CheckSock(); + servSock.CheckSock(); + + TBaseSocket::Check(cliSock.Bind(&cliAddr)); + TBaseSocket::Check(servSock.Bind(&servAddr)); + + // client + const char reqStr[] = "Hello, world!!!"; + TBaseSocket::Check(cliSock.SendTo(reqStr, sizeof(reqStr), &servAddr)); + + // server + TBaseSocket::Check(servSock.RecvFrom(buf, 256, &servFromAddr)); + UNIT_ASSERT(strcmp(reqStr, buf) == 0); + const char repStr[] = "The World's greatings to you"; + TBaseSocket::Check(servSock.SendTo(repStr, sizeof(repStr), &servFromAddr)); + + // client + TBaseSocket::Check(cliSock.RecvFrom(buf, 256, &cliFromAddr)); + UNIT_ASSERT(strcmp(repStr, buf) == 0); + } + + void RunLocalDgramTest(const char* localServerSockName, const char* localClientSockName) { + char buf[256]; + TSockAddrLocalDgram servAddr(localServerSockName); + TSockAddrLocalDgram cliAddr(localClientSockName); + TSockAddrLocalDgram servFromAddr; + TSockAddrLocalDgram cliFromAddr; + TLocalDgramSocket cliSock; + TLocalDgramSocket servSock; + cliSock.CheckSock(); + servSock.CheckSock(); + + TBaseSocket::Check(cliSock.Bind(&cliAddr), "bind client"); + TBaseSocket::Check(servSock.Bind(&servAddr), "bind server"); + + // client + const char reqStr[] = "Hello, world!!!"; + TBaseSocket::Check(cliSock.SendTo(reqStr, sizeof(reqStr), &servAddr), "send from client"); + + // server + TBaseSocket::Check(servSock.RecvFrom(buf, 256, &servFromAddr), "receive from client"); + UNIT_ASSERT(strcmp(reqStr, buf) == 0); + const char repStr[] = "The World's greatings to you"; + TBaseSocket::Check(servSock.SendTo(repStr, sizeof(repStr), &servFromAddr), "send to client"); + + // client + TBaseSocket::Check(cliSock.RecvFrom(buf, 256, &cliFromAddr), "receive from server"); + UNIT_ASSERT(strcmp(repStr, buf) == 0); + } Y_UNIT_TEST(LocalDgramTest) { - const char* localServerSockName = "./serv_sock"; - const char* localClientSockName = "./cli_sock"; - RunLocalDgramTest(localServerSockName, localClientSockName); + const char* localServerSockName = "./serv_sock"; + const char* localClientSockName = "./cli_sock"; + RunLocalDgramTest(localServerSockName, localClientSockName); NFs::Remove(localServerSockName); NFs::Remove(localClientSockName); - } + } - template <class A, class S> + template <class A, class S> void RunInetStreamTest(const char* ip) { - char buf[256]; + char buf[256]; A servAddr(ip, 0); A newAddr; S cliSock; S servSock; S newSock; - cliSock.CheckSock(); - servSock.CheckSock(); - newSock.CheckSock(); - - // server - int yes = 1; - CheckedSetSockOpt(servSock, SOL_SOCKET, SO_REUSEADDR, yes, "servSock, SO_REUSEADDR"); - TBaseSocket::Check(servSock.Bind(&servAddr), "bind"); - TBaseSocket::Check(servSock.Listen(10), "listen"); - - // client - TBaseSocket::Check(cliSock.Connect(&servAddr), "connect"); - - // server - TBaseSocket::Check(servSock.Accept(&newSock, &newAddr), "accept"); - - // client - const char reqStr[] = "Hello, world!!!"; - TBaseSocket::Check(cliSock.Send(reqStr, sizeof(reqStr)), "send"); - - // server - new - TBaseSocket::Check(newSock.Recv(buf, 256), "recv"); - UNIT_ASSERT(strcmp(reqStr, buf) == 0); - const char repStr[] = "The World's greatings to you"; - TBaseSocket::Check(newSock.Send(repStr, sizeof(repStr)), "send"); - - // client - TBaseSocket::Check(cliSock.Recv(buf, 256), "recv"); - UNIT_ASSERT(strcmp(repStr, buf) == 0); - } + cliSock.CheckSock(); + servSock.CheckSock(); + newSock.CheckSock(); + + // server + int yes = 1; + CheckedSetSockOpt(servSock, SOL_SOCKET, SO_REUSEADDR, yes, "servSock, SO_REUSEADDR"); + TBaseSocket::Check(servSock.Bind(&servAddr), "bind"); + TBaseSocket::Check(servSock.Listen(10), "listen"); + + // client + TBaseSocket::Check(cliSock.Connect(&servAddr), "connect"); + + // server + TBaseSocket::Check(servSock.Accept(&newSock, &newAddr), "accept"); + + // client + const char reqStr[] = "Hello, world!!!"; + TBaseSocket::Check(cliSock.Send(reqStr, sizeof(reqStr)), "send"); + + // server - new + TBaseSocket::Check(newSock.Recv(buf, 256), "recv"); + UNIT_ASSERT(strcmp(reqStr, buf) == 0); + const char repStr[] = "The World's greatings to you"; + TBaseSocket::Check(newSock.Send(repStr, sizeof(repStr)), "send"); + + // client + TBaseSocket::Check(cliSock.Recv(buf, 256), "recv"); + UNIT_ASSERT(strcmp(repStr, buf) == 0); + } Y_UNIT_TEST(InetStreamTest) { RunInetStreamTest<TSockAddrInetStream, TInetStreamSocket>("127.0.0.1"); @@ -119,50 +119,50 @@ Y_UNIT_TEST_SUITE(TSocketTest) { RunInetStreamTest<TSockAddrInet6Stream, TInet6StreamSocket>("::1"); } - void RunLocalStreamTest(const char* localServerSockName) { - char buf[256]; - TSockAddrLocalStream servAddr(localServerSockName); - TSockAddrLocalStream newAddr; - TLocalStreamSocket cliSock; - TLocalStreamSocket servSock; - TLocalStreamSocket newSock; - cliSock.CheckSock(); - servSock.CheckSock(); - newSock.CheckSock(); - - // server - TBaseSocket::Check(servSock.Bind(&servAddr), "bind"); - TBaseSocket::Check(servSock.Listen(10), "listen"); - - NThreading::TLegacyFuture<void> f([&]() { - // server - TBaseSocket::Check(servSock.Accept(&newSock, &newAddr), "accept"); - }); - - // client - TBaseSocket::Check(cliSock.Connect(&servAddr), "connect"); - - f.Get(); - - // client - const char reqStr[] = "Hello, world!!!"; - TBaseSocket::Check(cliSock.Send(reqStr, sizeof(reqStr)), "send"); - - // server - new - TBaseSocket::Check(newSock.Recv(buf, 256), "recv"); - UNIT_ASSERT(strcmp(reqStr, buf) == 0); - const char repStr[] = "The World's greatings to you"; - TBaseSocket::Check(newSock.Send(repStr, sizeof(repStr)), "send"); - - // client - TBaseSocket::Check(cliSock.Recv(buf, 256), "recv"); - UNIT_ASSERT(strcmp(repStr, buf) == 0); - } + void RunLocalStreamTest(const char* localServerSockName) { + char buf[256]; + TSockAddrLocalStream servAddr(localServerSockName); + TSockAddrLocalStream newAddr; + TLocalStreamSocket cliSock; + TLocalStreamSocket servSock; + TLocalStreamSocket newSock; + cliSock.CheckSock(); + servSock.CheckSock(); + newSock.CheckSock(); + + // server + TBaseSocket::Check(servSock.Bind(&servAddr), "bind"); + TBaseSocket::Check(servSock.Listen(10), "listen"); + + NThreading::TLegacyFuture<void> f([&]() { + // server + TBaseSocket::Check(servSock.Accept(&newSock, &newAddr), "accept"); + }); + + // client + TBaseSocket::Check(cliSock.Connect(&servAddr), "connect"); + + f.Get(); + + // client + const char reqStr[] = "Hello, world!!!"; + TBaseSocket::Check(cliSock.Send(reqStr, sizeof(reqStr)), "send"); + + // server - new + TBaseSocket::Check(newSock.Recv(buf, 256), "recv"); + UNIT_ASSERT(strcmp(reqStr, buf) == 0); + const char repStr[] = "The World's greatings to you"; + TBaseSocket::Check(newSock.Send(repStr, sizeof(repStr)), "send"); + + // client + TBaseSocket::Check(cliSock.Recv(buf, 256), "recv"); + UNIT_ASSERT(strcmp(repStr, buf) == 0); + } Y_UNIT_TEST(LocalStreamTest) { - const char* localServerSockName = "./serv_sock2"; - RunLocalStreamTest(localServerSockName); + const char* localServerSockName = "./serv_sock2"; + RunLocalStreamTest(localServerSockName); NFs::Remove(localServerSockName); - } + } -} +} |