namespace {
/// @brief Client side connection timeout.
+/// @todo Make it configurable.
const long CONNECTION_TIMEOUT = 5000;
}
// Capture error code and parsed data.
received_ec = ec;
received_feed = feed;
- // Stop the IO service so as we can continue.
+ // Got the IO service so stop IO service. This causes to
+ // stop IO service when all handlers have been invoked.
io_service->stopWork();
}, ClientConnection::Timeout(CONNECTION_TIMEOUT));
io_service->run();
#include <exceptions/exceptions.h>
#include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp>
-#include <array>
namespace isc {
namespace agent {
bindServerSocket(server_response, true);
// The client side communication is synchronous. To be able to respond
- // to this we need to run the server side socket at the same time.
- // Running IO service in a thread guarantees that the server responds
- // as soon as it receives the control command.
+ // to this we need to run the server side socket at the same time as the
+ // client. Running IO service in a thread guarantees that the server
+ //responds as soon as it receives the control command.
isc::util::thread::Thread th(boost::bind(&IOService::run,
getIOService().get()));
ConstElementPtr answer = mgr_.handleCommand("foo", ConstElementPtr(),
command);
+ // Cancel all asynchronous operations and let the handlers to be invoked
+ // with operation_aborted error code.
server_socket_->stopServer();
getIOService()->stopWork();
+ // Wait for the thread to finish.
th.wait();
EXPECT_EQ(expected_responses, server_socket_->getResponseNum());
-
checkAnswer(answer, expected_result0, expected_result1, expected_result2);
}
ConstElementPtr answer = mgr_.handleCommand("list-commands", ConstElementPtr(),
command);
+ // Cancel all asynchronous operations and let the handlers to be invoked
+ // with operation_aborted error code.
server_socket_->stopServer();
getIOService()->stopWork();
+ // Wait for the thread to finish.
th.wait();
// Answer of 3 is specific to the stub response we send when the
connect_handler_invoked = true;
// Operation aborted indicates that IO service has been stopped. This
// shouldn't happen here.
- if (ec && ec.value() != boost::asio::error::operation_aborted) {
+ if (ec && (ec.value() != boost::asio::error::operation_aborted)) {
ADD_FAILURE() << "error occurred while asynchronously connecting"
" via unix domain socket: " << ec.message();
}
server_acceptor_.listen();
accept();
+ // When threads are in use, we need to post a handler which will be invoked
+ // when the thread has already started and the IO service is running. The
+ // main thread can move forward when it receives this signal from the handler.
if (use_thread) {
io_service_.post(boost::bind(&TestServerUnixSocket::signalRunning,
this));
/// @brief Asynchronously receive data over the socket.
///
/// This method schedules asynchronous receive and installs the
- /// @ref UnixDomainSocket::receiveHandler is a callback.
+ /// @ref UnixDomainSocketImpl::receiveHandler is a callback.
///
/// @param data Pointer to a buffer into which the data should be read.
/// @param length Length of the buffer.
///
/// @param data Pointer to data to be sent.
/// @param length Number of bytes to be sent.
- /// @param handler Callback to be invoked when data have been sent or an
+ /// @param handler Callback to be invoked when data have been sent or
/// sending error is signalled.
void asyncSend(const void* data, const size_t length, const Handler& handler);
/// @brief Test timeout in ms.
const long TEST_TIMEOUT = 10000;
+// Test fixture class for @ref ClientConnection.
class ClientConnectionTest : public ::testing::Test {
public: