Skip to content

Commit 5086a99

Browse files
committed
net: remove Sock default constructor, it's not necessary
1 parent 7829272 commit 5086a99

File tree

5 files changed

+14
-13
lines changed

5 files changed

+14
-13
lines changed

src/test/fuzz/util/net.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ CAddress ConsumeAddress(FuzzedDataProvider& fuzzed_data_provider) noexcept
5656
}
5757

5858
FuzzedSock::FuzzedSock(FuzzedDataProvider& fuzzed_data_provider)
59-
: m_fuzzed_data_provider{fuzzed_data_provider}, m_selectable{fuzzed_data_provider.ConsumeBool()}
59+
: Sock{fuzzed_data_provider.ConsumeIntegralInRange<SOCKET>(INVALID_SOCKET - 1, INVALID_SOCKET)},
60+
m_fuzzed_data_provider{fuzzed_data_provider},
61+
m_selectable{fuzzed_data_provider.ConsumeBool()}
6062
{
61-
m_socket = fuzzed_data_provider.ConsumeIntegralInRange<SOCKET>(INVALID_SOCKET - 1, INVALID_SOCKET);
6263
}
6364

6465
FuzzedSock::~FuzzedSock()

src/test/sock_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ BOOST_AUTO_TEST_CASE(move_assignment)
6060
{
6161
const SOCKET s = CreateSocket();
6262
Sock* sock1 = new Sock(s);
63-
Sock* sock2 = new Sock();
63+
Sock* sock2 = new Sock(INVALID_SOCKET);
6464
*sock2 = std::move(*sock1);
6565
delete sock1;
6666
BOOST_CHECK(!SocketIsClosed(s));
@@ -98,7 +98,7 @@ BOOST_AUTO_TEST_CASE(send_and_receive)
9898
SendAndRecvMessage(*sock0, *sock1);
9999

100100
Sock* sock0moved = new Sock(std::move(*sock0));
101-
Sock* sock1moved = new Sock();
101+
Sock* sock1moved = new Sock(INVALID_SOCKET);
102102
*sock1moved = std::move(*sock1);
103103

104104
delete sock0;

src/test/util/net.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ constexpr auto ALL_NETWORKS = std::array{
106106
class StaticContentsSock : public Sock
107107
{
108108
public:
109-
explicit StaticContentsSock(const std::string& contents) : m_contents{contents}
109+
explicit StaticContentsSock(const std::string& contents)
110+
: Sock{INVALID_SOCKET},
111+
m_contents{contents}
110112
{
111-
// Just a dummy number that is not INVALID_SOCKET.
112-
m_socket = INVALID_SOCKET - 1;
113113
}
114114

115115
~StaticContentsSock() override { m_socket = INVALID_SOCKET; }
@@ -192,6 +192,11 @@ class StaticContentsSock : public Sock
192192
return true;
193193
}
194194

195+
bool IsConnected(std::string&) const override
196+
{
197+
return true;
198+
}
199+
195200
private:
196201
const std::string m_contents;
197202
mutable size_t m_consumed{0};

src/util/sock.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ static inline bool IOErrorIsPermanent(int err)
2424
return err != WSAEAGAIN && err != WSAEINTR && err != WSAEWOULDBLOCK && err != WSAEINPROGRESS;
2525
}
2626

27-
Sock::Sock() : m_socket(INVALID_SOCKET) {}
28-
2927
Sock::Sock(SOCKET s) : m_socket(s) {}
3028

3129
Sock::Sock(Sock&& other)

src/util/sock.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ static constexpr auto MAX_WAIT_FOR_IO = 1s;
2626
class Sock
2727
{
2828
public:
29-
/**
30-
* Default constructor, creates an empty object that does nothing when destroyed.
31-
*/
32-
Sock();
29+
Sock() = delete;
3330

3431
/**
3532
* Take ownership of an existent socket.

0 commit comments

Comments
 (0)