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-
This commit is contained in:
Hennadii Stepanov
2026-06-27 11:26:41 +01:00
parent 7ac25c9177
commit f395acdeee
13 changed files with 49 additions and 49 deletions

View File

@@ -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>(

View File

@@ -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.
}

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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);
}
}

View File

@@ -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",

View File

@@ -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.

View File

@@ -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);

View File

@@ -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;
}
}

View File

@@ -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()

View File

@@ -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);
}
}

View File

@@ -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