summaryrefslogtreecommitdiff
path: root/cmds/statsd/src/shell/ShellSubscriber.cpp
diff options
context:
space:
mode:
authorYao Chen <yaochen@google.com>2019-01-03 16:49:14 -0800
committerYao Chen <yaochen@google.com>2019-01-03 17:00:39 -0800
commit35cb8d6537614dbd56396c47c35cbabd46a411ad (patch)
treeb03999db3778236e07efd1ca58cc635349b27c38 /cmds/statsd/src/shell/ShellSubscriber.cpp
parent20a1afd998de4454ec930cf1ccf76ac9f2e661d7 (diff)
Add a timeout option in shell subscriber.
Test: cts added Change-Id: I0fe854fcfd5535ed03e502a4cad3f57079b45381
Diffstat (limited to 'cmds/statsd/src/shell/ShellSubscriber.cpp')
-rw-r--r--cmds/statsd/src/shell/ShellSubscriber.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/cmds/statsd/src/shell/ShellSubscriber.cpp b/cmds/statsd/src/shell/ShellSubscriber.cpp
index 22883f3c205a..52d5ffc33317 100644
--- a/cmds/statsd/src/shell/ShellSubscriber.cpp
+++ b/cmds/statsd/src/shell/ShellSubscriber.cpp
@@ -30,7 +30,8 @@ namespace statsd {
const static int FIELD_ID_ATOM = 1;
-void ShellSubscriber::startNewSubscription(int in, int out, sp<IResultReceiver> resultReceiver) {
+void ShellSubscriber::startNewSubscription(int in, int out, sp<IResultReceiver> resultReceiver,
+ int timeoutSec) {
VLOG("start new shell subscription");
{
std::lock_guard<std::mutex> lock(mMutex);
@@ -50,11 +51,18 @@ void ShellSubscriber::startNewSubscription(int in, int out, sp<IResultReceiver>
// Read config forever until EOF is reached. Clients may send multiple configs -- each new
// config replace the previous one.
readConfig(in);
+ VLOG("timeout : %d", timeoutSec);
// Now we have read an EOF we now wait for the semaphore until the client exits.
VLOG("Now wait for client to exit");
std::unique_lock<std::mutex> lk(mMutex);
- mShellDied.wait(lk, [this, resultReceiver] { return mResultReceiver != resultReceiver; });
+
+ if (timeoutSec > 0) {
+ mShellDied.wait_for(lk, timeoutSec * 1s,
+ [this, resultReceiver] { return mResultReceiver != resultReceiver; });
+ } else {
+ mShellDied.wait(lk, [this, resultReceiver] { return mResultReceiver != resultReceiver; });
+ }
}
void ShellSubscriber::updateConfig(const ShellSubscription& config) {