From 25eb738ac4348f5f0f582b99f199ef5d06e1fea2 Mon Sep 17 00:00:00 2001 From: Ruben Perez Date: Fri, 23 Jan 2026 11:06:41 +0100 Subject: [PATCH 1/3] Initial impl --- CMakeLists.txt | 6 +++ include/boost/corosio/acceptor.hpp | 5 +++ include/boost/corosio/endpoint.hpp | 5 +++ include/boost/corosio/io_buffer_param.hpp | 5 +++ include/boost/corosio/io_context.hpp | 5 +++ include/boost/corosio/io_object.hpp | 5 +++ include/boost/corosio/io_stream.hpp | 5 +++ include/boost/corosio/read.hpp | 5 +++ include/boost/corosio/resolver.hpp | 5 +++ include/boost/corosio/resolver_results.hpp | 5 +++ include/boost/corosio/signal_set.hpp | 5 +++ include/boost/corosio/socket.hpp | 5 +++ include/boost/corosio/tcp_server.hpp | 5 +++ include/boost/corosio/timer.hpp | 5 +++ include/boost/corosio/tls/context.hpp | 5 +++ include/boost/corosio/tls/openssl_stream.hpp | 5 +++ include/boost/corosio/tls/tls_stream.hpp | 5 +++ include/boost/corosio/tls/wolfssl_stream.hpp | 5 +++ include/boost/corosio/write.hpp | 5 +++ modules/boost_corosio.cppm | 41 ++++++++++++++++++++ 20 files changed, 137 insertions(+) create mode 100644 modules/boost_corosio.cppm diff --git a/CMakeLists.txt b/CMakeLists.txt index 8026f95e..b90dc5bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,6 +38,7 @@ option(BOOST_COROSIO_BUILD_BENCH "Build boost::corosio benchmarks" ${BOOST_COROS option(BOOST_COROSIO_BUILD_EXAMPLES "Build boost::corosio examples" ${BOOST_COROSIO_IS_ROOT}) option(BOOST_COROSIO_BUILD_DOCS "Build boost::corosio documentation" OFF) option(BOOST_COROSIO_MRDOCS_BUILD "Building for MrDocs documentation generation" OFF) +option(BOOST_COROSIO_USE_MODULES "Whether to build boost::corosio using C++20 modules or not" OFF) # Check if environment variable BOOST_SRC_DIR is set if (NOT DEFINED BOOST_SRC_DIR AND DEFINED ENV{BOOST_SRC_DIR}) @@ -185,6 +186,11 @@ add_library(boost_corosio ${BOOST_COROSIO_HEADERS} ${BOOST_COROSIO_SOURCES}) add_library(Boost::corosio ALIAS boost_corosio) boost_corosio_setup_properties(boost_corosio) +if (BOOST_COROSIO_USE_MODULES) + target_sources(boost_corosio PUBLIC FILE_SET CXX_MODULES BASE_DIRS modules FILES modules/boost_corosio.cppm) + target_compile_definitions(boost_corosio PUBLIC BOOST_COROSIO_USE_MODULES) +endif() + #------------------------------------------------- # # WolfSSL diff --git a/include/boost/corosio/acceptor.hpp b/include/boost/corosio/acceptor.hpp index 7863a387..7804988a 100644 --- a/include/boost/corosio/acceptor.hpp +++ b/include/boost/corosio/acceptor.hpp @@ -10,6 +10,10 @@ #ifndef BOOST_COROSIO_ACCEPTOR_HPP #define BOOST_COROSIO_ACCEPTOR_HPP +#if !defined(BOOST_COROSIO_SOURCE) && defined(BOOST_COROSIO_USE_MODULES) +import boost.corosio; +#else + #include #include #include @@ -286,3 +290,4 @@ class BOOST_COROSIO_DECL acceptor : public io_object } // namespace boost #endif +#endif diff --git a/include/boost/corosio/endpoint.hpp b/include/boost/corosio/endpoint.hpp index 7ca1cb9f..219d02d8 100644 --- a/include/boost/corosio/endpoint.hpp +++ b/include/boost/corosio/endpoint.hpp @@ -10,6 +10,10 @@ #ifndef BOOST_COROSIO_ENDPOINT_HPP #define BOOST_COROSIO_ENDPOINT_HPP +#if !defined(BOOST_COROSIO_SOURCE) && defined(BOOST_COROSIO_USE_MODULES) +import boost.corosio; +#else + #include #include #include @@ -187,3 +191,4 @@ class endpoint } // namespace boost #endif +#endif diff --git a/include/boost/corosio/io_buffer_param.hpp b/include/boost/corosio/io_buffer_param.hpp index 4a14e1e5..da116678 100644 --- a/include/boost/corosio/io_buffer_param.hpp +++ b/include/boost/corosio/io_buffer_param.hpp @@ -10,6 +10,10 @@ #ifndef BOOST_COROSIO_IO_BUFFER_PARAM_HPP #define BOOST_COROSIO_IO_BUFFER_PARAM_HPP +#if !defined(BOOST_COROSIO_SOURCE) && defined(BOOST_COROSIO_USE_MODULES) +import boost.corosio; +#else + #include #include @@ -383,3 +387,4 @@ class io_buffer_param } // namespace boost #endif +#endif diff --git a/include/boost/corosio/io_context.hpp b/include/boost/corosio/io_context.hpp index d9378767..baca061f 100644 --- a/include/boost/corosio/io_context.hpp +++ b/include/boost/corosio/io_context.hpp @@ -10,6 +10,10 @@ #ifndef BOOST_COROSIO_IO_CONTEXT_HPP #define BOOST_COROSIO_IO_CONTEXT_HPP +#if !defined(BOOST_COROSIO_SOURCE) && defined(BOOST_COROSIO_USE_MODULES) +import boost.corosio; +#else + #include #include #include @@ -433,3 +437,4 @@ get_executor() const noexcept -> } // namespace boost #endif +#endif diff --git a/include/boost/corosio/io_object.hpp b/include/boost/corosio/io_object.hpp index df380cea..78eef6bb 100644 --- a/include/boost/corosio/io_object.hpp +++ b/include/boost/corosio/io_object.hpp @@ -10,6 +10,10 @@ #ifndef BOOST_COROSIO_IO_OBJECT_HPP #define BOOST_COROSIO_IO_OBJECT_HPP +#if !defined(BOOST_COROSIO_SOURCE) && defined(BOOST_COROSIO_USE_MODULES) +import boost.corosio; +#else + #include #include @@ -70,3 +74,4 @@ class BOOST_COROSIO_DECL io_object } // namespace boost #endif +#endif diff --git a/include/boost/corosio/io_stream.hpp b/include/boost/corosio/io_stream.hpp index 03b8ed75..f5d3e083 100644 --- a/include/boost/corosio/io_stream.hpp +++ b/include/boost/corosio/io_stream.hpp @@ -10,6 +10,10 @@ #ifndef BOOST_COROSIO_IO_STREAM_HPP #define BOOST_COROSIO_IO_STREAM_HPP +#if !defined(BOOST_COROSIO_SOURCE) && defined(BOOST_COROSIO_USE_MODULES) +import boost.corosio; +#else + #include #include #include @@ -247,3 +251,4 @@ class BOOST_COROSIO_DECL io_stream : public io_object } // namespace boost #endif +#endif diff --git a/include/boost/corosio/read.hpp b/include/boost/corosio/read.hpp index d9f9e7f6..145e497c 100644 --- a/include/boost/corosio/read.hpp +++ b/include/boost/corosio/read.hpp @@ -10,6 +10,10 @@ #ifndef BOOST_COROSIO_READ_HPP #define BOOST_COROSIO_READ_HPP +#if !defined(BOOST_COROSIO_SOURCE) && defined(BOOST_COROSIO_USE_MODULES) +import boost.corosio; +#else + #include #include #include @@ -218,3 +222,4 @@ read(io_stream& ios, std::string& s) } // namespace boost #endif +#endif diff --git a/include/boost/corosio/resolver.hpp b/include/boost/corosio/resolver.hpp index 3d40e1b4..669d1107 100644 --- a/include/boost/corosio/resolver.hpp +++ b/include/boost/corosio/resolver.hpp @@ -10,6 +10,10 @@ #ifndef BOOST_COROSIO_RESOLVER_HPP #define BOOST_COROSIO_RESOLVER_HPP +#if !defined(BOOST_COROSIO_SOURCE) && defined(BOOST_COROSIO_USE_MODULES) +import boost.corosio; +#else + #include #include #include @@ -341,3 +345,4 @@ class BOOST_COROSIO_DECL resolver : public io_object } // namespace boost #endif +#endif diff --git a/include/boost/corosio/resolver_results.hpp b/include/boost/corosio/resolver_results.hpp index ac7a9d6d..22f02474 100644 --- a/include/boost/corosio/resolver_results.hpp +++ b/include/boost/corosio/resolver_results.hpp @@ -10,6 +10,10 @@ #ifndef BOOST_COROSIO_RESOLVER_RESULTS_HPP #define BOOST_COROSIO_RESOLVER_RESULTS_HPP +#if !defined(BOOST_COROSIO_SOURCE) && defined(BOOST_COROSIO_USE_MODULES) +import boost.corosio; +#else + #include #include @@ -206,3 +210,4 @@ class resolver_results } // namespace boost #endif +#endif diff --git a/include/boost/corosio/signal_set.hpp b/include/boost/corosio/signal_set.hpp index 9a335f3d..e5783729 100644 --- a/include/boost/corosio/signal_set.hpp +++ b/include/boost/corosio/signal_set.hpp @@ -10,6 +10,10 @@ #ifndef BOOST_COROSIO_SIGNAL_SET_HPP #define BOOST_COROSIO_SIGNAL_SET_HPP +#if !defined(BOOST_COROSIO_SOURCE) && defined(BOOST_COROSIO_USE_MODULES) +import boost.corosio; +#else + #include #include #include @@ -355,3 +359,4 @@ class BOOST_COROSIO_DECL signal_set : public io_object } // namespace boost #endif +#endif diff --git a/include/boost/corosio/socket.hpp b/include/boost/corosio/socket.hpp index ad767d37..35a53b9c 100644 --- a/include/boost/corosio/socket.hpp +++ b/include/boost/corosio/socket.hpp @@ -10,6 +10,10 @@ #ifndef BOOST_COROSIO_SOCKET_HPP #define BOOST_COROSIO_SOCKET_HPP +#if !defined(BOOST_COROSIO_SOURCE) && defined(BOOST_COROSIO_USE_MODULES) +import boost.corosio; +#else + #include #include #include @@ -335,3 +339,4 @@ class BOOST_COROSIO_DECL socket : public io_stream } // namespace boost #endif +#endif diff --git a/include/boost/corosio/tcp_server.hpp b/include/boost/corosio/tcp_server.hpp index 45c0f4f9..d16406d1 100644 --- a/include/boost/corosio/tcp_server.hpp +++ b/include/boost/corosio/tcp_server.hpp @@ -10,6 +10,10 @@ #ifndef BOOST_COROSIO_TCP_SERVER_HPP #define BOOST_COROSIO_TCP_SERVER_HPP +#if !defined(BOOST_COROSIO_SOURCE) && defined(BOOST_COROSIO_USE_MODULES) +import boost.corosio; +#else + #include #include #include @@ -335,3 +339,4 @@ class BOOST_COROSIO_DECL } // boost #endif +#endif diff --git a/include/boost/corosio/timer.hpp b/include/boost/corosio/timer.hpp index dfea548e..96f2851c 100644 --- a/include/boost/corosio/timer.hpp +++ b/include/boost/corosio/timer.hpp @@ -10,6 +10,10 @@ #ifndef BOOST_COROSIO_TIMER_HPP #define BOOST_COROSIO_TIMER_HPP +#if !defined(BOOST_COROSIO_SOURCE) && defined(BOOST_COROSIO_USE_MODULES) +import boost.corosio; +#else + #include #include #include @@ -218,3 +222,4 @@ class BOOST_COROSIO_DECL timer : public io_object } // namespace boost #endif +#endif diff --git a/include/boost/corosio/tls/context.hpp b/include/boost/corosio/tls/context.hpp index 2a1591e1..0beb888a 100644 --- a/include/boost/corosio/tls/context.hpp +++ b/include/boost/corosio/tls/context.hpp @@ -10,6 +10,10 @@ #ifndef BOOST_COROSIO_TLS_CONTEXT_HPP #define BOOST_COROSIO_TLS_CONTEXT_HPP +#if !defined(BOOST_COROSIO_SOURCE) && defined(BOOST_COROSIO_USE_MODULES) +import boost.corosio; +#else + #include #include @@ -865,3 +869,4 @@ class BOOST_COROSIO_DECL context } // namespace boost #endif +#endif diff --git a/include/boost/corosio/tls/openssl_stream.hpp b/include/boost/corosio/tls/openssl_stream.hpp index 1d9d6eef..4267ef6c 100644 --- a/include/boost/corosio/tls/openssl_stream.hpp +++ b/include/boost/corosio/tls/openssl_stream.hpp @@ -10,6 +10,10 @@ #ifndef BOOST_COROSIO_TLS_OPENSSL_STREAM_HPP #define BOOST_COROSIO_TLS_OPENSSL_STREAM_HPP +#if !defined(BOOST_COROSIO_SOURCE) && defined(BOOST_COROSIO_USE_MODULES) +import boost.corosio; +#else + #include #include @@ -69,3 +73,4 @@ class BOOST_COROSIO_DECL openssl_stream : public tls_stream } // namespace boost #endif +#endif diff --git a/include/boost/corosio/tls/tls_stream.hpp b/include/boost/corosio/tls/tls_stream.hpp index 694cc271..81687dfb 100644 --- a/include/boost/corosio/tls/tls_stream.hpp +++ b/include/boost/corosio/tls/tls_stream.hpp @@ -10,6 +10,10 @@ #ifndef BOOST_COROSIO_TLS_TLS_STREAM_HPP #define BOOST_COROSIO_TLS_TLS_STREAM_HPP +#if !defined(BOOST_COROSIO_SOURCE) && defined(BOOST_COROSIO_USE_MODULES) +import boost.corosio; +#else + #include #include #include @@ -263,3 +267,4 @@ class BOOST_COROSIO_DECL tls_stream : public io_stream } // namespace boost #endif +#endif diff --git a/include/boost/corosio/tls/wolfssl_stream.hpp b/include/boost/corosio/tls/wolfssl_stream.hpp index 80850f82..e94a6aba 100644 --- a/include/boost/corosio/tls/wolfssl_stream.hpp +++ b/include/boost/corosio/tls/wolfssl_stream.hpp @@ -10,6 +10,10 @@ #ifndef BOOST_COROSIO_TLS_WOLFSSL_STREAM_HPP #define BOOST_COROSIO_TLS_WOLFSSL_STREAM_HPP +#if !defined(BOOST_COROSIO_SOURCE) && defined(BOOST_COROSIO_USE_MODULES) +import boost.corosio; +#else + #include #include #include @@ -71,3 +75,4 @@ class BOOST_COROSIO_DECL } // namespace boost #endif +#endif diff --git a/include/boost/corosio/write.hpp b/include/boost/corosio/write.hpp index b223efeb..7b9f4dd6 100644 --- a/include/boost/corosio/write.hpp +++ b/include/boost/corosio/write.hpp @@ -10,6 +10,10 @@ #ifndef BOOST_COROSIO_WRITE_HPP #define BOOST_COROSIO_WRITE_HPP +#if !defined(BOOST_COROSIO_SOURCE) && defined(BOOST_COROSIO_USE_MODULES) +import boost.corosio; +#else + #include #include #include @@ -99,3 +103,4 @@ write(io_stream& ios, ConstBufferSequence const& buffers) } // namespace boost #endif +#endif diff --git a/modules/boost_corosio.cppm b/modules/boost_corosio.cppm new file mode 100644 index 00000000..16fe9b00 --- /dev/null +++ b/modules/boost_corosio.cppm @@ -0,0 +1,41 @@ +module; + +#include + +export module boost.corosio; + +export namespace boost::corosio { + +using corosio::acceptor; +using corosio::endpoint; +using corosio::io_buffer_param; +using corosio::io_context; +using corosio::io_object; +using corosio::io_stream; +using corosio::read; +using corosio::resolve_flags; +using corosio::resolver; +using corosio::resolver_entry; +using corosio::resolver_results; +using corosio::signal_set; +using corosio::socket; +using corosio::tcp_server; +using corosio::timer; +using corosio::write; + +// I think this should be in tls +using corosio::tls_stream; +using corosio::openssl_stream; +using corosio::wolfssl_stream; + +namespace tls { +using corosio::tls::context; +using corosio::tls::file_format; +using corosio::tls::password_purpose; +using corosio::tls::revocation_policy; +using corosio::tls::role; +using corosio::tls::verify_mode; +using corosio::tls::version; +} // namespace tls + +} // namespace boost::corosio From 1b0964029e2c20dd7addbe2042c7333689b60649 Mon Sep 17 00:00:00 2001 From: Ruben Perez Date: Fri, 23 Jan 2026 11:13:27 +0100 Subject: [PATCH 2/3] Fix build errors without modules --- example/client/http_client.cpp | 6 +++--- test/unit/resolver.cpp | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/example/client/http_client.cpp b/example/client/http_client.cpp index 59a587ea..d9e397bc 100644 --- a/example/client/http_client.cpp +++ b/example/client/http_client.cpp @@ -35,8 +35,8 @@ do_request( "Host: " + std::string(host) + "\r\n" "Connection: close\r\n" "\r\n"; - (co_await corosio::write( - stream, capy::const_buffer(request.data(), request.size()))).value(); + co_await corosio::write( + stream, capy::const_buffer(request.data(), request.size())); // Read the entire response std::string response; @@ -59,7 +59,7 @@ run_client( s.open(); // Connect to the server (throws on error) - (co_await s.connect(corosio::endpoint(addr, port))).value(); + co_await s.connect(corosio::endpoint(addr, port)); co_await do_request(s, addr.to_string()); } diff --git a/test/unit/resolver.cpp b/test/unit/resolver.cpp index 5f939327..9bee0e70 100644 --- a/test/unit/resolver.cpp +++ b/test/unit/resolver.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include "test_suite.hpp" From 712f4a2588734387e7a6482c271dded1d2c7e222 Mon Sep 17 00:00:00 2001 From: Ruben Perez Date: Fri, 23 Jan 2026 16:02:50 +0100 Subject: [PATCH 3/3] changes --- modules/boost_corosio.cppm | 7 +++++++ test/unit/io_context.cpp | 1 + test/unit/resolver.cpp | 1 + 3 files changed, 9 insertions(+) diff --git a/modules/boost_corosio.cppm b/modules/boost_corosio.cppm index 16fe9b00..3bc95037 100644 --- a/modules/boost_corosio.cppm +++ b/modules/boost_corosio.cppm @@ -22,6 +22,10 @@ using corosio::socket; using corosio::tcp_server; using corosio::timer; using corosio::write; +using corosio::operator|; +using corosio::operator&; +using corosio::operator&=; +using corosio::operator|=; // I think this should be in tls using corosio::tls_stream; @@ -38,4 +42,7 @@ using corosio::tls::verify_mode; using corosio::tls::version; } // namespace tls + } // namespace boost::corosio + + diff --git a/test/unit/io_context.cpp b/test/unit/io_context.cpp index 79ea1907..c99c9394 100644 --- a/test/unit/io_context.cpp +++ b/test/unit/io_context.cpp @@ -11,6 +11,7 @@ #include #include +#include #include #include diff --git a/test/unit/resolver.cpp b/test/unit/resolver.cpp index 9bee0e70..f7d4cc71 100644 --- a/test/unit/resolver.cpp +++ b/test/unit/resolver.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include "test_suite.hpp"