From f395acdeeeaa1f3fd75d3cedbf2731fa24083e9f Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Sat, 27 Jun 2026 11:26:41 +0100 Subject: [PATCH] scripted-diff: Rename `Sock::{RECV,SEND,ERR}` The `ERR` macro is defined on illumos-based systems in the `regset.h` header included by the Boost.Test framework, which causes a compilation error. -BEGIN VERIFY SCRIPT- ren1() { sed -i "s/\<$1\>/$2/g" $( git grep -l "$1" ./src/util/sock.* ./src/httpserver.h ) ; } ren1 RECV RecvEvent ren1 SEND SendEvent ren1 ERR ErrorEvent ren2() { sed -i "s/\<$1\>/$2/g" $( git grep -l "$1" ./src/ ) ; } ren2 Sock::RECV Sock::RecvEvent ren2 Sock::SEND Sock::SendEvent ren2 Sock::ERR Sock::ErrorEvent -END VERIFY SCRIPT- --- src/bitcoin-cli.cpp | 8 ++++---- src/common/pcp.cpp | 2 +- src/httpserver.cpp | 12 ++++++------ src/httpserver.h | 4 ++-- src/i2p.cpp | 2 +- src/net.cpp | 12 ++++++------ src/netbase.cpp | 4 ++-- src/test/pcp_tests.cpp | 4 ++-- src/test/sock_tests.cpp | 2 +- src/test/util/net.cpp | 8 ++++---- src/torcontrol.cpp | 6 +++--- src/util/sock.cpp | 24 ++++++++++++------------ src/util/sock.h | 10 +++++----- 13 files changed, 49 insertions(+), 49 deletions(-) diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index a724f13d5a0..c4510e3fb2a 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( 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 HTTPClient::Recv(const std::chrono::time_point 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( diff --git a/src/common/pcp.cpp b/src/common/pcp.cpp index 22c42477322..7b22e82eda8 100644 --- a/src/common/pcp.cpp +++ b/src/common/pcp.cpp @@ -247,7 +247,7 @@ std::optional> PCPSendRecv(Sock &sock, const std::string &p while ((cur_time = time_point_cast(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 99e30ff6633..75ccf6528f5 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& 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 509dbf98cf1..792b3690b92 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 cf37272632f..657e3f23594 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 951e804f887..ba7e59db1f0 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -2089,7 +2089,7 @@ Sock::EventsPerSock CConnman::GenerateWaitSockets(std::span 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 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& 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 ab3caafdee9..002be572767 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 9f69e63e2cf..bb108af363c 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 35914a41298..d9ebc4af5fa 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 1415c8d4968..de1de042ca2 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(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 56cad01948f..f7749d4a1ed 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 0175d669156..da26ca54f08 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(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 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 50c1ab00b41..97da86dfd65 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