// Forward command and receive reply.
IOServicePtr io_service(new IOService());;
- ClientConnection conn(*io_service);
+ ClientConnection conn(io_service);
boost::system::error_code received_ec;
ConstJSONFeedPtr received_feed;
conn.start(ClientConnection::SocketPath(socket_name),
// Create http listener. It will open up a TCP socket and be
// prepared to accept incoming connection.
HttpListenerPtr http_listener
- (new HttpListener(*getIOService(), server_address,
+ (new HttpListener(getIOService(), server_address,
server_port, tls_context, rcf,
HttpListener::RequestTimeout(TIMEOUT_AGENT_RECEIVE_COMMAND),
HttpListener::IdleTimeout(TIMEOUT_AGENT_IDLE_CONNECTION_TIMEOUT)));
/// @param use_thread Indicates if the IO service will be ran in thread.
void bindServerSocket(const std::string& response,
const bool use_thread = false) {
- server_socket_.reset(new test::TestServerUnixSocket(*getIOService(),
+ server_socket_.reset(new test::TestServerUnixSocket(getIOService(),
unixSocketFilePath(),
response));
server_socket_->startTimer(TEST_TIMEOUT);
// Tests that the SIGINT triggers a normal shutdown.
TEST_F(CtrlAgentControllerTest, sigintShutdown) {
// Setup to raise SIGHUP in 1 ms.
- TimedSignal sighup(*getIOService(), SIGINT, 1);
+ TimedSignal sighup(getIOService(), SIGINT, 1);
// Write valid_agent_config and then run launch() for a maximum
// of 1000 ms.
// Tests that the SIGTERM triggers a normal shutdown.
TEST_F(CtrlAgentControllerTest, sigtermShutdown) {
// Setup to raise SIGTERM in 1 ms.
- TimedSignal sighup(*getIOService(), SIGTERM, 1);
+ TimedSignal sighup(getIOService(), SIGTERM, 1);
// Write valid_agent_config and then run launch() for a maximum of 1 s.
time_duration elapsed_time;
// Schedule reconfiguration.
scheduleTimedWrite(second_config, 100);
// Schedule SIGHUP signal to trigger reconfiguration.
- TimedSignal sighup(*getIOService(), SIGHUP, 200);
+ TimedSignal sighup(getIOService(), SIGHUP, 200);
// Start the server.
time_duration elapsed_time;
// Schedule reconfiguration.
scheduleTimedWrite(second_config, 100);
// Schedule SIGHUP signal to trigger reconfiguration.
- TimedSignal sighup(*getIOService(), SIGHUP, 200);
+ TimedSignal sighup(getIOService(), SIGHUP, 200);
// Start the server.
time_duration elapsed_time;
// Schedule reconfiguration.
scheduleTimedWrite(second_config, 100);
// Schedule SIGHUP signal to trigger reconfiguration.
- TimedSignal sighup(*getIOService(), SIGHUP, 200);
+ TimedSignal sighup(getIOService(), SIGHUP, 200);
// Start the server.
time_duration elapsed_time;
TEST_F(CtrlAgentProcessTest, shutdown) {
// Use an asiolink IntervalTimer and callback to generate the
// shutdown invocation. (Note IntervalTimer setup is in milliseconds).
- IntervalTimer timer(*getIOService());
+ IntervalTimer timer(getIOService());
timer.setup(std::bind(&CtrlAgentProcessTest::genShutdownCallback, this),
200);
// Instruct the listener to start listening and set state accordingly.
try {
- listener_->startListening(*io_service_);
+ listener_->startListening(io_service_);
mgr_state_ = RUNNING;
} catch (const isc::Exception& ex) {
isc_throw(D2QueueMgrError, "D2QueueMgr listener start failed: "
scheduleTimedWrite("{ \"string_test\": BOGUS JSON }", 100);
// Setup to raise SIGHUP in 200 ms.
- TimedSignal sighup(*getIOService(), SIGHUP, 200);
+ TimedSignal sighup(getIOService(), SIGHUP, 200);
// Write valid_d2_config and then run launch() for a maximum of 500 ms.
time_duration elapsed_time;
scheduleTimedWrite(second_cfg, 100);
// Setup to raise SIGHUP in 200 ms.
- TimedSignal sighup(*getIOService(), SIGHUP, 200);
+ TimedSignal sighup(getIOService(), SIGHUP, 200);
// Write valid_d2_config and then run launch() for a maximum of 500ms.
time_duration elapsed_time;
// Tests that the SIGINT triggers a normal shutdown.
TEST_F(D2ControllerTest, sigintShutdown) {
// Setup to raise SIGINT in 1 ms.
- TimedSignal sighup(*getIOService(), SIGINT, 1);
+ TimedSignal sighup(getIOService(), SIGINT, 1);
// Write valid_d2_config and then run launch() for a maximum of 1000 ms.
time_duration elapsed_time;
// Tests that the SIGTERM triggers a normal shutdown.
TEST_F(D2ControllerTest, sigtermShutdown) {
// Setup to raise SIGTERM in 1 ms.
- TimedSignal sighup(*getIOService(), SIGTERM, 1);
+ TimedSignal sighup(getIOService(), SIGTERM, 1);
// Write valid_d2_config and then run launch() for a maximum of 1 s.
time_duration elapsed_time;
TEST_F(D2ProcessTest, normalShutdown) {
// Use an asiolink IntervalTimer and callback to generate the
// shutdown invocation. (Note IntervalTimer setup is in milliseconds).
- isc::asiolink::IntervalTimer timer(*getIOService());
+ isc::asiolink::IntervalTimer timer(getIOService());
timer.setup(std::bind(&D2ProcessTest::genShutdownCallback, this),
2 * 1000);
TEST_F(D2ProcessTest, fatalErrorShutdown) {
// Use an asiolink IntervalTimer and callback to generate the
// the exception. (Note IntervalTimer setup is in milliseconds).
- isc::asiolink::IntervalTimer timer(*getIOService());
+ isc::asiolink::IntervalTimer timer(getIOService());
timer.setup(std::bind(&D2ProcessTest::genFatalErrorCallback, this),
2 * 1000);
NameChangeSender::RequestSendHandler {
public:
asiolink::IOServicePtr io_service_;
- NameChangeSenderPtr sender_;
+ NameChangeSenderPtr sender_;
isc::asiolink::IntervalTimer test_timer_;
D2QueueMgrPtr queue_mgr_;
std::vector<NameChangeRequestPtr> received_ncrs_;
QueueMgrUDPTest() : io_service_(new isc::asiolink::IOService()),
- test_timer_(*io_service_),
+ test_timer_(io_service_),
send_result_(NameChangeSender::SUCCESS) {
isc::asiolink::IOAddress addr(TEST_ADDRESS);
// Create our sender instance. Note that reuse_address is true.
ASSERT_EQ(D2QueueMgr::RUNNING, queue_mgr_->getMgrState());
// Place the sender into sending state.
- ASSERT_NO_THROW(sender_->startSending(*io_service_));
+ ASSERT_NO_THROW(sender_->startSending(io_service_));
ASSERT_TRUE(sender_->amSending());
// Iterate over the list of requests sending and receiving
// Create a server based on the transaction's current server, and
// start it listening.
- FauxServer server(*io_service_, *(trans->getCurrentServer()));
+ FauxServer server(io_service_, *(trans->getCurrentServer()));
server.receive(FauxServer::USE_RCODE, dns::Rcode::NOERROR());
// Run sweep and IO until everything is done.
ASSERT_EQ(1, trans->getUpdateAttempts());
ASSERT_EQ(StateModel::NOP_EVT, trans->getNextEvent());
- // Create a server based on the transaction's current server,
- // and start it listening.
- FauxServer server(*io_service_, *(trans->getCurrentServer()));
+ // Create a server based on the transaction's current server, and
+ // start it listening.
+ FauxServer server(io_service_, *(trans->getCurrentServer()));
server.receive(FauxServer::USE_RCODE, dns::Rcode::NOERROR());
// Run sweep and IO until everything is done.
ASSERT_TRUE(trans->getCurrentServer());
// Create a server and start it listening.
- FauxServer server(*io_service_, *(trans->getCurrentServer()));
+ FauxServer server(io_service_, *(trans->getCurrentServer()));
server.receive(FauxServer::CORRUPT_RESP);
// Run sweep and IO until everything is done.
// that all of configured servers have the same address.
// and start it listening.
asiolink::IOAddress server_ip("127.0.0.1");
- FauxServer server(*io_service_, server_ip, 5301);
+ FauxServer server(io_service_, server_ip, 5301);
server.receive(FauxServer::USE_RCODE, dns::Rcode::NOERROR());
// Run sweep and IO until everything is done.
// Create a server based on the transaction's current server, and
// start it listening.
- FauxServer server(*io_service_, *(trans->getCurrentServer()));
+ FauxServer server(io_service_, *(trans->getCurrentServer()));
server.receive(FauxServer::USE_RCODE, dns::Rcode::NOERROR());
// Run sweep and IO until everything is done.
ASSERT_EQ(1, trans->getUpdateAttempts());
ASSERT_EQ(StateModel::NOP_EVT, trans->getNextEvent());
- // Create a server based on the transaction's current server,
- // and start it listening.
- FauxServer server(*io_service_, *(trans->getCurrentServer()));
+ // Create a server based on the transaction's current server, and
+ // start it listening.
+ FauxServer server(io_service_, *(trans->getCurrentServer()));
server.receive(FauxServer::USE_RCODE, dns::Rcode::NOERROR());
// Run sweep and IO until everything is done.
/// stops the IO service and causes the function to return.
void runTimersWithTimeout(const IOServicePtr& io_service, const long timeout_ms,
std::function<bool()> cond = std::function<bool()>()) {
- IntervalTimer timer(*io_service);
+ IntervalTimer timer(io_service);
std::atomic<bool> stopped(false);
timer.setup([&io_service, &stopped]() {
stopped = true;
/// stops the IO service and causes the function to return.
void runTimersWithTimeout(const IOServicePtr& io_service, const long timeout_ms,
std::function<bool()> cond = std::function<bool()>()) {
- IntervalTimer timer(*io_service);
+ IntervalTimer timer(io_service);
std::atomic<bool> stopped(false);
timer.setup([&io_service, &stopped]() {
stopped = true;
}
IOServicePtr io_service(new IOService());
- HttpClient client(*io_service, false);
+ HttpClient client(io_service, false);
boost::system::error_code received_ec;
string receive_errmsg;
HttpResponseJsonPtr response(new HttpResponseJson());
/// @brief Constructor.
UnixControlSocketTest()
- : ThreadedTest(), io_service_() {
+ : ThreadedTest(), io_service_(new IOService()) {
}
void SetUp() override {
// io_service must be stopped after the thread returns,
// otherwise the thread may never return if it is
// waiting for the completion of some asynchronous tasks.
- io_service_.stop();
+ io_service_->stop();
removeUnixSocketFile();
}
void reflectServer();
/// @brief IOService object.
- IOService io_service_;
+ IOServicePtr io_service_;
}; // UnixControlSocketTest
/// @brief Server method running in a thread reflecting the command.
UnixControlSocketTest::reflectServer() {
// Acceptor.
boost::asio::local::stream_protocol::acceptor
- acceptor(io_service_.getInternalIOService());
+ acceptor(io_service_->getInternalIOService());
EXPECT_NO_THROW_LOG(acceptor.open());
boost::asio::local::stream_protocol::endpoint
endpoint(unixSocketFilePath());
EXPECT_NO_THROW_LOG(acceptor.bind(endpoint));
EXPECT_NO_THROW_LOG(acceptor.listen());
boost::asio::local::stream_protocol::socket
- socket(io_service_.getInternalIOService());
+ socket(io_service_->getInternalIOService());
// Ready.
signalReady();
accepted = true;
});
while (!accepted && !timeout) {
- io_service_.runOne();
+ io_service_->runOne();
}
ASSERT_FALSE(ec);
received = cnt;
});
while (!received && !timeout) {
- io_service_.runOne();
+ io_service_->runOne();
}
ASSERT_FALSE(ec);
rbuf.resize(received);
sent = cnt;
});
while (!sent && !timeout) {
- io_service_.runOne();
+ io_service_->runOne();
}
ASSERT_FALSE(ec);
/// @brief Test fixture class for http control sockets.
class HttpControlSocketTest : public ThreadedTest {
public:
+ /// @brief Constructor.
+ HttpControlSocketTest() : io_service_(new IOService()) {
+ }
+
void SetUp() override {
SysrepoSetup::cleanSharedMemory();
}
// io_service must be stopped after the thread returns,
// otherwise the thread may never return if it is
// waiting for the completion of some asynchronous tasks.
- io_service_.stop();
+ io_service_->stop();
}
/// @brief Returns socket URL.
signalReady();
// Until stop() is called run IO service.
while (!isStopping()) {
- io_service_.runOne();
+ io_service_->runOne();
}
// Main thread signalled that the thread should
// terminate. Launch any outstanding IO service
// handlers.
- io_service_.poll();
+ io_service_->poll();
// Nothing more to do. Signal that the thread is
// done so as the main thread can close HTTP
// listener and clean up after the test.
// If the thread is blocked on running the IO
// service, post the empty handler to cause
// runOne to return.
- io_service_.post([]() { return; });
+ io_service_->post([]() { return; });
// We asked that the thread stops. Let's wait
// for it to signal that it has stopped.
waitStopped();
}
/// @brief IOService object.
- IOService io_service_;
+ IOServicePtr io_service_;
/// @brief Pointer to listener.
HttpListenerPtr listener_;
HttpControlSocketTest::createReflectListener() {
HttpResponseCreatorFactoryPtr
factory(new TestHttpResponseCreatorFactory());
- listener_.reset(new
- HttpListener(io_service_,
- IOAddress(SERVER_ADDRESS), SERVER_PORT,
- TlsContextPtr(), factory,
- HttpListener::RequestTimeout(2000),
- HttpListener::IdleTimeout(2000)));
+ listener_.reset(new HttpListener(io_service_,
+ IOAddress(SERVER_ADDRESS), SERVER_PORT,
+ TlsContextPtr(), factory,
+ HttpListener::RequestTimeout(2000),
+ HttpListener::IdleTimeout(2000)));
}
// Verifies that the createControlSocket template can create a http
// Tests that the SIGINT triggers a normal shutdown.
TEST_F(NetconfControllerTest, sigintShutdown) {
// Setup to raise SIGINT in 1 ms.
- TimedSignal sighup(*getIOService(), SIGINT, 1);
+ TimedSignal sighup(getIOService(), SIGINT, 1);
// Write valid_netconf_config and then run launch() for a maximum
// of 500 ms.
// Tests that the SIGTERM triggers a normal shutdown.
TEST_F(NetconfControllerTest, sigtermShutdown) {
// Setup to raise SIGTERM in 1 ms.
- TimedSignal sighup(*getIOService(), SIGTERM, 1);
+ TimedSignal sighup(getIOService(), SIGTERM, 1);
// Write valid_netconf_config and then run launch() for a maximum
// of 500 ms.
TEST_F(NetconfProcessTest, shutdown) {
// Use an asiolink IntervalTimer and callback to generate the
// shutdown invocation. (Note IntervalTimer setup is in milliseconds).
- IntervalTimer timer(*getIOService());
+ IntervalTimer timer(getIOService());
timer.setup(std::bind(&NetconfProcessTest::genShutdownCallback, this),
200);
// Timeout.
bool timeout = false;
- IntervalTimer timer(*io_service_);
+ IntervalTimer timer(io_service_);
timer.setup([&timeout]() {
timeout = true;
FAIL() << "timeout";
UnixControlSocket::sendCommand(ConstElementPtr command) {
// We are using our own IO service because this method is synchronous.
IOServicePtr io_service(new IOService());
- ClientConnection conn(*io_service);
+ ClientConnection conn(io_service);
boost::system::error_code received_ec;
ConstJSONFeedPtr received_feed;
}
if (!timer_) {
- timer_.reset(new IntervalTimer(*io_service_));
+ timer_.reset(new IntervalTimer(io_service_));
}
if (settings_modified) {
// Create the client and(or) listener as appropriate.
if (!config_->getEnableMultiThreading()) {
// Not configured for multi-threading, start a client in ST mode.
- client_.reset(new HttpClient(*io_service_, false));
+ client_.reset(new HttpClient(io_service_, false));
} else {
// Create an MT-mode client.
- client_.reset(new HttpClient(*io_service_, true,
+ client_.reset(new HttpClient(io_service_, true,
config_->getHttpClientThreads(), true));
// If we're configured to use our own listener create and start it.
int
HAService::synchronize(std::string& status_message, const std::string& server_name,
const unsigned int max_period) {
-
lease_sync_filter_.apply();
- IOService io_service;
+ IOServicePtr io_service(new IOService());
HttpClient client(io_service, false);
asyncSyncLeases(client, server_name, max_period, Lease4Ptr(),
// The synchronization process is completed, so let's break
// the IO service so as we can return the response to the
// controlling client.
- io_service.stop();
+ io_service->stop();
});
} else {
status_message = error_message;
}
- io_service.stop();
+ io_service->stop();
}
});
// The synchronization process is completed, so let's break
// the IO service so as we can return the response to the
// controlling client.
- io_service.stop();
+ io_service->stop();
});
}
} else {
// Also stop IO service if there is no need to enable DHCP
// service.
- io_service.stop();
+ io_service->stop();
}
});
// Run the IO service until it is stopped by any of the callbacks. This
// makes it synchronous.
- io_service.run();
+ io_service->run();
// End measuring duration.
stopwatch.stop();
return (true);
}
- IOService io_service;
+ IOServicePtr io_service(new IOService());
HttpClient client(io_service, false);
auto remote_config = config_->getFailoverPeerConfig();
bool updates_successful = true;
asyncSendLeaseUpdatesFromBacklog(client, remote_config,
[&](const bool success, const std::string&, const int) {
- io_service.stop();
+ io_service->stop();
updates_successful = success;
});
Stopwatch stopwatch;
// Run the IO service until it is stopped by the callback. This makes it synchronous.
- io_service.run();
+ io_service->run();
// End measuring duration.
stopwatch.stop();
bool
HAService::sendHAReset() {
- IOService io_service;
+ IOServicePtr io_service(new IOService());
HttpClient client(io_service, false);
auto remote_config = config_->getFailoverPeerConfig();
bool reset_successful = true;
asyncSendHAReset(client, remote_config,
[&](const bool success, const std::string&, const int) {
- io_service.stop();
+ io_service->stop();
reset_successful = success;
});
// Run the IO service until it is stopped by the callback. This makes it synchronous.
- io_service.run();
+ io_service->run();
return (reset_successful);
}
// to know the type of the expected response.
HttpResponseJsonPtr response = boost::make_shared<HttpResponseJson>();
- IOService io_service;
+ IOServicePtr io_service(new IOService());
HttpClient client(io_service, false);
boost::system::error_code captured_ec;
const HttpResponsePtr& response,
const std::string& error_str) {
- io_service.stop();
+ io_service->stop();
// There are three possible groups of errors. One is the IO error
// causing issues in communication with the peer. Another one is
// Run the IO service until it is stopped by any of the callbacks. This
// makes it synchronous.
- io_service.run();
+ io_service->run();
// If there was a communication problem with the partner we assume that
// the partner is already down while we receive this command.
// to know the type of the expected response.
HttpResponseJsonPtr response = boost::make_shared<HttpResponseJson>();
- IOService io_service;
+ IOServicePtr io_service(new IOService());
HttpClient client(io_service, false);
std::string error_message;
const HttpResponsePtr& response,
const std::string& error_str) {
- io_service.stop();
+ io_service->stop();
// Handle first two groups of errors.
if (ec || !error_str.empty()) {
// Run the IO service until it is stopped by any of the callbacks. This
// makes it synchronous.
- io_service.run();
+ io_service->run();
// There was an error in communication with the partner or the
// partner was unable to revert its state.
factory_(new TestHttpResponseCreatorFactory()),
factory2_(new TestHttpResponseCreatorFactory()),
factory3_(new TestHttpResponseCreatorFactory()),
- listener_(new HttpListener(*io_service_, IOAddress(SERVER_ADDRESS),
+ listener_(new HttpListener(io_service_, IOAddress(SERVER_ADDRESS),
SERVER_PORT, TlsContextPtr(), factory_,
HttpListener::RequestTimeout(REQUEST_TIMEOUT),
HttpListener::IdleTimeout(IDLE_TIMEOUT))),
- listener2_(new HttpListener(*io_service_, IOAddress(SERVER_ADDRESS),
+ listener2_(new HttpListener(io_service_, IOAddress(SERVER_ADDRESS),
SERVER_PORT + 1, TlsContextPtr(), factory2_,
HttpListener::RequestTimeout(REQUEST_TIMEOUT),
HttpListener::IdleTimeout(IDLE_TIMEOUT))),
- listener3_(new HttpListener(*io_service_, IOAddress(SERVER_ADDRESS),
+ listener3_(new HttpListener(io_service_, IOAddress(SERVER_ADDRESS),
SERVER_PORT + 2, TlsContextPtr(), factory3_,
HttpListener::RequestTimeout(REQUEST_TIMEOUT),
HttpListener::IdleTimeout(IDLE_TIMEOUT))),
void
HATest::runIOService(long ms) {
io_service_->restart();
- IntervalTimer timer(*io_service_);
+ IntervalTimer timer(io_service_);
timer.setup(std::bind(&IOService::stop, io_service_), ms,
IntervalTimer::ONE_SHOT);
io_service_->run();
void
HATest::runIOService(long ms, std::function<bool()> stop_condition) {
io_service_->restart();
- IntervalTimer timer(*io_service_);
+ IntervalTimer timer(io_service_);
bool timeout = false;
timer.setup(std::bind(&HATest::stopIOServiceHandler, this, std::ref(timeout)),
ms, IntervalTimer::ONE_SHOT);
/// want keep the same data). Organising the data in this way keeps copying to
/// a minimum.
struct IOFetchData {
-
+ IOServicePtr io_service_; ///< The IO service
// The first two members are shared pointers to a base class because what is
// actually instantiated depends on whether the fetch is over UDP or TCP,
// which is not known until construction of the IOFetch. Use of a shared
// pointer here is merely to ensure deletion when the data object is deleted.
- boost::scoped_ptr<IOAsioSocket<IOFetch> > socket;
+ boost::scoped_ptr<IOAsioSocket<IOFetch>> socket;
///< Socket to use for I/O
boost::scoped_ptr<IOEndpoint> remote_snd;///< Where the fetch is sent
boost::scoped_ptr<IOEndpoint> remote_rcv;///< Where the response came from
- OutputBufferPtr msgbuf; ///< Wire buffer for question
- OutputBufferPtr received; ///< Received data put here
+ OutputBufferPtr msgbuf; ///< Wire buffer for question
+ OutputBufferPtr received; ///< Received data put here
IOFetch::Callback* callback; ///< Called on I/O Completion
boost::asio::deadline_timer timer; ///< Timer to measure timeouts
IOFetch::Protocol protocol; ///< Protocol being used
/// \param wait Timeout for the fetch (in ms).
///
/// TODO: May need to alter constructor (see comment 4 in Trac ticket #554)
- IOFetchData(IOFetch::Protocol proto, IOService& service,
+ IOFetchData(IOFetch::Protocol proto, const IOServicePtr& service,
const IOAddress& address, uint16_t port, OutputBufferPtr& buff,
- IOFetch::Callback* cb, int wait) :
+ IOFetch::Callback* cb, int wait) : io_service_(service),
socket((proto == IOFetch::UDP) ?
static_cast<IOAsioSocket<IOFetch>*>(
- new UDPSocket<IOFetch>(service)) :
+ new UDPSocket<IOFetch>(io_service_)) :
static_cast<IOAsioSocket<IOFetch>*>(
- new TCPSocket<IOFetch>(service))
+ new TCPSocket<IOFetch>(io_service_))
),
remote_snd((proto == IOFetch::UDP) ?
static_cast<IOEndpoint*>(new UDPEndpoint(address, port)) :
msgbuf(new OutputBuffer(512)),
received(buff),
callback(cb),
- timer(service.getInternalIOService()),
+ timer(io_service_->getInternalIOService()),
protocol(proto),
cumulative(0),
expected(0),
/// IOFetch Constructor - just initialize the private data
-IOFetch::IOFetch(Protocol protocol, IOService& service,
+IOFetch::IOFetch(Protocol protocol, const IOServicePtr& service,
const isc::dns::Question& question, const IOAddress& address,
uint16_t port, OutputBufferPtr& buff, Callback* cb, int wait, bool edns) {
MessagePtr query_msg(new Message(Message::RENDER));
cb, wait, edns);
}
-IOFetch::IOFetch(Protocol protocol, IOService& service,
+IOFetch::IOFetch(Protocol protocol, const IOServicePtr& service,
OutputBufferPtr& outpkt, const IOAddress& address, uint16_t port,
OutputBufferPtr& buff, Callback* cb, int wait) :
data_(new IOFetchData(protocol, service,
data_->packet = true;
}
-IOFetch::IOFetch(Protocol protocol, IOService& service,
+IOFetch::IOFetch(Protocol protocol, const IOServicePtr& service,
ConstMessagePtr query_message, const IOAddress& address, uint16_t port,
OutputBufferPtr& buff, Callback* cb, int wait) {
MessagePtr msg(new Message(Message::RENDER));
void
IOFetch::initIOFetch(MessagePtr& query_msg, Protocol protocol,
- IOService& service,
+ const IOServicePtr& service,
const isc::dns::Question& question,
const IOAddress& address, uint16_t port,
OutputBufferPtr& buff, Callback* cb, int wait, bool edns) {
/// -1 indicates no timeout.
/// \param edns true if the request should be EDNS. The default value is
/// true.
- IOFetch(Protocol protocol, isc::asiolink::IOService& service,
+ IOFetch(Protocol protocol, const isc::asiolink::IOServicePtr& service,
const isc::dns::Question& question,
const isc::asiolink::IOAddress& address,
uint16_t port, isc::util::OutputBufferPtr& buff, Callback* cb,
/// and deleting it if necessary.
/// \param wait Timeout for the fetch (in ms). The default value of
/// -1 indicates no timeout.
- IOFetch(Protocol protocol, isc::asiolink::IOService& service,
+ IOFetch(Protocol protocol, const isc::asiolink::IOServicePtr& service,
isc::dns::ConstMessagePtr query_message,
const isc::asiolink::IOAddress& address,
uint16_t port, isc::util::OutputBufferPtr& buff, Callback* cb,
/// (default = 53)
/// \param wait Timeout for the fetch (in ms). The default value of
/// -1 indicates no timeout.
- IOFetch(Protocol protocol, isc::asiolink::IOService& service,
+ IOFetch(Protocol protocol, const isc::asiolink::IOServicePtr& service,
isc::util::OutputBufferPtr& outpkt,
const isc::asiolink::IOAddress& address,
uint16_t port, isc::util::OutputBufferPtr& buff, Callback* cb,
/// parameter "query_message"
/// \param query_message the message to be sent out.
void initIOFetch(isc::dns::MessagePtr& query_message, Protocol protocol,
- isc::asiolink::IOService& service,
+ const isc::asiolink::IOServicePtr& service,
const isc::dns::Question& question,
const isc::asiolink::IOAddress& address, uint16_t port,
isc::util::OutputBufferPtr& buff, Callback* cb, int wait,
class IOFetchTest : public virtual ::testing::Test, public virtual IOFetch::Callback
{
public:
- IOService service_; ///< Service to run the query
+ IOServicePtr service_; ///< Service to run the query
IOFetch::Result expected_; ///< Expected result of the callback
bool run_; ///< Did the callback run already?
Question question_; ///< What to ask
/// \brief Constructor
IOFetchTest() :
- service_(),
+ service_(new IOService()),
expected_(IOFetch::NOTSET),
run_(false),
question_(Name("example.net"), RRClass::IN(), RRType::A()),
// Timeout interval chosen to ensure no timeout
protocol_(IOFetch::TCP), // for initialization - will be changed
cumulative_(0),
- timer_(service_.getInternalIOService()),
+ timer_(service_->getInternalIOService()),
receive_buffer_(),
expected_buffer_(new OutputBuffer(512)),
send_buffer_(),
}
// ... and cause the run loop to exit.
- service_.stop();
+ service_->stop();
}
// The next set of methods are the tests themselves. A number of the TCP
expected_ = IOFetch::STOPPED;
// Post the query
- service_.post(fetch);
+ service_->post(fetch);
// Post query_.stop() (yes, the std::bind thing is just
// query_.stop()).
- service_.post(std::bind(&IOFetch::stop, fetch, IOFetch::STOPPED));
+ service_->post(std::bind(&IOFetch::stop, fetch, IOFetch::STOPPED));
// Run both of them. run() returns when everything in the I/O service
// queue has completed.
- service_.run();
+ service_->run();
EXPECT_TRUE(run_);
}
// Stop before it is started
fetch.stop();
- service_.post(fetch);
+ service_->post(fetch);
- service_.run();
+ service_->run();
EXPECT_TRUE(run_);
}
protocol_ = protocol;
expected_ = IOFetch::TIME_OUT;
- service_.post(fetch);
- service_.run();
+ service_->post(fetch);
+ service_->run();
EXPECT_TRUE(run_);
}
}
// Socket into which the connection will be accepted.
- tcp::socket socket(service_.getInternalIOService());
+ tcp::socket socket(service_->getInternalIOService());
// Acceptor object - called when the connection is made, the handler
// will initiate a read on the socket.
- tcp::acceptor acceptor(service_.getInternalIOService(),
+ tcp::acceptor acceptor(service_->getInternalIOService(),
tcp::endpoint(tcp::v4(), TEST_PORT));
acceptor.async_accept(socket,
std::bind(&IOFetchTest::tcpAcceptHandler, this, &socket, ph::_1));
// Post the TCP fetch object to send the query and receive the response.
- service_.post(tcp_fetch_);
+ service_->post(tcp_fetch_);
// ... and execute all the callbacks. This exits when the fetch
// completes.
- service_.run();
+ service_->run();
EXPECT_TRUE(run_); // Make sure the callback did execute
// Tidy up
protocol_ = IOFetch::UDP;
// Set up the server.
- udp::socket socket(service_.getInternalIOService(), udp::v4());
+ udp::socket socket(service_->getInternalIOService(), udp::v4());
socket.set_option(socket_base::reuse_address(true));
socket.bind(udp::endpoint(TEST_HOST, TEST_PORT));
return_data_ = "Message returned to the client";
std::bind(&IOFetchTest::udpReceiveHandler,
this, &remote, &socket,
ph::_1, ph::_2, bad_qid, second_send));
- service_.post(udp_fetch_);
+ service_->post(udp_fetch_);
if (debug_) {
cout << "udpSendReceive: async_receive_from posted,"
"waiting for callback" << endl;
}
- service_.run();
+ service_->run();
socket.close();
/// @note The caller must not provide a null pointer to the TLS context.
template <typename Callback, typename TlsStreamImpl>
TlsStreamBase<Callback, TlsStreamImpl>::
-TlsStreamBase(IOService& service, TlsContextPtr context)
- : TlsStreamImpl(service.getInternalIOService(), context->getContext()),
- role_(context->getRole()) {
+TlsStreamBase(const IOServicePtr& io_service, TlsContextPtr context)
+ : StreamService(io_service), TlsStreamImpl(io_service->getInternalIOService(),
+ context->getContext()), role_(context->getRole()) {
}
/// @brief Botan boost ASIO TLS stream.
/// @param service I/O Service object used to manage the stream.
/// @param context Pointer to the TLS context.
/// @note The caller must not provide a null pointer to the TLS context.
- TlsStream(IOService& service, TlsContextPtr context)
+ TlsStream(const IOServicePtr& service, TlsContextPtr context)
: Base(service, context) {
}
/// @note The caller must not provide a null pointer to the TLS context.
template <typename Callback, typename TlsStreamImpl>
TlsStreamBase<Callback, TlsStreamImpl>::
-TlsStreamBase(IOService& service, TlsContextPtr context)
- : TlsStreamImpl(service.getInternalIOService()), role_(context->getRole()) {
+TlsStreamBase(const IOServicePtr& io_service, TlsContextPtr context)
+ : StreamService(io_service), TlsStreamImpl(io_service->getInternalIOService()),
+ role_(context->getRole()) {
}
/// @brief Botan fake TLS stream.
/// @param service I/O Service object used to manage the stream.
/// @param context Pointer to the TLS context.
/// @note The caller must not provide a null pointer to the TLS context.
- TlsStream(IOService& service, TlsContextPtr context)
+ TlsStream(const IOServicePtr& service, TlsContextPtr context)
: Base(service, context) {
}
TlsRole role_;
};
+class StreamService {
+public:
+ /// @brief Constructor.
+ StreamService(const IOServicePtr& io_service) : io_service_(io_service) {
+ }
+private:
+ /// @brief The IO service used to handle events.
+ IOServicePtr io_service_;
+};
+
/// @brief TLS stream base class.
///
/// @tparam Callback The type of callbacks.
/// @tparam TlsStreamImpl The type of underlying TLS streams.
template <typename Callback, typename TlsStreamImpl>
-class TlsStreamBase : public TlsStreamImpl {
+class TlsStreamBase : public StreamService, public TlsStreamImpl {
public:
/// @brief Constructor.
/// @param service I/O Service object used to manage the stream.
/// @param context Pointer to the TLS context.
/// @note The caller must not provide a null pointer to the TLS context.
- TlsStreamBase(IOService& service, TlsContextPtr context);
+ TlsStreamBase(const IOServicePtr& service, TlsContextPtr context);
/// @brief Destructor.
virtual ~TlsStreamBase() { }
/// @brief Constructor.
///
/// @param io_service The IO service used to handle events.
- IntervalTimerImpl(IOService& io_service);
+ IntervalTimerImpl(const IOServicePtr& io_service);
/// @brief Destructor.
~IntervalTimerImpl();
/// @brief The interval in milliseconds.
std::atomic<long> interval_;
+ /// @brief The IO service used to handle events.
+ IOServicePtr io_service_;
+
/// @brief The asio timer.
boost::asio::deadline_timer timer_;
static const long INVALIDATED_INTERVAL = -1;
};
-IntervalTimerImpl::IntervalTimerImpl(IOService& io_service) :
- interval_(0), timer_(io_service.getInternalIOService()),
+IntervalTimerImpl::IntervalTimerImpl(const IOServicePtr& io_service) :
+ interval_(0), io_service_(io_service), timer_(io_service_->getInternalIOService()),
mode_(IntervalTimer::REPEATING) {
}
}
}
-IntervalTimer::IntervalTimer(IOService& io_service) :
+IntervalTimer::IntervalTimer(const IOServicePtr& io_service) :
impl_(new IntervalTimerImpl(io_service)) {
}
/// memory allocation fails inside the method.
/// This constructor may also throw \c boost::system::system_error.
///
- /// \param io_service A reference to an instance of IOService
- IntervalTimer(IOService& io_service);
+ /// \param io_service A smart pointer to an instance of IOService
+ IntervalTimer(const IOServicePtr& io_service);
/// \brief The destructor.
///
/// @brief Constructor.
///
/// @param io_service Reference to the IO service.
- explicit IOAcceptor(IOService& io_service)
- : IOSocket(),
- acceptor_(new typename ProtocolType::acceptor(io_service.getInternalIOService())) {
+ explicit IOAcceptor(const IOServicePtr& io_service)
+ : IOSocket(), io_service_(io_service),
+ acceptor_(new typename ProtocolType::acceptor(io_service_->getInternalIOService())) {
}
/// @brief Destructor.
acceptor_->async_accept(socket.getASIOSocket(), callback);
}
+ /// @brief The IO service used to handle events.
+ IOServicePtr io_service_;
/// @brief Underlying ASIO acceptor implementation.
boost::shared_ptr<typename ProtocolType::acceptor> acceptor_;
};
-
} // end of namespace asiolink
} // end of isc
///
/// @param io_service the process IO service.
/// @param handler the signal handler.
- IOSignalSetImpl(IOServicePtr io_service, IOSignalHandler handler);
+ IOSignalSetImpl(const IOServicePtr& io_service, IOSignalHandler handler);
/// @brief Destructor.
~IOSignalSetImpl();
void callback(const boost::system::error_code& ec, int signum);
};
-IOSignalSetImpl::IOSignalSetImpl(IOServicePtr io_service,
+IOSignalSetImpl::IOSignalSetImpl(const IOServicePtr& io_service,
IOSignalHandler handler)
: io_service_(io_service),
signal_set_(io_service_->getInternalIOService()),
}
}
-IOSignalSet::IOSignalSet(IOServicePtr io_service, IOSignalHandler handler) :
+IOSignalSet::IOSignalSet(const IOServicePtr& io_service, IOSignalHandler handler) :
impl_(new IOSignalSetImpl(io_service, handler)) {
// It can throw but the error is fatal...
impl_->install();
///
/// @param io_service IOService to which to send the signal.
/// @param handler Handler to call when a signal is received.
- IOSignalSet(asiolink::IOServicePtr io_service, IOSignalHandler handler);
+ IOSignalSet(const asiolink::IOServicePtr& io_service, IOSignalHandler handler);
/// @brief Destructor.
~IOSignalSet();
/// @note The caller must not provide a null pointer to the TLS context.
template <typename Callback, typename TlsStreamImpl>
TlsStreamBase<Callback, TlsStreamImpl>::
-TlsStreamBase(IOService& service, TlsContextPtr context)
- : TlsStreamImpl(service.getInternalIOService(), context->getContext()),
- role_(context->getRole()) {
+TlsStreamBase(const IOServicePtr& io_service, TlsContextPtr context)
+ : StreamService(io_service), TlsStreamImpl(io_service->getInternalIOService(),
+ context->getContext()), role_(context->getRole()) {
}
/// @brief OpenSSL TLS stream.
/// @param service I/O Service object used to manage the stream.
/// @param context Pointer to the TLS context.
/// @note The caller must not provide a null pointer to the TLS context.
- TlsStream(IOService& service, TlsContextPtr context)
+ TlsStream(const IOServicePtr& service, TlsContextPtr context)
: Base(service, context) {
}
/// @brief Constructor.
///
/// @param io_service IO service.
- explicit TCPAcceptor(IOService& io_service)
+ explicit TCPAcceptor(const IOServicePtr& io_service)
: IOAcceptor<boost::asio::ip::tcp, C>(io_service) {
}
/// socket. In this case, the open() and close() methods are used.
///
/// \param service I/O Service object used to manage the socket.
- TCPSocket(IOService& service);
+ TCPSocket(const IOServicePtr& service);
/// \brief Destructor
virtual ~TCPSocket();
}
private:
+
+ /// @brief The IO service used to handle events.
+ IOServicePtr io_service_;
+
/// Two variables to hold the socket - a socket and a pointer to it. This
/// handles the case where a socket is passed to the TCPSocket on
/// construction, or where it is asked to manage its own socket.
// Constructor - create socket on the fly
template <typename C>
-TCPSocket<C>::TCPSocket(IOService& service) :
- socket_ptr_(new boost::asio::ip::tcp::socket(service.getInternalIOService())),
+TCPSocket<C>::TCPSocket(const IOServicePtr& io_service) : io_service_(io_service),
+ socket_ptr_(new boost::asio::ip::tcp::socket(io_service_->getInternalIOService())),
socket_(*socket_ptr_)
{
}
class IntervalTimerTest : public ::testing::Test {
protected:
IntervalTimerTest() :
- io_service_(), timer_called_(false), timer_cancel_success_(false)
+ io_service_(new IOService()), timer_called_(false), timer_cancel_success_(false)
{}
~IntervalTimerTest() {}
class TimerCallBack {
TimerCallBack(IntervalTimerTest* test_obj) : test_obj_(test_obj) {}
void operator()() const {
test_obj_->timer_called_ = true;
- test_obj_->io_service_.stop();
+ test_obj_->io_service_->stop();
return;
}
private:
} else if (count_ == 2) {
// Second time of call back.
// Stop io_service to stop all timers.
- test_obj_->io_service_.stop();
+ test_obj_->io_service_->stop();
// Compare the value of counter_.counter_ with stored one.
// If TimerCallBackCounter was not called (expected behavior),
// they are same.
// Second time of call back.
// If it reaches here, re-setup() is failed (unexpected).
// We should stop here.
- test_obj_->io_service_.stop();
+ test_obj_->io_service_->stop();
}
return;
}
int& counter_;
};
protected:
- IOService io_service_;
+ IOServicePtr io_service_;
bool timer_called_;
bool timer_cancel_success_;
};
// setup timer
itimer.setup(TimerCallBack(this), 100);
EXPECT_EQ(100, itimer.getInterval());
- io_service_.run();
+ io_service_->run();
// Control reaches here after io_service_ was stopped by TimerCallBack.
// delta: difference between elapsed time and 100 milliseconds.
itimer_canceller.setup(
TimerCallBackCancelDeleter(this, itimer_counter, callback_canceller),
300);
- io_service_.run();
+ io_service_->run();
EXPECT_TRUE(timer_cancel_success_);
}
unsigned int counter = 0;
itimer_counter.setup(TimerCallBackCanceller(counter, itimer_counter), 100);
itimer_watcher.setup(TimerCallBack(this), 200);
- io_service_.run();
+ io_service_->run();
EXPECT_EQ(1, counter);
EXPECT_EQ(0, itimer_counter.getInterval());
// - increments internal counter in callback function
// (TimerCallBackCounter)
// interval: 300 milliseconds
- // - io_service_.stop() (TimerCallBack)
+ // - io_service_->stop() (TimerCallBack)
// interval: 100 milliseconds
// itimer_overwriter (B)
// (Calls TimerCallBackOverwriter)
start = boost::posix_time::microsec_clock::universal_time();
itimer.setup(TimerCallBackCounter(this), 300);
itimer_overwriter.setup(TimerCallBackOverwriter(this, itimer), 400);
- io_service_.run();
+ io_service_->run();
// Control reaches here after io_service_ was stopped by
// TimerCallBackCounter or TimerCallBackOverwriter.
// we've hit our goals. It won't return zero unless is out of
// work or the service has been stopped by the test timer.
int cnt = 0;
- while (((cnt = io_service_.runOne()) > 0) && (repeater_count < 5)) {
+ while (((cnt = io_service_->runOne()) > 0) && (repeater_count < 5)) {
// deliberately empty
};
// Run until a single event handler executes. This should be our
// one-shot expiring.
- io_service_.runOne();
+ io_service_->runOne();
// Verify the timer expired once.
ASSERT_EQ(one_shot_count, 1);
// Run until a single event handler executes. This should be our
// one-shot expiring.
- io_service_.runOne();
+ io_service_->runOne();
// Verify the timer expired once.
ASSERT_EQ(one_shot_count, 2);
// we've hit our goals. It won't return zero unless is out of
// work or the service has been stopped by the test timer.
int cnt = 0;
- while ((cnt = io_service_.runOne()) && (one_shot_count < 4)) {
+ while ((cnt = io_service_->runOne()) && (one_shot_count < 4)) {
// deliberately empty
};
/// @brief Constructor.
IOSignalTest() :
- io_service_(new asiolink::IOService()), test_timer_(*io_service_),
- test_time_ms_(0), io_signal_set_(),
- processed_signals_(), stop_at_count_(0), handler_throw_error_(false) {
+ io_service_(new asiolink::IOService()), test_timer_(io_service_),
+ test_time_ms_(0), io_signal_set_(), processed_signals_(), stop_at_count_(0),
+ handler_throw_error_(false) {
io_signal_set_.reset(new IOSignalSet(io_service_,
std::bind(&IOSignalTest::processSignal,
ASSERT_NO_THROW(io_signal_set_->add(SIGINT));
// Use TimedSignal to generate SIGINT 100 ms after we start IOService::run.
- TimedSignal sig_int(*io_service_, SIGINT, 100);
+ TimedSignal sig_int(io_service_, SIGINT, 100);
// The first handler executed is the IOSignal's internal timer expire
// callback.
ASSERT_NO_THROW(io_signal_set_->remove(SIGINT));
// Use TimedSignal to generate SIGINT 100 ms after we start IOService::run.
- TimedSignal sig_int_too_late(*io_service_, SIGINT, 100);
+ TimedSignal sig_int_too_late(io_service_, SIGINT, 100);
// The first handler executed is the IOSignal's internal timer expire
// callback.
// User a repeating TimedSignal so we should generate a signal every 1 ms
// until we hit our stop count.
- TimedSignal sig_int(*io_service_, SIGINT, 1,
+ TimedSignal sig_int(io_service_, SIGINT, 1,
asiolink::IntervalTimer::REPEATING);
// Start processing IO. This should continue until we stop either by
stop_at_count_ = 1;
// Use TimedSignal to generate SIGINT after we start IOService::run.
- TimedSignal sig_int(*io_service_, SIGINT, 100,
+ TimedSignal sig_int(io_service_, SIGINT, 100,
asiolink::IntervalTimer::REPEATING);
// Set the test flag to cause the handler to throw an exception.
// Since signal order arrival cannot be guaranteed, we'll use
// explicit one shot signals so we can guarantee how many
// of each signal we should get.
- TimedSignal sig1(*io_service_, SIGINT, 2);
- TimedSignal sig2(*io_service_, SIGUSR1, 2);
- TimedSignal sig3(*io_service_, SIGINT, 2);
- TimedSignal sig4(*io_service_, SIGUSR2, 2);
- TimedSignal sig5(*io_service_, SIGINT, 2);
- TimedSignal sig6(*io_service_, SIGUSR1, 2);
- TimedSignal sig7(*io_service_, SIGINT, 2);
- TimedSignal sig8(*io_service_, SIGUSR2, 2);
+ TimedSignal sig1(io_service_, SIGINT, 2);
+ TimedSignal sig2(io_service_, SIGUSR1, 2);
+ TimedSignal sig3(io_service_, SIGINT, 2);
+ TimedSignal sig4(io_service_, SIGUSR2, 2);
+ TimedSignal sig5(io_service_, SIGINT, 2);
+ TimedSignal sig6(io_service_, SIGUSR1, 2);
+ TimedSignal sig7(io_service_, SIGINT, 2);
+ TimedSignal sig8(io_service_, SIGUSR2, 2);
// Start processing IO. This should continue until we stop either by
// hitting the stop count or if things go wrong, max test time.
/// @brief Constructor.
ProcessSpawnTest() :
- io_service_(getIOService()), test_timer_(*io_service_),
+ io_service_(getIOService()), test_timer_(io_service_),
test_time_ms_(0), io_signal_set_(), processed_signals_() {
io_signal_set_.reset(new IOSignalSet(io_service_,
/// connect() to connect to the server.
///
/// @param io_service IO service to be stopped on error.
- explicit TCPClient(IOService& io_service)
- : io_service_(io_service.getInternalIOService()), socket_(io_service_) {
+ explicit TCPClient(const IOServicePtr& io_service)
+ : io_service_(io_service), socket_(io_service_->getInternalIOService()) {
}
/// @brief Destructor.
if (ec.value() != boost::asio::error::in_progress) {
ADD_FAILURE() << "error occurred while connecting: "
<< ec.message();
- io_service_.stop();
+ io_service_->stop();
}
}
}
private:
- /// @brief Holds reference to the IO service.
- boost::asio::io_service& io_service_;
+ /// @brief Holds the IO service.
+ IOServicePtr io_service_;
/// @brief A socket used for the connection.
boost::asio::ip::tcp::socket socket_;
/// @param acceptor Reference to the TCP acceptor on which asyncAccept
/// will be called.
/// @param callback Callback function for the asyncAccept.
- explicit Acceptor(IOService& io_service, TestTCPAcceptor& acceptor,
+ explicit Acceptor(const IOServicePtr& io_service, TestTCPAcceptor& acceptor,
const TCPAcceptorCallback& callback)
: socket_(io_service), acceptor_(acceptor), callback_(callback) {
}
/// against endlessly running IO service when TCP connections are
/// unsuccessful.
TCPAcceptorTest()
- : io_service_(), acceptor_(io_service_),
+ : io_service_(new IOService()), acceptor_(io_service_),
asio_endpoint_(boost::asio::ip::address::from_string(SERVER_ADDRESS),
SERVER_PORT),
endpoint_(asio_endpoint_), test_timer_(io_service_), connections_(),
} else {
++aborted_connections_num_;
}
- io_service_.stop();
+ io_service_->stop();
}
// We have reached the maximum number of connections - end the test.
if (++connections_num_ >= max_connections_) {
- io_service_.stop();
+ io_service_->stop();
return;
}
/// It stops the IO service and reports test timeout.
void timeoutHandler() {
ADD_FAILURE() << "Timeout occurred while running the test!";
- io_service_.stop();
+ io_service_->stop();
}
/// @brief IO service.
- IOService io_service_;
+ IOServicePtr io_service_;
/// @brief TCPAcceptor under test.
TestTCPAcceptor acceptor_;
// Run the IO service until we have accepted 10 connections, an error
// or test timeout occurred.
- io_service_.run();
+ io_service_->run();
// Make sure that all accepted connections have been recorded.
EXPECT_EQ(10, connections_num_);
acceptor_.close();
// Run the IO service.
- io_service_.run();
+ io_service_->run();
// The connections should have been aborted.
EXPECT_EQ(1, connections_num_);
TEST(TCPSocket, processReceivedData) {
const uint16_t PACKET_SIZE = 16382; // Amount of "real" data in the buffer
- IOService service; // Used to instantiate socket
+ IOServicePtr service(new IOService); // Used to instantiate socket
TCPSocket<TCPCallback> test(service); // Socket under test
uint8_t inbuff[PACKET_SIZE + 2]; // Buffer to check
OutputBufferPtr outbuff(new OutputBuffer(16));
TEST(TCPSocket, sequenceTest) {
// Common objects.
- IOService service; // Service object for async control
+ IOServicePtr service(new IOService()); // Service object for async control
// The client - the TCPSocket being tested
- TCPSocket<TCPCallback> client(service);// Socket under test
+ TCPSocket<TCPCallback> client(service); // Socket under test
TCPCallback client_cb("Client"); // Async I/O callback function
TCPEndpoint client_remote_endpoint; // Where client receives message from
OutputBufferPtr client_buffer(new OutputBuffer(128));
TCPEndpoint server_endpoint(server_address, SERVER_PORT);
// Endpoint describing server
TCPEndpoint server_remote_endpoint; // Address where server received message from
- tcp::socket server_socket(service.getInternalIOService());
+ tcp::socket server_socket(service->getInternalIOService());
// Socket used for server
// Step 1. Create the connection between the client and the server. Set
server_cb.queued() = TCPCallback::ACCEPT;
server_cb.called() = TCPCallback::NONE;
server_cb.setCode(42); // Some error
- tcp::acceptor acceptor(service.getInternalIOService(),
- tcp::endpoint(tcp::v4(), SERVER_PORT));
+ tcp::acceptor acceptor(service->getInternalIOService(),
+ tcp::endpoint(tcp::v4(), SERVER_PORT));
acceptor.set_option(tcp::acceptor::reuse_address(true));
acceptor.async_accept(server_socket, server_cb);
client.open(&server_endpoint, client_cb);
// Run the open and the accept callback and check that they ran.
- service.runOne();
- service.runOne();
+ service->runOne();
+ service->runOne();
EXPECT_EQ(TCPCallback::ACCEPT, server_cb.called());
EXPECT_EQ(0, server_cb.getCode());
// Wait for the client callback to complete. (Must do this first on
// Solaris: if we do the synchronous read first, the test hangs.)
- service.runOne();
+ service->runOne();
// Synchronously read the data from the server.;
serverRead(server_socket, server_cb);
bool server_complete = false;
bool client_complete = false;
while (!server_complete || !client_complete) {
- service.runOne();
+ service->runOne();
// Has the server run?
if (!server_complete) {
/// connect() to connect to the server.
///
/// @param io_service IO service to be stopped on error.
- explicit TLSClient(IOService& io_service)
- : io_service_(io_service.getInternalIOService()), socket_(io_service_) {
+ explicit TLSClient(const IOServicePtr& io_service)
+ : io_service_(io_service), socket_(io_service_->getInternalIOService()) {
}
/// @brief Destructor.
if (ec.value() != error::in_progress) {
ADD_FAILURE() << "error occurred while connecting: "
<< ec.message();
- io_service_.stop();
+ io_service_->stop();
}
}
}
private:
/// @brief Holds reference to the IO service.
- io_service& io_service_;
+ IOServicePtr io_service_;
/// @brief A socket used for the connection.
ip::tcp::socket socket_;
/// @param acceptor Reference to the TLS acceptor on which asyncAccept
/// will be called.
/// @param callback Callback function for the asyncAccept.
- explicit Acceptor(IOService& io_service,
+ explicit Acceptor(const IOServicePtr& io_service,
TlsContextPtr context,
TestTLSAcceptor& acceptor,
const TLSAcceptorCallback& callback)
- : socket_(io_service, context), acceptor_(acceptor),
+ : io_service_(io_service), socket_(io_service_, context), acceptor_(acceptor),
callback_(callback) {
}
private:
+ /// @brief IO service used by the tests.
+ IOServicePtr io_service_;
+
/// @brief Socket into which connection is accepted.
TLSSocket<SocketCallback> socket_;
/// against endlessly running IO service when TLS connections are
/// unsuccessful.
TLSAcceptorTest()
- : io_service_(), acceptor_(io_service_),
+ : io_service_(new IOService()), acceptor_(io_service_),
asio_endpoint_(ip::address::from_string(SERVER_ADDRESS),
SERVER_PORT),
endpoint_(asio_endpoint_), test_timer_(io_service_), connections_(),
} else {
++aborted_connections_num_;
}
- io_service_.stop();
+ io_service_->stop();
}
// We have reached the maximum number of connections - end the test.
if (++connections_num_ >= max_connections_) {
- io_service_.stop();
+ io_service_->stop();
return;
}
/// It stops the IO service and reports test timeout.
void timeoutHandler() {
ADD_FAILURE() << "Timeout occurred while running the test!";
- io_service_.stop();
+ io_service_->stop();
}
/// @brief IO service.
- IOService io_service_;
+ IOServicePtr io_service_;
/// @brief TLSAcceptor under test.
TestTLSAcceptor acceptor_;
// Run the IO service until we have accepted 10 connections, an error
// or test timeout occurred.
- io_service_.run();
+ io_service_->run();
// Make sure that all accepted connections have been recorded.
EXPECT_EQ(10, connections_num_);
acceptor_.close();
// Run the IO service.
- io_service_.run();
+ io_service_->run();
// The connections should have been aborted.
EXPECT_EQ(1, connections_num_);
const uint16_t PACKET_SIZE = 16382;
// Used to instantiate socket
- IOService service;
+ IOServicePtr service(new IOService());
TlsContextPtr context(new TlsContext(CLIENT));
// Socket under test
TLSSocket<TLSCallback> test(service, context);
// Common objects.
// Service object for async control
- IOService service;
+ IOServicePtr service(new IOService());
// The client - the TLSSocket being tested
TlsContextPtr client_ctx;
TlsContextPtr server_ctx;
test::configServer(server_ctx);
// Stream used for server.
- TlsStreamImpl server(service.getInternalIOService(), server_ctx->getContext());
+ TlsStreamImpl server(service->getInternalIOService(), server_ctx->getContext());
// Step 1. Create the connection between the client and the server. Set
// up the server to accept incoming connections and have the client open
server_cb.queued() = TLSCallback::ACCEPT;
server_cb.called() = TLSCallback::NONE;
server_cb.setCode(42); // Some error
- tcp::acceptor acceptor(service.getInternalIOService(),
+ tcp::acceptor acceptor(service->getInternalIOService(),
tcp::endpoint(tcp::v4(), SERVER_PORT));
acceptor.set_option(tcp::acceptor::reuse_address(true));
acceptor.async_accept(server.lowest_layer(), server_cb);
// Run the open and the accept callback and check that they ran.
while ((server_cb.called() == TLSCallback::NONE) ||
(client_cb.called() == TLSCallback::NONE)) {
- service.runOne();
+ service->runOne();
}
EXPECT_EQ(TLSCallback::ACCEPT, server_cb.called());
EXPECT_EQ(0, server_cb.getCode());
while ((server_cb.called() == TLSCallback::NONE) ||
(client_cb.called() == TLSCallback::NONE)) {
- service.runOne();
+ service->runOne();
}
EXPECT_EQ(TLSCallback::HANDSHAKE, client_cb.called());
EXPECT_EQ(0, client_cb.getCode());
// Wait for the client callback to complete. (Must do this first on
// Solaris: if we do the synchronous read first, the test hangs.)
while (client_cb.called() == TLSCallback::NONE) {
- service.runOne();
+ service->runOne();
}
// Synchronously read the data from the server.;
bool server_complete = false;
bool client_complete = false;
while (!server_complete || !client_complete) {
- service.runOne();
+ service->runOne();
// Has the server run?
if (!server_complete) {
// Test if we can get a stream.
TEST(TLSTest, stream) {
- IOService service;
+ IOServicePtr service(new IOService());
TlsContextPtr ctx(new TlsContext(TlsRole::CLIENT));
boost::scoped_ptr<TlsStream<TestCallback> > st;
EXPECT_NO_THROW(st.reset(new TlsStream<TestCallback>(service, ctx)));
// Test what happens when handshake is forgotten.
TEST(TLSTest, noHandshake) {
- IOService service;
+ IOServicePtr service(new IOService());
// Server part.
TlsContextPtr server_ctx;
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
acceptor.async_accept(server.lowest_layer(), accept_cb);
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service.runOne();
+ service->runOne();
}
// Verify the error codes.
TestCallback send_cb;
async_write(client, boost::asio::buffer(send_buf), send_cb);
while (!timeout && !send_cb.getCalled()) {
- service.runOne();
+ service->runOne();
}
timer1.cancel();
TestCallback receive_cb;
server.async_read_some(boost::asio::buffer(receive_buf), receive_cb);
while (!timeout && !receive_cb.getCalled()) {
- service.runOne();
+ service->runOne();
}
timer2.cancel();
// Test what happens when the server was not configured.
TEST(TLSTest, serverNotConfigured) {
- IOService service;
+ IOServicePtr service(new IOService());
// Server part.
TlsContextPtr server_ctx(new TlsContext(TlsRole::SERVER));
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
acceptor.async_accept(server.lowest_layer(), accept_cb);
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service.runOne();
+ service->runOne();
}
// Verify the error codes.
TestCallback client_cb;
client.handshake(client_cb);
while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
- service.runOne();
+ service->runOne();
}
timer.cancel();
// Test what happens when the client was not configured.
TEST(TLSTest, clientNotConfigured) {
- IOService service;
+ IOServicePtr service(new IOService());
// Server part.
TlsContextPtr server_ctx;
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
acceptor.async_accept(server.lowest_layer(), accept_cb);
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service.runOne();
+ service->runOne();
}
// Verify the error codes.
TestCallback client_cb;
client.async_handshake(roleToImpl(TlsRole::CLIENT), client_cb);
while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
- service.runOne();
+ service->runOne();
}
timer.cancel();
// Test what happens when the client is HTTP (vs HTTPS).
TEST(TLSTest, clientHTTPnoS) {
- IOService service;
+ IOServicePtr service(new IOService());
// Server part.
TlsContextPtr server_ctx;
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
acceptor.async_accept(server.lowest_layer(), accept_cb);
// Client part.
- tcp::socket client(service.getInternalIOService());
+ tcp::socket client(service->getInternalIOService());
// Connect to.
client.open(tcp::v4());
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service.runOne();
+ service->runOne();
}
// Verify the error codes.
client.async_send(boost::asio::buffer(send_buf), client_cb);
while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
- service.runOne();
+ service->runOne();
}
timer.cancel();
// Test what happens when the client does not use HTTP nor HTTP.
TEST(TLSTest, unknownClient) {
- IOService service;
+ IOServicePtr service(new IOService());
// Server part.
TlsContextPtr server_ctx;
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
acceptor.async_accept(server.lowest_layer(), accept_cb);
// Client part.
- tcp::socket client(service.getInternalIOService());
+ tcp::socket client(service->getInternalIOService());
// Connect to.
client.open(tcp::v4());
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service.runOne();
+ service->runOne();
}
// Verify the error codes.
client.async_send(boost::asio::buffer(send_buf), client_cb);
while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
- service.runOne();
+ service->runOne();
}
timer.cancel();
// Test what happens when the client uses a certificate from another CA.
TEST(TLSTest, anotherClient) {
- IOService service;
+ IOServicePtr service(new IOService());
// Server part.
TlsContextPtr server_ctx;
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
acceptor.async_accept(server.lowest_layer(), accept_cb);
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service.runOne();
+ service->runOne();
}
// Verify the error codes.
TestCallback client_cb;
client.async_handshake(roleToImpl(TlsRole::CLIENT), client_cb);
while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
- service.runOne();
+ service->runOne();
}
timer.cancel();
// Test what happens when the client uses a self-signed certificate.
TEST(TLSTest, selfSigned) {
- IOService service;
+ IOServicePtr service(new IOService());
// Server part.
TlsContextPtr server_ctx;
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
acceptor.async_accept(server.lowest_layer(), accept_cb);
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service.runOne();
+ service->runOne();
}
// Verify the error codes.
TestCallback client_cb;
client.async_handshake(roleToImpl(TlsRole::CLIENT), client_cb);
while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
- service.runOne();
+ service->runOne();
}
timer.cancel();
// Test what happens when handshake is forgotten.
TEST(TLSTest, noHandshakeCloseonError) {
- IOService service;
+ IOServicePtr service(new IOService());
// Server part.
TlsContextPtr server_ctx;
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
acceptor.async_accept(server.lowest_layer(), accept_cb);
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service.runOne();
+ service->runOne();
}
// Verify the error codes.
TestCallback send_cb(&client.lowest_layer());
async_write(client, boost::asio::buffer(send_buf), send_cb);
while (!timeout && !send_cb.getCalled()) {
- service.runOne();
+ service->runOne();
}
timer1.cancel();
TestCallback receive_cb;
server.async_read_some(boost::asio::buffer(receive_buf), receive_cb);
while (!timeout && !receive_cb.getCalled()) {
- service.runOne();
+ service->runOne();
}
timer2.cancel();
// Test what happens when the server was not configured.
TEST(TLSTest, serverNotConfiguredCloseonError) {
- IOService service;
+ IOServicePtr service(new IOService());
// Server part.
TlsContextPtr server_ctx(new TlsContext(TlsRole::SERVER));
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
acceptor.async_accept(server.lowest_layer(), accept_cb);
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service.runOne();
+ service->runOne();
}
// Verify the error codes.
TestCallback client_cb;
client.handshake(client_cb);
while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
- service.runOne();
+ service->runOne();
}
timer.cancel();
// Test what happens when the client was not configured.
TEST(TLSTest, clientNotConfiguredCloseonError) {
- IOService service;
+ IOServicePtr service(new IOService());
// Server part.
TlsContextPtr server_ctx;
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
acceptor.async_accept(server.lowest_layer(), accept_cb);
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service.runOne();
+ service->runOne();
}
// Verify the error codes.
TestCallback client_cb(&client.lowest_layer());
client.async_handshake(roleToImpl(TlsRole::CLIENT), client_cb);
while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
- service.runOne();
+ service->runOne();
}
timer.cancel();
// Test what happens when the client is HTTP (vs HTTPS).
TEST(TLSTest, clientHTTPnoSCloseonError) {
- IOService service;
+ IOServicePtr service(new IOService());
// Server part.
TlsContextPtr server_ctx;
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
acceptor.async_accept(server.lowest_layer(), accept_cb);
// Client part.
- tcp::socket client(service.getInternalIOService());
+ tcp::socket client(service->getInternalIOService());
// Connect to.
client.open(tcp::v4());
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service.runOne();
+ service->runOne();
}
// Verify the error codes.
client.async_send(boost::asio::buffer(send_buf), client_cb);
while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
- service.runOne();
+ service->runOne();
}
timer.cancel();
// Test what happens when the client uses a certificate from another CA.
TEST(TLSTest, anotherClientCloseonError) {
- IOService service;
+ IOServicePtr service(new IOService());
// Server part.
TlsContextPtr server_ctx;
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
acceptor.async_accept(server.lowest_layer(), accept_cb);
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service.runOne();
+ service->runOne();
}
// Verify the error codes.
TestCallback client_cb;
client.async_handshake(roleToImpl(TlsRole::CLIENT), client_cb);
while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
- service.runOne();
+ service->runOne();
}
timer.cancel();
// Test what happens when the client uses a self-signed certificate.
TEST(TLSTest, selfSignedCloseonError) {
- IOService service;
+ IOServicePtr service(new IOService());
// Server part.
TlsContextPtr server_ctx;
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
acceptor.async_accept(server.lowest_layer(), accept_cb);
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service.runOne();
+ service->runOne();
}
// Verify the error codes.
TestCallback client_cb;
client.async_handshake(roleToImpl(TlsRole::CLIENT), client_cb);
while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
- service.runOne();
+ service->runOne();
}
timer.cancel();
// Test what happens when the client uses a certificate from another CA
// but the client certificate request and validation are disabled.
TEST(TLSTest, anotherClientNoReq) {
- IOService service;
+ IOServicePtr service(new IOService());
// Server part.
TlsContextPtr server_ctx;
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
acceptor.async_accept(server.lowest_layer(), accept_cb);
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service.runOne();
+ service->runOne();
}
// Verify the error codes.
TestCallback client_cb;
client.async_handshake(roleToImpl(TlsRole::CLIENT), client_cb);
while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
- service.runOne();
+ service->runOne();
}
timer.cancel();
// Test what happens when the server uses a certificate without subject
// alternative name (but still a version 3 certificate).
TEST(TLSTest, serverRaw) {
- IOService service;
+ IOServicePtr service(new IOService());
// Server part.
TlsContextPtr server_ctx;
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
acceptor.async_accept(server.lowest_layer(), accept_cb);
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service.runOne();
+ service->runOne();
}
// Verify the error codes.
TestCallback client_cb;
client.async_handshake(roleToImpl(TlsRole::CLIENT), client_cb);
while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
- service.runOne();
+ service->runOne();
}
timer.cancel();
// Test what happens when the client uses a trusted self-signed certificate.
// Not really a failure case as it works...
TEST(TLSTest, trustedSelfSigned) {
- IOService service;
+ IOServicePtr service(new IOService());
// Server part.
TlsContextPtr server_ctx;
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
acceptor.async_accept(server.lowest_layer(), accept_cb);
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service.runOne();
+ service->runOne();
}
// Verify the error codes.
TestCallback client_cb;
client.async_handshake(roleToImpl(TlsRole::CLIENT), client_cb);
while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
- service.runOne();
+ service->runOne();
}
timer.cancel();
// Test what happens when the shutdown receiver is inactive.
TEST(TLSTest, shutdownInactive) {
- IOService service;
+ IOServicePtr service(new IOService());
// Server part.
TlsContextPtr server_ctx(new TlsContext(TlsRole::SERVER));
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
acceptor.async_accept(server.lowest_layer(), accept_cb);
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service.runOne();
+ service->runOne();
}
// Verify the error codes.
TestCallback client_cb;
client.handshake(client_cb);
while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
- service.runOne();
+ service->runOne();
}
timer.cancel();
TestCallback shutdown_cb;
client.shutdown(shutdown_cb);
while (!timeout && !shutdown_cb.getCalled()) {
- service.runOne();
+ service->runOne();
}
timer2.cancel();
// Test what happens when the shutdown receiver is active.
TEST(TLSTest, shutdownActive) {
- IOService service;
+ IOServicePtr service(new IOService());
// Server part.
TlsContextPtr server_ctx(new TlsContext(TlsRole::SERVER));
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
acceptor.async_accept(server.lowest_layer(), accept_cb);
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service.runOne();
+ service->runOne();
}
// Verify the error codes.
TestCallback client_cb;
client.handshake(client_cb);
while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
- service.runOne();
+ service->runOne();
}
timer.cancel();
TestCallback shutdown_cb;
client.shutdown(shutdown_cb);
while (!timeout && (!shutdown_cb.getCalled() || !receive_cb.getCalled())) {
- service.runOne();
+ service->runOne();
}
timer2.cancel();
// Test what happens when the shutdown receiver is inactive on shutdown
// and immediate close.
TEST(TLSTest, shutdownCloseInactive) {
- IOService service;
+ IOServicePtr service(new IOService());
// Server part.
TlsContextPtr server_ctx(new TlsContext(TlsRole::SERVER));
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
acceptor.async_accept(server.lowest_layer(), accept_cb);
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service.runOne();
+ service->runOne();
}
// Verify the error codes.
TestCallback client_cb;
client.handshake(client_cb);
while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
- service.runOne();
+ service->runOne();
}
timer.cancel();
client.shutdown(shutdown_cb);
// Post a close which should be called after the shutdown.
- service.post([&client] { client.lowest_layer().close(); });
+ service->post([&client] { client.lowest_layer().close(); });
while (!timeout && !shutdown_cb.getCalled()) {
- service.runOne();
+ service->runOne();
}
timer2.cancel();
// Test what happens when the shutdown receiver is active with an
// immediate close.
TEST(TLSTest, shutdownCloseActive) {
- IOService service;
+ IOServicePtr service(new IOService());
// Server part.
TlsContextPtr server_ctx(new TlsContext(TlsRole::SERVER));
// Accept a client.
tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT));
- tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+ tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
acceptor.set_option(tcp::acceptor::reuse_address(true));
TestCallback accept_cb;
acceptor.async_accept(server.lowest_layer(), accept_cb);
// Run accept and connect.
while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
- service.runOne();
+ service->runOne();
}
// Verify the error codes.
TestCallback client_cb;
client.handshake(client_cb);
while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
- service.runOne();
+ service->runOne();
}
timer.cancel();
client.shutdown(shutdown_cb);
// Post a close which should be called after the shutdown.
- service.post([&client] { client.lowest_layer().close(); });
+ service->post([&client] { client.lowest_layer().close(); });
while (!timeout && (!shutdown_cb.getCalled() || !receive_cb.getCalled())) {
- service.runOne();
+ service->runOne();
}
timer2.cancel();
// two bytes of a buffer.
TEST(UDPSocket, processReceivedData) {
- IOService service; // Used to instantiate socket
- UDPSocket<UDPCallback> test(service); // Socket under test
- uint8_t inbuff[32]; // Buffer to check
- OutputBufferPtr outbuff(new OutputBuffer(16));
- // Where data is put
- // cppcheck-suppress variableScope
- size_t expected; // Expected amount of data
- // cppcheck-suppress variableScope
- size_t offset; // Where to put next data
- // cppcheck-suppress variableScope
- size_t cumulative; // Cumulative data received
+ IOServicePtr service(new IOService()); // Used to instantiate socket
+ UDPSocket<UDPCallback> test(service); // Socket under test
+ uint8_t inbuff[32]; // Buffer to check
+ OutputBufferPtr outbuff(new OutputBuffer(16)); // Where data is put
+ // cppcheck-suppress variableScope
+ size_t expected; // Expected amount of data
+ // cppcheck-suppress variableScope
+ size_t offset; // Where to put next data
+ // cppcheck-suppress variableScope
+ size_t cumulative; // Cumulative data received
// Set some dummy values in the buffer to check
for (uint8_t i = 0; i < sizeof(inbuff); ++i) {
// message to a server, receiving an asynchronous message from the server and
// closing.
TEST(UDPSocket, SequenceTest) {
-
// Common objects.
- IOService service; // Service object for async control
-
+ IOServicePtr service(new IOService()); // Service object for async control
// Server
- IOAddress server_address(SERVER_ADDRESS); // Address of target server
- UDPCallback server_cb("Server"); // Server callback
- UDPEndpoint server_endpoint( // Endpoint describing server
- server_address, SERVER_PORT);
- UDPEndpoint server_remote_endpoint; // Address where server received message from
+ IOAddress server_address(SERVER_ADDRESS); // Address of target server
+ UDPCallback server_cb("Server"); // Server callback
+ UDPEndpoint server_endpoint(server_address, SERVER_PORT); // Endpoint describing server
+ UDPEndpoint server_remote_endpoint; // Address where server received message from
// The client - the UDPSocket being tested
- UDPSocket<UDPCallback> client(service);// Socket under test
- UDPCallback client_cb("Client"); // Async I/O callback function
- UDPEndpoint client_remote_endpoint; // Where client receives message from
- size_t client_cumulative = 0; // Cumulative data received
- size_t client_offset = 0; // Offset into buffer where data is put
- size_t client_expected = 0; // Expected amount of data
- OutputBufferPtr client_buffer(new OutputBuffer(16));
- // Where data is put
+ UDPSocket<UDPCallback> client(service); // Socket under test
+ UDPCallback client_cb("Client"); // Async I/O callback function
+ UDPEndpoint client_remote_endpoint; // Where client receives message from
+ size_t client_cumulative = 0; // Cumulative data received
+ size_t client_offset = 0; // Offset into buffer where data is put
+ size_t client_expected = 0; // Expected amount of data
+ OutputBufferPtr client_buffer(new OutputBuffer(16)); // Where data is put
// The server - with which the client communicates. For convenience, we
// use the same io_service, and use the endpoint object created for
// the client to send to as the endpoint object in the constructor.
- boost::asio::ip::udp::socket server(service.getInternalIOService(),
+ boost::asio::ip::udp::socket server(service->getInternalIOService(),
server_endpoint.getASIOEndpoint());
server.set_option(socket_base::reuse_address(true));
EXPECT_FALSE(server_cb.getCalled());
// Write something to the server using the client - the callback should not
- // be called until we call the io_service.run() method.
+ // be called until we call the io_service->run() method.
client_cb.setCalled(false);
client_cb.setCode(7); // Arbitrary number
client.asyncSend(OUTBOUND_DATA, sizeof(OUTBOUND_DATA), &server_endpoint, client_cb);
EXPECT_FALSE(client_cb.getCalled());
// Execute the two callbacks.
- service.runOne();
- service.runOne();
+ service->runOne();
+ service->runOne();
EXPECT_TRUE(client_cb.getCalled());
EXPECT_EQ(0, client_cb.getCode());
server_remote_endpoint.getASIOEndpoint(), server_cb);
// Expect two callbacks to run.
- service.runOne();
- service.runOne();
+ service->runOne();
+ service->runOne();
EXPECT_TRUE(client_cb.getCalled());
EXPECT_EQ(0, client_cb.getCode());
///
/// Removes unix socket descriptor before the test.
UnixDomainSocketTest() :
- io_service_(),
+ io_service_(new IOService()),
test_socket_(new test::TestServerUnixSocket(io_service_,
unixSocketFilePath())),
response_(),
}
/// @brief IO service used by the tests.
- IOService io_service_;
+ IOServicePtr io_service_;
/// @brief Server side unix socket used in these tests.
test::TestServerUnixSocketPtr test_socket_;
// Run IO service to generate server's response.
while ((test_socket_->getResponseNum() < 1) &&
(!test_socket_->isStopped())) {
- io_service_.runOne();
+ io_service_->runOne();
}
// Receive response from the socket.
));
// Run IO service until connect handler is invoked.
while (!connect_handler_invoked && (!test_socket_->isStopped())) {
- io_service_.runOne();
+ io_service_->runOne();
}
// We are going to asynchronously send the 'foo' over the unix socket.
// Run IO service to generate server's response.
while ((test_socket_->getResponseNum() < 1) &&
(!test_socket_->isStopped())) {
- io_service_.runOne();
+ io_service_->runOne();
}
// There is no guarantee that all data have been sent so we only check that
// Run IO service until we get the full response from the server.
while ((response_.size() < expected_response.size()) &&
!test_socket_->isStopped()) {
- io_service_.runOne();
+ io_service_->runOne();
}
// Check that the entire response has been received and is correct.
EXPECT_TRUE(ec);
});
while (!connect_handler_invoked && !test_socket_->isStopped()) {
- io_service_.runOne();
+ io_service_->runOne();
}
// Send
EXPECT_TRUE(ec);
});
while (!send_handler_invoked && !test_socket_->isStopped()) {
- io_service_.runOne();
+ io_service_->runOne();
}
// Receive
EXPECT_TRUE(ec);
});
while (!receive_handler_invoked && !test_socket_->isStopped()) {
- io_service_.runOne();
+ io_service_->runOne();
}
}
/// @brief Constructor.
///
/// @param io_service Reference to the IO service.
- ConnectionPool(IOService& io_service)
+ ConnectionPool(IOServicePtr& io_service)
: io_service_(io_service), connections_(), next_socket_(),
response_num_(0) {
}
/// @return Pointer to the socket.
UnixSocketPtr getSocket() {
if (!next_socket_) {
- next_socket_.reset(new UnixSocket(io_service_.getInternalIOService()));
+ next_socket_.reset(new UnixSocket(io_service_->getInternalIOService()));
}
return (next_socket_);
}
private:
- /// @brief Reference to the IO service.
- IOService& io_service_;
+ /// @brief Pointer to the IO service.
+ IOServicePtr io_service_;
/// @brief Container holding established connections.
std::set<ConnectionPtr> connections_;
};
-TestServerUnixSocket::TestServerUnixSocket(IOService& io_service,
+TestServerUnixSocket::TestServerUnixSocket(const IOServicePtr& io_service,
const std::string& socket_file_path,
const std::string& custom_response)
: io_service_(io_service),
server_endpoint_(socket_file_path),
- server_acceptor_(io_service_.getInternalIOService()),
+ server_acceptor_(io_service_->getInternalIOService()),
test_timer_(io_service_),
custom_response_(custom_response),
- connection_pool_(new ConnectionPool(io_service)),
+ connection_pool_(new ConnectionPool(io_service_)),
stopped_(false),
running_(false) {
}
// 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(std::bind(&TestServerUnixSocket::signalRunning,
- this));
+ io_service_->post(std::bind(&TestServerUnixSocket::signalRunning, this));
}
}
void
TestServerUnixSocket::accept() {
server_acceptor_.async_accept(*(connection_pool_->getSocket()),
- std::bind(&TestServerUnixSocket::acceptHandler, this,
- ph::_1)); // error
+ std::bind(&TestServerUnixSocket::acceptHandler, this, ph::_1)); // error
}
void
void
TestServerUnixSocket::timeoutHandler() {
ADD_FAILURE() << "Timeout occurred while running the test!";
- io_service_.stop();
+ io_service_->stop();
stopped_ = true;
}
/// @param io_service IO service.
/// @param socket_file_path Socket file path.
/// @param custom_response Custom response to be sent to the client.
- TestServerUnixSocket(IOService& io_service,
+ TestServerUnixSocket(const IOServicePtr& io_service,
const std::string& socket_file_path,
const std::string& custom_response = "");
void signalRunning();
/// @brief IO service used by the tests.
- IOService& io_service_;
+ IOServicePtr io_service_;
/// @brief Server endpoint.
boost::asio::local::stream_protocol::endpoint server_endpoint_;
/// raised.
/// @param mode selects between a one-shot signal or a signal which repeats
/// at "milliseconds" interval.
- TimedSignal(asiolink::IOService& io_service, int signum, int milliseconds,
+ TimedSignal(asiolink::IOServicePtr& io_service, int signum, int milliseconds,
const asiolink::IntervalTimer::Mode& mode =
asiolink::IntervalTimer::ONE_SHOT)
: timer_(new asiolink::IntervalTimer(io_service)) {
/// @brief Constructor.
///
/// @param io_service IO service.
- explicit TLSAcceptor(IOService& io_service) : TCPAcceptor<C>(io_service) {
+ explicit TLSAcceptor(const IOServicePtr& io_service) : TCPAcceptor<C>(io_service) {
}
/// @brief Destructor.
///
/// @param service I/O Service object used to manage the socket.
/// @param context Pointer to TLS context.
- TLSSocket(IOService& service, TlsContextPtr context);
+ TLSSocket(const IOServicePtr& service, TlsContextPtr context);
/// @brief Destructor.
virtual ~TLSSocket() { }
}
private:
+ /// @brief The IO service used to handle events.
+ IOServicePtr io_service_;
+
/// Two variables to hold the stream - a stream and a pointer to it. This
/// handles the case where a stream is passed to the TLSSocket on
/// construction, or where it is asked to manage its own stream.
// Constructor - create socket on the fly.
template <typename C>
-TLSSocket<C>::TLSSocket(IOService& service, TlsContextPtr context) :
- stream_ptr_(new TlsStream<C>(service, context)),
- stream_(*stream_ptr_), socket_(stream_.lowest_layer()), send_buffer_()
-{
+TLSSocket<C>::TLSSocket(const IOServicePtr& io_service, TlsContextPtr context)
+ : io_service_(io_service),
+ stream_ptr_(new TlsStream<C>(io_service, context)),
+ stream_(*stream_ptr_), socket_(stream_.lowest_layer()), send_buffer_() {
}
// Open the socket.
/// socket. In this case, the open() and close() methods are used.
///
/// \param service I/O Service object used to manage the socket.
- UDPSocket(IOService& service);
+ UDPSocket(const IOServicePtr& service);
/// \brief Destructor
virtual ~UDPSocket();
private:
+ /// @brief The IO service used to handle events.
+ IOServicePtr io_service_;
+
// Two variables to hold the socket - a socket and a pointer to it. This
// handles the case where a socket is passed to the UDPSocket on
// construction, or where it is asked to manage its own socket.
// Constructor - create socket on the fly
template <typename C>
-UDPSocket<C>::UDPSocket(IOService& service) :
- socket_ptr_(new boost::asio::ip::udp::socket(service.getInternalIOService())),
+UDPSocket<C>::UDPSocket(const IOServicePtr& io_service) : io_service_(io_service),
+ socket_ptr_(new boost::asio::ip::udp::socket(io_service_->getInternalIOService())),
socket_(*socket_ptr_), isopen_(false)
{
}
/// @brief Constructor.
///
/// @param io_service IO service to be used by the socket class.
- UnixDomainSocketImpl(IOService& io_service)
- : socket_(io_service.getInternalIOService()) {
+ UnixDomainSocketImpl(const IOServicePtr& io_service)
+ : io_service_(io_service), socket_(io_service_->getInternalIOService()) {
}
/// @brief Destructor.
/// @brief Closes the socket.
void close();
+ /// @brief The IO service used to handle events.
+ IOServicePtr io_service_;
+
/// @brief Instance of the boost asio unix domain socket.
stream_protocol::socket socket_;
};
}
}
-UnixDomainSocket::UnixDomainSocket(IOService& io_service)
+UnixDomainSocket::UnixDomainSocket(const IOServicePtr& io_service)
: impl_(new UnixDomainSocketImpl(io_service)) {
}
///
/// @param io_service Reference to IOService to be used by this
/// class.
- explicit UnixDomainSocket(IOService& io_service);
+ explicit UnixDomainSocket(const IOServicePtr& io_service);
/// @brief Returns native socket representation.
virtual int getNative() const;
/// @brief Constructor.
///
/// @param io_service Reference to the IO service.
- explicit UnixDomainSocketAcceptor(IOService& io_service)
+ explicit UnixDomainSocketAcceptor(const IOServicePtr& io_service)
: IOAcceptor<boost::asio::local::stream_protocol,
std::function<void(const boost::system::error_code&)> >(io_service) {
}
/// @brief Constructor.
///
/// @param io_service Reference to the IO service.
- explicit ClientConnectionImpl(IOService& io_service);
+ explicit ClientConnectionImpl(const IOServicePtr& io_service);
/// @brief This method schedules timer or reschedules existing timer.
///
long timeout_;
};
-ClientConnectionImpl::ClientConnectionImpl(IOService& io_service)
+ClientConnectionImpl::ClientConnectionImpl(const IOServicePtr& io_service)
: socket_(io_service), feed_(), current_command_(), timer_(io_service),
timeout_(0) {
}
terminate(boost::asio::error::timed_out, handler);
}
-ClientConnection::ClientConnection(asiolink::IOService& io_service)
+ClientConnection::ClientConnection(const IOServicePtr& io_service)
: impl_(new ClientConnectionImpl(io_service)) {
}
impl_->start(socket_path, command, handler, timeout);
}
-
} // end of namespace config
} // end of namespace isc
/// @brief Constructor.
///
/// @param io_service Reference to the IO service.
- explicit ClientConnection(asiolink::IOService& io_service);
+ explicit ClientConnection(const asiolink::IOServicePtr& io_service);
/// @brief Starts asynchronous transaction with a remote endpoint.
///
// Create the HTTP listener. It will open up a TCP socket and be
// prepared to accept incoming connections.
- http_listener_.reset(new HttpListener(*thread_io_service_, address_,
+ http_listener_.reset(new HttpListener(thread_io_service_, address_,
port_, tls_context_, rcf,
HttpListener::RequestTimeout(TIMEOUT_AGENT_RECEIVE_COMMAND),
HttpListener::IdleTimeout(TIMEOUT_AGENT_IDLE_CONNECTION_TIMEOUT)));
const boost::shared_ptr<UnixDomainSocket>& socket,
ConnectionPool& connection_pool,
const long timeout)
- : socket_(socket), timeout_timer_(*io_service), timeout_(timeout),
+ : socket_(socket), timeout_timer_(io_service), timeout_(timeout),
buf_(), response_(), connection_pool_(connection_pool), feed_(),
response_in_progress_(false), watch_socket_(new util::WatchSocket()) {
void receiveHandler(const boost::system::error_code& ec,
size_t bytes_transferred);
-
/// @brief Handler invoked when the data is sent over the control socket.
///
/// If there are still data to be sent, another asynchronous send is
doSend();
}
-
}
namespace isc {
try {
// Start asynchronous acceptor service.
- acceptor_.reset(new UnixDomainSocketAcceptor(*io_service_));
+ acceptor_.reset(new UnixDomainSocketAcceptor(io_service_));
UnixDomainSocketEndpoint endpoint(socket_name_);
acceptor_->open(endpoint);
acceptor_->bind(endpoint);
void
CommandMgrImpl::doAccept() {
// Create a socket into which the acceptor will accept new connection.
- socket_.reset(new UnixDomainSocket(*io_service_));
+ socket_.reset(new UnixDomainSocket(io_service_));
acceptor_->asyncAccept(*socket_, [this](const boost::system::error_code& ec) {
if (!ec) {
// New connection is arriving. Start asynchronous transmission.
return (impl_->acceptor_ ? impl_->acceptor_->getNative() : -1);
}
-
CommandMgr&
CommandMgr::instance() {
static CommandMgr cmd_mgr;
impl_->timeout_ = timeout;
}
-
-}; // end of isc::config
-}; // end of isc
+} // end of isc::config
+} // end of isc
///
/// Removes unix socket descriptor before the test.
ClientConnectionTest() :
- io_service_(),
+ io_service_(new IOService()),
test_socket_(new test::TestServerUnixSocket(io_service_,
unixSocketFilePath())) {
removeUnixSocketFile();
}
/// @brief IO service used by the tests.
- IOService io_service_;
+ IOServicePtr io_service_;
/// @brief Server side unix socket used in these tests.
test::TestServerUnixSocketPtr test_socket_;
});
// Run the connection.
while (!handler_invoked && !test_socket_->isStopped()) {
- io_service_.runOne();
+ io_service_->runOne();
}
}
}, ClientConnection::Timeout(1000));
while (!handler_invoked && !test_socket_->isStopped()) {
- io_service_.runOne();
+ io_service_->runOne();
}
}
});
while (!handler_invoked && !test_socket_->isStopped()) {
- io_service_.runOne();
+ io_service_->runOne();
}
}
/// Starts test timer which detects timeouts, deregisters all commands
/// from CommandMgr, and enables multi-threading mode.
CmdHttpListenerTest()
- : listener_(), io_service_(), test_timer_(io_service_),
+ : listener_(), io_service_(new IOService()), test_timer_(io_service_),
run_io_service_timer_(io_service_), clients_(), num_threads_(),
num_clients_(), num_in_progress_(0), num_finished_(0), chunk_size_(0),
pause_cnt_(0) {
if (fail_on_timeout) {
ADD_FAILURE() << "Timeout occurred while running the test!";
}
- io_service_.stop();
+ io_service_->stop();
}
/// @brief Runs IO service with optional timeout.
size_t num_done = 0;
while (num_done != request_limit) {
// Always call restart() before we call run();
- io_service_.restart();
+ io_service_->restart();
// Run until a client stops the service.
- io_service_.run();
+ io_service_->run();
// If all the clients are done receiving, the test is done.
num_done = 0;
CmdHttpListenerPtr listener_;
/// @brief IO service used in drive the test and test clients.
- IOService io_service_;
+ IOServicePtr io_service_;
/// @brief Asynchronous timer service to detect timeouts.
IntervalTimer test_timer_;
/// @param tsig_key A pointer to an @c D2TsigKeyPtr object that will
/// (if not null) be used to sign the DNS Update message and verify the
/// response.
- void doUpdate(asiolink::IOService& io_service,
+ void doUpdate(const asiolink::IOServicePtr& io_service,
const asiolink::IOAddress& ns_addr,
const uint16_t ns_port,
D2UpdateMessage& update,
}
void
-DNSClientImpl::doUpdate(asiolink::IOService& io_service,
+DNSClientImpl::doUpdate(const asiolink::IOServicePtr& io_service,
const IOAddress& ns_addr,
const uint16_t ns_port,
D2UpdateMessage& update,
// Post the task to the task queue in the IO service. Caller will actually
// run these tasks by executing IOService::run.
- io_service.post(io_fetch);
+ io_service->post(io_fetch);
// Update sent statistics.
incrStats("update-sent");
}
void
-DNSClient::doUpdate(asiolink::IOService& io_service,
+DNSClient::doUpdate(const asiolink::IOServicePtr& io_service,
const IOAddress& ns_addr,
const uint16_t ns_port,
D2UpdateMessage& update,
/// @param tsig_key A pointer to an @c D2TsigKeyPtr object that will
/// (if not null) be used to sign the DNS Update message and verify the
/// response.
- void doUpdate(asiolink::IOService& io_service,
+ void doUpdate(const asiolink::IOServicePtr& io_service,
const asiolink::IOAddress& ns_addr,
const uint16_t ns_port,
D2UpdateMessage& update,
// for the current server. If not we would need to add that.
D2ParamsPtr d2_params = cfg_mgr_->getD2Params();
- dns_client_->doUpdate(*io_service_, current_server_->getIpAddress(),
+ dns_client_->doUpdate(io_service_, current_server_->getIpAddress(),
current_server_->getPort(), *dns_update_request_,
d2_params->getDnsServerTimeout(), tsig_key_);
// Message is on its way, so the next event should be NOP_EVT.
public D2StatTest {
public:
/// @brief The IOService which handles IO operations.
- IOService service_;
+ IOServicePtr service_;
/// @brief The UDP socket.
std::unique_ptr<udp::socket> socket_;
/// waiting for a response. Some of the tests are checking DNSClient behavior
/// in case when response from the server is not received. Tests output would
/// become messy if such errors were logged.
- DNSClientTest() : service_(), socket_(), endpoint_(),
+ DNSClientTest() : service_(new IOService()), socket_(), endpoint_(),
status_(DNSClient::SUCCESS), corrupt_response_(false),
expect_response_(true), test_timer_(service_),
received_(0), expected_(0), go_on_(false) {
virtual void operator()(DNSClient::Status status) {
status_ = status;
if (!expected_ || (expected_ == ++received_)) {
- service_.stop();
+ service_->stop();
}
if (expect_response_) {
///
/// This callback stops all running (hanging) tasks on IO service.
void testTimeoutHandler() {
- service_.stop();
+ service_->stop();
FAIL() << "Test timeout hit.";
}
// This starts the execution of tasks posted to IOService. run() blocks
// until stop() is called in the completion callback function.
- service_.run();
+ service_->run();
}
// responses. The reuse address option is set so as both sockets can
// use the same address. This new socket is bound to the test address
// and port, where requests will be sent.
- socket_.reset(new udp::socket(service_.getInternalIOService(),
+ socket_.reset(new udp::socket(service_->getInternalIOService(),
boost::asio::ip::udp::v4()));
socket_->set_option(socket_base::reuse_address(true));
socket_->bind(udp::endpoint(address::from_string(TEST_ADDRESS),
// Kick of the message exchange by actually running the scheduled
// "send" and "receive" operations.
- service_.run();
+ service_->run();
socket_->close();
// Since the callback, operator(), calls stop() on the io_service,
// we must reset it in order for subsequent calls to run() or
// runOne() to work.
- service_.restart();
+ service_->restart();
}
/// @brief Performs a single request-response exchange with or without TSIG.
ASSERT_NO_THROW(message.setZone(Name("example.com"), RRClass::IN()));
// Setup our "loopback" server.
- udp::socket udp_socket(service_.getInternalIOService(), boost::asio::ip::udp::v4());
+ udp::socket udp_socket(service_->getInternalIOService(), boost::asio::ip::udp::v4());
udp_socket.set_option(socket_base::reuse_address(true));
udp_socket.bind(udp::endpoint(address::from_string(TEST_ADDRESS),
TEST_PORT));
// Kick of the message exchange by actually running the scheduled
// "send" and "receive" operations.
- service_.run();
+ service_->run();
udp_socket.close();
// Since the callback, operator(), calls stop() on the io_service,
// we must reset it in order for subsequent calls to run() or
// runOne() to work.
- service_.restart();
+ service_->restart();
}
};
ASSERT_TRUE(name_change->selectFwdServer());
// Create a server and start it listening.
- FauxServer server(*io_service_, *(name_change->getCurrentServer()));
+ FauxServer server(io_service_, *(name_change->getCurrentServer()));
server.receive(FauxServer::CORRUPT_RESP);
// Build a valid request, call sendUpdate and process the response.
ASSERT_TRUE(name_change->selectFwdServer());
// Create a server and start it listening.
- FauxServer server(*io_service_, *(name_change->getCurrentServer()));
+ FauxServer server(io_service_, *(name_change->getCurrentServer()));
server.receive (FauxServer::USE_RCODE, dns::Rcode::NOERROR());
// Build a valid request, call sendUpdate and process the response.
ASSERT_TRUE(name_change->selectFwdServer());
// Create a server and start it listening.
- FauxServer server(*io_service_, *(name_change->getCurrentServer()));
+ FauxServer server(io_service_, *(name_change->getCurrentServer()));
server.receive (FauxServer::USE_RCODE, dns::Rcode::NOERROR());
// Do the update.
// Create a server, tell it to sign responses with a "random" key,
// then start it listening.
- FauxServer server(*io_service_, *(name_change->getCurrentServer()));
+ FauxServer server(io_service_, *(name_change->getCurrentServer()));
server.receive (FauxServer::INVALID_TSIG, dns::Rcode::NOERROR());
// Do the update.
// Create a server, tell it to sign responses with a "random" key,
// then start it listening.
- FauxServer server(*io_service_, *(name_change->getCurrentServer()));
+ FauxServer server(io_service_, *(name_change->getCurrentServer()));
server.receive (FauxServer::INVALID_TSIG, dns::Rcode::NOERROR());
// Perform an update without TSIG.
ASSERT_TRUE(name_change->selectFwdServer());
// Create a server, set its TSIG key, and then start it listening.
- FauxServer server(*io_service_, *(name_change->getCurrentServer()));
+ FauxServer server(io_service_, *(name_change->getCurrentServer()));
// Since we create a new server instance each time we need to tell
// it not reschedule receives automatically.
server.perpetual_receive_ = false;
" \"port\": 100 } ] } "
"] } }";
-
const char* TEST_DNS_SERVER_IP = "127.0.0.1";
size_t TEST_DNS_SERVER_PORT = 5301;
//*************************** FauxServer class ***********************
-FauxServer::FauxServer(asiolink::IOService& io_service,
+FauxServer::FauxServer(asiolink::IOServicePtr& io_service,
asiolink::IOAddress& address, size_t port)
- :io_service_(io_service), address_(address), port_(port),
- server_socket_(), receive_pending_(false), perpetual_receive_(true),
- tsig_key_() {
+ : io_service_(io_service), address_(address), port_(port),
+ server_socket_(), receive_pending_(false), perpetual_receive_(true),
+ tsig_key_() {
- server_socket_.reset(new boost::asio::ip::udp::socket(io_service_.getInternalIOService(),
- boost::asio::ip::udp::v4()));
+ server_socket_.reset(new boost::asio::ip::udp::socket(io_service_->getInternalIOService(),
+ boost::asio::ip::udp::v4()));
server_socket_->set_option(boost::asio::socket_base::reuse_address(true));
isc::asiolink::UDPEndpoint endpoint(address_, port_);
server_socket_->bind(endpoint.getASIOEndpoint());
}
-FauxServer::FauxServer(asiolink::IOService& io_service,
+FauxServer::FauxServer(asiolink::IOServicePtr& io_service,
DnsServerInfo& server)
- :io_service_(io_service), address_(server.getIpAddress()),
- port_(server.getPort()), server_socket_(), receive_pending_(false),
- perpetual_receive_(true), tsig_key_() {
- server_socket_.reset(new boost::asio::ip::udp::socket(io_service_.getInternalIOService(),
- boost::asio::ip::udp::v4()));
+ : io_service_(io_service), address_(server.getIpAddress()),
+ port_(server.getPort()), server_socket_(), receive_pending_(false),
+ perpetual_receive_(true), tsig_key_() {
+ server_socket_.reset(new boost::asio::ip::udp::socket(io_service_->getInternalIOService(),
+ boost::asio::ip::udp::v4()));
server_socket_->set_option(boost::asio::socket_base::reuse_address(true));
isc::asiolink::UDPEndpoint endpoint(address_, port_);
server_socket_->bind(endpoint.getASIOEndpoint());
}
-
FauxServer::~FauxServer() {
}
}
}
-
-
//********************** TimedIO class ***********************
TimedIO::TimedIO()
- : io_service_(new isc::asiolink::IOService()),
- timer_(*io_service_), run_time_(0) {
+ : io_service_(new isc::asiolink::IOService()), timer_(io_service_),
+ run_time_(0) {
}
TimedIO::~TimedIO() {
setupForIPv6Transaction(chg_type, change_mask, makeTSIGKeyInfo(key_name));
}
-
//********************** Functions ****************************
void
INVALID_TSIG // Generate a response with the wrong TSIG key
};
- /// @brief Reference to IOService to use for IO processing.
- asiolink::IOService& io_service_;
+ /// @brief The IO service used to handle events.
+ asiolink::IOServicePtr io_service_;
/// @brief IP address at which to listen for requests.
const asiolink::IOAddress& address_;
/// @param io_service IOService to be used for socket IO.
/// @param address IP address at which the server should listen.
/// @param port Port number at which the server should listen.
- FauxServer(asiolink::IOService& io_service, asiolink::IOAddress& address,
+ FauxServer(asiolink::IOServicePtr& io_service, asiolink::IOAddress& address,
size_t port);
/// @brief Constructor
/// @param io_service IOService to be used for socket IO.
/// @param server DnsServerInfo of server the DNS server. This supplies the
/// server's ip address and port.
- FauxServer(asiolink::IOService& io_service, DnsServerInfo& server);
+ FauxServer(asiolink::IOServicePtr& io_service, DnsServerInfo& server);
/// @brief Destructor
virtual ~FauxServer();
void
-NameChangeListener::startListening(isc::asiolink::IOService& io_service) {
+NameChangeListener::startListening(const isc::asiolink::IOServicePtr& io_service) {
if (amListening()) {
// This amounts to a programmatic error.
isc_throw(NcrListenerError, "NameChangeListener is already listening");
NameChangeSender::NameChangeSender(RequestSendHandler& send_handler,
size_t send_queue_max)
: sending_(false), send_handler_(send_handler),
- send_queue_max_(send_queue_max), io_service_(NULL), mutex_(new mutex) {
+ send_queue_max_(send_queue_max), mutex_(new mutex) {
// Queue size must be big enough to hold at least 1 entry.
setQueueMaxSize(send_queue_max);
}
void
-NameChangeSender::startSending(isc::asiolink::IOService& io_service) {
+NameChangeSender::startSending(const isc::asiolink::IOServicePtr& io_service) {
if (amSending()) {
// This amounts to a programmatic error.
isc_throw(NcrSenderError, "NameChangeSender is already sending");
}
void
-NameChangeSender::startSendingInternal(isc::asiolink::IOService& io_service) {
+NameChangeSender::startSendingInternal(const isc::asiolink::IOServicePtr& io_service) {
// Clear send marker.
ncr_to_send_.reset();
// Remember io service we're given.
- io_service_ = &io_service;
+ io_service_ = io_service;
open(io_service);
// Set our status to sending.
setSending(false);
// If there is an outstanding IO to complete, attempt to process it.
- if (ioReady() && io_service_ != NULL) {
+ if (ioReady() && io_service_) {
try {
runReadyIO();
} catch (const std::exception& ex) {
DHCP_DDNS_NCR_SEND_CLOSE_ERROR).arg(ex.what());
}
- io_service_ = NULL;
+ io_service_.reset();
}
void
isc::Exception(file, line, what) { };
};
-
/// @brief Abstract interface for receiving NameChangeRequests.
///
/// NameChangeListener provides the means to:
///
/// @throw NcrListenError if the listener is already "listening" or
/// in the event the open or doReceive methods fail.
- void startListening(isc::asiolink::IOService& io_service);
+ void startListening(const isc::asiolink::IOServicePtr& io_service);
/// @brief Closes the IO source and stops listen logic.
///
void stopListening();
protected:
+
/// @brief Initiates an asynchronous receive
///
/// Sets context information to indicate that IO is in progress and invokes
///
/// @throw If the implementation encounters an error it MUST
/// throw it as an isc::Exception or derivative.
- virtual void open(isc::asiolink::IOService& io_service) = 0;
+ virtual void open(const isc::asiolink::IOServicePtr& io_service) = 0;
/// @brief Abstract method which closes the IO source.
///
/// @brief Defines a smart pointer to an instance of a listener.
typedef boost::shared_ptr<NameChangeListener> NameChangeListenerPtr;
-
/// @brief Thrown when a NameChangeSender encounters an error.
class NcrSenderError : public isc::Exception {
public:
isc::Exception(file, line, what) { };
};
-
/// @brief Abstract interface for sending NameChangeRequests.
///
/// NameChangeSender provides the means to:
///
/// @throw NcrSenderError if the sender is already "sending" or
/// NcrSenderOpenError if the open fails.
- void startSending(isc::asiolink::IOService & io_service);
+ void startSending(const isc::asiolink::IOServicePtr& io_service);
/// @brief Closes the IO sink and stops send logic.
///
/// @brief Prepares the IO for transmission in a thread safe context.
///
/// @param io_service is the IOService that will handle IO event processing.
- void startSendingInternal(isc::asiolink::IOService & io_service);
+ void startSendingInternal(const isc::asiolink::IOServicePtr & io_service);
/// @brief Queues the given request to be sent in a thread safe context.
///
///
/// @throw If the implementation encounters an error it MUST
/// throw it as an isc::Exception or derivative.
- virtual void open(isc::asiolink::IOService& io_service) = 0;
+ virtual void open(const isc::asiolink::IOServicePtr& io_service) = 0;
/// @brief Abstract method which closes the IO sink.
///
sending_ = value;
}
+protected:
+
+ /// @brief Pointer to the IOService currently being used by the sender.
+ /// @note We need to remember the io_service but we receive it by
+ /// reference. Use a raw pointer to store it. This value should never be
+ /// exposed and is only valid while in send mode.
+ asiolink::IOServicePtr io_service_;
+
+private:
+
/// @brief Boolean indicator which tracks sending status.
bool sending_;
/// @brief Pointer to the request which is in the process of being sent.
NameChangeRequestPtr ncr_to_send_;
- /// @brief Pointer to the IOService currently being used by the sender.
- /// @note We need to remember the io_service but we receive it by
- /// reference. Use a raw pointer to store it. This value should never be
- /// exposed and is only valid while in send mode.
- asiolink::IOService* io_service_;
-
/// @brief The mutex used to protect internal state.
const boost::scoped_ptr<std::mutex> mutex_;
};
}
void
-NameChangeUDPListener::open(isc::asiolink::IOService& io_service) {
+NameChangeUDPListener::open(const isc::asiolink::IOServicePtr& io_service) {
// create our endpoint and bind the low level socket to it.
isc::asiolink::UDPEndpoint endpoint(ip_address_, port_);
+ io_service_ = io_service;
+
// Create the low level socket.
try {
asio_socket_.reset(new boost::asio::ip::udp::
- socket(io_service.getInternalIOService(),
+ socket(io_service_->getInternalIOService(),
(ip_address_.isV4() ? boost::asio::ip::udp::v4() :
boost::asio::ip::udp::v6())));
asio_socket_->bind(endpoint.getASIOEndpoint());
} catch (const boost::system::system_error& ex) {
asio_socket_.reset();
+ io_service_.reset();
isc_throw (NcrUDPError, ex.code().message());
}
}
socket_.reset();
+ io_service_.reset();
}
void
}
void
-NameChangeUDPSender::open(isc::asiolink::IOService& io_service) {
+NameChangeUDPSender::open(const isc::asiolink::IOServicePtr& io_service) {
// create our endpoint and bind the low level socket to it.
isc::asiolink::UDPEndpoint endpoint(ip_address_, port_);
+ io_service_ = io_service;
+
// Create the low level socket.
try {
asio_socket_.reset(new boost::asio::ip::udp::
- socket(io_service.getInternalIOService(),
+ socket(io_service_->getInternalIOService(),
(ip_address_.isV4() ? boost::asio::ip::udp::v4() :
boost::asio::ip::udp::v6())));
// Bind the low level socket to our endpoint.
asio_socket_->bind(endpoint.getASIOEndpoint());
} catch (const boost::system::system_error& ex) {
+ asio_socket_.reset();
+ io_service_.reset();
isc_throw (NcrUDPError, ex.code().message());
}
closeWatchSocket();
watch_socket_.reset();
+ io_service_.reset();
}
void
#include <boost/shared_array.hpp>
-
/// responsibility of the completion handler to perform the steps necessary
/// to interpret the raw data provided by the service outcome. The
/// UDPCallback operator implementation is mostly a pass through.
/// @param io_service the IOService which will monitor the socket.
///
/// @throw NcrUDPError if the open fails.
- virtual void open(isc::asiolink::IOService& io_service);
+ virtual void open(const isc::asiolink::IOServicePtr& io_service);
/// @brief Closes the UDPSocket.
///
/// the socket receive completion.
void receiveCompletionHandler(const bool successful,
const UDPCallback* recv_callback);
+
private:
+
+ /// @brief The IO service used to handle events.
+ isc::asiolink::IOServicePtr io_service_;
+
/// @brief IP address on which to listen for requests.
isc::asiolink::IOAddress ip_address_;
//@}
};
-
/// @brief Provides the ability to send NameChangeRequests via UDP socket
///
/// This class is a derivation of the NameChangeSender which is capable of
/// @brief Destructor
virtual ~NameChangeUDPSender();
-
/// @brief Opens a UDP socket using the given IOService.
///
/// Creates a NameChangeUDPSocket bound to the sender's IP address
/// @param io_service the IOService which will monitor the socket.
///
/// @throw NcrUDPError if the open fails.
- virtual void open(isc::asiolink::IOService& io_service);
-
+ virtual void open(const isc::asiolink::IOServicePtr& io_service);
/// @brief Closes the UDPSocket.
///
using namespace std;
using namespace isc;
+using namespace isc::asiolink;
using namespace isc::util;
using namespace isc::dhcp_ddns;
/// 1. Given valid parameters, the listener constructor works
TEST(NameChangeUDPListenerBasicTest, constructionTests) {
// Verify the default constructor works.
- isc::asiolink::IOAddress ip_address(TEST_ADDRESS);
+ IOAddress ip_address(TEST_ADDRESS);
uint32_t port = LISTENER_PORT;
- isc::asiolink::IOService io_service;
SimpleListenHandler ncr_handler;
// Verify that valid constructor works.
EXPECT_NO_THROW(NameChangeUDPListener(ip_address, port, FMT_JSON,
/// 4. Return to the listening state after stopping
TEST(NameChangeUDPListenerBasicTest, basicListenTests) {
// Verify the default constructor works.
- isc::asiolink::IOAddress ip_address(TEST_ADDRESS);
+ IOAddress ip_address(TEST_ADDRESS);
uint32_t port = LISTENER_PORT;
- isc::asiolink::IOService io_service;
+ IOServicePtr io_service(new IOService());
SimpleListenHandler ncr_handler;
NameChangeListenerPtr listener;
EXPECT_TRUE(listener->isIoPending());
// Verify that IO pending is false, after cancel event occurs.
- EXPECT_NO_THROW(io_service.runOne());
+ EXPECT_NO_THROW(io_service->runOne());
EXPECT_FALSE(listener->isIoPending());
// Verify that attempting to stop listening when we are not is ok.
/// @brief Compares two NameChangeRequests for equality.
bool checkSendVsReceived(NameChangeRequestPtr sent_ncr,
NameChangeRequestPtr received_ncr) {
- return ((sent_ncr && received_ncr) &&
- (*sent_ncr == *received_ncr));
+ return ((sent_ncr && received_ncr) && (*sent_ncr == *received_ncr));
}
/// @brief Text fixture for testing NameChangeUDPListener
class NameChangeUDPListenerTest : public virtual ::testing::Test,
NameChangeListener::RequestReceiveHandler {
public:
- isc::asiolink::IOService io_service_;
+ IOServicePtr io_service_;
NameChangeListener::Result result_;
NameChangeRequestPtr sent_ncr_;
NameChangeRequestPtr received_ncr_;
NameChangeListenerPtr listener_;
- isc::asiolink::IntervalTimer test_timer_;
+ IntervalTimer test_timer_;
/// @brief Constructor
//
// Instantiates the listener member and the test timer. The timer is used
// to ensure a test doesn't go awry and hang forever.
NameChangeUDPListenerTest()
- : io_service_(), result_(NameChangeListener::SUCCESS),
+ : io_service_(new IOService()), result_(NameChangeListener::SUCCESS),
test_timer_(io_service_) {
- isc::asiolink::IOAddress addr(TEST_ADDRESS);
+ IOAddress addr(TEST_ADDRESS);
listener_.reset(new NameChangeUDPListener(addr, LISTENER_PORT,
FMT_JSON, *this, true));
// Create a UDP socket through which our "sender" will send the NCR.
boost::asio::ip::udp::socket
- udp_socket(io_service_.getInternalIOService(), boost::asio::ip::udp::v4());
+ udp_socket(io_service_->getInternalIOService(), boost::asio::ip::udp::v4());
// Create an endpoint pointed at the listener.
boost::asio::ip::udp::endpoint
///
/// This callback stops all running (hanging) tasks on IO service.
void testTimeoutHandler() {
- io_service_.stop();
+ io_service_->stop();
FAIL() << "Test timeout hit.";
}
};
ASSERT_NO_THROW(sendNcr(valid_msgs[i]));
// Execute no more then one event, which should be receive complete.
- EXPECT_NO_THROW(io_service_.runOne());
+ EXPECT_NO_THROW(io_service_->runOne());
// Verify the "application" status value for a successful complete.
EXPECT_EQ(NameChangeListener::SUCCESS, result_);
EXPECT_FALSE(listener_->amListening());
// Verify that IO pending is false, after cancel event occurs.
- EXPECT_NO_THROW(io_service_.runOne());
+ EXPECT_NO_THROW(io_service_->runOne());
EXPECT_FALSE(listener_->isIoPending());
}
/// 3. Default construction provides default max queue size
/// 4. Construction with a custom max queue size works
TEST_F(NameChangeUDPSenderBasicTest, constructionTests) {
- isc::asiolink::IOAddress ip_address(TEST_ADDRESS);
+ IOAddress ip_address(TEST_ADDRESS);
uint32_t port = SENDER_PORT;
- isc::asiolink::IOService io_service;
SimpleSendHandler ncr_handler;
// Verify that constructing with an queue size of zero is not allowed.
// Enable multi-threading
MultiThreadingMgr::instance().setMode(true);
- isc::asiolink::IOAddress ip_address(TEST_ADDRESS);
+ IOAddress ip_address(TEST_ADDRESS);
uint32_t port = SENDER_PORT;
- isc::asiolink::IOService io_service;
SimpleSendHandler ncr_handler;
// Verify that constructing with an queue size of zero is not allowed.
/// @brief Tests NameChangeUDPSender basic send functionality
TEST_F(NameChangeUDPSenderBasicTest, basicSendTests) {
- isc::asiolink::IOAddress ip_address(TEST_ADDRESS);
- isc::asiolink::IOService io_service;
+ IOAddress ip_address(TEST_ADDRESS);
+ IOServicePtr io_service(new IOService());
SimpleSendHandler ncr_handler;
// Tests are based on a list of messages, get the count now.
// Enable multi-threading
MultiThreadingMgr::instance().setMode(true);
- isc::asiolink::IOAddress ip_address(TEST_ADDRESS);
- isc::asiolink::IOService io_service;
+ IOAddress ip_address(TEST_ADDRESS);
+ IOServicePtr io_service(new IOService());
SimpleSendHandler ncr_handler;
// Tests are based on a list of messages, get the count now.
/// @brief Tests that sending gets kick-started if the queue isn't empty
/// when startSending is called.
TEST_F(NameChangeUDPSenderBasicTest, autoStart) {
- isc::asiolink::IOAddress ip_address(TEST_ADDRESS);
- isc::asiolink::IOService io_service;
+ IOAddress ip_address(TEST_ADDRESS);
+ IOServicePtr io_service(new IOService());
SimpleSendHandler ncr_handler;
// Tests are based on a list of messages, get the count now.
// Enable multi-threading
MultiThreadingMgr::instance().setMode(true);
- isc::asiolink::IOAddress ip_address(TEST_ADDRESS);
- isc::asiolink::IOService io_service;
+ IOAddress ip_address(TEST_ADDRESS);
+ IOServicePtr io_service(new IOService());
SimpleSendHandler ncr_handler;
// Tests are based on a list of messages, get the count now.
/// @brief Tests NameChangeUDPSender basic send with INADDR_ANY and port 0.
TEST_F(NameChangeUDPSenderBasicTest, anyAddressSend) {
- isc::asiolink::IOAddress ip_address(TEST_ADDRESS);
- isc::asiolink::IOAddress any_address("0.0.0.0");
- isc::asiolink::IOService io_service;
+ IOAddress ip_address(TEST_ADDRESS);
+ IOAddress any_address("0.0.0.0");
+ IOServicePtr io_service(new IOService());
SimpleSendHandler ncr_handler;
// Tests are based on a list of messages, get the count now.
// Enable multi-threading
MultiThreadingMgr::instance().setMode(true);
- isc::asiolink::IOAddress ip_address(TEST_ADDRESS);
- isc::asiolink::IOAddress any_address("0.0.0.0");
- isc::asiolink::IOService io_service;
+ IOAddress ip_address(TEST_ADDRESS);
+ IOAddress any_address("0.0.0.0");
+ IOServicePtr io_service(new IOService());
SimpleSendHandler ncr_handler;
// Tests are based on a list of messages, get the count now.
/// @brief Test the NameChangeSender::assumeQueue method.
TEST_F(NameChangeUDPSenderBasicTest, assumeQueue) {
- isc::asiolink::IOAddress ip_address(TEST_ADDRESS);
+ IOAddress ip_address(TEST_ADDRESS);
uint32_t port = SENDER_PORT;
- isc::asiolink::IOService io_service;
+ IOServicePtr io_service(new IOService());
SimpleSendHandler ncr_handler;
NameChangeRequestPtr ncr;
// Enable multi-threading
MultiThreadingMgr::instance().setMode(true);
- isc::asiolink::IOAddress ip_address(TEST_ADDRESS);
+ IOAddress ip_address(TEST_ADDRESS);
uint32_t port = SENDER_PORT;
- isc::asiolink::IOService io_service;
+ IOServicePtr io_service(new IOService());
SimpleSendHandler ncr_handler;
NameChangeRequestPtr ncr;
NameChangeListener::RequestReceiveHandler,
NameChangeSender::RequestSendHandler {
public:
- isc::asiolink::IOService io_service_;
+ IOServicePtr io_service_;
NameChangeListener::Result recv_result_;
NameChangeSender::Result send_result_;
NameChangeListenerPtr listener_;
NameChangeSenderPtr sender_;
- isc::asiolink::IntervalTimer test_timer_;
+ IntervalTimer test_timer_;
std::vector<NameChangeRequestPtr> sent_ncrs_;
std::vector<NameChangeRequestPtr> received_ncrs_;
NameChangeUDPTest()
- : io_service_(), recv_result_(NameChangeListener::SUCCESS),
+ : io_service_(new IOService()), recv_result_(NameChangeListener::SUCCESS),
send_result_(NameChangeSender::SUCCESS), test_timer_(io_service_) {
- isc::asiolink::IOAddress addr(TEST_ADDRESS);
+ IOAddress addr(TEST_ADDRESS);
// Create our listener instance. Note that reuse_address is true.
listener_.reset(
new NameChangeUDPListener(addr, LISTENER_PORT, FMT_JSON,
///
/// This callback stops all running (hanging) tasks on IO service.
void testTimeoutHandler() {
- io_service_.stop();
+ io_service_->stop();
FAIL() << "Test timeout hit.";
}
// Execute callbacks until we have sent and received all of messages.
while (sender_->getQueueSize() > 0 || (received_ncrs_.size() < num_msgs)) {
- EXPECT_NO_THROW(io_service_.runOne());
+ EXPECT_NO_THROW(io_service_->runOne());
}
// Send queue should be empty.
EXPECT_FALSE(listener_->amListening());
// Verify that IO pending is false, after cancel event occurs.
- EXPECT_NO_THROW(io_service_.runOne());
+ EXPECT_NO_THROW(io_service_->runOne());
EXPECT_FALSE(listener_->isIoPending());
// Verify that we can gracefully stop sending.
// Execute callbacks until we have sent and received all of messages.
while (sender_->getQueueSize() > 0 || (received_ncrs_.size() < num_msgs)) {
- EXPECT_NO_THROW(io_service_.runOne());
+ EXPECT_NO_THROW(io_service_->runOne());
}
// Send queue should be empty.
EXPECT_FALSE(listener_->amListening());
// Verify that IO pending is false, after cancel event occurs.
- EXPECT_NO_THROW(io_service_.runOne());
+ EXPECT_NO_THROW(io_service_->runOne());
EXPECT_FALSE(listener_->isIoPending());
// Verify that we can gracefully stop sending.
// Tests error handling of a failure to mark the watch socket ready, when
// sendRequest() is called.
TEST_F(NameChangeUDPSenderBasicTest, watchClosedBeforeSendRequest) {
- isc::asiolink::IOAddress ip_address(TEST_ADDRESS);
- isc::asiolink::IOService io_service;
+ IOAddress ip_address(TEST_ADDRESS);
+ IOServicePtr io_service(new IOService());
SimpleSendHandler ncr_handler;
// Create the sender and put into send mode.
// Enable multi-threading
MultiThreadingMgr::instance().setMode(true);
- isc::asiolink::IOAddress ip_address(TEST_ADDRESS);
- isc::asiolink::IOService io_service;
+ IOAddress ip_address(TEST_ADDRESS);
+ IOServicePtr io_service(new IOService());
SimpleSendHandler ncr_handler;
// Create the sender and put into send mode.
// Tests error handling of a failure to mark the watch socket ready, when
// sendNext() is called during completion handling.
TEST_F(NameChangeUDPSenderBasicTest, watchClosedAfterSendRequest) {
- isc::asiolink::IOAddress ip_address(TEST_ADDRESS);
- isc::asiolink::IOService io_service;
+ IOAddress ip_address(TEST_ADDRESS);
+ IOServicePtr io_service(new IOService());
SimpleSendHandler ncr_handler;
// Create the sender and put into send mode.
// Enable multi-threading
MultiThreadingMgr::instance().setMode(true);
- isc::asiolink::IOAddress ip_address(TEST_ADDRESS);
- isc::asiolink::IOService io_service;
+ IOAddress ip_address(TEST_ADDRESS);
+ IOServicePtr io_service(new IOService());
SimpleSendHandler ncr_handler;
// Create the sender and put into send mode.
// Tests error handling of a failure to clear the watch socket during
// completion handling.
TEST_F(NameChangeUDPSenderBasicTest, watchSocketBadRead) {
- isc::asiolink::IOAddress ip_address(TEST_ADDRESS);
- isc::asiolink::IOService io_service;
+ IOAddress ip_address(TEST_ADDRESS);
+ IOServicePtr io_service(new IOService());
SimpleSendHandler ncr_handler;
// Create the sender and put into send mode.
// Enable multi-threading
MultiThreadingMgr::instance().setMode(true);
- isc::asiolink::IOAddress ip_address(TEST_ADDRESS);
- isc::asiolink::IOService io_service;
+ IOAddress ip_address(TEST_ADDRESS);
+ IOServicePtr io_service(new IOService());
SimpleSendHandler ncr_handler;
// Create the sender and put into send mode.
// Create a our own service instance when we are not being multiplexed
// into an external service..
private_io_service_.reset(new asiolink::IOService());
- startSender(error_handler, *private_io_service_);
+ startSender(error_handler, private_io_service_);
LOG_INFO(dhcpsrv_logger, DHCPSRV_DHCP_DDNS_SENDER_STARTED)
.arg(d2_client_config_->toText());
}
void
D2ClientMgr::startSender(D2ClientErrorHandler error_handler,
- isc::asiolink::IOService& io_service) {
+ const isc::asiolink::IOServicePtr& io_service) {
if (amSending()) {
return;
}
/// @throw D2ClientError if sender instance is null. Underlying layer
/// may throw NCRSenderExceptions exceptions.
void startSender(D2ClientErrorHandler error_handler,
- isc::asiolink::IOService& io_service);
+ const isc::asiolink::IOServicePtr& io_service);
/// @brief Enables sending NameChangeRequests to kea-dhcp-ddns
///
///
/// @param timeout_ms Amount of time after which the method returns.
void runTimersWithTimeout(const long timeout_ms) {
- IntervalTimer timer(*io_service_);
+ IntervalTimer timer(io_service_);
timer.setup([this]() {
io_service_->stop();
}, timeout_ms, IntervalTimer::ONE_SHOT);
void
CfgIfaceTest::doWait(const long timeout) {
- asiolink::IntervalTimer timer(*io_service_);
+ asiolink::IntervalTimer timer(io_service_);
timer.setup([this]() {
io_service_->stop();
}, timeout, asiolink::IntervalTimer::ONE_SHOT);
#include <sys/select.h>
using namespace std;
+using namespace isc::asiolink;
using namespace isc::dhcp;
using namespace isc;
namespace ph = std::placeholders;
// Update the configuration with one that is enabled.
D2ClientConfigPtr new_cfg;
- isc::asiolink::IOAddress server_ip(server_address);
- isc::asiolink::IOAddress sender_ip(server_ip.isV4() ?
- D2ClientConfig::DFT_V4_SENDER_IP :
- D2ClientConfig::DFT_V6_SENDER_IP);
+ IOAddress server_ip(server_address);
+ IOAddress sender_ip(server_ip.isV4() ? D2ClientConfig::DFT_V4_SENDER_IP :
+ D2ClientConfig::DFT_V6_SENDER_IP);
ASSERT_NO_THROW(new_cfg.reset(new D2ClientConfig(true,
server_ip, server_port,
enableDdns("127.0.0.1", 53001, dhcp_ddns::NCR_UDP);
// Place sender in send mode using an external IO service.
- asiolink::IOService io_service;
+ asiolink::IOServicePtr io_service(new IOService());
ASSERT_NO_THROW(startSender(getErrorHandler(), io_service));
// select_fd should evaluate to NOT ready to read.
enableDdns("::1", 53001, dhcp_ddns::NCR_UDP);
// Place sender in send mode using an external IO service.
- asiolink::IOService io_service;
+ asiolink::IOServicePtr io_service(new IOService());
ASSERT_NO_THROW(startSender(getErrorHandler(), io_service));
// select_fd should evaluate to NOT ready to read.
///
/// @param ms Duration in milliseconds.
void setTestTime(const uint32_t ms) {
- IntervalTimer timer(*io_service_);
+ IntervalTimer timer(io_service_);
timer.setup([this]() {
io_service_->stop();
}, ms, IntervalTimer::ONE_SHOT);
bool waitForProcess(const Memfile_LeaseMgr& lease_mgr,
const uint8_t timeout) {
const uint32_t iterations_max = timeout * 1000;
- IntervalTimer fast_path_timer(*io_service_);
- IntervalTimer timer(*io_service_);
+ IntervalTimer fast_path_timer(io_service_);
+ IntervalTimer timer(io_service_);
bool elapsed = false;
timer.setup([&]() {
io_service_->stop();
void
TimerMgrTest::doWait(const long timeout, const bool /*call_receive*/) {
- IntervalTimer timer(*io_service_);
+ IntervalTimer timer(io_service_);
timer.setup([this]() {
io_service_->stop();
}, timeout, IntervalTimer::ONE_SHOT);
/// during the timer registration.
/// @param interval Timer interval in milliseconds.
/// @param mode Interval timer scheduling mode.
- TimerInfo(asiolink::IOService& io_service,
+ TimerInfo(const asiolink::IOServicePtr& io_service,
const asiolink::IntervalTimer::Callback& user_callback,
const long interval,
const asiolink::IntervalTimer::Mode& mode)
// Create a structure holding the configuration for the timer. It will
// create the instance if the IntervalTimer. It will also hold the
// callback, interval and scheduling mode parameters.
- TimerInfoPtr timer_info(new TimerInfo(*io_service_, callback,
+ TimerInfoPtr timer_info(new TimerInfo(io_service_, callback,
interval, scheduling_mode));
// Actually register the timer.
/// @param conn_pool Back pointer to the connection pool to which this
/// connection belongs.
/// @param url URL associated with this connection.
- explicit Connection(IOService& io_service,
+ explicit Connection(const IOServicePtr& io_service,
const TlsContextPtr& tls_context,
const ConnectionPoolPtr& conn_pool,
const Url& url);
/// connections.
/// @param max_url_connections maximum number of concurrent
/// connections allowed per URL.
- explicit ConnectionPool(IOService& io_service, size_t max_url_connections)
+ explicit ConnectionPool(const IOServicePtr& io_service, size_t max_url_connections)
: io_service_(io_service), destinations_(), pool_mutex_(),
max_url_connections_(max_url_connections) {
}
/// should be processed.
void postProcessNextRequest(const Url& url,
const TlsContextPtr& tls_context) {
- io_service_.post(std::bind(&ConnectionPool::processNextRequest,
- shared_from_this(), url, tls_context));
+ io_service_->post(std::bind(&ConnectionPool::processNextRequest,
+ shared_from_this(), url, tls_context));
}
/// @brief Queue next request for sending to the server.
}
/// @brief A reference to the IOService that drives socket IO.
- IOService& io_service_;
+ IOServicePtr io_service_;
/// @brief Map of Destinations by URL and TLS context.
std::map<DestinationDescriptor, DestinationPtr> destinations_;
size_t max_url_connections_;
};
-Connection::Connection(IOService& io_service,
+Connection::Connection(const IOServicePtr& io_service,
const TlsContextPtr& tls_context,
const ConnectionPoolPtr& conn_pool,
const Url& url)
/// the thread pool threads will be created and started, with the
/// operational state being RUNNING. Applicable only when thread-pool size
/// is greater than zero.
- HttpClientImpl(IOService& io_service, size_t thread_pool_size = 0,
+ HttpClientImpl(const IOServicePtr& io_service, size_t thread_pool_size = 0,
bool defer_thread_start = false)
: thread_pool_size_(thread_pool_size), thread_pool_() {
if (thread_pool_size_ > 0) {
// Create the connection pool. Note that we use the thread_pool_size
// as the maximum connections per URL value.
- conn_pool_.reset(new ConnectionPool(*thread_io_service_, thread_pool_size_));
+ conn_pool_.reset(new ConnectionPool(thread_io_service_, thread_pool_size_));
// Create the thread pool.
thread_pool_.reset(new IoServiceThreadPool(thread_io_service_, thread_pool_size_,
IoServiceThreadPoolPtr thread_pool_;
};
-HttpClient::HttpClient(IOService& io_service, bool multi_threading_enabled,
+HttpClient::HttpClient(const IOServicePtr& io_service, bool multi_threading_enabled,
size_t thread_pool_size, bool defer_thread_start) {
if (!multi_threading_enabled && thread_pool_size) {
isc_throw(InvalidOperation,
/// the thread pool threads will be created and started, with the
/// operational state being RUNNING. Applicable only when thread-pool size
/// is greater than zero.
- explicit HttpClient(asiolink::IOService& io_service,
+ explicit HttpClient(const asiolink::IOServicePtr& io_service,
bool multi_threading_enabled,
size_t thread_pool_size = 0,
bool defer_thread_start = false);
callback_(ec, length);
}
-HttpConnection::HttpConnection(asiolink::IOService& io_service,
+HttpConnection::HttpConnection(const asiolink::IOServicePtr& io_service,
const HttpAcceptorPtr& acceptor,
const TlsContextPtr& tls_context,
HttpConnectionPool& connection_pool,
/// @param request_timeout Configured timeout for a HTTP request.
/// @param idle_timeout Timeout after which persistent HTTP connection is
/// closed by the server.
- HttpConnection(asiolink::IOService& io_service,
+ HttpConnection(const asiolink::IOServicePtr& io_service,
const HttpAcceptorPtr& acceptor,
const asiolink::TlsContextPtr& tls_context,
HttpConnectionPool& connection_pool,
namespace isc {
namespace http {
-HttpListener::HttpListener(IOService& io_service,
+HttpListener::HttpListener(const IOServicePtr& io_service,
const asiolink::IOAddress& server_address,
const unsigned short server_port,
const TlsContextPtr& tls_context,
///
/// @throw HttpListenerError when any of the specified parameters is
/// invalid.
- HttpListener(asiolink::IOService& io_service,
+ HttpListener(const asiolink::IOServicePtr& io_service,
const asiolink::IOAddress& server_address,
const unsigned short server_port,
const asiolink::TlsContextPtr& tls_context,
namespace isc {
namespace http {
-HttpListenerImpl::HttpListenerImpl(IOService& io_service,
+HttpListenerImpl::HttpListenerImpl(const IOServicePtr& io_service,
const asiolink::IOAddress& server_address,
const unsigned short server_port,
const TlsContextPtr& tls_context,
///
/// @throw HttpListenerError when any of the specified parameters is
/// invalid.
- HttpListenerImpl(asiolink::IOService& io_service,
+ HttpListenerImpl(const asiolink::IOServicePtr& io_service,
const asiolink::IOAddress& server_address,
const unsigned short server_port,
const asiolink::TlsContextPtr& tls_context,
virtual HttpConnectionPtr createConnection(const HttpResponseCreatorPtr& response_creator,
const HttpAcceptorCallback& callback);
- /// @brief Reference to the IO service.
- asiolink::IOService& io_service_;
+ /// @brief Pointer to the IO service.
+ asiolink::IOServicePtr io_service_;
/// @brief TLS context.
asiolink::TlsContextPtr tls_context_;
/// @brief Constructor.
MultiThreadingHttpClientTest()
- : io_service_(), client_(), listener_(), factory_(), listeners_(), factories_(),
+ : io_service_(new IOService()), client_(), listener_(), factory_(), listeners_(), factories_(),
test_timer_(io_service_), num_threads_(0), num_batches_(0), num_listeners_(0),
expected_requests_(0), num_in_progress_(0), num_finished_(0), paused_(false),
pause_cnt_(0) {
if (fail_on_timeout) {
ADD_FAILURE() << "Timeout occurred while running the test!";
}
- io_service_.stop();
+ io_service_->stop();
}
/// @brief Runs the test's IOService until the desired number of requests
void runIOService(size_t request_limit) {
while (getRRCount() < request_limit) {
// Always call reset() before we call run();
- io_service_.restart();
+ io_service_->restart();
// Run until a client stops the service.
- io_service_.run();
+ io_service_->run();
}
}
num_in_progress_ = 0;
test_cv_.notify_all();
// Stop the test's IOService.
- io_service_.stop();
+ io_service_->stop();
} else {
// I'm done but others aren't wait here.
bool ret = test_cv_.wait_for(lck, std::chrono::seconds(10),
std::unique_lock<std::mutex> lck(test_mutex_);
clientRRs_.push_back(clientRR);
++num_finished_;
- if ((num_finished_ >= expected_requests_) && !io_service_.stopped()) {
- io_service_.stop();
+ if ((num_finished_ >= expected_requests_) && !io_service_->stopped()) {
+ io_service_->stop();
}
}
}
/// @brief IO service used in the tests.
- IOService io_service_;
+ IOServicePtr io_service_;
/// @brief Instance of the client used in the tests.
HttpClientPtr client_;
/// @brief Constructor.
HttpConnectionPoolTest()
- : io_service_(),
+ : io_service_(new IOService()),
acceptor_(new HttpAcceptor(io_service_)),
connection_pool_(),
response_creator_(new TestHttpResponseCreator()) {
ASSERT_EQ(1, pool.hasConnection(conn1));
}
- IOService io_service_; ///< IO service.
+ IOServicePtr io_service_; ///< IO service.
HttpAcceptorPtr acceptor_; ///< Test acceptor.
HttpConnectionPool connection_pool_; ///< Test connection pool.
HttpResponseCreatorPtr response_creator_; ///< Test response creator.
class HttpListenerImplCustom : public HttpListenerImpl {
public:
- HttpListenerImplCustom(IOService& io_service,
+ HttpListenerImplCustom(const IOServicePtr& io_service,
const IOAddress& server_address,
const unsigned short server_port,
const TlsContextPtr& tls_context,
///
/// @throw HttpListenerError when any of the specified parameters is
/// invalid.
- HttpListenerCustom(IOService& io_service,
+ HttpListenerCustom(const IOServicePtr& io_service,
const IOAddress& server_address,
const unsigned short server_port,
const TlsContextPtr& tls_context,
/// @param request_timeout Configured timeout for a HTTP request.
/// @param idle_timeout Timeout after which persistent HTTP connection is
/// closed by the server.
- HttpConnectionLongWriteBuffer(IOService& io_service,
+ HttpConnectionLongWriteBuffer(const IOServicePtr& io_service,
const HttpAcceptorPtr& acceptor,
const TlsContextPtr& tls_context,
HttpConnectionPool& connection_pool,
/// @param request_timeout Configured timeout for a HTTP request.
/// @param idle_timeout Timeout after which persistent HTTP connection is
/// closed by the server.
- HttpConnectionTransactionChange(IOService& io_service,
+ HttpConnectionTransactionChange(const IOServicePtr& io_service,
const HttpAcceptorPtr& acceptor,
const TlsContextPtr& tls_context,
HttpConnectionPool& connection_pool,
///
/// Starts test timer which detects timeouts.
HttpListenerTest()
- : io_service_(), factory_(new TestHttpResponseCreatorFactory()),
+ : io_service_(new IOService()), factory_(new TestHttpResponseCreatorFactory()),
test_timer_(io_service_), run_io_service_timer_(io_service_), clients_() {
test_timer_.setup(std::bind(&HttpListenerTest::timeoutHandler, this, true),
TEST_TIMEOUT, IntervalTimer::ONE_SHOT);
if (fail_on_timeout) {
ADD_FAILURE() << "Timeout occurred while running the test!";
}
- io_service_.stop();
+ io_service_->stop();
}
/// @brief Runs IO service with optional timeout.
/// @param timeout Optional value specifying for how long the io service
/// should be ran.
void runIOService(long timeout = 0) {
- io_service_.restart();
+ io_service_->restart();
if (timeout > 0) {
run_io_service_timer_.setup(std::bind(&HttpListenerTest::timeoutHandler,
this, false),
timeout, IntervalTimer::ONE_SHOT);
}
- io_service_.run();
- io_service_.restart();
- io_service_.poll();
+ io_service_->run();
+ io_service_->restart();
+ io_service_->poll();
}
/// @brief Returns HTTP OK response expected by unit tests.
}
/// @brief IO service used in the tests.
- IOService io_service_;
+ IOServicePtr io_service_;
/// @brief Pointer to the response creator factory.
HttpResponseCreatorFactoryPtr factory_;
EXPECT_EQ(httpOk(HttpVersion::HTTP_11()), client->getResponse());
listener.stop();
- io_service_.poll();
+ io_service_->poll();
}
EXPECT_TRUE(client->isConnectionClosed());
listener.stop();
- io_service_.poll();
+ io_service_->poll();
}
// This test verifies that persistent HTTP connection is established by default
EXPECT_TRUE(client->isConnectionClosed());
listener.stop();
- io_service_.poll();
+ io_service_->poll();
}
// This test verifies that "keep-alive" connection is closed by the server after
EXPECT_TRUE(client->isConnectionClosed());
listener.stop();
- io_service_.poll();
+ io_service_->poll();
}
// This test verifies that persistent connection is closed by the server after
EXPECT_TRUE(client->isConnectionClosed());
listener.stop();
- io_service_.poll();
+ io_service_->poll();
}
// This test verifies that HTTP/1.1 connection remains open even if there is an
EXPECT_TRUE(client->isConnectionClosed());
listener.stop();
- io_service_.poll();
+ io_service_->poll();
}
// This test verifies that the HTTP listener can't be started twice.
// This test verifies that listener can't be bound to the port to which
// other server is bound.
TEST_F(HttpListenerTest, addressInUse) {
- tcp::acceptor acceptor(io_service_.getInternalIOService());
+ tcp::acceptor acceptor(io_service_->getInternalIOService());
// Use other port than SERVER_PORT to make sure that this TCP connection
// doesn't affect subsequent tests.
tcp::endpoint endpoint(address::from_string(SERVER_ADDRESS),
listener_.stop();
listener2_.stop();
listener3_.stop();
- io_service_.poll();
+ io_service_->poll();
MultiThreadingMgr::instance().setMode(false);
}
const HttpResponsePtr&,
const std::string&) {
if (++resp_num > 1) {
- io_service_.stop();
+ io_service_->stop();
}
EXPECT_FALSE(ec);
}));
const HttpResponsePtr&,
const std::string&) {
if (++resp_num > 1) {
- io_service_.stop();
+ io_service_->stop();
}
EXPECT_FALSE(ec);
}));
const HttpResponsePtr&,
const std::string&) {
if (++resp_num > 1) {
- io_service_.stop();
+ io_service_->stop();
}
EXPECT_FALSE(ec);
}));
const HttpResponsePtr&,
const std::string&) {
if (++resp_num > 1) {
- io_service_.stop();
+ io_service_->stop();
}
EXPECT_FALSE(ec);
}));
const HttpResponsePtr&,
const std::string&) {
if (++resp_num > 1) {
- io_service_.stop();
+ io_service_->stop();
}
if (ec) {
ADD_FAILURE() << "asyncSendRequest failed: " << ec.message();
const HttpResponsePtr&,
const std::string&) {
if (++resp_num > 1) {
- io_service_.stop();
+ io_service_->stop();
}
if (ec) {
ADD_FAILURE() << "asyncSendRequest failed: " << ec.message();
request1, response1,
[this](const boost::system::error_code& ec, const HttpResponsePtr&,
const std::string&) {
- io_service_.stop();
+ io_service_->stop();
EXPECT_FALSE(ec);
}));
request2, response2,
[this](const boost::system::error_code& ec, const HttpResponsePtr&,
const std::string&) {
- io_service_.stop();
+ io_service_->stop();
EXPECT_FALSE(ec);
}));
[this](const boost::system::error_code& ec,
const HttpResponsePtr&,
const std::string&) {
- io_service_.stop();
+ io_service_->stop();
// The server should have returned an IO error.
EXPECT_TRUE(ec);
}));
[this](const boost::system::error_code& ec,
const HttpResponsePtr& response,
const std::string& parsing_error) {
- io_service_.stop();
+ io_service_->stop();
// There should be no IO error (answer from the server is received).
EXPECT_FALSE(ec);
// The response object is NULL because it couldn't be finalized.
const HttpResponsePtr& response,
const std::string&) {
if (++cb_num > 1) {
- io_service_.stop();
+ io_service_->stop();
}
// In this particular case we know exactly the type of the
// IO error returned, because the client explicitly sets this
const HttpResponsePtr&,
const std::string&) {
if (++cb_num > 1) {
- io_service_.stop();
+ io_service_->stop();
}
}));
const HttpResponsePtr& response,
const std::string&) {
if (++cb_num > 1) {
- io_service_.stop();
+ io_service_->stop();
}
// In this particular case we know exactly the type of the
// IO error returned, because the client explicitly sets this
const HttpResponsePtr&,
const std::string&) {
if (++cb_num > 1) {
- io_service_.stop();
+ io_service_->stop();
}
}));
[this](const boost::system::error_code& ec,
const HttpResponsePtr&,
const std::string&) {
- io_service_.stop();
+ io_service_->stop();
// Everything should be ok.
EXPECT_TRUE(ec.value() == 0);
const HttpResponsePtr&,
const std::string&) {
if (++resp_num > 1) {
- io_service_.stop();
+ io_service_->stop();
}
EXPECT_FALSE(ec);
const HttpResponsePtr&,
const std::string&) {
if (++resp_num > 1) {
- io_service_.stop();
+ io_service_->stop();
}
EXPECT_FALSE(ec);
},
const HttpResponsePtr&,
const std::string&) {
if (++resp_num == 1) {
- io_service_.stop();
+ io_service_->stop();
}
EXPECT_EQ(1, monitor.connect_cnt_); // We should have 1 connect.
const HttpResponsePtr&,
const std::string&) {
if (++resp_num == 1) {
- io_service_.stop();
+ io_service_->stop();
}
EXPECT_EQ(2, monitor.connect_cnt_); // We should have 1 connect.
/// @param io_service IO service to be stopped on error or completion.
/// @param server_address string containing the IP address of the server.
/// @param port port number of the server.
- explicit TestHttpClient(IOService& io_service,
+ explicit TestHttpClient(const IOServicePtr& io_service,
const std::string& server_address = "127.0.0.1",
uint16_t port = 18123)
- : io_service_(io_service.getInternalIOService()), socket_(io_service_),
+ : io_service_(io_service), socket_(io_service_->getInternalIOService()),
buf_(), response_(), server_address_(server_address),
server_port_(port), receive_done_(false) {
}
if (ec.value() != boost::asio::error::in_progress) {
ADD_FAILURE() << "error occurred while connecting: "
<< ec.message();
- io_service_.stop();
+ io_service_->stop();
return;
}
}
} else {
ADD_FAILURE() << "error occurred while connecting: "
<< ec.message();
- io_service_.stop();
+ io_service_->stop();
return;
}
}
// Error occurred, bail...
ADD_FAILURE() << "error occurred while receiving HTTP"
" response from the server: " << ec.message();
- io_service_.stop();
+ io_service_->stop();
}
}
// expecting.
if (response_.find("\r\n\r\n", 0) != std::string::npos) {
receive_done_ = true;
- io_service_.stop();
+ io_service_->stop();
} else {
receivePartialResponse();
}
private:
- /// @brief Holds reference to the IO service.
- boost::asio::io_service& io_service_;
+ /// @brief Holds pointer to the IO service.
+ isc::asiolink::IOServicePtr io_service_;
/// @brief A socket used for the connection.
boost::asio::ip::tcp::socket socket_;
///
/// Starts test timer which detects timeouts.
HttpListenerTest()
- : io_service_(), factory_(new TestHttpResponseCreatorFactory()),
+ : io_service_(new IOService()), factory_(new TestHttpResponseCreatorFactory()),
test_timer_(io_service_), run_io_service_timer_(io_service_) {
test_timer_.setup(std::bind(&HttpListenerTest::timeoutHandler, this, true),
TEST_TIMEOUT, IntervalTimer::ONE_SHOT);
if (fail_on_timeout) {
ADD_FAILURE() << "Timeout occurred while running the test!";
}
- io_service_.stop();
+ io_service_->stop();
}
/// @brief Runs IO service with optional timeout.
/// @param timeout Optional value specifying for how long the io service
/// should be ran (ms).
void runIOService(long timeout = 0) {
- io_service_.restart();
+ io_service_->restart();
if (timeout > 0) {
run_io_service_timer_.setup(std::bind(&HttpListenerTest::timeoutHandler,
this, false),
timeout, IntervalTimer::ONE_SHOT);
}
- io_service_.run();
- io_service_.restart();
- io_service_.poll();
+ io_service_->run();
+ io_service_->restart();
+ io_service_->poll();
}
/// @brief IO service used in the tests.
- IOService io_service_;
+ IOServicePtr io_service_;
/// @brief Pointer to the response creator factory.
HttpResponseCreatorFactoryPtr factory_;
listener_->stop();
listener2_->stop();
listener3_->stop();
- io_service_.poll();
+ io_service_->poll();
MultiThreadingMgr::instance().setMode(false);
HttpRequest::recordSubject_ = false;
HttpRequest::recordIssuer_ = false;
const HttpResponsePtr&,
const std::string&) {
if (++resp_num > 1) {
- io_service_.stop();
+ io_service_->stop();
}
if (ec) {
ADD_FAILURE() << "asyncSendRequest failed: " << ec.message();
const HttpResponsePtr&,
const std::string&) {
if (++resp_num > 1) {
- io_service_.stop();
+ io_service_->stop();
}
if (ec) {
ADD_FAILURE() << "asyncSendRequest failed: " << ec.message();
const HttpResponsePtr&,
const std::string&) {
if (++resp_num > 1) {
- io_service_.stop();
+ io_service_->stop();
}
if (ec) {
ADD_FAILURE() << "asyncSendRequest failed: " << ec.message();
const HttpResponsePtr&,
const std::string&) {
if (++resp_num > 1) {
- io_service_.stop();
+ io_service_->stop();
}
if (ec) {
ADD_FAILURE() << "asyncSendRequest failed: " << ec.message();
const HttpResponsePtr&,
const std::string&) {
if (++resp_num > 1) {
- io_service_.stop();
+ io_service_->stop();
}
if (ec) {
ADD_FAILURE() << "asyncSendRequest failed: " << ec.message();
const HttpResponsePtr&,
const std::string&) {
if (++resp_num > 1) {
- io_service_.stop();
+ io_service_->stop();
}
if (ec) {
ADD_FAILURE() << "asyncSendRequest failed: " << ec.message();
request1, response1,
[this](const boost::system::error_code& ec, const HttpResponsePtr&,
const std::string&) {
- io_service_.stop();
+ io_service_->stop();
if (ec) {
ADD_FAILURE() << "asyncSendRequest failed: " << ec.message();
}
request2, response2,
[this](const boost::system::error_code& ec, const HttpResponsePtr&,
const std::string&) {
- io_service_.stop();
+ io_service_->stop();
if (ec) {
ADD_FAILURE() << "asyncSendRequest failed: " << ec.message();
}
[this](const boost::system::error_code& ec,
const HttpResponsePtr&,
const std::string&) {
- io_service_.stop();
+ io_service_->stop();
// The server should have returned an IO error.
if (!ec) {
ADD_FAILURE() << "asyncSendRequest didn't fail";
[this](const boost::system::error_code& ec,
const HttpResponsePtr& response,
const std::string& parsing_error) {
- io_service_.stop();
+ io_service_->stop();
// There should be no IO error (answer from the server is received).
if (ec) {
ADD_FAILURE() << "asyncSendRequest failed: " << ec.message();
const HttpResponsePtr& response,
const std::string&) {
if (++cb_num > 1) {
- io_service_.stop();
+ io_service_->stop();
}
// In this particular case we know exactly the type of the
// IO error returned, because the client explicitly sets this
const HttpResponsePtr&,
const std::string&) {
if (++cb_num > 1) {
- io_service_.stop();
+ io_service_->stop();
}
}));
const HttpResponsePtr& response,
const std::string&) {
if (++cb_num > 1) {
- io_service_.stop();
+ io_service_->stop();
}
// In this particular case we know exactly the type of the
// IO error returned, because the client explicitly sets this
const HttpResponsePtr&,
const std::string&) {
if (++cb_num > 1) {
- io_service_.stop();
+ io_service_->stop();
}
}));
[this](const boost::system::error_code& ec,
const HttpResponsePtr&,
const std::string&) {
- io_service_.stop();
+ io_service_->stop();
// Everything should be ok.
if (ec) {
const HttpResponsePtr&,
const std::string&) {
if (++resp_num > 1) {
- io_service_.stop();
+ io_service_->stop();
}
if (ec) {
const HttpResponsePtr&,
const std::string&) {
if (++resp_num > 1) {
- io_service_.stop();
+ io_service_->stop();
}
if (ec) {
ADD_FAILURE() << "asyncSendRequest failed: " << ec.message();
const HttpResponsePtr&,
const std::string&) {
if (++resp_num == 1) {
- io_service_.stop();
+ io_service_->stop();
}
// We should have 1 connect.
const HttpResponsePtr&,
const std::string&) {
if (++resp_num == 1) {
- io_service_.stop();
+ io_service_->stop();
}
// We should have 1 connect.
class HttpListenerImplCustom : public HttpListenerImpl {
public:
- HttpListenerImplCustom(IOService& io_service,
+ HttpListenerImplCustom(const IOServicePtr& io_service,
const IOAddress& server_address,
const unsigned short server_port,
const TlsContextPtr& tls_context,
///
/// @throw HttpListenerError when any of the specified parameters is
/// invalid.
- HttpListenerCustom(IOService& io_service,
+ HttpListenerCustom(const IOServicePtr& io_service,
const IOAddress& server_address,
const unsigned short server_port,
const TlsContextPtr& tls_context,
/// @param request_timeout Configured timeout for a HTTP request.
/// @param idle_timeout Timeout after which persistent HTTP connection is
/// closed by the server.
- HttpConnectionLongWriteBuffer(IOService& io_service,
+ HttpConnectionLongWriteBuffer(const IOServicePtr& io_service,
const HttpAcceptorPtr& acceptor,
const TlsContextPtr& tls_context,
HttpConnectionPool& connection_pool,
/// @param request_timeout Configured timeout for a HTTP request.
/// @param idle_timeout Timeout after which persistent HTTP connection is
/// closed by the server.
- HttpConnectionTransactionChange(IOService& io_service,
+ HttpConnectionTransactionChange(const IOServicePtr& io_service,
const HttpAcceptorPtr& acceptor,
const TlsContextPtr& tls_context,
HttpConnectionPool& connection_pool,
///
/// @param io_service IO service to be stopped on error.
/// @param tls_context TLS context.
- TestHttpClient(IOService& io_service, TlsContextPtr tls_context)
- : io_service_(io_service.getInternalIOService()),
- stream_(io_service_, tls_context->getContext()),
- buf_(), response_() {
+ TestHttpClient(const IOServicePtr& io_service, TlsContextPtr tls_context)
+ : io_service_(io_service), stream_(io_service_->getInternalIOService(),
+ tls_context->getContext()), buf_(), response_() {
}
/// @brief Destructor.
if (ec.value() != boost::asio::error::in_progress) {
ADD_FAILURE() << "error occurred while connecting: "
<< ec.message();
- io_service_.stop();
+ io_service_->stop();
return;
}
}
if (ec) {
ADD_FAILURE() << "error occurred during handshake: "
<< ec.message();
- io_service_.stop();
+ io_service_->stop();
return;
}
sendRequest(request);
} else {
ADD_FAILURE() << "error occurred while connecting: "
<< ec.message();
- io_service_.stop();
+ io_service_->stop();
return;
}
}
// Error occurred, bail...
ADD_FAILURE() << "error occurred while receiving HTTP"
" response from the server: " << ec.message();
- io_service_.stop();
+ io_service_->stop();
}
}
// Two consecutive new lines end the part of the response we're
// expecting.
if (response_.find("\r\n\r\n", 0) != std::string::npos) {
- io_service_.stop();
+ io_service_->stop();
} else {
receivePartialResponse();
private:
- /// @brief Holds reference to the IO service.
- boost::asio::io_service& io_service_;
+ /// @brief Holds pointer to the IO service.
+ isc::asiolink::IOServicePtr io_service_;
/// @brief A socket used for the connection.
TlsStreamImpl stream_;
///
/// Starts test timer which detects timeouts.
HttpsListenerTest()
- : io_service_(), factory_(new TestHttpResponseCreatorFactory()),
+ : io_service_(new IOService()), factory_(new TestHttpResponseCreatorFactory()),
test_timer_(io_service_), run_io_service_timer_(io_service_),
clients_(), server_context_(), client_context_() {
configServer(server_context_);
if (fail_on_timeout) {
ADD_FAILURE() << "Timeout occurred while running the test!";
}
- io_service_.stop();
+ io_service_->stop();
}
/// @brief Runs IO service with optional timeout.
/// @param timeout Optional value specifying for how long the io service
/// should be ran.
void runIOService(long timeout = 0) {
- io_service_.restart();
+ io_service_->restart();
if (timeout > 0) {
run_io_service_timer_.setup(std::bind(&HttpsListenerTest::timeoutHandler,
this, false),
timeout, IntervalTimer::ONE_SHOT);
}
- io_service_.run();
- io_service_.restart();
- io_service_.poll();
+ io_service_->run();
+ io_service_->restart();
+ io_service_->poll();
}
/// @brief Returns HTTP OK response expected by unit tests.
}
/// @brief IO service used in the tests.
- IOService io_service_;
+ IOServicePtr io_service_;
/// @brief Pointer to the response creator factory.
HttpResponseCreatorFactoryPtr factory_;
EXPECT_EQ(httpOk(HttpVersion::HTTP_11()), client->getResponse());
listener.stop();
- io_service_.poll();
+ io_service_->poll();
}
EXPECT_TRUE(client->isConnectionClosed());
listener.stop();
- io_service_.poll();
+ io_service_->poll();
}
// This test verifies that persistent HTTP connection is established by default
EXPECT_TRUE(client->isConnectionClosed());
listener.stop();
- io_service_.poll();
+ io_service_->poll();
}
// This test verifies that "keep-alive" connection is closed by the server after
EXPECT_TRUE(client->isConnectionClosed());
listener.stop();
- io_service_.poll();
+ io_service_->poll();
}
// This test verifies that persistent connection is closed by the server after
EXPECT_TRUE(client->isConnectionClosed());
listener.stop();
- io_service_.poll();
+ io_service_->poll();
}
// This test verifies that HTTP/1.1 connection remains open even if there is an
EXPECT_TRUE(client->isConnectionClosed());
listener.stop();
- io_service_.poll();
+ io_service_->poll();
}
// This test verifies that the HTTP listener can't be started twice.
// This test verifies that listener can't be bound to the port to which
// other server is bound.
TEST_F(HttpsListenerTest, addressInUse) {
- tcp::acceptor acceptor(io_service_.getInternalIOService());
+ tcp::acceptor acceptor(io_service_->getInternalIOService());
// Use other port than SERVER_PORT to make sure that this TCP connection
// doesn't affect subsequent tests.
tcp::endpoint endpoint(address::from_string(SERVER_ADDRESS),
TEST_F(DStubControllerTest, launchRuntimeError) {
// Use an asiolink IntervalTimer and callback to generate the
// shutdown invocation. (Note IntervalTimer setup is in milliseconds).
- isc::asiolink::IntervalTimer timer(*getIOService());
+ isc::asiolink::IntervalTimer timer(getIOService());
timer.setup(genFatalErrorCallback, 2000);
// Write the valid, empty, config and then run launch() for 5000 ms
controller_->recordSignalOnly(true);
// Setup to raise SIGHUP in 10 ms.
- TimedSignal sighup(*getIOService(), SIGHUP, 10);
- TimedSignal sigint(*getIOService(), SIGINT, 100);
- TimedSignal sigterm(*getIOService(), SIGTERM, 200);
+ TimedSignal sighup(getIOService(), SIGHUP, 10);
+ TimedSignal sigint(getIOService(), SIGINT, 100);
+ TimedSignal sigterm(getIOService(), SIGTERM, 200);
// Write the valid, empty, config and then run launch() for 500 ms
time_duration elapsed_time;
scheduleTimedWrite("{ \"string_test\": BOGUS JSON }", 100);
// Setup to raise SIGHUP in 200 ms.
- TimedSignal sighup(*getIOService(), SIGHUP, 200);
+ TimedSignal sighup(getIOService(), SIGHUP, 200);
// Write the config and then run launch() for 500 ms
// After startup, which will load the initial configuration this enters
controller_->useAlternateParser(true);
// Setup to raise SIGHUP in 200 ms.
- TimedSignal sighup(*getIOService(), SIGHUP, 200);
+ TimedSignal sighup(getIOService(), SIGHUP, 200);
// Write the config and then run launch() for 500 ms
// After startup, which will load the initial configuration this enters
scheduleTimedWrite("{ \"string_test\": \"second value\" }", 100);
// Setup to raise SIGHUP in 200 ms and another at 400 ms.
- TimedSignal sighup(*getIOService(), SIGHUP, 200);
- TimedSignal sighup2(*getIOService(), SIGHUP, 400);
+ TimedSignal sighup(getIOService(), SIGHUP, 200);
+ TimedSignal sighup2(getIOService(), SIGHUP, 400);
// Write the config and then run launch() for 800 ms
time_duration elapsed_time;
// Tests that the SIGINT triggers a normal shutdown.
TEST_F(DStubControllerTest, sigintShutdown) {
// Setup to raise SIGHUP in 1 ms.
- TimedSignal sighup(*getIOService(), SIGINT, 1);
+ TimedSignal sighup(getIOService(), SIGINT, 1);
// Write the config and then run launch() for 1000 ms
time_duration elapsed_time;
// Tests that the SIGTERM triggers a normal shutdown.
TEST_F(DStubControllerTest, sigtermShutdown) {
// Setup to raise SIGHUP in 1 ms.
- TimedSignal sighup(*getIOService(), SIGTERM, 1);
+ TimedSignal sighup(getIOService(), SIGTERM, 1);
// Write the config and then run launch() for 1000 ms
time_duration elapsed_time;
DControllerTest::scheduleTimedWrite(const std::string& config,
int write_time_ms) {
new_cfg_content_ = config;
- write_timer_.reset(new asiolink::IntervalTimer(*getIOService()));
+ write_timer_.reset(new asiolink::IntervalTimer(getIOService()));
write_timer_->setup(std::bind(&DControllerTest::timedWriteCallback, this),
write_time_ms, asiolink::IntervalTimer::ONE_SHOT);
}
writeFile(config);
// Shutdown (without error) after runtime.
- isc::asiolink::IntervalTimer timer(*getIOService());
+ isc::asiolink::IntervalTimer timer(getIOService());
timer.setup(genShutdownCallback, run_time_ms);
// Record start time, and invoke launch().
writeFile(config);
// Shutdown (without error) after runtime.
- isc::asiolink::IntervalTimer timer(*getIOService());
+ isc::asiolink::IntervalTimer timer(getIOService());
timer.setup([&] { callback(); genShutdownCallback(); }, run_time_ms);
// Record start time, and invoke launch().
thread_io_service_.reset(new IOService());
// Create a new TCPListener derivation using the factory.
- tcp_listener_ = listener_factory_(*thread_io_service_,
+ tcp_listener_ = listener_factory_(thread_io_service_,
address_,
port_,
tls_context_,
/// @brief Defines a factory function for creating TcpListeners.
typedef std::function<
- TcpListenerPtr(asiolink::IOService& io_service,
+ TcpListenerPtr(const asiolink::IOServicePtr& io_service,
const asiolink::IOAddress& server_address,
const unsigned short server_port,
const asiolink::TlsContextPtr& tls_context,
callback_(ec, length);
}
-TcpConnection::TcpConnection(asiolink::IOService& io_service,
+TcpConnection::TcpConnection(const asiolink::IOServicePtr& io_service,
const TcpConnectionAcceptorPtr& acceptor,
const TlsContextPtr& tls_context,
TcpConnectionPool& connection_pool,
const TcpConnectionFilterCallback& connection_filter,
const long idle_timeout,
const size_t read_max /* = 32768 */)
- : tls_context_(tls_context),
+ : io_service_(io_service),
+ tls_context_(tls_context),
idle_timeout_(idle_timeout),
idle_timer_(io_service),
tcp_socket_(),
/// @param idle_timeout Timeout after which a TCP connection is
/// closed by the server.
/// @param read_max maximum size of a single socket read. Defaults to 32K.
- TcpConnection(asiolink::IOService& io_service,
+ TcpConnection(const asiolink::IOServicePtr& io_service,
const TcpConnectionAcceptorPtr& acceptor,
const asiolink::TlsContextPtr& tls_context,
TcpConnectionPool& connection_pool,
return (input_buf_.size());
}
+ /// @brief The IO service used to handle events.
+ asiolink::IOServicePtr io_service_;
+
/// @brief TLS context.
asiolink::TlsContextPtr tls_context_;
namespace isc {
namespace tcp {
-TcpListener::TcpListener(IOService& io_service,
+TcpListener::TcpListener(const IOServicePtr& io_service,
const IOAddress& server_address,
const unsigned short server_port,
const TlsContextPtr& tls_context,
///
/// @throw TcpListenerError when any of the specified parameters is
/// invalid.
- TcpListener(asiolink::IOService& io_service,
+ TcpListener(const asiolink::IOServicePtr& io_service,
const asiolink::IOAddress& server_address,
const unsigned short server_port,
const asiolink::TlsContextPtr& tls_context,
const TcpConnectionAcceptorCallback& acceptor_callback,
const TcpConnectionFilterCallback& connection_filter);
- /// @brief Reference to the IO service.
- asiolink::IOService& io_service_;
+ /// @brief Pointer to the IO service.
+ asiolink::IOServicePtr io_service_;
/// @brief TLS context.
asiolink::TlsContextPtr tls_context_;
///
/// Starts test timer which detects timeouts, and enables multi-threading mode.
MtTcpListenerMgrTest()
- : mt_listener_mgr_(), io_service_(), test_timer_(io_service_),
+ : mt_listener_mgr_(), io_service_(new IOService()), test_timer_(io_service_),
run_io_service_timer_(io_service_), clients_(), num_threads_(),
num_clients_(), num_in_progress_(0), num_finished_(0), chunk_size_(0),
pause_cnt_(0), response_handler_(0) {
}
/// @brief TcpListener factory for MtTcpListener to instantiate new listeners.
- TcpListenerPtr listenerFactory(asiolink::IOService& io_service,
+ TcpListenerPtr listenerFactory(const asiolink::IOServicePtr& io_service,
const asiolink::IOAddress& server_address,
const unsigned short server_port,
const asiolink::TlsContextPtr& tls_context,
///
/// @param fail_on_timeout Specifies if test failure should be reported.
void clientDone() {
- io_service_.stop();
+ io_service_->stop();
}
/// @brief Initiates a command via a new TCP client.
if (fail_on_timeout) {
ADD_FAILURE() << "Timeout occurred while running the test!";
}
- io_service_.stop();
+ io_service_->stop();
}
/// @brief Runs IO service with optional timeout.
size_t num_done = 0;
while (num_done != request_limit) {
// Always call restart() before we call run();
- io_service_.restart();
+ io_service_->restart();
// Run until a client stops the service.
- io_service_.run();
+ io_service_->run();
// If all the clients are done receiving, the test is done.
num_done = 0;
// Create an MtTcpListenerMgr with prescribed number of threads.
createMtTcpListenerMgr(num_threads,
std::bind(&MtTcpListenerMgrTest::synchronizedCommandHandler,
- this, ph::_1));
+ this, ph::_1));
// Start it and verify it is running.
ASSERT_NO_THROW_LOG(mt_listener_mgr_->start());
MtTcpListenerMgrPtr mt_listener_mgr_;
/// @brief IO service used in drive the test and test clients.
- IOService io_service_;
+ IOServicePtr io_service_;
/// @brief Asynchronous timer service to detect timeouts.
IntervalTimer test_timer_;
///
/// Starts test timer which detects timeouts.
TcpListenerTest()
- : io_service_(), test_timer_(io_service_),
+ : io_service_(new IOService()), test_timer_(io_service_),
run_io_service_timer_(io_service_),
clients_(), clients_done_(0) {
test_timer_.setup(std::bind(&TcpListenerTest::timeoutHandler, this, true),
if (fail_on_timeout) {
ADD_FAILURE() << "Timeout occurred while running the test!";
}
- io_service_.stop();
+ io_service_->stop();
}
/// @brief Callback function each client invokes when done.
++clients_done_;
if (clients_done_ >= clients_.size()) {
// They're all done or dead. Stop the service.
- io_service_.stop();
+ io_service_->stop();
}
}
/// @param timeout Optional value specifying for how long the io service
/// should be ran.
void runIOService(long timeout = 0) {
- io_service_.restart();
+ io_service_->restart();
if (timeout > 0) {
run_io_service_timer_.setup(std::bind(&TcpListenerTest::timeoutHandler,
timeout,
IntervalTimer::ONE_SHOT);
}
- io_service_.run();
- io_service_.restart();
- io_service_.poll();
+ io_service_->run();
+ io_service_->restart();
+ io_service_->poll();
}
/// @brief Filter that denies every other connection.
}
/// @brief IO service used in the tests.
- IOService io_service_;
+ IOServicePtr io_service_;
/// @brief Asynchronous timer service to detect timeouts.
IntervalTimer test_timer_;
ASSERT_EQ(expected_entries, listener.audit_trail_->getConnectionTrail(1));
listener.stop();
- io_service_.poll();
+ io_service_->poll();
}
// This test verifies that a TCP connection can receive a complete
EXPECT_FALSE(client->expectedEof());
listener.stop();
- io_service_.poll();
+ io_service_->poll();
}
// This test verifies that a TCP connection can be established and used to
EXPECT_TRUE(client->expectedEof());
listener.stop();
- io_service_.poll();
+ io_service_->poll();
}
TEST_F(TcpListenerTest, multipleClientsListen) {
}
listener.stop();
- io_service_.poll();
+ io_service_->poll();
}
// Verify that the listener handles multiple requests for multiple
}
listener.stop();
- io_service_.poll();
+ io_service_->poll();
}
// Verify that connection filtering can eliminate specific connections.
}
listener.stop();
- io_service_.poll();
+ io_service_->poll();
}
// Exercises TcpStreamRequest::postBuffer() through various
/// @param tls_context
/// @param server_address string containing the IP address of the server.
/// @param port port number of the server.
- explicit TcpTestClient(isc::asiolink::IOService& io_service,
+ explicit TcpTestClient(const isc::asiolink::IOServicePtr& io_service,
std::function<void()> done_callback,
isc::asiolink::TlsContextPtr tls_context =
isc::asiolink::TlsContextPtr(),
const std::string& server_address = "127.0.0.1",
uint16_t port = 18123)
- : io_service_(io_service.getInternalIOService()),
+ : io_service_(io_service),
tls_context_(tls_context),
tcp_socket_(), tls_socket_(),
done_callback_(done_callback),
private:
- /// @brief Holds reference to the IO service.
- boost::asio::io_service& io_service_;
+ /// @brief Holds pointer to the IO service.
+ isc::asiolink::IOServicePtr io_service_;
/// @brief TLS context.
isc::asiolink::TlsContextPtr tls_context_;
typedef std::function<std::string(const std::string&)> ResponseHandler;
/// @brief Constructor
- TcpTestConnection(IOService& io_service,
+ TcpTestConnection(const IOServicePtr& io_service,
const TcpConnectionAcceptorPtr& acceptor,
const TlsContextPtr& tls_context,
TcpConnectionPool& connection_pool,
class TcpTestListener : public TcpListener {
public:
/// @brief Constructor
- TcpTestListener(IOService& io_service,
+ TcpTestListener(const IOServicePtr& io_service,
const IOAddress& server_address,
const unsigned short server_port,
const TlsContextPtr& tls_context,
///
/// Starts test timer which detects timeouts.
TlsListenerTest()
- : io_service_(), test_timer_(io_service_),
+ : io_service_(new IOService()), test_timer_(io_service_),
run_io_service_timer_(io_service_),
clients_(), clients_done_(0) {
test_timer_.setup(std::bind(&TlsListenerTest::timeoutHandler, this, true),
if (fail_on_timeout) {
ADD_FAILURE() << "Timeout occurred while running the test!";
}
- io_service_.stop();
+ io_service_->stop();
}
/// @brief Callback function each client invokes when done.
++clients_done_;
if (clients_done_ >= clients_.size()) {
// They're all done or dead. Stop the service.
- io_service_.stop();
+ io_service_->stop();
}
}
/// @param timeout Optional value specifying for how long the io service
/// should be ran.
void runIOService(long timeout = 0) {
- io_service_.restart();
+ io_service_->restart();
if (timeout > 0) {
run_io_service_timer_.setup(std::bind(&TlsListenerTest::timeoutHandler,
timeout,
IntervalTimer::ONE_SHOT);
}
- io_service_.run();
- io_service_.restart();
- io_service_.poll();
+ io_service_->run();
+ io_service_->restart();
+ io_service_->poll();
}
/// @brief Filter that denies every other connection.
}
/// @brief IO service used in the tests.
- IOService io_service_;
+ IOServicePtr io_service_;
/// @brief Asynchronous timer service to detect timeouts.
IntervalTimer test_timer_;
ASSERT_EQ(expected_entries, listener.audit_trail_->getConnectionTrail(1));
listener.stop();
- io_service_.poll();
+ io_service_->poll();
}
// This test verifies that a TLS connection is denied to a client
EXPECT_FALSE(client->expectedEof());
listener.stop();
- io_service_.poll();
+ io_service_->poll();
}
// This test verifies that a TLS connection can be established and used to
EXPECT_TRUE(client->expectedEof());
listener.stop();
- io_service_.poll();
+ io_service_->poll();
}
// This test verifies that TLS connections with multiple clients.
}
listener.stop();
- io_service_.poll();
+ io_service_->poll();
}
// Verify that the listener handles multiple requests for multiple
}
listener.stop();
- io_service_.poll();
+ io_service_->poll();
}
// Verify that connection filtering can eliminate specific connections.
}
listener.stop();
- io_service_.poll();
+ io_service_->poll();
}
}