summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2023-09-27 12:19:25 -0700
committerMaciej Żenczykowski <maze@google.com>2023-10-09 23:08:16 +0000
commitddd5ff98ea659d25adfc0748a343b7da2405c835 (patch)
tree65b1e329a453be21f02bbc050d7d3bda5b5a578f /server
parentfb97cb549ff1f3174d32d75148164ccdb5a1b23a (diff)
downloadnetd-ddd5ff98ea659d25adfc0748a343b7da2405c835.tar.gz
MDnsSdListener.cpp: switch to libbase properties functions.
It's less code, it's clearer code, and it removes the sleeps while waiting for a property to change (turning it into a wait on a futex) for better responsiveness too. Bug: http://b/302208409 Test: treehugger Change-Id: I1d01ce639ad474ace5864a76d17e548c0f3b249c
Diffstat (limited to 'server')
-rw-r--r--server/MDnsSdListener.cpp36
1 files changed, 8 insertions, 28 deletions
diff --git a/server/MDnsSdListener.cpp b/server/MDnsSdListener.cpp
index 6955e8fc..7a9cb0bc 100644
--- a/server/MDnsSdListener.cpp
+++ b/server/MDnsSdListener.cpp
@@ -37,7 +37,7 @@
#define DBG 1
#define VDBG 1
-#include <cutils/properties.h>
+#include <android-base/properties.h>
#include <log/log.h>
#include <netdutils/ThreadUtil.h>
#include <sysutils/SocketClient.h>
@@ -61,6 +61,8 @@ using android::net::mdns::aidl::IMDnsEventListener;
using android::net::mdns::aidl::RegistrationInfo;
using android::net::mdns::aidl::ResolutionInfo;
+using namespace std::chrono_literals;
+
static unsigned ifaceIndexToNetId(uint32_t interfaceIndex) {
char interfaceName[IFNAMSIZ] = {};
unsigned netId;
@@ -388,35 +390,13 @@ MDnsSdListener::Monitor::~Monitor() {
delete mRescanThread;
if (VDBG) ALOGD("Monitor recycled");
}
-#define NAP_TIME 200 // 200 ms between polls
-static int wait_for_property(const char *name, const char *desired_value, int maxwait)
-{
- char value[PROPERTY_VALUE_MAX] = {'\0'};
- int maxnaps = (maxwait * 1000) / NAP_TIME;
-
- if (maxnaps < 1) {
- maxnaps = 1;
- }
-
- while (maxnaps-- > 0) {
- usleep(NAP_TIME * 1000);
- if (property_get(name, value, nullptr)) {
- if (desired_value == nullptr || strcmp(value, desired_value) == 0) {
- return 0;
- }
- }
- }
- return -1; /* failure */
-}
int MDnsSdListener::Monitor::startService() {
- char property_value[PROPERTY_VALUE_MAX];
std::lock_guard guard(mMutex);
- property_get(MDNS_SERVICE_STATUS, property_value, "");
- if (strcmp("running", property_value) != 0) {
+ if (android::base::GetProperty(MDNS_SERVICE_STATUS, "") != "running") {
ALOGD("Starting MDNSD");
- property_set("ctl.start", MDNS_SERVICE_NAME);
- wait_for_property(MDNS_SERVICE_STATUS, "running", 5);
+ android::base::SetProperty("ctl.start", MDNS_SERVICE_NAME);
+ android::base::WaitForProperty(MDNS_SERVICE_STATUS, "running", 5s);
return -1;
}
return 0;
@@ -426,8 +406,8 @@ int MDnsSdListener::Monitor::stopService() {
std::lock_guard guard(mMutex);
if (mHead == nullptr) {
ALOGD("Stopping MDNSD");
- property_set("ctl.stop", MDNS_SERVICE_NAME);
- wait_for_property(MDNS_SERVICE_STATUS, "stopped", 5);
+ android::base::SetProperty("ctl.stop", MDNS_SERVICE_NAME);
+ android::base::WaitForProperty(MDNS_SERVICE_STATUS, "stopped", 5s);
return -1;
}
return 0;