scripted-diff: Rename `Sock::{RECV,SEND,ERR}`
What changed, and why it matters
This commit is a simple rename of three internal constants used by Bitcoin Core's socket-handling code. The old names (RECV, SEND, ERR) clashed with a macro named ERR on illumos-based operating systems, preventing the software from compiling. The new names (RecvEvent, SendEvent, ErrorEvent) avoid that clash. There is no change to program logic, behavior, or security.
No security action needed. Treat as a normal build-compatibility fix.
Security signals we found
No strong security signals were identified.
Evidence from the diff
A scripted diff renames Sock::RECV/SEND/ERR to Sock::RecvEvent/SendEvent/ErrorEvent across 13 files. The values (0b001, 0b010, 0b100) and all bitwise operations remain identical. The change only fixes a build failure on illumos caused by a macro collision in regset.h included via Boost.Test. No functional code paths were altered.
Changed components
src/util/sock.hsrc/util/sock.cppsrc/net.cppsrc/netbase.cppsrc/httpserver.cppsrc/httpserver.hsrc/bitcoin-cli.cppsrc/i2p.cppsrc/torcontrol.cppsrc/common/pcp.cppsrc/test/sock_tests.cppsrc/test/pcp_tests.cppsrc/test/util/net.cppInspect captured patch +49 / −49
diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp
index a724f13d..c4510e3f 100644
--- a/src/bitcoin-cli.cpp
+++ b/src/bitcoin-cli.cpp
@@ -912,11 +912,11 @@ bool HTTPClient::SendRequest(std::string_view request)
Sock::Event event{0};
auto time_left = std::chrono::duration_cast<std::chrono::milliseconds>(
deadline - std::chrono::steady_clock::now());
- if (time_left.count() <= 0 || !m_socket->Wait(time_left, Sock::SEND, &event)) {
+ if (time_left.count() <= 0 || !m_socket->Wait(time_left, Sock::SendEvent, &event)) {
return false;
}
- if (!(event & Sock::SEND)) {
+ if (!(event & Sock::SendEvent)) {
continue;
}
@@ -1122,10 +1122,10 @@ std::optional<std::string> HTTPClient::Recv(const std::chrono::time_point<std::c
{
auto wait_for_readable{[this](std::chrono::milliseconds timeout) -> bool {
Sock::Event event{0};
- if (!m_socket->Wait(timeout, Sock::RECV, &event)) {
+ if (!m_socket->Wait(timeout, Sock::RecvEvent, &event)) {
return false;
}
- return (event & Sock::RECV) != 0;
+ return (event & Sock::RecvEvent) != 0;
}};
auto time_left = std::chrono::duration_cast<std::chrono::milliseconds>(
diff --git a/src/common/pcp.cpp b/src/common/pcp.cpp
index 22c42477..7b22e82e 100644
--- a/src/common/pcp.cpp
+++ b/src/common/pcp.cpp
@@ -247,7 +247,7 @@ std::optional<std::vector<uint8_t>> PCPSendRecv(Sock &sock, const std::string &p
while ((cur_time = time_point_cast<milliseconds>(MockableSteadyClock::now())) < deadline) {
if (interrupt) return std::nullopt;
Sock::Event occurred = 0;
- if (!sock.Wait(deadline - cur_time, Sock::RECV, &occurred)) {
+ if (!sock.Wait(deadline - cur_time, Sock::RecvEvent, &occurred)) {
LogWarning("%s: Could not wait on socket: %s\n", protocol, NetworkErrorString(WSAGetLastError()));
return std::nullopt; // Network-level error, probably no use retrying.
}
diff --git a/src/httpserver.cpp b/src/httpserver.cpp
index 99e30ff6..75ccf652 100644
--- a/src/httpserver.cpp
+++ b/src/httpserver.cpp
@@ -841,9 +841,9 @@ void HTTPServer::SocketHandlerConnected(const IOReadiness& io_readiness) const
}
const std::shared_ptr<HTTPRemoteClient>& client{it->second};
- bool send_ready = events.occurred & Sock::SEND;
- bool recv_ready = events.occurred & Sock::RECV;
- bool err_ready = events.occurred & Sock::ERR;
+ bool send_ready = events.occurred & Sock::SendEvent;
+ bool recv_ready = events.occurred & Sock::RecvEvent;
+ bool err_ready = events.occurred & Sock::ErrorEvent;
if (send_ready) {
// Try to send as much data as is ready for this client.
@@ -909,7 +909,7 @@ void HTTPServer::SocketHandlerListening(const Sock::EventsPerSock& events_per_so
return;
}
const auto it = events_per_sock.find(sock);
- if (it != events_per_sock.end() && it->second.occurred & Sock::RECV) {
+ if (it != events_per_sock.end() && it->second.occurred & Sock::RecvEvent) {
CService addr_accepted;
auto sock_accepted{AcceptConnection(*sock, addr_accepted)};
@@ -926,7 +926,7 @@ HTTPServer::IOReadiness HTTPServer::GenerateWaitSockets() const
IOReadiness io_readiness;
for (const auto& sock : m_listen) {
- io_readiness.events_per_sock.emplace(sock, Sock::Events{Sock::RECV});
+ io_readiness.events_per_sock.emplace(sock, Sock::Events{Sock::RecvEvent});
}
for (const auto& http_client : m_connected) {
@@ -935,7 +935,7 @@ HTTPServer::IOReadiness HTTPServer::GenerateWaitSockets() const
// Check if client is ready to send data. Don't try to receive again
// until the send buffer is cleared (all data sent to client).
- Sock::Event event = (http_client->m_send_ready ? Sock::SEND : Sock::RECV);
+ Sock::Event event = (http_client->m_send_ready ? Sock::SendEvent : Sock::RecvEvent);
io_readiness.events_per_sock.emplace(sock, Sock::Events{event});
io_readiness.httpclients_per_sock.emplace(sock, http_client);
}
diff --git a/src/httpserver.h b/src/httpserver.h
index 509dbf98..792b3690 100644
--- a/src/httpserver.h
+++ b/src/httpserver.h
@@ -333,8 +333,8 @@ private:
struct IOReadiness {
/**
* Map of socket -> socket events. For example:
- * socket1 -> { requested = SEND|RECV, occurred = RECV }
- * socket2 -> { requested = SEND, occurred = SEND }
+ * socket1 -> { requested = SendEvent|RecvEvent, occurred = RecvEvent }
+ * socket2 -> { requested = SendEvent, occurred = SendEvent }
*/
Sock::EventsPerSock events_per_sock;
diff --git a/src/i2p.cpp b/src/i2p.cpp
index cf372726..657e3f23 100644
--- a/src/i2p.cpp
+++ b/src/i2p.cpp
@@ -164,7 +164,7 @@ bool Session::Accept(Connection& conn)
while (!m_interrupt->interrupted()) {
Sock::Event occurred;
- if (!conn.sock->Wait(MAX_WAIT_FOR_IO, Sock::RECV, &occurred)) {
+ if (!conn.sock->Wait(MAX_WAIT_FOR_IO, Sock::RecvEvent, &occurred)) {
errmsg = "wait on socket failed";
break;
}
diff --git a/src/net.cpp b/src/net.cpp
index 951e804f..ba7e59db 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -2089,7 +2089,7 @@ Sock::EventsPerSock CConnman::GenerateWaitSockets(std::span<CNode* const> nodes)
Sock::EventsPerSock events_per_sock;
for (const ListenSocket& hListenSocket : vhListenSocket) {
- events_per_sock.emplace(hListenSocket.sock, Sock::Events{Sock::RECV});
+ events_per_sock.emplace(hListenSocket.sock, Sock::Events{Sock::RecvEvent});
}
for (CNode* pnode : nodes) {
@@ -2107,7 +2107,7 @@ Sock::EventsPerSock CConnman::GenerateWaitSockets(std::span<CNode* const> nodes)
LOCK(pnode->m_sock_mutex);
if (pnode->m_sock) {
- Sock::Event event = (select_send ? Sock::SEND : 0) | (select_recv ? Sock::RECV : 0);
+ Sock::Event event = (select_send ? Sock::SendEvent : 0) | (select_recv ? Sock::RecvEvent : 0);
events_per_sock.emplace(pnode->m_sock, Sock::Events{event});
}
}
@@ -2169,9 +2169,9 @@ void CConnman::SocketHandlerConnected(const std::vector<CNode*>& nodes,
}
const auto it = events_per_sock.find(pnode->m_sock);
if (it != events_per_sock.end()) {
- recvSet = it->second.occurred & Sock::RECV;
- sendSet = it->second.occurred & Sock::SEND;
- errorSet = it->second.occurred & Sock::ERR;
+ recvSet = it->second.occurred & Sock::RecvEvent;
+ sendSet = it->second.occurred & Sock::SendEvent;
+ errorSet = it->second.occurred & Sock::ErrorEvent;
}
}
@@ -2255,7 +2255,7 @@ void CConnman::SocketHandlerListening(const Sock::EventsPerSock& events_per_sock
return;
}
const auto it = events_per_sock.find(listen_socket.sock);
- if (it != events_per_sock.end() && it->second.occurred & Sock::RECV) {
+ if (it != events_per_sock.end() && it->second.occurred & Sock::RecvEvent) {
AcceptConnection(listen_socket);
}
}
diff --git a/src/netbase.cpp b/src/netbase.cpp
index ab3caafd..002be572 100644
--- a/src/netbase.cpp
+++ b/src/netbase.cpp
@@ -333,7 +333,7 @@ static IntrRecvError InterruptibleRecv(uint8_t* data, size_t len, std::chrono::m
// we're approaching the end of the specified total timeout
const auto remaining = std::chrono::milliseconds{endTime - curTime};
const auto timeout = std::min(remaining, std::chrono::milliseconds{MAX_WAIT_FOR_IO});
- if (!sock.Wait(timeout, Sock::RECV)) {
+ if (!sock.Wait(timeout, Sock::RecvEvent)) {
return IntrRecvError::NetworkError;
}
} else {
@@ -603,7 +603,7 @@ static bool ConnectToSocket(const Sock& sock,
// Connection didn't actually fail, but is being established
// asynchronously. Thus, use async I/O api (select/poll)
// synchronously to check for successful connection with a timeout.
- const Sock::Event requested = Sock::RECV | Sock::SEND;
+ const Sock::Event requested = Sock::RecvEvent | Sock::SendEvent;
Sock::Event occurred;
if (!sock.Wait(timeout, requested, &occurred)) {
LogInfo("wait for connect to %s failed: %s\n",
diff --git a/src/test/pcp_tests.cpp b/src/test/pcp_tests.cpp
index 9f69e63e..bb108af3 100644
--- a/src/test/pcp_tests.cpp
+++ b/src/test/pcp_tests.cpp
@@ -191,14 +191,14 @@ public:
Event* occurred = nullptr) const override
{
// Only handles receive events.
- if (AtEndOfScript() || requested != Sock::RECV) {
+ if (AtEndOfScript() || requested != Sock::RecvEvent) {
m_clock += timeout;
} else {
std::chrono::milliseconds delay = std::min(m_time_left, timeout);
m_clock += delay;
m_time_left -= delay;
if (CurOp().op == TestOp::RECV && m_time_left == 0s && occurred != nullptr) {
- *occurred = Sock::RECV;
+ *occurred = Sock::RecvEvent;
}
if (CurOp().op == TestOp::NOP) {
// This was a pure delay operation, move to the next op.
diff --git a/src/test/sock_tests.cpp b/src/test/sock_tests.cpp
index 35914a41..d9ebc4af 100644
--- a/src/test/sock_tests.cpp
+++ b/src/test/sock_tests.cpp
@@ -148,7 +148,7 @@ BOOST_AUTO_TEST_CASE(wait)
{
TcpSocketPair socks = TcpSocketPair{};
- std::thread waiter([&socks]() { (void)socks.receiver.Wait(24h, Sock::RECV); });
+ std::thread waiter([&socks]() { (void)socks.receiver.Wait(24h, Sock::RecvEvent); });
BOOST_REQUIRE_EQUAL(socks.sender.Send("a", 1, 0), 1);
diff --git a/src/test/util/net.cpp b/src/test/util/net.cpp
index 1415c8d4..de1de042 100644
--- a/src/test/util/net.cpp
+++ b/src/test/util/net.cpp
@@ -400,17 +400,17 @@ bool DynSock::WaitMany(std::chrono::milliseconds timeout, EventsPerSock& events_
for (;;) {
// Check all sockets for readiness without waiting.
for (auto& [sock, events] : events_per_sock) {
- if ((events.requested & Sock::SEND) != 0) {
+ if ((events.requested & Sock::SendEvent) != 0) {
// Always ready for Send().
- events.occurred |= Sock::SEND;
+ events.occurred |= Sock::SendEvent;
at_least_one_event_occurred = true;
}
- if ((events.requested & Sock::RECV) != 0) {
+ if ((events.requested & Sock::RecvEvent) != 0) {
auto dyn_sock = reinterpret_cast<const DynSock*>(sock.get());
uint8_t b;
if (dyn_sock->m_pipes->recv.GetBytes(&b, 1, MSG_PEEK) == 1 || (dyn_sock->m_accept_sockets && !dyn_sock->m_accept_sockets->Empty())) {
- events.occurred |= Sock::RECV;
+ events.occurred |= Sock::RecvEvent;
at_least_one_event_occurred = true;
}
}
diff --git a/src/torcontrol.cpp b/src/torcontrol.cpp
index 56cad019..f7749d4a 100644
--- a/src/torcontrol.cpp
+++ b/src/torcontrol.cpp
@@ -133,16 +133,16 @@ bool TorControlConnection::WaitForData(std::chrono::milliseconds timeout)
if (!m_sock) return false;
Sock::Event event{0};
- if (!m_sock->Wait(timeout, Sock::RECV, &event)) {
+ if (!m_sock->Wait(timeout, Sock::RecvEvent, &event)) {
return false;
}
- if (event & Sock::ERR) {
+ if (event & Sock::ErrorEvent) {
LogDebug(BCLog::TOR, "Socket error detected");
Disconnect();
return false;
}
- return (event & Sock::RECV);
+ return (event & Sock::RecvEvent);
}
bool TorControlConnection::ReceiveAndProcess()
diff --git a/src/util/sock.cpp b/src/util/sock.cpp
index 0175d669..da26ca54 100644
--- a/src/util/sock.cpp
+++ b/src/util/sock.cpp
@@ -168,10 +168,10 @@ bool Sock::WaitMany(std::chrono::milliseconds timeout, EventsPerSock& events_per
pfds.emplace_back();
auto& pfd = pfds.back();
pfd.fd = sock->m_socket;
- if (events.requested & RECV) {
+ if (events.requested & RecvEvent) {
pfd.events |= POLLIN;
}
- if (events.requested & SEND) {
+ if (events.requested & SendEvent) {
pfd.events |= POLLOUT;
}
}
@@ -186,13 +186,13 @@ bool Sock::WaitMany(std::chrono::milliseconds timeout, EventsPerSock& events_per
assert(sock->m_socket == static_cast<SOCKET>(pfds[i].fd));
events.occurred = 0;
if (pfds[i].revents & POLLIN) {
- events.occurred |= RECV;
+ events.occurred |= RecvEvent;
}
if (pfds[i].revents & POLLOUT) {
- events.occurred |= SEND;
+ events.occurred |= SendEvent;
}
if (pfds[i].revents & (POLLERR | POLLHUP)) {
- events.occurred |= ERR;
+ events.occurred |= ErrorEvent;
}
++i;
}
@@ -212,10 +212,10 @@ bool Sock::WaitMany(std::chrono::milliseconds timeout, EventsPerSock& events_per
return false;
}
const auto& s = sock->m_socket;
- if (events.requested & RECV) {
+ if (events.requested & RecvEvent) {
FD_SET(s, &recv);
}
- if (events.requested & SEND) {
+ if (events.requested & SendEvent) {
FD_SET(s, &send);
}
FD_SET(s, &err);
@@ -232,13 +232,13 @@ bool Sock::WaitMany(std::chrono::milliseconds timeout, EventsPerSock& events_per
const auto& s = sock->m_socket;
events.occurred = 0;
if (FD_ISSET(s, &recv)) {
- events.occurred |= RECV;
+ events.occurred |= RecvEvent;
}
if (FD_ISSET(s, &send)) {
- events.occurred |= SEND;
+ events.occurred |= SendEvent;
}
if (FD_ISSET(s, &err)) {
- events.occurred |= ERR;
+ events.occurred |= ErrorEvent;
}
}
@@ -283,7 +283,7 @@ void Sock::SendComplete(std::span<const unsigned char> data,
// Wait for a short while (or the socket to become ready for sending) before retrying
// if nothing was sent.
const auto wait_time = std::min(deadline - now, std::chrono::milliseconds{MAX_WAIT_FOR_IO});
- (void)Wait(wait_time, SEND);
+ (void)Wait(wait_time, SendEvent);
}
}
@@ -373,7 +373,7 @@ std::string Sock::RecvUntilTerminator(uint8_t terminator,
// Wait for a short while (or the socket to become ready for reading) before retrying.
const auto wait_time = std::min(deadline - now, std::chrono::milliseconds{MAX_WAIT_FOR_IO});
- (void)Wait(wait_time, RECV);
+ (void)Wait(wait_time, RecvEvent);
}
}
diff --git a/src/util/sock.h b/src/util/sock.h
index 50c1ab00..97da86df 100644
--- a/src/util/sock.h
+++ b/src/util/sock.h
@@ -148,25 +148,25 @@ public:
/**
* If passed to `Wait()`, then it will wait for readiness to read from the socket.
*/
- static constexpr Event RECV = 0b001;
+ static constexpr Event RecvEvent = 0b001;
/**
* If passed to `Wait()`, then it will wait for readiness to send to the socket.
*/
- static constexpr Event SEND = 0b010;
+ static constexpr Event SendEvent = 0b010;
/**
* Ignored if passed to `Wait()`, but could be set in the occurred events if an
* exceptional condition has occurred on the socket or if it has been disconnected.
*/
- static constexpr Event ERR = 0b100;
+ static constexpr Event ErrorEvent = 0b100;
/**
* Wait for readiness for input (recv) or output (send).
* @param[in] timeout Wait this much for at least one of the requested events to occur.
- * @param[in] requested Wait for those events, bitwise-or of `RECV` and `SEND`.
+ * @param[in] requested Wait for those events, bitwise-or of `RecvEvent` and `SendEvent`.
* @param[out] occurred If not nullptr and the function returns `true`, then this
- * indicates which of the requested events occurred (`ERR` will be added, even if
+ * indicates which of the requested events occurred (`ErrorEvent` will be added, even if
* not requested, if an exceptional event occurs on the socket).
* A timeout is indicated by return value of `true` and `occurred` being set to 0.
* @return true on success (or timeout, if `occurred` of 0 is returned), false otherwise
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.