diff options
author | Andrew Stitcher <astitcher@apache.org> | 2009-05-04 15:55:21 +0000 |
---|---|---|
committer | Andrew Stitcher <astitcher@apache.org> | 2009-05-04 15:55:21 +0000 |
commit | 564d179640cf49feeb8ff84133f892499afb0e65 (patch) | |
tree | d6fb4c2f2c789379937c2b622772cea2aed69e1d /cpp/src/tests/PollerTest.cpp | |
parent | c912884c11debf57e8c154fba7dbbcae8ea34d90 (diff) | |
download | qpid-python-564d179640cf49feeb8ff84133f892499afb0e65.tar.gz |
Refactored the DispatchHandle/Poller code to remove a long standing
set of race conditions.
- Changed Poller naming for better clarity with
new semantics.
- Changed Poller semantics to avoid DispatchHandle
keeping so much state
- Changed Poller so that it will never re-enable a
Handle until Poller::wait is called again on the same thread
that returned the Handle.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@771338 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/tests/PollerTest.cpp')
-rw-r--r-- | cpp/src/tests/PollerTest.cpp | 58 |
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"; |