mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-02 09:15:04 +02:00
Merge bitcoin/bitcoin#25421: net: convert standalone IsSelectableSocket() and SetSocketNonBlocking() to Sock methods
b527b54950net: convert standalone SetSocketNonBlocking() to Sock::SetNonBlocking() (Vasil Dimov)29f66f7682moveonly: move SetSocketNonBlocking() from netbase to util/sock (Vasil Dimov)b4bac55679net: convert standalone IsSelectableSocket() to Sock::IsSelectable() (Vasil Dimov)5db7d2ca0amoveonly: move IsSelectableSocket() from compat.h to sock.{h,cpp} (Vasil Dimov) Pull request description: _This is a piece of #21878, chopped off to ease review._ * convert standalone `IsSelectableSocket()` to `Sock::IsSelectable()` * convert standalone `SetSocketNonBlocking()` to `Sock::SetNonBlocking()` This further encapsulates syscalls inside the `Sock` class and makes the callers mockable. ACKs for top commit: jonatack: ACKb527b54950review/debug build/unit tests at each commit, cross-referenced the changes with `man select` and `man errno`, ran a signet node on the last commit with ip4/ip6//tor/i2p/cjdns and network connections were nominal dergoegge: Code review ACKb527b54950Tree-SHA512: af783ce558c7a89e173f7ab323fb3517103d765c19b5d14de29f64706b4e1fea3653492e8ea73ae972699986aaddf2ae72c7cfaa7dad7614254283083b7d2632
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
#include <memory>
|
||||
|
||||
FuzzedSock::FuzzedSock(FuzzedDataProvider& fuzzed_data_provider)
|
||||
: m_fuzzed_data_provider{fuzzed_data_provider}
|
||||
: m_fuzzed_data_provider{fuzzed_data_provider}, m_selectable{fuzzed_data_provider.ConsumeBool()}
|
||||
{
|
||||
m_socket = fuzzed_data_provider.ConsumeIntegralInRange<SOCKET>(INVALID_SOCKET - 1, INVALID_SOCKET);
|
||||
}
|
||||
@@ -254,6 +254,24 @@ int FuzzedSock::GetSockName(sockaddr* name, socklen_t* name_len) const
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool FuzzedSock::SetNonBlocking() const
|
||||
{
|
||||
constexpr std::array setnonblocking_errnos{
|
||||
EBADF,
|
||||
EPERM,
|
||||
};
|
||||
if (m_fuzzed_data_provider.ConsumeBool()) {
|
||||
SetFuzzedErrNo(m_fuzzed_data_provider, setnonblocking_errnos);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FuzzedSock::IsSelectable() const
|
||||
{
|
||||
return m_selectable;
|
||||
}
|
||||
|
||||
bool FuzzedSock::Wait(std::chrono::milliseconds timeout, Event requested, Event* occurred) const
|
||||
{
|
||||
constexpr std::array wait_errnos{
|
||||
|
||||
@@ -47,6 +47,13 @@ class FuzzedSock : public Sock
|
||||
*/
|
||||
mutable std::optional<uint8_t> m_peek_data;
|
||||
|
||||
/**
|
||||
* Whether to pretend that the socket is select(2)-able. This is randomly set in the
|
||||
* constructor. It should remain constant so that repeated calls to `IsSelectable()`
|
||||
* return the same value.
|
||||
*/
|
||||
const bool m_selectable;
|
||||
|
||||
public:
|
||||
explicit FuzzedSock(FuzzedDataProvider& fuzzed_data_provider);
|
||||
|
||||
@@ -72,6 +79,10 @@ public:
|
||||
|
||||
int GetSockName(sockaddr* name, socklen_t* name_len) const override;
|
||||
|
||||
bool SetNonBlocking() const override;
|
||||
|
||||
bool IsSelectable() const override;
|
||||
|
||||
bool Wait(std::chrono::milliseconds timeout, Event requested, Event* occurred = nullptr) const override;
|
||||
|
||||
bool WaitMany(std::chrono::milliseconds timeout, EventsPerSock& events_per_sock) const override;
|
||||
|
||||
@@ -166,6 +166,10 @@ public:
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool SetNonBlocking() const override { return true; }
|
||||
|
||||
bool IsSelectable() const override { return true; }
|
||||
|
||||
bool Wait(std::chrono::milliseconds timeout,
|
||||
Event requested,
|
||||
Event* occurred = nullptr) const override
|
||||
|
||||
Reference in New Issue
Block a user