aboutsummaryrefslogtreecommitdiffstats
path: root/util/network/sock_ut.cpp
diff options
context:
space:
mode:
authorAndrey Fomichev <andrey.fomichev@gmail.com>2022-02-10 16:49:12 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:12 +0300
commite542cc14db4240643a06bb0dde87ecf361f101ab (patch)
tree3b03a4b94acd11a4eca042532035806e5fa08ad1 /util/network/sock_ut.cpp
parente2ac73225f30f7fcf7df3cb225cba257f56144c1 (diff)
downloadydb-e542cc14db4240643a06bb0dde87ecf361f101ab.tar.gz
Restoring authorship annotation for Andrey Fomichev <andrey.fomichev@gmail.com>. Commit 1 of 2.
Diffstat (limited to 'util/network/sock_ut.cpp')
-rw-r--r--util/network/sock_ut.cpp52
1 files changed, 26 insertions, 26 deletions
diff --git a/util/network/sock_ut.cpp b/util/network/sock_ut.cpp
index fd8c783747..83f4a19d50 100644
--- a/util/network/sock_ut.cpp
+++ b/util/network/sock_ut.cpp
@@ -2,7 +2,7 @@
#include <library/cpp/testing/unittest/registar.h>
#include <library/cpp/threading/future/legacy_future.h>
-
+
#include <util/system/fs.h>
Y_UNIT_TEST_SUITE(TSocketTest) {
@@ -16,25 +16,25 @@ Y_UNIT_TEST_SUITE(TSocketTest) {
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);
@@ -45,25 +45,25 @@ Y_UNIT_TEST_SUITE(TSocketTest) {
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";
@@ -71,7 +71,7 @@ Y_UNIT_TEST_SUITE(TSocketTest) {
NFs::Remove(localServerSockName);
NFs::Remove(localClientSockName);
}
-
+
template <class A, class S>
void RunInetStreamTest(const char* ip) {
char buf[256];
@@ -89,28 +89,28 @@ Y_UNIT_TEST_SUITE(TSocketTest) {
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");
}
@@ -129,11 +129,11 @@ Y_UNIT_TEST_SUITE(TSocketTest) {
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");
@@ -141,28 +141,28 @@ Y_UNIT_TEST_SUITE(TSocketTest) {
// 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);
NFs::Remove(localServerSockName);
}
-
+
}