aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorlaanwj <126646+laanwj@users.noreply.github.com>2022-06-22 10:59:54 +0200
committerlaanwj <126646+laanwj@users.noreply.github.com>2022-06-22 11:07:17 +0200
commita085a554913ae8f4ed83afac830ce6dc39c9cc65 (patch)
treee5fc3b744a6562125f67c1cff713b623fee901eb /src/test
parentb1a824dd06aa58618947783edee2dd891b5204dc (diff)
parenta724c39606273dfe4c6f9887ef8b77d0a98f1b34 (diff)
Merge bitcoin/bitcoin#25428: Remove Sock::Release() and CloseSocket()
a724c39606273dfe4c6f9887ef8b77d0a98f1b34 net: rename Sock::Reset() to Sock::Close() and make it private (Vasil Dimov) e8ff3f0c52e7512a580bc907dc72e5bb141b4217 net: remove CloseSocket() (Vasil Dimov) 175fb2670a2a24220afb3eea99b7b65b0aa89c76 net: remove now unused Sock::Release() (Vasil Dimov) Pull request description: _This is a piece of #21878, chopped off to ease review._ * `Sock::Release()` is unused, thus remove it * `CloseSocket()` is only called from `Sock::Reset()`, so move the body of `CloseSocket()` inside `Sock::Reset()` and remove `CloseSocket()` - this helps to hide low level file descriptor sockets inside the `Sock` class. * Rename `Sock::Reset()` to `Sock::Close()` and make it `private` - to be used only in the destructor and in the `Sock` assignment operator. This simplifies the public API by removing one method from it. ACKs for top commit: laanwj: Code review ACK a724c39606273dfe4c6f9887ef8b77d0a98f1b34 Tree-SHA512: 4b12586642b3d049092fadcb1877132e285ec66a80af92563a7703c6970e278e0f2064fba45c7eaa78eb65db94b3641fd5e5264f7b4f61116d1a6f3333868639
Diffstat (limited to 'src/test')
-rw-r--r--src/test/fuzz/util.cpp9
-rw-r--r--src/test/fuzz/util.h2
-rw-r--r--src/test/sock_tests.cpp18
-rw-r--r--src/test/util/net.h7
4 files changed, 3 insertions, 33 deletions
diff --git a/src/test/fuzz/util.cpp b/src/test/fuzz/util.cpp
index 883698aff1..8f5e771e37 100644
--- a/src/test/fuzz/util.cpp
+++ b/src/test/fuzz/util.cpp
@@ -24,10 +24,10 @@ FuzzedSock::FuzzedSock(FuzzedDataProvider& fuzzed_data_provider)
FuzzedSock::~FuzzedSock()
{
// Sock::~Sock() will be called after FuzzedSock::~FuzzedSock() and it will call
- // Sock::Reset() (not FuzzedSock::Reset()!) which will call CloseSocket(m_socket).
+ // close(m_socket) if m_socket is not INVALID_SOCKET.
// Avoid closing an arbitrary file descriptor (m_socket is just a random very high number which
// theoretically may concide with a real opened file descriptor).
- Reset();
+ m_socket = INVALID_SOCKET;
}
FuzzedSock& FuzzedSock::operator=(Sock&& other)
@@ -36,11 +36,6 @@ FuzzedSock& FuzzedSock::operator=(Sock&& other)
return *this;
}
-void FuzzedSock::Reset()
-{
- m_socket = INVALID_SOCKET;
-}
-
ssize_t FuzzedSock::Send(const void* data, size_t len, int flags) const
{
constexpr std::array send_errnos{
diff --git a/src/test/fuzz/util.h b/src/test/fuzz/util.h
index 66d00b1767..0819d326fd 100644
--- a/src/test/fuzz/util.h
+++ b/src/test/fuzz/util.h
@@ -55,8 +55,6 @@ public:
FuzzedSock& operator=(Sock&& other) override;
- void Reset() override;
-
ssize_t Send(const void* data, size_t len, int flags) const override;
ssize_t Recv(void* buf, size_t len, int flags) const override;
diff --git a/src/test/sock_tests.cpp b/src/test/sock_tests.cpp
index 9e98f4f0b1..01a402833d 100644
--- a/src/test/sock_tests.cpp
+++ b/src/test/sock_tests.cpp
@@ -69,24 +69,6 @@ BOOST_AUTO_TEST_CASE(move_assignment)
BOOST_CHECK(SocketIsClosed(s));
}
-BOOST_AUTO_TEST_CASE(release)
-{
- SOCKET s = CreateSocket();
- Sock* sock = new Sock(s);
- BOOST_CHECK_EQUAL(sock->Release(), s);
- delete sock;
- BOOST_CHECK(!SocketIsClosed(s));
- BOOST_REQUIRE(CloseSocket(s));
-}
-
-BOOST_AUTO_TEST_CASE(reset)
-{
- const SOCKET s = CreateSocket();
- Sock sock(s);
- sock.Reset();
- BOOST_CHECK(SocketIsClosed(s));
-}
-
#ifndef WIN32 // Windows does not have socketpair(2).
static void CreateSocketPair(int s[2])
diff --git a/src/test/util/net.h b/src/test/util/net.h
index 37d278645a..edb45d7c8e 100644
--- a/src/test/util/net.h
+++ b/src/test/util/net.h
@@ -100,7 +100,7 @@ public:
m_socket = INVALID_SOCKET - 1;
}
- ~StaticContentsSock() override { Reset(); }
+ ~StaticContentsSock() override { m_socket = INVALID_SOCKET; }
StaticContentsSock& operator=(Sock&& other) override
{
@@ -108,11 +108,6 @@ public:
return *this;
}
- void Reset() override
- {
- m_socket = INVALID_SOCKET;
- }
-
ssize_t Send(const void*, size_t len, int) const override { return len; }
ssize_t Recv(void* buf, size_t len, int flags) const override