lordgamez commented on code in PR #1595:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1595#discussion_r1251853900
##########
libminifi/src/c2/ControllerSocketProtocol.cpp:
##########
@@ -66,7 +70,54 @@
ControllerSocketProtocol::ControllerSocketProtocol(core::controller::ControllerS
configuration_(std::move(configuration)),
socket_restart_processor_(update_sink_) {
gsl_Expects(configuration_);
- stream_factory_ = minifi::io::StreamFactory::getInstance(configuration_);
+}
+
+ControllerSocketProtocol::~ControllerSocketProtocol() {
+ stopListener();
+}
+
+void ControllerSocketProtocol::stopListener() {
+ io_context_.stop();
+ if (acceptor_) {
+ acceptor_->close();
+ }
+ if (server_thread_.joinable()) {
+ server_thread_.join();
+ }
+ io_context_.restart();
+}
+
+asio::awaitable<void> ControllerSocketProtocol::startAccept() {
+ while (true) {
+ auto [accept_error, socket] = co_await
acceptor_->async_accept(utils::net::use_nothrow_awaitable);
+ if (accept_error) {
+ logger_->log_error("Controller socket accept failed with the following
message: '%s'", accept_error.message());
+ continue;
+ }
+ auto stream =
std::make_unique<io::AsioStream<asio::ip::tcp::socket>>(std::move(socket));
+ co_spawn(io_context_, handleCommand(std::move(stream)), asio::detached);
+ }
+}
+
+asio::awaitable<void>
ControllerSocketProtocol::startAcceptSsl(std::shared_ptr<minifi::controllers::SSLContextService>
ssl_context_service) {
+ while (true) { // NOLINT(clang-analyzer-core.NullDereference) suppressing
asio library linter warning
+ auto [accept_error, socket] = co_await
acceptor_->async_accept(utils::net::use_nothrow_awaitable);
+ if (accept_error) {
+ logger_->log_error("Controller socket accept failed with the following
message: '%s'", accept_error.message());
+ continue;
+ }
+ asio::ssl::context ssl_context =
utils::net::getSslContext(*ssl_context_service, asio::ssl::context::tls_server);
+ asio::ssl::stream<asio::ip::tcp::socket> ssl_socket(std::move(socket),
ssl_context);
+
+ auto [handshake_error] = co_await
ssl_socket.async_handshake(utils::net::HandshakeType::server,
utils::net::use_nothrow_awaitable);
Review Comment:
I think you're right, I moved it to a separate co_spawned executor with the
`handleCommand` in b0301bcc074899dc342ca39188d7f76fca4d65dd
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]