mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-06 11:13:02 +02:00
net: rename Sock::Reset() to Sock::Close() and make it private
Outside of `Sock`, `Sock::Reset()` was used in just one place (in `i2p.cpp`) which can use the assignment operator instead. This simplifies the public `Sock` API by having one method less.
This commit is contained in:
@@ -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 close(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{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -69,14 +69,6 @@ BOOST_AUTO_TEST_CASE(move_assignment)
|
||||
BOOST_CHECK(SocketIsClosed(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])
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user