2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-31 05:55:28 +00:00

[#3602] use weak ptr

This commit is contained in:
Razvan Becheriu
2024-09-24 07:36:51 +03:00
parent d8c9dca3d1
commit 7f08d90c1a
9 changed files with 34 additions and 16 deletions

View File

@@ -149,7 +149,10 @@ public:
this, true),
TEST_TIMEOUT, IntervalTimer::ONE_SHOT);
// Run until the client stops the service or an error occurs.
io_service->run();
try {
io_service->run();
} catch (...) {
}
test_timer.cancel();
if (io_service->stopped()) {
io_service->restart();

View File

@@ -187,7 +187,10 @@ public:
this, true),
TEST_TIMEOUT, IntervalTimer::ONE_SHOT);
// Run until the client stops the service or an error occurs.
io_service->run();
try {
io_service->run();
} catch (...) {
}
test_timer.cancel();
if (io_service->stopped()) {
io_service->restart();

View File

@@ -68,7 +68,7 @@ SocketCallback::operator()(boost::system::error_code ec, size_t length) {
HttpConnection::HttpConnection(const asiolink::IOServicePtr& io_service,
const HttpAcceptorPtr& acceptor,
const TlsContextPtr& tls_context,
HttpConnectionPool& connection_pool,
HttpConnectionPoolPtr connection_pool,
const HttpResponseCreatorPtr& response_creator,
const HttpAcceptorCallback& callback,
const long request_timeout,
@@ -234,11 +234,16 @@ HttpConnection::close() {
void
HttpConnection::shutdownConnection() {
auto connection_pool = connection_pool_.lock();
try {
LOG_DEBUG(http_logger, isc::log::DBGLVL_TRACE_BASIC,
HTTP_CONNECTION_SHUTDOWN)
.arg(getRemoteEndpointAddressAsText());
connection_pool_.shutdown(shared_from_this());
if (connection_pool) {
connection_pool->shutdown(shared_from_this());
} else {
shutdown();
}
} catch (...) {
LOG_ERROR(http_logger, HTTP_CONNECTION_SHUTDOWN_FAILED);
}
@@ -246,11 +251,16 @@ HttpConnection::shutdownConnection() {
void
HttpConnection::stopThisConnection() {
auto connection_pool = connection_pool_.lock();
try {
LOG_DEBUG(http_logger, isc::log::DBGLVL_TRACE_BASIC,
HTTP_CONNECTION_STOP)
.arg(getRemoteEndpointAddressAsText());
connection_pool_.stop(shared_from_this());
if (connection_pool) {
connection_pool->stop(shared_from_this());
} else {
close();
}
} catch (...) {
LOG_ERROR(http_logger, HTTP_CONNECTION_STOP_FAILED);
}

View File

@@ -245,7 +245,7 @@ public:
HttpConnection(const asiolink::IOServicePtr& io_service,
const HttpAcceptorPtr& acceptor,
const asiolink::TlsContextPtr& tls_context,
HttpConnectionPool& connection_pool,
std::shared_ptr<HttpConnectionPool> connection_pool,
const HttpResponseCreatorPtr& response_creator,
const HttpAcceptorCallback& callback,
const long request_timeout,
@@ -441,7 +441,7 @@ protected:
HttpAcceptorPtr acceptor_;
/// @brief Connection pool holding this connection.
HttpConnectionPool& connection_pool_;
std::weak_ptr<HttpConnectionPool> connection_pool_;
/// @brief Pointer to the @ref HttpResponseCreator object used to create
/// HTTP responses.

View File

@@ -71,6 +71,9 @@ protected:
std::mutex mutex_;
};
/// @brief Pointer to the @ref HttpConnection.
typedef std::shared_ptr<HttpConnectionPool> HttpConnectionPoolPtr;
}
}

View File

@@ -26,7 +26,7 @@ HttpListenerImpl::HttpListenerImpl(const IOServicePtr& io_service,
const long request_timeout,
const long idle_timeout)
: io_service_(io_service), tls_context_(tls_context), acceptor_(),
endpoint_(), connections_(),
endpoint_(), connections_(new HttpConnectionPool()),
creator_factory_(creator_factory),
request_timeout_(request_timeout), idle_timeout_(idle_timeout),
use_external_(false) {
@@ -102,7 +102,7 @@ HttpListenerImpl::start() {
void
HttpListenerImpl::stop() {
connections_.stopAll();
connections_->stopAll();
if (use_external_) {
IfaceMgr::instance().deleteExternalSocket(acceptor_->getNative());
}
@@ -124,7 +124,7 @@ HttpListenerImpl::accept() {
conn->addExternalSockets(true);
}
// Add this new connection to the pool.
connections_.start(conn);
connections_->start(conn);
}
void

View File

@@ -128,7 +128,7 @@ protected:
boost::scoped_ptr<asiolink::TCPEndpoint> endpoint_;
/// @brief Pool of active connections.
HttpConnectionPool connections_;
HttpConnectionPoolPtr connections_;
/// @brief Pointer to the @ref HttpResponseCreatorFactory.
HttpResponseCreatorFactoryPtr creator_factory_;
@@ -144,7 +144,6 @@ protected:
bool use_external_;
};
} // end of namespace isc::http
} // end of namespace isc

View File

@@ -107,7 +107,7 @@ public:
HttpConnectionPoolTest()
: io_service_(new IOService()),
acceptor_(new HttpAcceptor(io_service_)),
connection_pool_(),
connection_pool_(new HttpConnectionPool()),
response_creator_(new TestHttpResponseCreator()) {
MultiThreadingMgr::instance().setMode(false);
}
@@ -219,7 +219,7 @@ public:
IOServicePtr io_service_; ///< IO service.
HttpAcceptorPtr acceptor_; ///< Test acceptor.
HttpConnectionPool connection_pool_; ///< Test connection pool.
HttpConnectionPoolPtr connection_pool_; ///< Test connection pool.
HttpResponseCreatorPtr response_creator_; ///< Test response creator.
};

View File

@@ -125,7 +125,7 @@ public:
HttpConnectionLongWriteBuffer(const IOServicePtr& io_service,
const HttpAcceptorPtr& acceptor,
const TlsContextPtr& tls_context,
HttpConnectionPool& connection_pool,
HttpConnectionPoolPtr connection_pool,
const HttpResponseCreatorPtr& response_creator,
const HttpAcceptorCallback& callback,
const long request_timeout,
@@ -172,7 +172,7 @@ public:
HttpConnectionTransactionChange(const IOServicePtr& io_service,
const HttpAcceptorPtr& acceptor,
const TlsContextPtr& tls_context,
HttpConnectionPool& connection_pool,
HttpConnectionPoolPtr connection_pool,
const HttpResponseCreatorPtr& response_creator,
const HttpAcceptorCallback& callback,
const long request_timeout,