Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add clear_resolved_cache implementation#893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
deanberris merged 3 commits intocpp-netlib:masterfromgns333:master
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletionsboost/network/protocol/http/policies/async_resolver.hpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -36,18 +36,21 @@ struct async_resolver : std::enable_shared_from_this<async_resolver<Tag> > {
typedef std::function<void(resolver_type &, string_type, std::uint16_t,
resolve_completion_function)> resolve_function;

void clear_resolved_cache() { clear_cache_.store(true); }

protected:
bool cache_resolved_;
std::atomic<bool> clear_cache_;
endpoint_cache endpoint_cache_;
std::shared_ptr<boost::asio::io_service> service_;
std::shared_ptr<boost::asio::io_service::strand> resolver_strand_;

explicit async_resolver(bool cache_resolved)
: cache_resolved_(cache_resolved), endpoint_cache_() {}
: cache_resolved_(cache_resolved),clear_cache_(false),endpoint_cache_() {}

void resolve(resolver_type &resolver_, string_type const &host,
std::uint16_t port, resolve_completion_function once_resolved) {
if (cache_resolved_) {
if (cache_resolved_ && !clear_cache_.load()) {
typename endpoint_cache::iterator iter =
endpoint_cache_.find(boost::to_lower_copy(host));
if (iter != endpoint_cache_.end()) {
Expand All@@ -74,6 +77,9 @@ struct async_resolver : std::enable_shared_from_this<async_resolver<Tag> > {
typename endpoint_cache::iterator iter;
bool inserted = false;
if (!ec && cache_resolved_) {
if (clear_cache_.exchange(false)) {
endpoint_cache_.clear();
}
std::tie(iter, inserted) = endpoint_cache_.insert(std::make_pair(
host, std::make_pair(endpoint_iterator, resolver_iterator())));
once_resolved(ec, iter->second);
Expand Down
9 changes: 8 additions & 1 deletionboost/network/protocol/http/policies/sync_resolver.hpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -27,19 +27,26 @@ struct sync_resolver {
typedef std::pair<resolver_iterator, resolver_iterator>
resolver_iterator_pair;

void clear_resolved_cache() { clear_cache_.store(true); }

protected:
typedef typename string<Tag>::type string_type;
typedef std::unordered_map<string_type, resolver_iterator_pair>
resolved_cache;
resolved_cache endpoint_cache_;
bool cache_resolved_;
std::atomic<bool> clear_cache_;

explicit sync_resolver(bool cache_resolved) : cache_resolved_(cache_resolved) {}
explicit sync_resolver(bool cache_resolved)
: cache_resolved_(cache_resolved), clear_cache_(false) {}

resolver_iterator_pair resolve(resolver_type& resolver_,
string_type /*unused*/const& hostname,
string_type const& port) {
if (cache_resolved_) {
if (clear_cache_.exchange(false)) {
endpoint_cache_.clear();
}
typename resolved_cache::iterator cached_iterator =
endpoint_cache_.find(hostname);
if (cached_iterator == endpoint_cache_.end()) {
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp