summaryrefslogtreecommitdiff
path: root/cpp/src/tests/PollerTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/tests/PollerTest.cpp')
-rw-r--r--cpp/src/tests/PollerTest.cpp58
1 files changed, 33 insertions, 25 deletions
diff --git a/cpp/src/tests/PollerTest.cpp b/cpp/src/tests/PollerTest.cpp
index 5b6b09ef65..19f641ca36 100644
--- a/cpp/src/tests/PollerTest.cpp
+++ b/cpp/src/tests/PollerTest.cpp
@@ -111,7 +111,8 @@ int main(int /*argc*/, char** /*argv*/)
PollerHandle h0(f0);
PollerHandle h1(f1);
- poller->addFd(h0, Poller::INOUT);
+ poller->registerHandle(h0);
+ poller->monitorHandle(h0, Poller::INOUT);
// h0 should be writable
Poller::Event event = poller->wait();
@@ -123,19 +124,16 @@ int main(int /*argc*/, char** /*argv*/)
cout << "Wrote(0): " << bytesWritten << " bytes\n";
// Wait for 500ms - h0 no longer writable
- poller->rearmFd(h0);
event = poller->wait(500000000);
assert(event.handle == 0);
// Test we can read it all now
- poller->addFd(h1, Poller::INOUT);
+ poller->registerHandle(h1);
+ poller->monitorHandle(h1, Poller::INOUT);
event = poller->wait();
assert(event.handle == &h1);
assert(event.type == Poller::READ_WRITABLE);
- // Can't interrupt, it's not active
- assert(poller->interrupt(h1) == false);
-
bytesRead = readALot(sv[1]);
assert(bytesRead == bytesWritten);
cout << "Read(1): " << bytesRead << " bytes\n";
@@ -145,39 +143,52 @@ int main(int /*argc*/, char** /*argv*/)
event = poller->wait();
assert(event.handle == &h0);
assert(event.type == Poller::INTERRUPTED);
- assert(poller->interrupt(h0) == false);
// Test multiple interrupts
- poller->rearmFd(h0);
- poller->rearmFd(h1);
assert(poller->interrupt(h0) == true);
assert(poller->interrupt(h1) == true);
- // Make sure we can't interrupt them again
- assert(poller->interrupt(h0) == false);
- assert(poller->interrupt(h1) == false);
+ // Make sure we can interrupt them again
+ assert(poller->interrupt(h0) == true);
+ assert(poller->interrupt(h1) == true);
- // Make sure that they both come out in the correct order
+ // Make sure that they both come out
event = poller->wait();
- assert(event.handle == &h0);
assert(event.type == Poller::INTERRUPTED);
- assert(poller->interrupt(h0) == false);
+ assert(event.handle == &h0 || event.handle == &h1);
+ if (event.handle == &h0) {
+ event = poller->wait();
+ assert(event.type == Poller::INTERRUPTED);
+ assert(event.handle == &h1);
+ } else {
+ event = poller->wait();
+ assert(event.type == Poller::INTERRUPTED);
+ assert(event.handle == &h0);
+ }
+
+ poller->unmonitorHandle(h1, Poller::INOUT);
+
event = poller->wait();
- assert(event.handle == &h1);
- assert(event.type == Poller::INTERRUPTED);
- assert(poller->interrupt(h1) == false);
+ assert(event.handle == &h0);
+ assert(event.type == Poller::WRITABLE);
- // At this point h1 should have been disabled from the poller
- // (as it was just returned) and h0 can write again
- poller->rearmFd(h0);
+ // We didn't write anything so it should still be writable
event = poller->wait();
assert(event.handle == &h0);
assert(event.type == Poller::WRITABLE);
- // Now both the handles should be disabled
+ poller->unmonitorHandle(h0, Poller::INOUT);
+
event = poller->wait(500000000);
assert(event.handle == 0);
+ poller->unregisterHandle(h1);
+ poller->unregisterHandle(h0);
+
+ // Make sure we can't interrupt them now
+ assert(poller->interrupt(h0) == false);
+ assert(poller->interrupt(h1) == false);
+
// Test shutdown
poller->shutdown();
event = poller->wait();
@@ -188,9 +199,6 @@ int main(int /*argc*/, char** /*argv*/)
assert(event.handle == 0);
assert(event.type == Poller::SHUTDOWN);
- poller->delFd(h1);
- poller->delFd(h0);
-
return 0;
} catch (exception& e) {
cout << "Caught exception " << e.what() << "\n";