From 1ed664275b53fe388810b5ce203ede4779671ec7 Mon Sep 17 00:00:00 2001 From: Antoine Van Malleghem Date: Mon, 20 Jul 2026 16:57:26 +1000 Subject: [PATCH] Update Asio strand usage This upstreams part of RoboStack patch patch/ros-rolling-async-web-server-cpp.patch. The upstream branch already uses boost::asio::io_context, so the remaining build fix is to use the modern strand executor form, bind_executor, and the current resolver result API. This keeps the change focused on compatibility with newer Boost.Asio without reintroducing an older io_service compatibility path. Signed-off-by: Tobias Fischer --- include/async_web_server_cpp/http_connection.hpp | 2 +- src/http_connection.cpp | 5 +++-- src/http_server.cpp | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/async_web_server_cpp/http_connection.hpp b/include/async_web_server_cpp/http_connection.hpp index b1cbf6d..a7677c2 100644 --- a/include/async_web_server_cpp/http_connection.hpp +++ b/include/async_web_server_cpp/http_connection.hpp @@ -79,7 +79,7 @@ class HttpConnection : public boost::enable_shared_from_this, void handle_write(const boost::system::error_code& e, std::vector resources); - boost::asio::io_context::strand strand_; + boost::asio::strand strand_; boost::asio::ip::tcp::socket socket_; HttpServerRequestHandler request_handler_; boost::array buffer_; diff --git a/src/http_connection.cpp b/src/http_connection.cpp index fb5655c..c4afef1 100644 --- a/src/http_connection.cpp +++ b/src/http_connection.cpp @@ -8,7 +8,7 @@ namespace async_web_server_cpp HttpConnection::HttpConnection(boost::asio::io_context& io_service, HttpServerRequestHandler handler) - : strand_(io_service), socket_(io_service), request_handler_(handler), + : strand_(io_service.get_executor()), socket_(io_service), request_handler_(handler), write_in_progress_(false) { } @@ -77,7 +77,8 @@ void HttpConnection::async_read(ReadHandler callback) } socket_.async_read_some( boost::asio::buffer(buffer_), - strand_.wrap( + boost::asio::bind_executor( + strand_, boost::bind(&HttpConnection::handle_read_raw, shared_from_this(), callback, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred))); diff --git a/src/http_server.cpp b/src/http_server.cpp index d9f7df6..5b2b66c 100644 --- a/src/http_server.cpp +++ b/src/http_server.cpp @@ -13,7 +13,7 @@ HttpServer::HttpServer(const std::string& address, const std::string& port, { boost::asio::ip::tcp::resolver resolver(io_service_); - boost::asio::ip::tcp::endpoint endpoint = *resolver.resolve(address, port).begin(); + boost::asio::ip::tcp::endpoint endpoint = resolver.resolve(address, port).begin()->endpoint(); acceptor_.open(endpoint.protocol()); acceptor_.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true)); acceptor_.bind(endpoint);