aboutsummaryrefslogtreecommitdiff
path: root/res_stats.cpp
diff options
context:
space:
mode:
authorBernie Innocenti <codewiz@google.com>2018-09-25 14:23:19 +0900
committerBernie Innocenti <codewiz@google.com>2018-10-03 12:28:45 +0900
commit8fca66a3ba8ca1076d44a60fb15187e7c7fff482 (patch)
tree4d3e4c9c9e3aabe0638293a977e749897fcdc5aa /res_stats.cpp
parentbd42b10f05062989a730b61e610082920cb1b4ea (diff)
downloadDnsResolver-8fca66a3ba8ca1076d44a60fb15187e7c7fff482.tar.gz
Limit C linkage to public symbols
Switched all internal functions to C++ linkage. This makes it harder to accidentally call a function with a mismatched signature, and paves the way to using C++ data structures internally. This is the current list of symbols expoted by libnetd_resolv.so: _resolv_delete_cache_for_net _resolv_flush_cache_for_net _resolv_set_nameservers_for_net android_getaddrinfofornet android_getaddrinfofornetcontext android_gethostbyaddrfornet android_gethostbyaddrfornetcontext android_gethostbynamefornet android_gethostbynamefornetcontext android_net_res_stats_aggregate android_net_res_stats_get_info_for_net android_net_res_stats_get_usable_servers A mass-renaming pass would improve consistency. Perhaps we could use the prefix "netd_resolv_", or just "resolv_" for brevity. Once we begin shipping netd binaries using this interface, we might have to live with it for some time. Test: atest netd_integration_test (after flashing with new netd binary) Change-Id: I52f32add73fd908ad4a715ef8f8aff1f8d9733d0
Diffstat (limited to 'res_stats.cpp')
-rw-r--r--res_stats.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/res_stats.cpp b/res_stats.cpp
index e2cfd178..e6c2b65b 100644
--- a/res_stats.cpp
+++ b/res_stats.cpp
@@ -33,16 +33,16 @@ static_assert(kVerboseLogging == false,
"Do not enable in release builds.");
#endif
-/* Calculate the round-trip-time from start time t0 and end time t1. */
-int _res_stats_calculate_rtt(const struct timespec* t1, const struct timespec* t0) {
+// Calculate the round-trip-time from start time t0 and end time t1.
+int _res_stats_calculate_rtt(const timespec* t1, const timespec* t0) {
// Divide ns by one million to get ms, multiply s by thousand to get ms (obvious)
long ms0 = t0->tv_sec * 1000 + t0->tv_nsec / 1000000;
long ms1 = t1->tv_sec * 1000 + t1->tv_nsec / 1000000;
return (int) (ms1 - ms0);
}
-/* Create a sample for calculating server reachability statistics. */
-void _res_stats_set_sample(struct __res_sample* sample, time_t now, int rcode, int rtt) {
+// Create a sample for calculating server reachability statistics.
+void _res_stats_set_sample(__res_sample* sample, time_t now, int rcode, int rtt) {
VLOG << __func__ << ": rcode = " << rcode << ", sec = " << rtt;
sample->at = now;
sample->rcode = rcode;
@@ -116,7 +116,10 @@ void android_net_res_stats_aggregate(struct __res_stats* stats, int* successes,
*last_sample_time = last;
}
-bool _res_stats_usable_server(const struct __res_params* params, struct __res_stats* stats) {
+// Returns true if the server is considered unusable, i.e. if the success rate is not lower than the
+// threshold for the stored stored samples. If not enough samples are stored, the server is
+// considered usable.
+static bool res_stats_usable_server(const struct __res_params* params, struct __res_stats* stats) {
int successes = -1;
int errors = -1;
int timeouts = -1;
@@ -160,7 +163,7 @@ void android_net_res_stats_get_usable_servers(const struct __res_params* params,
bool usable_servers[]) {
unsigned usable_servers_found = 0;
for (int ns = 0; ns < nscount; ns++) {
- bool usable = _res_stats_usable_server(params, &stats[ns]);
+ bool usable = res_stats_usable_server(params, &stats[ns]);
if (usable) {
++usable_servers_found;
}