diff --git a/src/common/net/asio_http_cli.h b/src/common/net/asio_http_cli.h index 033becb59..439e216e4 100644 --- a/src/common/net/asio_http_cli.h +++ b/src/common/net/asio_http_cli.h @@ -490,6 +490,23 @@ class AsioHttpClientPool } }; + // Define ClientKey struct inside the AsioHttpClientPool class + struct ClientKey { + std::string host; + std::string service; + + bool operator==(const ClientKey& rhs) const { + return host == rhs.host && service == rhs.service; + } + + // Custom hash function for ClientKey + struct Hash { + std::size_t operator()(const ClientKey& key) const { + return std::hash()(key.host) ^ (std::hash()(key.service) << 1); + } + }; + }; + explicit AsioHttpClientPool(const std::shared_ptr& io_ptr) : io_ptr_(io_ptr), mgr_strand_(boost::asio::make_strand(*io_ptr_)), @@ -550,7 +567,7 @@ class AsioHttpClientPool co_return std::shared_ptr(); } - auto client_key = client_options.host + client_options.service; + ClientKey client_key{client_options.host, client_options.service}; auto itr = client_map_.find(client_key); if (itr != client_map_.end()) { @@ -605,7 +622,7 @@ class AsioHttpClientPool std::atomic state_ = State::kPreInit; // client管理 - std::unordered_map> client_map_; + std::unordered_map, ClientKey::Hash> client_map_; }; } // namespace aimrt::common::net