Skip to content

Commit 59f20f0

Browse files
committed
[#3478] Checkpoint: handle acceptor
1 parent d619d7b commit 59f20f0

9 files changed

+65
-4
lines changed

src/lib/http/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ libkea_http_la_CPPFLAGS = $(AM_CPPFLAGS)
4949
libkea_http_la_LDFLAGS = $(AM_LDFLAGS)
5050
libkea_http_la_LDFLAGS += -no-undefined -version-info 81:0:0
5151

52-
libkea_http_la_LIBADD = $(top_builddir)/src/lib/hooks/libkea-hooks.la
52+
libkea_http_la_LIBADD = $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la
53+
libkea_http_la_LIBADD += $(top_builddir)/src/lib/hooks/libkea-hooks.la
5354
libkea_http_la_LIBADD += $(top_builddir)/src/lib/cc/libkea-cc.la
5455
libkea_http_la_LIBADD += $(top_builddir)/src/lib/asiolink/libkea-asiolink.la
5556
libkea_http_la_LIBADD += $(top_builddir)/src/lib/log/libkea-log.la

src/lib/http/connection.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ HttpConnection::HttpConnection(const asiolink::IOServicePtr& io_service,
7979
acceptor_(acceptor),
8080
connection_pool_(connection_pool),
8181
response_creator_(response_creator),
82-
acceptor_callback_(callback) {
82+
acceptor_callback_(callback),
83+
use_external_(false) {
8384
if (!tls_context) {
8485
tcp_socket_.reset(new asiolink::TCPSocket<SocketCallback>(io_service));
8586
} else {
@@ -92,6 +93,11 @@ HttpConnection::~HttpConnection() {
9293
close();
9394
}
9495

96+
void
97+
HttpConnection::addExternalSockets(bool use_external) {
98+
use_external_ = use_external;
99+
}
100+
95101
void
96102
HttpConnection::recordParameters(const HttpRequestPtr& request) const {
97103
if (!request) {

src/lib/http/connection.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,14 @@ class HttpConnection : public boost::enable_shared_from_this<HttpConnection> {
255255
/// Closes current connection.
256256
virtual ~HttpConnection();
257257

258+
/// @brief Use external sockets flag.
259+
///
260+
/// Add sockets as external sockets of the interface manager
261+
/// so available I/O on them makes a waiting select to return.
262+
///
263+
/// @param use_external True add external sockets (default false).
264+
void addExternalSockets(bool use_external = false);
265+
258266
/// @brief Asynchronously accepts new connection.
259267
///
260268
/// When the connection is established successfully, the timeout timer is
@@ -424,6 +432,9 @@ class HttpConnection : public boost::enable_shared_from_this<HttpConnection> {
424432

425433
/// @brief External TCP acceptor callback.
426434
HttpAcceptorCallback acceptor_callback_;
435+
436+
/// @brief Use external sockets flag.
437+
bool use_external_;
427438
};
428439

429440
} // end of namespace isc::http

src/lib/http/listener.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ HttpListener::getNative() const {
4747
return (impl_->getNative());
4848
}
4949

50+
void
51+
HttpListener::addExternalSockets(bool use_external) {
52+
impl_->addExternalSockets(use_external);
53+
}
54+
5055
void
5156
HttpListener::start() {
5257
impl_->start();

src/lib/http/listener.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,14 @@ class HttpListener {
118118
/// @brief file descriptor of the underlying acceptor socket.
119119
int getNative() const;
120120

121+
/// @brief Use external sockets flag.
122+
///
123+
/// Add sockets as external sockets of the interface manager
124+
/// so available I/O on them makes a waiting select to return.
125+
///
126+
/// @param use_external True add external sockets (default false).
127+
void addExternalSockets(bool use_external = false);
128+
121129
/// @brief Starts accepting new connections.
122130
///
123131
/// This method starts accepting and handling new HTTP connections on

src/lib/http/listener_impl.cc

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66

77
#include <config.h>
88
#include <asiolink/asio_wrapper.h>
9+
#include <dhcp/iface_mgr.h>
910
#include <http/connection_pool.h>
1011
#include <http/listener.h>
1112
#include <http/listener_impl.h>
1213

1314
using namespace isc::asiolink;
15+
using namespace isc::dhcp;
1416
namespace ph = std::placeholders;
1517

1618
namespace isc {
@@ -26,7 +28,8 @@ HttpListenerImpl::HttpListenerImpl(const IOServicePtr& io_service,
2628
: io_service_(io_service), tls_context_(tls_context), acceptor_(),
2729
endpoint_(), connections_(),
2830
creator_factory_(creator_factory),
29-
request_timeout_(request_timeout), idle_timeout_(idle_timeout) {
31+
request_timeout_(request_timeout), idle_timeout_(idle_timeout),
32+
use_external_(false) {
3033
// Create the TCP or TLS acceptor.
3134
if (!tls_context) {
3235
acceptor_.reset(new HttpAcceptor(io_service));
@@ -72,10 +75,18 @@ HttpListenerImpl::getNative() const {
7275
return (acceptor_ ? acceptor_->getNative() : -1);
7376
}
7477

78+
void
79+
HttpListenerImpl::addExternalSockets(bool use_external) {
80+
use_external_ = use_external;
81+
}
82+
7583
void
7684
HttpListenerImpl::start() {
7785
try {
7886
acceptor_->open(*endpoint_);
87+
if (use_external_) {
88+
IfaceMgr::instance().addExternalSocket(acceptor_->getNative(), 0);
89+
}
7990
acceptor_->setOption(HttpAcceptor::ReuseAddress(true));
8091
acceptor_->bind(*endpoint_);
8192
acceptor_->listen();
@@ -92,6 +103,9 @@ HttpListenerImpl::start() {
92103
void
93104
HttpListenerImpl::stop() {
94105
connections_.stopAll();
106+
if (use_external_) {
107+
IfaceMgr::instance().deleteExternalSocket(acceptor_->getNative());
108+
}
95109
acceptor_->close();
96110
}
97111

@@ -105,6 +119,10 @@ HttpListenerImpl::accept() {
105119
std::bind(&HttpListenerImpl::acceptHandler, this, ph::_1);
106120
HttpConnectionPtr conn = createConnection(response_creator,
107121
acceptor_callback);
122+
// Transmit the use external sockets flag.
123+
if (use_external_) {
124+
conn->addExternalSockets(true);
125+
}
108126
// Add this new connection to the pool.
109127
connections_.start(conn);
110128
}

src/lib/http/listener_impl.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ class HttpListenerImpl {
6262
/// @brief file descriptor of the underlying acceptor socket.
6363
int getNative() const;
6464

65+
/// @brief Use external sockets flag.
66+
///
67+
/// Add sockets as external sockets of the interface manager
68+
/// so available I/O on them makes a waiting select to return.
69+
///
70+
/// @param use_external True add external sockets.
71+
void addExternalSockets(bool use_external);
72+
6573
/// @brief Starts accepting new connections.
6674
///
6775
/// This method starts accepting and handling new HTTP connections on
@@ -130,6 +138,9 @@ class HttpListenerImpl {
130138
/// @brief Timeout after which idle persistent connection is closed by
131139
/// the server.
132140
long idle_timeout_;
141+
142+
/// @brief Use external sockets flag.
143+
bool use_external_;
133144
};
134145

135146

src/lib/http/tests/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ libhttp_unittests_CXXFLAGS = $(AM_CXXFLAGS)
6060
libhttp_unittests_LDFLAGS = $(AM_LDFLAGS) $(CRYPTO_LDFLAGS) $(GTEST_LDFLAGS)
6161

6262
libhttp_unittests_LDADD = $(top_builddir)/src/lib/http/libkea-http.la
63+
libhttp_unittests_LDADD += $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la
6364
libhttp_unittests_LDADD += $(top_builddir)/src/lib/hooks/libkea-hooks.la
6465
libhttp_unittests_LDADD += $(top_builddir)/src/lib/testutils/libkea-testutils.la
6566
libhttp_unittests_LDADD += $(top_builddir)/src/lib/cc/libkea-cc.la

src/lib/http/tests/request_parser_unittests.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ TEST_F(HttpRequestParserTest, postHttpRequestWithJson) {
9191
// Simulate receiving HTTP request in chunks.
9292
for (size_t i = 0; i < http_req.size(); i += http_req.size() / 10) {
9393
bool done = false;
94-
// Get the size of the data chunk.
94+
// Get the size of the data chunk.
9595
size_t chunk = http_req.size() / 10;
9696
// When we're near the end of the data stream, the chunk length may
9797
// vary.

0 commit comments

Comments
 (0)