-// Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2017-2018 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
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();
+ // Stop IO service immediatelly and let the thread die.
+ getIOService()->stop();
// Wait for the thread to finish.
th.wait();
+ // Cancel all asynchronous operations on the server.
+ server_socket_->stopServer();
+
+ // We have some cancelled operations for which we need to invoke the
+ // handlers with the operation_aborted error code.
+ getIOService()->get_io_service().reset();
+ getIOService()->poll();
+
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();
+ // Stop IO service immediatelly and let the thread die.
+ getIOService()->stop();
// Wait for the thread to finish.
th.wait();
+ // Cancel all asynchronous operations on the server.
+ server_socket_->stopServer();
+
+ // We have some cancelled operations for which we need to invoke the
+ // handlers with the operation_aborted error code.
+ getIOService()->get_io_service().reset();
+ getIOService()->poll();
+
// Answer of 3 is specific to the stub response we send when the
// command is forwarded. So having this value returned means that
// the command was forwarded as expected.
-// Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2017-2018 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
/// @brief Closes the socket.
void stop() {
- socket_->close();
+ try {
+ socket_->close();
+
+ } catch (...) {
+ // ignore errors when closing the socket.
+ }
}
/// @brief Handler invoked when data have been received over the socket.
size_t bytes_transferred) {
// This is most likely due to the abort.
if (ec) {
+ // An error occurred so let's close the socket.
+ stop();
return;
}
boost::asio::buffer(response.c_str(), response.size()));
}
- start();
+ /// @todo We're taking simplistic approach and send a response right away
+ /// after receiving data over the socket. Therefore, after responding we
+ /// do not schedule another read. We could extend this logic slightly to
+ /// parse the received data and see when we've got enough data before we
+ /// send a response. However, the current unit tests don't really require
+ /// that.
// Invoke callback function to notify that the response has been sent.
sent_response_callback_();