mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-31 14:05:33 +00:00
[#3478] Checkpoint: handle acceptor
This commit is contained in:
@@ -49,7 +49,8 @@ libkea_http_la_CPPFLAGS = $(AM_CPPFLAGS)
|
|||||||
libkea_http_la_LDFLAGS = $(AM_LDFLAGS)
|
libkea_http_la_LDFLAGS = $(AM_LDFLAGS)
|
||||||
libkea_http_la_LDFLAGS += -no-undefined -version-info 81:0:0
|
libkea_http_la_LDFLAGS += -no-undefined -version-info 81:0:0
|
||||||
|
|
||||||
libkea_http_la_LIBADD = $(top_builddir)/src/lib/hooks/libkea-hooks.la
|
libkea_http_la_LIBADD = $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la
|
||||||
|
libkea_http_la_LIBADD += $(top_builddir)/src/lib/hooks/libkea-hooks.la
|
||||||
libkea_http_la_LIBADD += $(top_builddir)/src/lib/cc/libkea-cc.la
|
libkea_http_la_LIBADD += $(top_builddir)/src/lib/cc/libkea-cc.la
|
||||||
libkea_http_la_LIBADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la
|
libkea_http_la_LIBADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la
|
||||||
libkea_http_la_LIBADD += $(top_builddir)/src/lib/log/libkea-log.la
|
libkea_http_la_LIBADD += $(top_builddir)/src/lib/log/libkea-log.la
|
||||||
|
@@ -79,7 +79,8 @@ HttpConnection::HttpConnection(const asiolink::IOServicePtr& io_service,
|
|||||||
acceptor_(acceptor),
|
acceptor_(acceptor),
|
||||||
connection_pool_(connection_pool),
|
connection_pool_(connection_pool),
|
||||||
response_creator_(response_creator),
|
response_creator_(response_creator),
|
||||||
acceptor_callback_(callback) {
|
acceptor_callback_(callback),
|
||||||
|
use_external_(false) {
|
||||||
if (!tls_context) {
|
if (!tls_context) {
|
||||||
tcp_socket_.reset(new asiolink::TCPSocket<SocketCallback>(io_service));
|
tcp_socket_.reset(new asiolink::TCPSocket<SocketCallback>(io_service));
|
||||||
} else {
|
} else {
|
||||||
@@ -92,6 +93,11 @@ HttpConnection::~HttpConnection() {
|
|||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
HttpConnection::addExternalSockets(bool use_external) {
|
||||||
|
use_external_ = use_external;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
HttpConnection::recordParameters(const HttpRequestPtr& request) const {
|
HttpConnection::recordParameters(const HttpRequestPtr& request) const {
|
||||||
if (!request) {
|
if (!request) {
|
||||||
|
@@ -255,6 +255,14 @@ public:
|
|||||||
/// Closes current connection.
|
/// Closes current connection.
|
||||||
virtual ~HttpConnection();
|
virtual ~HttpConnection();
|
||||||
|
|
||||||
|
/// @brief Use external sockets flag.
|
||||||
|
///
|
||||||
|
/// Add sockets as external sockets of the interface manager
|
||||||
|
/// so available I/O on them makes a waiting select to return.
|
||||||
|
///
|
||||||
|
/// @param use_external True add external sockets (default false).
|
||||||
|
void addExternalSockets(bool use_external = false);
|
||||||
|
|
||||||
/// @brief Asynchronously accepts new connection.
|
/// @brief Asynchronously accepts new connection.
|
||||||
///
|
///
|
||||||
/// When the connection is established successfully, the timeout timer is
|
/// When the connection is established successfully, the timeout timer is
|
||||||
@@ -424,6 +432,9 @@ protected:
|
|||||||
|
|
||||||
/// @brief External TCP acceptor callback.
|
/// @brief External TCP acceptor callback.
|
||||||
HttpAcceptorCallback acceptor_callback_;
|
HttpAcceptorCallback acceptor_callback_;
|
||||||
|
|
||||||
|
/// @brief Use external sockets flag.
|
||||||
|
bool use_external_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end of namespace isc::http
|
} // end of namespace isc::http
|
||||||
|
@@ -47,6 +47,11 @@ HttpListener::getNative() const {
|
|||||||
return (impl_->getNative());
|
return (impl_->getNative());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
HttpListener::addExternalSockets(bool use_external) {
|
||||||
|
impl_->addExternalSockets(use_external);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
HttpListener::start() {
|
HttpListener::start() {
|
||||||
impl_->start();
|
impl_->start();
|
||||||
|
@@ -118,6 +118,14 @@ public:
|
|||||||
/// @brief file descriptor of the underlying acceptor socket.
|
/// @brief file descriptor of the underlying acceptor socket.
|
||||||
int getNative() const;
|
int getNative() const;
|
||||||
|
|
||||||
|
/// @brief Use external sockets flag.
|
||||||
|
///
|
||||||
|
/// Add sockets as external sockets of the interface manager
|
||||||
|
/// so available I/O on them makes a waiting select to return.
|
||||||
|
///
|
||||||
|
/// @param use_external True add external sockets (default false).
|
||||||
|
void addExternalSockets(bool use_external = false);
|
||||||
|
|
||||||
/// @brief Starts accepting new connections.
|
/// @brief Starts accepting new connections.
|
||||||
///
|
///
|
||||||
/// This method starts accepting and handling new HTTP connections on
|
/// This method starts accepting and handling new HTTP connections on
|
||||||
|
@@ -6,11 +6,13 @@
|
|||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <asiolink/asio_wrapper.h>
|
#include <asiolink/asio_wrapper.h>
|
||||||
|
#include <dhcp/iface_mgr.h>
|
||||||
#include <http/connection_pool.h>
|
#include <http/connection_pool.h>
|
||||||
#include <http/listener.h>
|
#include <http/listener.h>
|
||||||
#include <http/listener_impl.h>
|
#include <http/listener_impl.h>
|
||||||
|
|
||||||
using namespace isc::asiolink;
|
using namespace isc::asiolink;
|
||||||
|
using namespace isc::dhcp;
|
||||||
namespace ph = std::placeholders;
|
namespace ph = std::placeholders;
|
||||||
|
|
||||||
namespace isc {
|
namespace isc {
|
||||||
@@ -26,7 +28,8 @@ HttpListenerImpl::HttpListenerImpl(const IOServicePtr& io_service,
|
|||||||
: io_service_(io_service), tls_context_(tls_context), acceptor_(),
|
: io_service_(io_service), tls_context_(tls_context), acceptor_(),
|
||||||
endpoint_(), connections_(),
|
endpoint_(), connections_(),
|
||||||
creator_factory_(creator_factory),
|
creator_factory_(creator_factory),
|
||||||
request_timeout_(request_timeout), idle_timeout_(idle_timeout) {
|
request_timeout_(request_timeout), idle_timeout_(idle_timeout),
|
||||||
|
use_external_(false) {
|
||||||
// Create the TCP or TLS acceptor.
|
// Create the TCP or TLS acceptor.
|
||||||
if (!tls_context) {
|
if (!tls_context) {
|
||||||
acceptor_.reset(new HttpAcceptor(io_service));
|
acceptor_.reset(new HttpAcceptor(io_service));
|
||||||
@@ -72,10 +75,18 @@ HttpListenerImpl::getNative() const {
|
|||||||
return (acceptor_ ? acceptor_->getNative() : -1);
|
return (acceptor_ ? acceptor_->getNative() : -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
HttpListenerImpl::addExternalSockets(bool use_external) {
|
||||||
|
use_external_ = use_external;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
HttpListenerImpl::start() {
|
HttpListenerImpl::start() {
|
||||||
try {
|
try {
|
||||||
acceptor_->open(*endpoint_);
|
acceptor_->open(*endpoint_);
|
||||||
|
if (use_external_) {
|
||||||
|
IfaceMgr::instance().addExternalSocket(acceptor_->getNative(), 0);
|
||||||
|
}
|
||||||
acceptor_->setOption(HttpAcceptor::ReuseAddress(true));
|
acceptor_->setOption(HttpAcceptor::ReuseAddress(true));
|
||||||
acceptor_->bind(*endpoint_);
|
acceptor_->bind(*endpoint_);
|
||||||
acceptor_->listen();
|
acceptor_->listen();
|
||||||
@@ -92,6 +103,9 @@ HttpListenerImpl::start() {
|
|||||||
void
|
void
|
||||||
HttpListenerImpl::stop() {
|
HttpListenerImpl::stop() {
|
||||||
connections_.stopAll();
|
connections_.stopAll();
|
||||||
|
if (use_external_) {
|
||||||
|
IfaceMgr::instance().deleteExternalSocket(acceptor_->getNative());
|
||||||
|
}
|
||||||
acceptor_->close();
|
acceptor_->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,6 +119,10 @@ HttpListenerImpl::accept() {
|
|||||||
std::bind(&HttpListenerImpl::acceptHandler, this, ph::_1);
|
std::bind(&HttpListenerImpl::acceptHandler, this, ph::_1);
|
||||||
HttpConnectionPtr conn = createConnection(response_creator,
|
HttpConnectionPtr conn = createConnection(response_creator,
|
||||||
acceptor_callback);
|
acceptor_callback);
|
||||||
|
// Transmit the use external sockets flag.
|
||||||
|
if (use_external_) {
|
||||||
|
conn->addExternalSockets(true);
|
||||||
|
}
|
||||||
// Add this new connection to the pool.
|
// Add this new connection to the pool.
|
||||||
connections_.start(conn);
|
connections_.start(conn);
|
||||||
}
|
}
|
||||||
|
@@ -62,6 +62,14 @@ public:
|
|||||||
/// @brief file descriptor of the underlying acceptor socket.
|
/// @brief file descriptor of the underlying acceptor socket.
|
||||||
int getNative() const;
|
int getNative() const;
|
||||||
|
|
||||||
|
/// @brief Use external sockets flag.
|
||||||
|
///
|
||||||
|
/// Add sockets as external sockets of the interface manager
|
||||||
|
/// so available I/O on them makes a waiting select to return.
|
||||||
|
///
|
||||||
|
/// @param use_external True add external sockets.
|
||||||
|
void addExternalSockets(bool use_external);
|
||||||
|
|
||||||
/// @brief Starts accepting new connections.
|
/// @brief Starts accepting new connections.
|
||||||
///
|
///
|
||||||
/// This method starts accepting and handling new HTTP connections on
|
/// This method starts accepting and handling new HTTP connections on
|
||||||
@@ -130,6 +138,9 @@ protected:
|
|||||||
/// @brief Timeout after which idle persistent connection is closed by
|
/// @brief Timeout after which idle persistent connection is closed by
|
||||||
/// the server.
|
/// the server.
|
||||||
long idle_timeout_;
|
long idle_timeout_;
|
||||||
|
|
||||||
|
/// @brief Use external sockets flag.
|
||||||
|
bool use_external_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@@ -60,6 +60,7 @@ libhttp_unittests_CXXFLAGS = $(AM_CXXFLAGS)
|
|||||||
libhttp_unittests_LDFLAGS = $(AM_LDFLAGS) $(CRYPTO_LDFLAGS) $(GTEST_LDFLAGS)
|
libhttp_unittests_LDFLAGS = $(AM_LDFLAGS) $(CRYPTO_LDFLAGS) $(GTEST_LDFLAGS)
|
||||||
|
|
||||||
libhttp_unittests_LDADD = $(top_builddir)/src/lib/http/libkea-http.la
|
libhttp_unittests_LDADD = $(top_builddir)/src/lib/http/libkea-http.la
|
||||||
|
libhttp_unittests_LDADD += $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la
|
||||||
libhttp_unittests_LDADD += $(top_builddir)/src/lib/hooks/libkea-hooks.la
|
libhttp_unittests_LDADD += $(top_builddir)/src/lib/hooks/libkea-hooks.la
|
||||||
libhttp_unittests_LDADD += $(top_builddir)/src/lib/testutils/libkea-testutils.la
|
libhttp_unittests_LDADD += $(top_builddir)/src/lib/testutils/libkea-testutils.la
|
||||||
libhttp_unittests_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la
|
libhttp_unittests_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la
|
||||||
|
@@ -91,7 +91,7 @@ TEST_F(HttpRequestParserTest, postHttpRequestWithJson) {
|
|||||||
// Simulate receiving HTTP request in chunks.
|
// Simulate receiving HTTP request in chunks.
|
||||||
for (size_t i = 0; i < http_req.size(); i += http_req.size() / 10) {
|
for (size_t i = 0; i < http_req.size(); i += http_req.size() / 10) {
|
||||||
bool done = false;
|
bool done = false;
|
||||||
// Get the size of the data chunk.
|
// Get the size of the data chunk.
|
||||||
size_t chunk = http_req.size() / 10;
|
size_t chunk = http_req.size() / 10;
|
||||||
// When we're near the end of the data stream, the chunk length may
|
// When we're near the end of the data stream, the chunk length may
|
||||||
// vary.
|
// vary.
|
||||||
|
Reference in New Issue
Block a user