summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2020-12-05 16:30:20 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2020-12-05 16:30:20 +0000
commit37e31c53ee371db126c31a3e3fca8c1904a3fba7 (patch)
treea371e626900d8475fcc3f96ebf496fca6b3cd68d /vespalib
parent807ff44ac51dae209de0cfe4c5a062f2e142b48b (diff)
Only handle wakeup if necessary.
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/tests/net/selector/selector_test.cpp7
-rw-r--r--vespalib/src/vespa/vespalib/net/selector.h6
2 files changed, 11 insertions, 2 deletions
diff --git a/vespalib/src/tests/net/selector/selector_test.cpp b/vespalib/src/tests/net/selector/selector_test.cpp
index 7d7a147bcb2..5c91dfdc122 100644
--- a/vespalib/src/tests/net/selector/selector_test.cpp
+++ b/vespalib/src/tests/net/selector/selector_test.cpp
@@ -77,7 +77,12 @@ struct Fixture {
}
Fixture &poll(int timeout_ms = 60000) {
selector.poll(timeout_ms);
- selector.dispatch(*this);
+ auto dispatchResult = selector.dispatch(*this);
+ if (wakeup) {
+ EXPECT_TRUE(dispatchResult == SelectorDispatchResult::WAKEUP_CALLED);
+ } else {
+ EXPECT_TRUE(dispatchResult == SelectorDispatchResult::NO_WAKEUP);
+ }
return *this;
}
void verify(bool expect_wakeup, std::vector<std::pair<bool,bool> > expect_events) {
diff --git a/vespalib/src/vespa/vespalib/net/selector.h b/vespalib/src/vespa/vespalib/net/selector.h
index 6b1967ddcd9..24b3abc806e 100644
--- a/vespalib/src/vespa/vespalib/net/selector.h
+++ b/vespalib/src/vespa/vespalib/net/selector.h
@@ -31,6 +31,7 @@ public:
};
//-----------------------------------------------------------------------------
+enum class SelectorDispatchResult {WAKEUP_CALLED, NO_WAKEUP};
template <typename Context>
class Selector
@@ -55,11 +56,13 @@ public:
void poll(int timeout_ms) { _events.extract(_epoll, timeout_ms); }
size_t num_events() const { return _events.size(); }
template <typename Handler>
- void dispatch(Handler &handler) {
+ SelectorDispatchResult dispatch(Handler &handler) {
+ SelectorDispatchResult result = SelectorDispatchResult::NO_WAKEUP;
for (const auto &evt: _events) {
if (evt.data.ptr == nullptr) {
_wakeup_pipe.read_tokens();
handler.handle_wakeup();
+ result = SelectorDispatchResult::WAKEUP_CALLED;
} else {
Context &ctx = *((Context *)(evt.data.ptr));
bool read = ((evt.events & (EPOLLIN | EPOLLERR | EPOLLHUP)) != 0);
@@ -67,6 +70,7 @@ public:
handler.handle_event(ctx, read, write);
}
}
+ return result;
}
};