summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2020-12-07 10:30:10 +0100
committerGitHub <noreply@github.com>2020-12-07 10:30:10 +0100
commitf2ececfb183ef73d6a53d74ee84798e0dc7eaf36 (patch)
treeea5f49f9b0e8e5eb5489583e1bdc7c2ca64acd06 /vespalib
parent60d60a7c1cdf2c9672acdbeeeff72a941140f72b (diff)
parent39e2644a2b4e71541afeca30f98edfbffcfe4a50 (diff)
Merge pull request #15695 from vespa-engine/balder/optional-wakeup-handling
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;
}
};