-
Notifications
You must be signed in to change notification settings - Fork 1
/
listing_3.13.cpp
29 lines (26 loc) · 752 Bytes
/
listing_3.13.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <mutex>
#include <map>
#include <string>
#include <boost/thread/shared_mutex.hpp>
class dns_entry {};
class dns_cache
{
std::map<std::string, dns_entry> entries;
mutable boost::shared_mutex entry_mutex;
public:
dns_entry find_entry(std::string const &domain) const
{
boost::shared_lock<boost::shared_mutex> lk(entry_mutex);
std::map<std::string, dns_entry>::const_iterator const it = entries.find(domain);
return (it == entries.end()) ? dns_entry() : it->second;
}
void update_or_add_entry(std::string const &domain, dns_entry const &dns_details)
{
std::lock_guard<boost::shared_mutex> lk(entry_mutex);
entries[domain] = dns_details;
}
};
int main()
{
return 0;
}