summaryrefslogtreecommitdiff
path: root/server/NetworkController.cpp
diff options
context:
space:
mode:
authorHugo Benichi <hugobenichi@google.com>2018-01-18 10:33:22 +0900
committerHugo Benichi <hugobenichi@google.com>2018-01-19 14:37:12 +0900
commita9e3c5da83c83063a50a50e3ed9ca7ee7a3bbb87 (patch)
tree155c182e808fd024e8eb848bee78c921c1f7cad0 /server/NetworkController.cpp
parentfa8616c1cc1d6972da1fbd5745c1e0c86ec5daea (diff)
TcpSocketMonitor: add polling loop
TcpSocketMonitor starts a sock_diag polling thread in its ctor whose polling interval can be controlled with setPollingInterval() and suspendPolling(). Initially the polling thread will immediately be suspended. The polling thread is automatically started when 1 or more physical network exists, and automatically stopped when there is 0 physical networks. By default the polling interval is set to 30 secs. Also fix some code indentation issues. Bug: 64147860 Test: tested manually, watching the result of $ adb shell dumpsys netd tcp_socket_info Change-Id: I7fe356a0a073ebc83486bc774a3002648e9dd457
Diffstat (limited to 'server/NetworkController.cpp')
-rw-r--r--server/NetworkController.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/server/NetworkController.cpp b/server/NetworkController.cpp
index 43a55bdd..5b2cd892 100644
--- a/server/NetworkController.cpp
+++ b/server/NetworkController.cpp
@@ -355,6 +355,9 @@ int NetworkController::createPhysicalNetworkLocked(unsigned netId, Permission pe
}
mNetworks[netId] = physicalNetwork;
+
+ updateTcpSocketMonitorPolling();
+
return 0;
}
@@ -448,6 +451,9 @@ int NetworkController::destroyNetwork(unsigned netId) {
mNetworks.erase(netId);
delete network;
_resolv_delete_cache_for_net(netId);
+
+ updateTcpSocketMonitorPolling();
+
return ret;
}
@@ -730,5 +736,22 @@ int NetworkController::modifyFallthroughLocked(unsigned vpnNetId, bool add) {
return 0;
}
+void NetworkController::updateTcpSocketMonitorPolling() {
+ bool physicalNetworkExists = false;
+ for (const auto& entry : mNetworks) {
+ const auto& network = entry.second;
+ if (network->getType() == Network::PHYSICAL && network->getNetId() >= MIN_NET_ID) {
+ physicalNetworkExists = true;
+ break;
+ }
+ }
+
+ if (physicalNetworkExists) {
+ android::net::gCtls->tcpSocketMonitor.resumePolling();
+ } else {
+ android::net::gCtls->tcpSocketMonitor.suspendPolling();
+ }
+}
+
} // namespace net
} // namespace android