mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-09-11 21:20:39 +02:00
refactor: Expose additional HTTPRemoteClient fields through accessors
This commit is contained in:
@@ -659,7 +659,7 @@ void HTTPRemoteClient::Send(const HTTPResponse& res, std::span<const std::byte>
|
|||||||
CService HTTPRequest::GetPeer() const
|
CService HTTPRequest::GetPeer() const
|
||||||
{
|
{
|
||||||
if (std::shared_ptr c{m_client.lock()}) {
|
if (std::shared_ptr c{m_client.lock()}) {
|
||||||
return c->m_addr;
|
return c->GetPeer();
|
||||||
} else {
|
} else {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@@ -989,7 +989,7 @@ HTTPServer::IOReadiness HTTPServer::GenerateWaitSockets() const
|
|||||||
|
|
||||||
for (const auto& http_client : m_connected) {
|
for (const auto& http_client : m_connected) {
|
||||||
// Safely copy the shared pointer to the socket
|
// Safely copy the shared pointer to the socket
|
||||||
std::shared_ptr<Sock> sock{WITH_LOCK(http_client->m_sock_mutex, return http_client->m_sock;)};
|
std::shared_ptr<Sock> sock{http_client->GetSock()};
|
||||||
|
|
||||||
// Check if client is ready to send data. Don't try to receive again
|
// 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).
|
// until the send buffer is cleared (all data sent to client).
|
||||||
@@ -997,8 +997,7 @@ HTTPServer::IOReadiness HTTPServer::GenerateWaitSockets() const
|
|||||||
// never hold m_sock_mutex and m_send_mutex at the same time here.
|
// never hold m_sock_mutex and m_send_mutex at the same time here.
|
||||||
// MaybeSendBytesFromBuffer() locks m_send_mutex then m_sock_mutex, so nesting
|
// MaybeSendBytesFromBuffer() locks m_send_mutex then m_sock_mutex, so nesting
|
||||||
// them in the opposite order here would risk a lock-order inversion deadlock.
|
// them in the opposite order here would risk a lock-order inversion deadlock.
|
||||||
const bool send_ready{WITH_LOCK(http_client->m_send_mutex, return http_client->m_send_ready;)};
|
Sock::Event event = (http_client->ReadyToSend() ? Sock::SendEvent : Sock::RecvEvent);
|
||||||
Sock::Event event = (send_ready ? Sock::SendEvent : Sock::RecvEvent);
|
|
||||||
io_readiness.events_per_sock.emplace(sock, Sock::Events{event});
|
io_readiness.events_per_sock.emplace(sock, Sock::Events{event});
|
||||||
io_readiness.httpclients_per_sock.emplace(sock, http_client);
|
io_readiness.httpclients_per_sock.emplace(sock, http_client);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -508,7 +508,7 @@ public:
|
|||||||
* Written to by http worker threads, read and erased by HTTPServer I/O thread
|
* Written to by http worker threads, read and erased by HTTPServer I/O thread
|
||||||
*/
|
*/
|
||||||
/// @{
|
/// @{
|
||||||
Mutex m_send_mutex;
|
mutable Mutex m_send_mutex;
|
||||||
std::vector<std::byte> m_send_buffer GUARDED_BY(m_send_mutex);
|
std::vector<std::byte> m_send_buffer GUARDED_BY(m_send_mutex);
|
||||||
/// @}
|
/// @}
|
||||||
|
|
||||||
@@ -570,6 +570,11 @@ public:
|
|||||||
HTTPRemoteClient(const HTTPRemoteClient&) = delete;
|
HTTPRemoteClient(const HTTPRemoteClient&) = delete;
|
||||||
HTTPRemoteClient& operator=(const HTTPRemoteClient&) = delete;
|
HTTPRemoteClient& operator=(const HTTPRemoteClient&) = delete;
|
||||||
|
|
||||||
|
const std::string& GetOrigin() const { return m_origin; }
|
||||||
|
const CService& GetPeer() const { return m_addr; }
|
||||||
|
std::shared_ptr<Sock> GetSock() EXCLUSIVE_LOCKS_REQUIRED(!m_sock_mutex) { return WITH_LOCK(m_sock_mutex, return m_sock;); }
|
||||||
|
bool ReadyToSend() const EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex) { return WITH_LOCK(m_send_mutex, return m_send_ready;); }
|
||||||
|
|
||||||
void Send(const HTTPResponse& res, std::span<const std::byte> reply_body, bool keep_alive) EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex, !m_sock_mutex);
|
void Send(const HTTPResponse& res, std::span<const std::byte> reply_body, bool keep_alive) EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex, !m_sock_mutex);
|
||||||
void Receive() EXCLUSIVE_LOCKS_REQUIRED(!m_sock_mutex);
|
void Receive() EXCLUSIVE_LOCKS_REQUIRED(!m_sock_mutex);
|
||||||
|
|
||||||
|
|||||||
@@ -857,7 +857,7 @@ BOOST_AUTO_TEST_CASE(http_server_socket_tests)
|
|||||||
// Inspect the connection pointed to from the request
|
// Inspect the connection pointed to from the request
|
||||||
client = requests.front()->GetClient();
|
client = requests.front()->GetClient();
|
||||||
BOOST_REQUIRE(client);
|
BOOST_REQUIRE(client);
|
||||||
BOOST_CHECK_EQUAL(client->m_origin, "5.5.5.5:6789");
|
BOOST_CHECK_EQUAL(client->GetOrigin(), "5.5.5.5:6789");
|
||||||
|
|
||||||
// Respond to request
|
// Respond to request
|
||||||
requests.front()->WriteReply(HTTP_OK, "874140\n");
|
requests.front()->WriteReply(HTTP_OK, "874140\n");
|
||||||
|
|||||||
Reference in New Issue
Block a user