Skip to content

Commit

Permalink
Unit tests for XmlRpcDispatch (#1232)
Browse files Browse the repository at this point in the history
* Unit tests for XmlRpcDispatch

* Fix handling of out-of-band (Exception) request and and event
processing to match previous select() implementation.
* Update comments to describe the events that actually trigger and
Exception state.
* Unit tests for XmlRpcDispatch to verify that it calls poll()
correctly, requests the correct events and calls the correct handler
for those events.

* Cleanup from internal review

* revert unnecessary whitespace changes
  • Loading branch information
trainman419 authored and dirk-thomas committed Nov 16, 2017
1 parent 46d5ba4 commit 04961fe
Show file tree
Hide file tree
Showing 4 changed files with 366 additions and 3 deletions.
2 changes: 1 addition & 1 deletion utilities/xmlrpcpp/include/xmlrpcpp/XmlRpcDispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace XmlRpc {
enum EventType {
ReadableEvent = 1, //!< data available to read
WritableEvent = 2, //!< connected/data can be written without blocking
Exception = 4 //!< uh oh
Exception = 4 //!< out-of-band data has arrived
};

//! Monitor this source for the event types specified by the event mask
Expand Down
7 changes: 5 additions & 2 deletions utilities/xmlrpcpp/src/XmlRpcDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ XmlRpcDispatch::work(double timeout)
const unsigned POLLIN_CHK = (POLLIN | POLLHUP | POLLERR); // Readable or connection lost
const unsigned POLLOUT_REQ = POLLOUT; // Request write
const unsigned POLLOUT_CHK = (POLLOUT | POLLERR); // Writable or connection lost
const unsigned POLLEX_CHK = (POLLPRI | POLLNVAL); // Exception or invalid fd
const unsigned POLLEX_REQ = POLLPRI; // Out-of-band data received
const unsigned POLLEX_CHK = (POLLPRI | POLLNVAL); // Out-of-band data or invalid fd

// Compute end time
_endTime = (timeout < 0.0) ? -1.0 : (getTime() + timeout);
Expand All @@ -110,6 +111,7 @@ XmlRpcDispatch::work(double timeout)
fds[i].events = 0;
if (it->getMask() & ReadableEvent) fds[i].events |= POLLIN_REQ;
if (it->getMask() & WritableEvent) fds[i].events |= POLLOUT_REQ;
if (it->getMask() & Exception) fds[i].events |= POLLEX_REQ;
}

// Check for events
Expand All @@ -132,11 +134,12 @@ XmlRpcDispatch::work(double timeout)
// Only handle requested events to avoid being prematurely removed from dispatch
bool readable = (pfd.events & POLLIN_REQ) == POLLIN_REQ;
bool writable = (pfd.events & POLLOUT_REQ) == POLLOUT_REQ;
bool oob = (pfd.events & POLLEX_REQ) == POLLEX_REQ;
if (readable && (pfd.revents & POLLIN_CHK))
newMask &= src->handleEvent(ReadableEvent);
if (writable && (pfd.revents & POLLOUT_CHK))
newMask &= src->handleEvent(WritableEvent);
if (pfd.revents & POLLEX_CHK)
if (oob && (pfd.revents & POLLEX_CHK))
newMask &= src->handleEvent(Exception);

// Find the source iterator. It may have moved as a result of the way
Expand Down
14 changes: 14 additions & 0 deletions utilities/xmlrpcpp/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ catkin_add_gtest(test_client
)
target_link_libraries(test_client mock_socket)

catkin_add_gtest(test_dispatch
test_dispatch.cpp
../src/XmlRpcDispatch.cpp
../src/XmlRpcSource.cpp
../src/XmlRpcUtil.cpp
../libb64/src/cdecode.c
../libb64/src/cencode.c
)
target_link_libraries(test_dispatch mock_socket)
set_target_properties(test_dispatch PROPERTIES
LINK_FLAGS
"-Wl,--wrap=select -Wl,--wrap=poll"
)

if(NOT WIN32)
catkin_add_gtest(test_socket
test_socket.cpp
Expand Down
Loading

0 comments on commit 04961fe

Please sign in to comment.