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
diff --git a/resolv/res_stats.cpp b/resolv/res_stats.cpp
index e2cfd17..e6c2b65 100644
--- a/resolv/res_stats.cpp
+++ b/resolv/res_stats.cpp
@@ -33,16 +33,16 @@
"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 @@
*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 @@
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;
}