response = "";
IOServicePtr io_service = getIOService();
ASSERT_TRUE(io_service);
- boost::scoped_ptr<TestHttpClient> client;
- client.reset(new TestHttpClient(io_service, SERVER_ADDRESS,
- SERVER_PORT));
+ TestHttpClientPtr client(new TestHttpClient(io_service, SERVER_ADDRESS,
+ SERVER_PORT));
ASSERT_TRUE(client);
// Send the command. This will trigger server's handler which
response = "";
IOServicePtr io_service = getIOService();
ASSERT_TRUE(io_service);
- boost::scoped_ptr<TestHttpsClient> client;
+
TlsContextPtr client_tls_context;
configClient(client_tls_context);
- client.reset(new TestHttpsClient(io_service, client_tls_context,
- SERVER_ADDRESS, SERVER_PORT));
+ TestHttpsClientPtr client(new TestHttpsClient(io_service, client_tls_context,
+ SERVER_ADDRESS, SERVER_PORT));
ASSERT_TRUE(client);
// Send the command. This will trigger server's handler which
LeaseMgrFactory::destroy();
StatsMgr::instance().removeAll();
- UnixCommandMgr::instance().closeCommandSocket();
CommandMgr::instance().deregisterAll();
UnixCommandMgr::instance().setConnectionTimeout(TIMEOUT_DHCP_SERVER_RECEIVE_COMMAND);
std::string response;
sendUnixCommand("{ \"command\": \"shutdown\" }", response);
- EXPECT_EQ("{ \"result\": 0, \"text\": \"Shutting down.\" }",response);
+ EXPECT_EQ("{ \"result\": 0, \"text\": \"Shutting down.\" }", response);
}
// Tests that the server properly responds to statistics commands. Note this
LeaseMgrFactory::destroy();
StatsMgr::instance().removeAll();
- if (HttpCommandMgr::instance().getHttpListener()) {
- HttpCommandMgr::instance().close();
- }
CommandMgr::instance().deregisterAll();
HttpCommandMgr::instance().setConnectionTimeout(TIMEOUT_DHCP_SERVER_RECEIVE_COMMAND);
response = "";
IOServicePtr io_service = getIOService();
ASSERT_TRUE(io_service);
- boost::scoped_ptr<TestHttpClient> client;
- client.reset(new TestHttpClient(io_service, SERVER_ADDRESS,
- SERVER_PORT));
+ TestHttpClientPtr client(new TestHttpClient(io_service, SERVER_ADDRESS,
+ SERVER_PORT));
ASSERT_TRUE(client);
// Send the command. This will trigger server's handler which receives
response = "";
IOServicePtr io_service = getIOService();
ASSERT_TRUE(io_service);
- boost::scoped_ptr<TestHttpsClient> client;
+
TlsContextPtr client_tls_context;
configClient(client_tls_context);
- client.reset(new TestHttpsClient(io_service, client_tls_context,
- SERVER_ADDRESS, SERVER_PORT));
+ TestHttpsClientPtr client(new TestHttpsClient(io_service, client_tls_context,
+ SERVER_ADDRESS, SERVER_PORT));
ASSERT_TRUE(client);
// Send the command. This will trigger server's handler which receives
LeaseMgrFactory::destroy();
StatsMgr::instance().removeAll();
- UnixCommandMgr::instance().closeCommandSocket();
CommandMgr::instance().deregisterAll();
UnixCommandMgr::instance().setConnectionTimeout(TIMEOUT_DHCP_SERVER_RECEIVE_COMMAND);
std::string response;
sendUnixCommand("{ \"command\": \"shutdown\" }", response);
- EXPECT_EQ("{ \"result\": 0, \"text\": \"Shutting down.\" }",response);
+ EXPECT_EQ("{ \"result\": 0, \"text\": \"Shutting down.\" }", response);
}
// Tests that the server properly responds to statistics commands. Note this
LeaseMgrFactory::destroy();
StatsMgr::instance().removeAll();
- if (HttpCommandMgr::instance().getHttpListener()) {
- HttpCommandMgr::instance().close();
- }
CommandMgr::instance().deregisterAll();
HttpCommandMgr::instance().setConnectionTimeout(TIMEOUT_DHCP_SERVER_RECEIVE_COMMAND);
response = "";
IOServicePtr io_service = getIOService();
ASSERT_TRUE(io_service);
- boost::scoped_ptr<TestHttpClient> client;
- client.reset(new TestHttpClient(io_service, SERVER_ADDRESS,
- SERVER_PORT));
+ TestHttpClientPtr client(new TestHttpClient(io_service, SERVER_ADDRESS,
+ SERVER_PORT));
ASSERT_TRUE(client);
// Send the command. This will trigger server's handler which receives
response = "";
IOServicePtr io_service = getIOService();
ASSERT_TRUE(io_service);
- boost::scoped_ptr<TestHttpsClient> client;
+
TlsContextPtr client_tls_context;
configClient(client_tls_context);
- client.reset(new TestHttpsClient(io_service, client_tls_context,
- SERVER_ADDRESS, SERVER_PORT));
+ TestHttpsClientPtr client(new TestHttpsClient(io_service, client_tls_context,
+ SERVER_ADDRESS, SERVER_PORT));
ASSERT_TRUE(client);
// Send the command. This will trigger server's handler which receives
// depends on the use case.
HttpResponseCreatorPtr response_creator = creator_factory_->create();
HttpAcceptorCallback acceptor_callback =
- std::bind(&HttpListenerImpl::acceptHandler, this, ph::_1);
+ std::bind(&HttpListenerImpl::acceptHandler, shared_from_this(), ph::_1);
HttpConnectionPtr conn = createConnection(response_creator,
acceptor_callback);
// Transmit the use external sockets flag.
#include <http/connection.h>
#include <http/connection_pool.h>
#include <http/response_creator_factory.h>
+#include <boost/enable_shared_from_this.hpp>
#include <boost/scoped_ptr.hpp>
namespace isc {
namespace http {
/// @brief Implementation of the @ref HttpListener.
-class HttpListenerImpl {
+class HttpListenerImpl : public boost::enable_shared_from_this<HttpListenerImpl> {
public:
/// @brief Constructor.
#include <boost/asio/read.hpp>
#include <boost/asio/buffer.hpp>
#include <boost/asio/ip/tcp.hpp>
+#include <boost/enable_shared_from_this.hpp>
#include <gtest/gtest.h>
using namespace boost::asio::ip;
};
/// @brief Entity which can connect to the HTTP server endpoint.
-class TestHttpClient : public BaseTestHttpClient {
+class TestHttpClient : public BaseTestHttpClient,
+ public boost::enable_shared_from_this<TestHttpClient> {
public:
/// @brief Constructor.
/// @param request HTTP request in the textual format.
virtual void startRequest(const std::string& request) {
tcp::endpoint endpoint(address::from_string(server_address_), server_port_);
+ auto ref = shared_from_this();
socket_.async_connect(endpoint,
- [this, request](const boost::system::error_code& ec) {
+ [this, ref, request](const boost::system::error_code& ec) {
receive_done_ = false;
if (ec) {
// One would expect that async_connect wouldn't return
/// @param request part of the HTTP request to be sent.
virtual void sendPartialRequest(std::string request) {
size_t chuck_size = std::min(TEST_HTTP_CHUCK_SIZE, request.size());
+ auto ref = shared_from_this();
socket_.async_send(boost::asio::buffer(request.data(), chuck_size),
- [this, request](const boost::system::error_code& ec,
- std::size_t bytes_transferred) mutable {
+ [this, ref, request](const boost::system::error_code& ec,
+ std::size_t bytes_transferred) mutable {
if (ec) {
if (ec.value() == boost::asio::error::operation_aborted) {
return;
/// @brief Receive response from the server.
virtual void receivePartialResponse() {
- socket_.async_read_some(boost::asio::buffer(buf_.data(), buf_.size()),
- [this](const boost::system::error_code& ec,
- std::size_t bytes_transferred) {
+ auto ref = shared_from_this();
+ socket_.async_read_some(boost::asio::buffer(ref->buf_.data(), ref->buf_.size()),
+ [this, ref](const boost::system::error_code& ec,
+ std::size_t bytes_transferred) {
if (ec) {
// IO service stopped so simply return.
if (ec.value() == boost::asio::error::operation_aborted) {
typedef boost::shared_ptr<TestHttpClient> TestHttpClientPtr;
/// @brief Entity which can connect to the HTTPS server endpoint.
-class TestHttpsClient : public BaseTestHttpClient {
+class TestHttpsClient : public BaseTestHttpClient,
+ public boost::enable_shared_from_this<TestHttpsClient> {
public:
/// @brief Constructor.
virtual void startRequest(const std::string& request) {
tcp::endpoint endpoint(address::from_string(server_address_),
server_port_);
+ auto ref = shared_from_this();
stream_.lowest_layer().async_connect(endpoint,
- [this, request](const boost::system::error_code& ec) {
+ [this, ref, request](const boost::system::error_code& ec) {
receive_done_ = false;
if (ec) {
// One would expect that async_connect wouldn't return
/// @param request part of the HTTP request to be sent.
virtual void sendPartialRequest(std::string request) {
size_t chuck_size = std::min(TEST_HTTP_CHUCK_SIZE, request.size());
+ auto ref = shared_from_this();
boost::asio::async_write(stream_,
- boost::asio::buffer(request.data(), chuck_size),
- [this, request](const boost::system::error_code& ec,
- std::size_t bytes_transferred) mutable {
+ boost::asio::buffer(request.data(), chuck_size),
+ [this, ref, request](const boost::system::error_code& ec,
+ std::size_t bytes_transferred) mutable {
if (ec) {
if (ec.value() == boost::asio::error::operation_aborted) {
return;
/// @brief Receive response from the server.
virtual void receivePartialResponse() {
- stream_.async_read_some(boost::asio::buffer(buf_.data(), buf_.size()),
- [this](const boost::system::error_code& ec,
- std::size_t bytes_transferred) {
+ auto ref = shared_from_this();
+ stream_.async_read_some(boost::asio::buffer(ref->buf_.data(), ref->buf_.size()),
+ [this, ref](const boost::system::error_code& ec,
+ std::size_t bytes_transferred) {
if (ec) {
// IO service stopped so simply return.
if (ec.value() == boost::asio::error::operation_aborted) {