From ecd2a8991f9fb51e8dad32a0904d3fc35586c365 Mon Sep 17 00:00:00 2001 From: ngrodzitski Date: Tue, 7 Nov 2023 13:17:29 +0100 Subject: [PATCH 01/16] Add CI builds with Boost.ASIO --- .github/workflows/ci.yml | 39 +++++++++++++++++++++++++++++-------- dev/restinio/CMakeLists.txt | 2 ++ externals.rb | 2 +- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5f2487c0..31ad8a79 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -77,48 +77,65 @@ jobs: Build-Linux: # The type of runner that the job will run on - name: Ubuntu-22.04 (${{ matrix.compiler.cname }}, ${{ matrix.build_type }}, C++${{ matrix.compiler.cppstd }}) + name: Ubuntu-22.04 (${{ matrix.build_settings.cname }}, ${{ matrix.build_type }}, C++${{ matrix.build_settings.cppstd }}, ${{matrix.build_settings.asio_source}} asio) runs-on: ubuntu-22.04 strategy: fail-fast: false matrix: - compiler: + build_settings: - cname: gcc-9 cxxname: g++-9 ar: gcc-ar-9 cppstd: 17 + asio_source: standalone + + - cname: gcc-9 + cxxname: g++-12 + ar: gcc-ar-12 + cppstd: 17 + asio_source: boost - cname: gcc-12 cxxname: g++-12 ar: gcc-ar-12 cppstd: 17 + asio_source: standalone - cname: gcc-12 cxxname: g++-12 ar: gcc-ar-12 cppstd: 20 + asio_source: standalone + - cname: gcc-12 + cxxname: g++-12 + ar: gcc-ar-12 + cppstd: 20 + asio_source: boost - cname: clang-13 cxxname: clang++-13 ar: llvm-ar-13 cppstd: 17 + asio_source: standalone - cname: clang-15 cxxname: clang++-15 ar: llvm-ar-15 cppstd: 17 + asio_source: standalone - cname: clang-15 cxxname: clang++-15 ar: llvm-ar-15 cppstd: 20 + asio_source: standalone build_type: - Release - Debug env: - CC: ${{ matrix.compiler.cname }} - CXX: ${{ matrix.compiler.cxxname }} - AR: ${{ matrix.compiler.ar }} - RESTINIO_BUILD_DIR: _build_${{ matrix.compiler.cname }}_cpp${{ matrix.compiler.cppstd }}_${{ matrix.build_type }} + CC: ${{ matrix.build_settings.cname }} + CXX: ${{ matrix.build_settings.cxxname }} + AR: ${{ matrix.build_settings.ar }} + RESTINIO_BUILD_DIR: _build_${{ matrix.build_settings.cname }}_cpp${{ matrix.build_settings.cppstd }}_${{ matrix.build_type }}_${{matrix.build_settings.asio_source}}_asio steps: - uses: actions/checkout@v3 @@ -131,6 +148,11 @@ jobs: run: | sudo gem install Mxx_ru + - name: Install Boost + if: ${{ matrix.build_settings.asio_source == 'boost' }} + run: | + sudo apt-get update && sudo apt-get install -y libboost-all-dev + - name: Configure shell: bash run: | @@ -139,8 +161,9 @@ jobs: cmake \ -B ${RESTINIO_BUILD_DIR} \ -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \ - -DRESTINIO_EXPLICIT_CPPSTD=${{ matrix.compiler.cppstd }} \ - -DRESTINIO_TEST_SUFFIX=" [${{ matrix.compiler.cname }}_cpp${{ matrix.compiler.cppstd }}_${{ matrix.build_type }}]" + -DRESTINIO_EXPLICIT_CPPSTD=${{ matrix.build_settings.cppstd }} \ + -DRESTINIO_ASIO_SOURCE=${{matrix.build_settings.asio_source}} \ + -DRESTINIO_TEST_SUFFIX=" [${{ matrix.build_settings.cname }}_cpp${{ matrix.build_settings.cppstd }}_${{ matrix.build_type }}]" - name: Build working-directory: ./dev shell: bash diff --git a/dev/restinio/CMakeLists.txt b/dev/restinio/CMakeLists.txt index 683cce47..23988565 100644 --- a/dev/restinio/CMakeLists.txt +++ b/dev/restinio/CMakeLists.txt @@ -77,6 +77,8 @@ elseif (RESTINIO_ASIO_SOURCE STREQUAL "boost") "Unable to identify how to depend on Boost::asio. " "Giving up...") endif () + + target_compile_definitions(${RESTINIO_LIBRARY_NAME} INTERFACE RESTINIO_USE_BOOST_ASIO) else () message(FATAL_ERROR "Invalid value for RESTINIO_ASIO_SOURCE (${RESTINIO_ASIO_SOURCE})") endif () diff --git a/externals.rb b/externals.rb index 11166cad..72c2044f 100644 --- a/externals.rb +++ b/externals.rb @@ -1,5 +1,5 @@ MxxRu::arch_externals :so5 do |e| - e.url 'https://github.com/Stiffstream/sobjectizer/archive/v.5.8.1.tar.gz' + e.url 'https://github.com/Stiffstream/sobjectizer/archive/v.5.7.5.tar.gz' e.map_dir 'dev/so_5' => 'dev' end From 88bc66a5e3fc5e976029c2a06d953c276cd513ff Mon Sep 17 00:00:00 2001 From: ngrodzitski Date: Tue, 7 Nov 2023 15:05:30 +0100 Subject: [PATCH 02/16] Make CI on 0.7-dev mandatory --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 31ad8a79..966f7f91 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,7 +5,7 @@ name: CI on: push: - branches: ["master"] + branches: ["master", "0.7-dev"] pull_request: jobs: From 3e7fad17746b3634271c7637b1cb41667c8e491f Mon Sep 17 00:00:00 2001 From: ngrodzitski Date: Tue, 7 Nov 2023 21:24:59 +0100 Subject: [PATCH 03/16] wip --- .github/workflows/ci.yml | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 966f7f91..12735493 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -148,12 +148,34 @@ jobs: run: | sudo gem install Mxx_ru - - name: Install Boost - if: ${{ matrix.build_settings.asio_source == 'boost' }} + + # run: | + # sudo apt-get update && sudo apt-get install -y libboost-all-dev + + - name: Configure (standalone ASIO) + if: ${{ matrix.build_settings.asio_source == 'standalone' }} + shell: bash run: | - sudo apt-get update && sudo apt-get install -y libboost-all-dev + mxxruexternals + cd dev + cmake \ + -B ${RESTINIO_BUILD_DIR} \ + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \ + -DRESTINIO_EXPLICIT_CPPSTD=${{ matrix.build_settings.cppstd }} \ + -DRESTINIO_TEST_SUFFIX=" [${{ matrix.build_settings.cname }}_cpp${{ matrix.build_settings.cppstd }}_${{ matrix.build_type }}]" - - name: Configure + - name: Obtain Boost + if: ${{ matrix.build_settings.asio_source == 'boost' }} + uses: MarkusJx/install-boost@v2.4.4 + id: install-boost + with: + boost_version: 1.83.0 + boost_install_dir: ${{github.workspace}}/local_boost + toolset: ${{ matrix.build_settings.cname }} + platform_version: 22.04 + + - name: Configure (Boost ASIO) + if: ${{ matrix.build_settings.asio_source == 'boost' }} shell: bash run: | mxxruexternals @@ -162,8 +184,10 @@ jobs: -B ${RESTINIO_BUILD_DIR} \ -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \ -DRESTINIO_EXPLICIT_CPPSTD=${{ matrix.build_settings.cppstd }} \ - -DRESTINIO_ASIO_SOURCE=${{matrix.build_settings.asio_source}} \ + -DRESTINIO_ASIO_SOURCE=boost \ + -DBOOST_ROOT=${{ steps.install-boost.outputs.BOOST_ROOT }} \ -DRESTINIO_TEST_SUFFIX=" [${{ matrix.build_settings.cname }}_cpp${{ matrix.build_settings.cppstd }}_${{ matrix.build_type }}]" + - name: Build working-directory: ./dev shell: bash From 28a60708e68a589563ee357f784242139c162f58 Mon Sep 17 00:00:00 2001 From: ngrodzitski Date: Tue, 7 Nov 2023 21:26:04 +0100 Subject: [PATCH 04/16] wip --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 12735493..4cbd8a20 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -168,7 +168,7 @@ jobs: if: ${{ matrix.build_settings.asio_source == 'boost' }} uses: MarkusJx/install-boost@v2.4.4 id: install-boost - with: + with: boost_version: 1.83.0 boost_install_dir: ${{github.workspace}}/local_boost toolset: ${{ matrix.build_settings.cname }} From b90bb0541b5005002132d4b04db5188c66b02ae5 Mon Sep 17 00:00:00 2001 From: ngrodzitski Date: Tue, 7 Nov 2023 22:15:45 +0100 Subject: [PATCH 05/16] wip3 --- .github/workflows/ci.yml | 69 +++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4cbd8a20..61d4ea81 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -83,48 +83,56 @@ jobs: fail-fast: false matrix: build_settings: - - cname: gcc-9 - cxxname: g++-9 - ar: gcc-ar-9 + - cname: gcc + cxxname: g++ + ar: gcc-ar + cversion: 9 cppstd: 17 asio_source: standalone - cname: gcc-9 - cxxname: g++-12 - ar: gcc-ar-12 + cxxname: g++-9 + ar: gcc-ar-9 + cversion: 9 cppstd: 17 asio_source: boost - - cname: gcc-12 - cxxname: g++-12 - ar: gcc-ar-12 + - cname: gcc + cxxname: g++ + ar: gcc-ar + cversion: 12 cppstd: 17 asio_source: standalone - - cname: gcc-12 - cxxname: g++-12 - ar: gcc-ar-12 + - cname: gcc + cxxname: g++ + ar: gcc-ar + cversion: 12 cppstd: 20 asio_source: standalone - - cname: gcc-12 - cxxname: g++-12 - ar: gcc-ar-12 + - cname: gcc + cxxname: g++ + ar: gcc-ar + cversion: 12 cppstd: 20 asio_source: boost - - cname: clang-13 - cxxname: clang++-13 - ar: llvm-ar-13 + - cname: clang + cxxname: clang++ + ar: llvm-ar + cversion: 13 cppstd: 17 asio_source: standalone - - cname: clang-15 - cxxname: clang++-15 - ar: llvm-ar-15 + - cname: clang + cxxname: clang++ + ar: llvm-ar + cversion: 15 cppstd: 17 asio_source: standalone - - cname: clang-15 - cxxname: clang++-15 - ar: llvm-ar-15 + - cname: clang + cxxname: clang++ + ar: llvm-ar + cversion: 15 cppstd: 20 asio_source: standalone @@ -132,15 +140,16 @@ jobs: - Release - Debug env: - CC: ${{ matrix.build_settings.cname }} - CXX: ${{ matrix.build_settings.cxxname }} - AR: ${{ matrix.build_settings.ar }} - RESTINIO_BUILD_DIR: _build_${{ matrix.build_settings.cname }}_cpp${{ matrix.build_settings.cppstd }}_${{ matrix.build_type }}_${{matrix.build_settings.asio_source}}_asio + CC: ${{ matrix.build_settings.cname }}-${{ matrix.build_settings.cversion }} + CXX: ${{ matrix.build_settings.cxxname }}-${{ matrix.build_settings.cversion }} + AR: ${{ matrix.build_settings.ar }}-${{ matrix.build_settings.cversion }} + RESTINIO_BUILD_TAG: ${{ matrix.build_settings.cname }}-${{ matrix.build_settings.cversion }}_cpp${{ matrix.build_settings.cppstd }}_${{ matrix.build_type }}_${{matrix.build_settings.asio_source}}_asio steps: - uses: actions/checkout@v3 - - name: Print env + - name: Prepare env run: | + echo "RESTINIO_BUILD_DIR=_build_${RESTINIO_BUILD_TAG}" >> $GITHUB_ENV echo github.event.action: ${{ github.event.action }} echo github.event_name: ${{ github.event_name }} @@ -162,7 +171,7 @@ jobs: -B ${RESTINIO_BUILD_DIR} \ -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \ -DRESTINIO_EXPLICIT_CPPSTD=${{ matrix.build_settings.cppstd }} \ - -DRESTINIO_TEST_SUFFIX=" [${{ matrix.build_settings.cname }}_cpp${{ matrix.build_settings.cppstd }}_${{ matrix.build_type }}]" + -DRESTINIO_TEST_SUFFIX=" [${RESTINIO_BUILD_TAG}]" - name: Obtain Boost if: ${{ matrix.build_settings.asio_source == 'boost' }} @@ -186,7 +195,7 @@ jobs: -DRESTINIO_EXPLICIT_CPPSTD=${{ matrix.build_settings.cppstd }} \ -DRESTINIO_ASIO_SOURCE=boost \ -DBOOST_ROOT=${{ steps.install-boost.outputs.BOOST_ROOT }} \ - -DRESTINIO_TEST_SUFFIX=" [${{ matrix.build_settings.cname }}_cpp${{ matrix.build_settings.cppstd }}_${{ matrix.build_type }}]" + -DRESTINIO_TEST_SUFFIX=" [${RESTINIO_BUILD_TAG}]" - name: Build working-directory: ./dev From 5eb90d33d44eab9c1e1e8962b3487c2096237a87 Mon Sep 17 00:00:00 2001 From: ngrodzitski Date: Tue, 7 Nov 2023 22:47:28 +0100 Subject: [PATCH 06/16] wip4 --- .github/workflows/ci.yml | 67 +++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 39 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 61d4ea81..eb02a9ce 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -77,62 +77,46 @@ jobs: Build-Linux: # The type of runner that the job will run on - name: Ubuntu-22.04 (${{ matrix.build_settings.cname }}, ${{ matrix.build_type }}, C++${{ matrix.build_settings.cppstd }}, ${{matrix.build_settings.asio_source}} asio) + name: Ubuntu-22.04 (${{ matrix.build_settings.toolset }}-${{ matrix.build_settings.toolset_version }}, ${{ matrix.build_type }}, C++${{ matrix.build_settings.cppstd }}, ${{matrix.build_settings.asio_source}} asio) runs-on: ubuntu-22.04 strategy: fail-fast: false matrix: build_settings: - - cname: gcc - cxxname: g++ - ar: gcc-ar - cversion: 9 + - toolset: gcc + toolset_version: 9 cppstd: 17 asio_source: standalone - - cname: gcc-9 - cxxname: g++-9 - ar: gcc-ar-9 - cversion: 9 + - toolset: gcc + toolset_version: 9 cppstd: 17 asio_source: boost - - cname: gcc - cxxname: g++ - ar: gcc-ar - cversion: 12 + - toolset: gcc + toolset_version: 12 cppstd: 17 asio_source: standalone - - cname: gcc - cxxname: g++ - ar: gcc-ar - cversion: 12 + - toolset: gcc + toolset_version: 12 cppstd: 20 asio_source: standalone - - cname: gcc - cxxname: g++ - ar: gcc-ar - cversion: 12 + - toolset: gcc + toolset_version: 12 cppstd: 20 asio_source: boost - - cname: clang - cxxname: clang++ - ar: llvm-ar - cversion: 13 + - toolset: clang + toolset_version: 13 cppstd: 17 asio_source: standalone - - cname: clang - cxxname: clang++ - ar: llvm-ar - cversion: 15 + - toolset: clang + toolset_version: 15 cppstd: 17 asio_source: standalone - - cname: clang - cxxname: clang++ - ar: llvm-ar - cversion: 15 + - toolset: clang + toolset_version: 15 cppstd: 20 asio_source: standalone @@ -140,18 +124,23 @@ jobs: - Release - Debug env: - CC: ${{ matrix.build_settings.cname }}-${{ matrix.build_settings.cversion }} - CXX: ${{ matrix.build_settings.cxxname }}-${{ matrix.build_settings.cversion }} - AR: ${{ matrix.build_settings.ar }}-${{ matrix.build_settings.cversion }} - RESTINIO_BUILD_TAG: ${{ matrix.build_settings.cname }}-${{ matrix.build_settings.cversion }}_cpp${{ matrix.build_settings.cppstd }}_${{ matrix.build_type }}_${{matrix.build_settings.asio_source}}_asio + RESTINIO_BUILD_TAG: ${{ matrix.build_settings.toolset }}-${{ matrix.build_settings.toolset_version }}_cpp${{ matrix.build_settings.cppstd }}_${{ matrix.build_type }}_${{matrix.build_settings.asio_source}}_asio steps: - uses: actions/checkout@v3 - name: Prepare env run: | - echo "RESTINIO_BUILD_DIR=_build_${RESTINIO_BUILD_TAG}" >> $GITHUB_ENV echo github.event.action: ${{ github.event.action }} echo github.event_name: ${{ github.event_name }} + echo "RESTINIO_BUILD_DIR=_build_${RESTINIO_BUILD_TAG}" >> $GITHUB_ENV + echo "CC=${{ matrix.build_settings.toolset }}-${{ matrix.build_settings.toolset_version }}" >> $GITHUB_ENV + if [ "${{ matrix.build_settings.toolset }}" != "gcc" ]; then + echo "CXX=g++-${{ matrix.build_settings.toolset_version }}" >> $GITHUB_ENV + echo "AR=gcc-ar-${{ matrix.build_settings.toolset_version }}" >> $GITHUB_ENV + else + echo "CXX=clang++-${{ matrix.build_settings.toolset_version }}" >> $GITHUB_ENV + echo "AR=llvm-ar-${{ matrix.build_settings.toolset_version }}" >> $GITHUB_ENV + fi - name: Install dependencies run: | @@ -180,7 +169,7 @@ jobs: with: boost_version: 1.83.0 boost_install_dir: ${{github.workspace}}/local_boost - toolset: ${{ matrix.build_settings.cname }} + toolset: ${{ matrix.build_settings.toolset }} platform_version: 22.04 - name: Configure (Boost ASIO) From 3e82b0b563bd11614781d8684fb012fe168b76db Mon Sep 17 00:00:00 2001 From: ngrodzitski Date: Tue, 7 Nov 2023 22:48:31 +0100 Subject: [PATCH 07/16] wip5 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eb02a9ce..aa522ea2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -134,7 +134,7 @@ jobs: echo github.event_name: ${{ github.event_name }} echo "RESTINIO_BUILD_DIR=_build_${RESTINIO_BUILD_TAG}" >> $GITHUB_ENV echo "CC=${{ matrix.build_settings.toolset }}-${{ matrix.build_settings.toolset_version }}" >> $GITHUB_ENV - if [ "${{ matrix.build_settings.toolset }}" != "gcc" ]; then + if [ "${{ matrix.build_settings.toolset }}" == "gcc" ]; then echo "CXX=g++-${{ matrix.build_settings.toolset_version }}" >> $GITHUB_ENV echo "AR=gcc-ar-${{ matrix.build_settings.toolset_version }}" >> $GITHUB_ENV else From 1e998a2ab7a4aeb663fcdf3a5e43bada59df8c71 Mon Sep 17 00:00:00 2001 From: Yauheni Akhotnikau Date: Wed, 8 Nov 2023 09:32:29 +0300 Subject: [PATCH 08/16] [skip ci] SObjectizer updated to v.5.8.1.1. --- externals.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/externals.rb b/externals.rb index 72c2044f..8fac1b19 100644 --- a/externals.rb +++ b/externals.rb @@ -1,5 +1,5 @@ MxxRu::arch_externals :so5 do |e| - e.url 'https://github.com/Stiffstream/sobjectizer/archive/v.5.7.5.tar.gz' + e.url 'https://github.com/Stiffstream/sobjectizer/archive/v.5.8.1.1.tar.gz' e.map_dir 'dev/so_5' => 'dev' end From 47877c5f5105db743f43dbf10786e5d0f8372473 Mon Sep 17 00:00:00 2001 From: Yauheni Akhotnikau Date: Wed, 8 Nov 2023 12:27:24 +0300 Subject: [PATCH 09/16] positive_decimal_number_producer removed from easy_parser. --- dev/restinio/helpers/easy_parser.hpp | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/dev/restinio/helpers/easy_parser.hpp b/dev/restinio/helpers/easy_parser.hpp index 15f8c588..d4d00e93 100644 --- a/dev/restinio/helpers/easy_parser.hpp +++ b/dev/restinio/helpers/easy_parser.hpp @@ -4261,26 +4261,6 @@ non_negative_decimal_number_p( digits_to_consume_t digits_limit ) noexcept }; } -//FIXME: remove in v.0.7.0! -// -// positive_decimal_number_p -// -/*! - * @brief A factory function to create a producer for non-negative - * decimal numbers. - * - * @deprecated Use non_negative_decimal_number_p. - * - * @since v.0.6.2 - */ -template< typename T > -[[deprecated]] [[nodiscard]] -inline auto -positive_decimal_number_producer() noexcept -{ - return non_negative_decimal_number_p(); -} - // // hexadecimal_number_p // From 9529fce0759f8c8209f64854586edc69ea4a96fc Mon Sep 17 00:00:00 2001 From: Yauheni Akhotnikau Date: Wed, 8 Nov 2023 12:40:22 +0300 Subject: [PATCH 10/16] Deprecated tls_context() removed from socket_type_dependent_settings_t. --- dev/restinio/tls.hpp | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/dev/restinio/tls.hpp b/dev/restinio/tls.hpp index 59f3e829..4a497bdd 100644 --- a/dev/restinio/tls.hpp +++ b/dev/restinio/tls.hpp @@ -291,22 +291,6 @@ class socket_type_dependent_settings_t< Settings, tls_socket_t > return std::move( this->tls_context( std::move(shared_context) ) ); } - //FIXME: should be removed in v.0.7. - /*! - * @deprecated - * This method is going to be removed in v.0.7. - * giveaway_tls_context() should be used instead. - */ - [[deprecated]] - asio_ns::ssl::context - tls_context() - { - asio_ns::ssl::context result{ std::move( *m_tls_context ) }; - m_tls_context.reset(); - - return result; - } - //! Get away the TLS-context from settings. /*! * @note From c7918c43b883b0d6aee6fca98e17c5d458d44b00 Mon Sep 17 00:00:00 2001 From: Yauheni Akhotnikau Date: Wed, 8 Nov 2023 12:59:35 +0300 Subject: [PATCH 11/16] Obsolete code fragment removed. --- dev/restinio/expected.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/dev/restinio/expected.hpp b/dev/restinio/expected.hpp index 5ac01826..1dad70a1 100644 --- a/dev/restinio/expected.hpp +++ b/dev/restinio/expected.hpp @@ -17,8 +17,6 @@ namespace restinio template< typename T, typename E > using expected_t = nonstd::expected; -//FIXME: is this symbol actually present in expected-lite? -// using nonstd::make_expected; using nonstd::make_unexpected; } /* namespace restinio */ From 02991cffae0c7842ad23e2b7600c64c2a642af29 Mon Sep 17 00:00:00 2001 From: Yauheni Akhotnikau Date: Wed, 8 Nov 2023 13:29:42 +0300 Subject: [PATCH 12/16] FIXME with absence of checking pool_size is fixed. --- dev/restinio/impl/ioctx_on_thread_pool.hpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/dev/restinio/impl/ioctx_on_thread_pool.hpp b/dev/restinio/impl/ioctx_on_thread_pool.hpp index f92ccf68..f208dce6 100644 --- a/dev/restinio/impl/ioctx_on_thread_pool.hpp +++ b/dev/restinio/impl/ioctx_on_thread_pool.hpp @@ -59,6 +59,21 @@ class external_io_context_for_thread_pool_t auto & io_context() noexcept { return m_ioctx; } }; +namespace pool_size_checking +{ + +[[nodiscard]] +inline std::size_t +ensure_pool_size_non_zero( std::size_t pool_size ) +{ + if( !pool_size ) + throw exception_t{ "pool_size can't be 0" }; + + return pool_size; +} + +} /* namespace pool_size_checking */ + /*! * Helper class for creating io_context and running it * (via `io_context::run()`) on a thread pool. @@ -79,13 +94,12 @@ class ioctx_on_thread_pool_t template< typename... Io_Context_Holder_Ctor_Args > ioctx_on_thread_pool_t( // Pool size. - //FIXME: better to use not_null from gsl. std::size_t pool_size, // Optional arguments for Io_Context_Holder instance. Io_Context_Holder_Ctor_Args && ...ioctx_holder_args ) : m_ioctx_holder{ std::forward(ioctx_holder_args)... } - , m_pool( pool_size ) + , m_pool( pool_size_checking::ensure_pool_size_non_zero( pool_size ) ) , m_status( status_t::stopped ) {} From 364ed4f1a71123a2cb82a26d1b5145b0680f1049 Mon Sep 17 00:00:00 2001 From: Yauheni Akhotnikau Date: Wed, 8 Nov 2023 16:13:49 +0300 Subject: [PATCH 13/16] Small code simplification. --- dev/restinio/http_server.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/restinio/http_server.hpp b/dev/restinio/http_server.hpp index 46e1f681..26659011 100644 --- a/dev/restinio/http_server.hpp +++ b/dev/restinio/http_server.hpp @@ -228,7 +228,7 @@ class http_server_t // allows to call operator() with server_settings_t& arg. typename = decltype( std::declval()( - *(static_cast*>(nullptr)))) > + std::declval&>() ) ) > http_server_t( io_context_holder_t io_context, Configurator && configurator ) From dd18079a92548818c282eaf5d568c8aae809668d Mon Sep 17 00:00:00 2001 From: Yauheni Akhotnikau Date: Thu, 9 Nov 2023 12:51:30 +0300 Subject: [PATCH 14/16] An attempt to resolve several FIXME. These FIXME related to stopping http_server started by using on_pool_runner_t. --- dev/restinio/http_server_run.hpp | 39 +++++++++++++++++++------------- dev/restinio/impl/acceptor.hpp | 22 ++++++++++-------- 2 files changed, 36 insertions(+), 25 deletions(-) diff --git a/dev/restinio/http_server_run.hpp b/dev/restinio/http_server_run.hpp index eb133db9..97bb32a4 100644 --- a/dev/restinio/http_server_run.hpp +++ b/dev/restinio/http_server_run.hpp @@ -686,6 +686,17 @@ initiate_shutdown( http_server_t & server ) } ); } +//FIXME: document this! +struct abort_app_in_error_callback_t +{ + [[noreturn]] + void + operator()( std::exception_ptr /*ex*/ ) const + { + std::abort(); + } +}; + // // on_pool_runner_t // @@ -863,37 +874,33 @@ public : bool started() const noexcept { return m_pool.started(); } - //FIXME: there should be a version of stop() with callbacks like - //for start() method above. + //FIXME: fix the description of this method! //! Stop the server. /*! * @note * This method is noexcept since v.0.6.7 */ + template< typename Error_CB = abort_app_in_error_callback_t > void - stop() noexcept + stop( Error_CB error_cb = Error_CB{} ) noexcept { + // NOTE: m_pool.stop() call be called only inside lambda-functions + // because they may be executed some time later after the return + // from close_async(). m_server.close_async( [this]{ // Stop running io_service. m_pool.stop(); }, - []( std::exception_ptr /*ex*/ ){ - //FIXME: the exception should be stored to be handled - //later in wait() method. - //NOTE: this fix is planned for v.0.7.0. - //std::rethrow_exception( ex ); + [this, callback = std::move(error_cb)]( std::exception_ptr ex ) { + // Stop running io_service anyway. + m_pool.stop(); + + // We have to call error_cb in this case. + callback( std::move(ex) ); } ); } - //FIXME this method should be replaced by two new method in v.0.7.0: - // - // enum class action_on_exception_t { drop, rethrow }; - // wait(action_on_exception_t action); - // - // template - // wait(Exception_Handler && on_exception); - // //! Wait for full stop of the server. /*! * @note diff --git a/dev/restinio/impl/acceptor.hpp b/dev/restinio/impl/acceptor.hpp index b0728d3f..b49df358 100644 --- a/dev/restinio/impl/acceptor.hpp +++ b/dev/restinio/impl/acceptor.hpp @@ -310,10 +310,12 @@ class acceptor_t final } else { - m_logger.trace( [&]{ - return fmt::format( - RESTINIO_FMT_FORMAT_STRING( "server already closed" ) ); - } ); + // v.0.7.0: suppress exceptions from logging. + restinio::utils::log_trace_noexcept( m_logger, + [&]{ + return fmt::format( + RESTINIO_FMT_FORMAT_STRING( "server already closed" ) ); + } ); } } @@ -548,11 +550,13 @@ class acceptor_t final m_acceptor.close(); - m_logger.info( [&]{ - return fmt::format( - RESTINIO_FMT_FORMAT_STRING( "server closed on {}" ), - fmtlib_tools::streamed( ep ) ); - } ); + // v.0.7.0: Suppress exceptions from this logging too. + restinio::utils::log_info_noexcept( m_logger, + [&]{ + return fmt::format( + RESTINIO_FMT_FORMAT_STRING( "server closed on {}" ), + fmtlib_tools::streamed( ep ) ); + } ); } //! Server endpoint. From c9fea195e16245db48d52692970abd5b6aef2861 Mon Sep 17 00:00:00 2001 From: Yauheni Akhotnikau Date: Thu, 9 Nov 2023 14:45:03 +0300 Subject: [PATCH 15/16] Several fixes for documentation and code. Fixes are related to http_server_t's open_async and close_async and using noexcept callbacks for those methods. --- dev/restinio/http_server.hpp | 57 ++++++++++++++----- dev/restinio/http_server_run.hpp | 94 +++++++++++++++++++++++++++++--- 2 files changed, 130 insertions(+), 21 deletions(-) diff --git a/dev/restinio/http_server.hpp b/dev/restinio/http_server.hpp index 26659011..099e0de7 100644 --- a/dev/restinio/http_server.hpp +++ b/dev/restinio/http_server.hpp @@ -137,7 +137,7 @@ external_io_context( asio_ns::io_context & ctx ) \endcode Async way for starting and stopping a http_server can be used if - http_server_t::open_async() and http_server_t::open_async() can be + http_server_t::open_async() and http_server_t::close_async() can be called from any other thread. For example: \code asio::io_context io_ctx; @@ -150,14 +150,18 @@ external_io_context( asio_ns::io_context & ctx ) io_ctx.run(); } }; + // This variable will be used for holding information about + // a possible exception in open_async. + std::exception_ptr exception_from_open_async; + // Start server in async way. Actual start will be performed // on the context of server_thread. server.open_async( // Ok callback. Nothing to do. - []{}, - // Error callback. Rethrow an exception. - []( auto ex_ptr ) { - std::rethrow_exception( ex_ptr ); + []() noexcept {}, + // Error callback. Just store information about an exception. + [&]( std::exception_ptr ex_ptr ) noexcept { + exception_from_open_async = ex_ptr; } ); ... // Wait while server_thread finishes its work. @@ -303,15 +307,40 @@ class http_server_t //! Closes server in async way. /*! - \note It doesn't call io_context to stop - (\see stop_io_context()). - - \attention - \a close_ok_cb and \a close_err_cb should be noexcept - functions/lambdas. This requirement is not enforced by - static_assert in RESTinio's code to avoid problems in - cases when `std::function` is used for these callbacks. - */ + * Usage example: + * \code + * restinio::http_server_t< my_traits > server{ ... }; + * + * server.open_async(...); + * + * // It's time to close the server. + * server.close_async( + * // OK callback. Will be called if acceptor and other + * // stuff is closed without problems. + * // Please note that OK callback should not throw exceptions. + * [&]() noexcept { + * ... // Some actions to perform if everything is OK. + * // For example, shutting down worker threads. + * }, + * // Error callback. Will be called if an exception is thrown + * // during closing acceptor or other stuff. + * // Please note that error callback should not throw exceptions. + * []( std::exception_ptr ex ) noexcept { + * ... // Some actions. Like storing `ex` somewhere. + * } ); + * \endcode + * + * \attention + * If an error is thrown during closing the acceptor and other stuff, + * the \a close_err_cb is called, but the state of the http_server_t + * is undefined. + * + * \attention + * \a close_ok_cb and \a close_err_cb should be noexcept + * functions/lambdas. This requirement is not enforced by + * static_assert in RESTinio's code to avoid problems in + * cases when `std::function` is used for these callbacks. + */ template < typename Server_Close_Ok_CB, typename Server_Close_Error_CB > diff --git a/dev/restinio/http_server_run.hpp b/dev/restinio/http_server_run.hpp index 97bb32a4..a579238f 100644 --- a/dev/restinio/http_server_run.hpp +++ b/dev/restinio/http_server_run.hpp @@ -686,12 +686,38 @@ initiate_shutdown( http_server_t & server ) } ); } -//FIXME: document this! +/*! + * @brief Type of a function to be used as the default on_error-callback. + * + * Since v.0.7.0 on_pool_runner_t::stop() accept a on_error callback that + * will be passed to http_server_t::close_async() and will be called if + * an exception is thrown in http_server_t::close_async(). + * This callback should perform some actions that can help the application + * to handle the problem. + * + * This type is intended to be used as the default on_error callback. + * + * If an exception in thrown inside http_server_t::close_async() then + * the application is in undefined state, it's unknown what can be done + * with http_server_t instance and whan can't be. + * + * Therefore the default on_error callback simply calls std::abort() to + * terminate the application and avoid the work in undefined state. + * + * If such behavour is not desirable the user can provide own + * on_error callback. + * + * @since v.0.7.0 + */ struct abort_app_in_error_callback_t { + /*! + * @attention + * It just calls std::abort(). + */ [[noreturn]] void - operator()( std::exception_ptr /*ex*/ ) const + operator()( std::exception_ptr /*ex*/ ) const noexcept { std::abort(); } @@ -846,8 +872,8 @@ public : "On_Error_Callback should be noexcept" ); m_server.open_async( - [callback = std::move(on_ok)]{ callback(); }, - [this, callback = std::move(on_error)]( std::exception_ptr ex ){ + [callback = std::move(on_ok)]() noexcept { callback(); }, + [this, callback = std::move(on_error)]( std::exception_ptr ex ) noexcept { // There is no sense to run pool. m_pool.stop(); @@ -874,11 +900,65 @@ public : bool started() const noexcept { return m_pool.started(); } - //FIXME: fix the description of this method! //! Stop the server. /*! + * This method stops the server by calling http_server_t::close_async() + * It means that stop will be performed asynchronously. To wait for the + * completion of stop operation the wait() method has to be used. + * + * The simple usage: + * @code + * using my_http_server = restinio::http_server_t; + * + * my_http_server server{...}; + * restinio::on_pool_runner_t runner{16, server}; + * + * runner.start(...); + * + * ... + * // Some time later. + * runner.stop(); + * + * ... // Some other actions. + * // Have to wait the completion of the stop() operation. + * runner.wait(); + * @endcode + * + * This method accepts @a error_cb callback that will be called + * if an exception is thrown in http_server_t::close_async(). + * + * The @a error_cb is an optional parameter, an instance of + * abort_app_in_error_callback_t is used by default. It means that + * if an exception is thrown on http_server_t::close_async() then + * the whole application will be terminated. If such behavior is not + * desirable a user has to provide own error callback: + * @code + * using my_http_server = restinio::http_server_t; + * + * my_http_server server{...}; + * restinio::on_pool_runner_t runner{16, server}; + * + * runner.start(...); + * + * ... + * // Some time later. + * runner.stop([](std::exception_ptr ex) { + * ... // Some handling of an exception. + * }); + * @endcode + * But it's important to note that if an exception is thrown inside + * http_server_t::close_async() then the instance of http_server_t + * is in undefined state. + * * @note * This method is noexcept since v.0.6.7 + * + * @tparam Error_CB Type of the callback to be used if an exception + * is thrown inside http_server_t::close_async(). This callback + * should be noexcept functor (however, the noexceptness is not + * checked at the compile-time to have a possibility to use + * std::function as error callback). See abort_app_in_error_callback_t + * for a prototype of Error_CB functor. */ template< typename Error_CB = abort_app_in_error_callback_t > void @@ -888,11 +968,11 @@ public : // because they may be executed some time later after the return // from close_async(). m_server.close_async( - [this]{ + [this]() noexcept { // Stop running io_service. m_pool.stop(); }, - [this, callback = std::move(error_cb)]( std::exception_ptr ex ) { + [this, callback = std::move(error_cb)]( std::exception_ptr ex ) noexcept { // Stop running io_service anyway. m_pool.stop(); From b426c99096644fc824883d01850ae3dc50e746ba Mon Sep 17 00:00:00 2001 From: Yauheni Akhotnikau Date: Thu, 9 Nov 2023 15:24:35 +0300 Subject: [PATCH 16/16] Fixes for Doxygen comments. --- dev/restinio/async_chain/common.hpp | 16 ++++++------- dev/restinio/async_chain/fixed_size.hpp | 20 +++++++++-------- dev/restinio/async_chain/growable_size.hpp | 26 ++++++++++++---------- 3 files changed, 33 insertions(+), 29 deletions(-) diff --git a/dev/restinio/async_chain/common.hpp b/dev/restinio/async_chain/common.hpp index a9007260..915eda9b 100644 --- a/dev/restinio/async_chain/common.hpp +++ b/dev/restinio/async_chain/common.hpp @@ -97,7 +97,7 @@ using generic_async_request_scheduler_t = /*! * @brief Special type to be used as an indicator that there are no more - * handlers in an async chain. + * schedulers in an async chain. * * This type will be used in on_next_result_t variant. * @@ -109,7 +109,7 @@ struct no_more_schedulers_t {}; * @brief Special type to be used as result of async_handling_controller's * on_next method. * - * The async_handling_controller_t::on_next may return an actual handler to + * The async_handling_controller_t::on_next may return an actual scheduler to * be called or (if there are no more handlers left) a special no_more_handler * value. This is described by on_next_result_t variant type. * @@ -165,7 +165,7 @@ class async_handling_controller_t virtual ~async_handling_controller_t() = default; /*! - * @brief Get reference to source request. + * @brief Get reference to the source request. * * Usage example: * @code @@ -188,11 +188,11 @@ class async_handling_controller_t private: /*! - * @brief Command to try find a next async handler to be invoked. + * @brief Command to try find a next scheduler to be invoked. * * Implementation of async_handling_controller_t should switch to the - * next handler in the chain and return the handler to be called next. - * If there are no such handlers, no_more_schedulers_t must be returned. + * next scheduler in the chain and return the scheduler to be called next. + * If there are no such schedulers, no_more_schedulers_t must be returned. * * @note * This method is intended to be called by next() function. @@ -208,7 +208,7 @@ namespace impl /*! * @brief Helper to make a negative response with "Not Implemented" status. * - * This helper will be used if there is no more handlers to call, but + * This helper will be used if there is no more schedulers to call, but * the request is still not handled. * * @tparam Request_Handle Type of request handle that holds the source request. @@ -225,7 +225,7 @@ make_not_implemented_response( const Request_Handle & req ) /*! * @brief Helper to make a negative response with "Internal Server Error" status. * - * This helper will be used if the current async handler returns + * This helper will be used if the current scheduler returns * schedule_result_t::failure. * * @tparam Request_Handle Type of request handle that holds the source request. diff --git a/dev/restinio/async_chain/fixed_size.hpp b/dev/restinio/async_chain/fixed_size.hpp index 0c835515..d6ba5856 100644 --- a/dev/restinio/async_chain/fixed_size.hpp +++ b/dev/restinio/async_chain/fixed_size.hpp @@ -17,12 +17,13 @@ namespace restinio::async_chain * @brief A holder of fixed-size chain of asynchronous handlers. * * @note - * An instance of that type is intended to be filled with actual handlers - * at the creation time. After that new handlers can't be added to the chain, + * An instance of that type is intended to be filled with actual schedulers + * at the creation time. After that new schedulers can't be added to the chain, * and old handlers can't be removed from the chain. * * Usage example for the case when there is no extra-data in a request object - * (please note that this is simplified example without actual asynchronous code): + * (please note that this is simplified example without actual asynchronous code, + * all schedulers work as synchronous handlers): * @code * struct my_traits : public restinio::default_traits_t { * using request_handler_t = restinio::async_chain::fixed_size_chain_t<3>; @@ -90,7 +91,8 @@ namespace restinio::async_chain * * Usage example for the case when some extra-data is incorporated into * a request object - * (please note that this is simplified example without actual asynchronous code): + * (please note that this is simplified example without actual asynchronous code, + * all schedulers work as synchronous handlers): * @code * struct my_extra_data_factory { * // A data formed by checker of HTTP-fields. @@ -164,7 +166,7 @@ namespace restinio::async_chain * ); * @endcode * - * @tparam Size The exact number of handlers in the chain. + * @tparam Size The exact number of schedulers in the chain. * * @tparam Extra_Data_Factory The type of extra-data-factory specified in * the server's traits. @@ -197,7 +199,7 @@ class fixed_size_chain_t * @brief Actual implementation of the controller interface. * * @note - * Object of this type holds a copy of the source array of handlers. + * Object of this type holds a copy of the source array of schedulers. */ class actual_controller_t final : public async_handling_controller_t< Extra_Data_Factory > @@ -206,7 +208,7 @@ class fixed_size_chain_t const actual_request_handle_t m_request; //! Request handlers. schedulers_array_t m_schedulers; - //! Index of the current handler to be used. + //! Index of the current scheduler to be used. /*! * @note * May be equal to or greater than m_schedulers.size() in the case @@ -246,7 +248,7 @@ class fixed_size_chain_t } }; - //! The array of request handlers. + //! The array of schedulers. /*! * @note * It's initialized in the constructor and then never changed. @@ -298,7 +300,7 @@ class fixed_size_chain_t } /*! - * Initiates execution of the first request handler in the chain. + * Initiates execution of the first scheduler in the chain. * * @note * Always returns request_handling_status_t::accepted. diff --git a/dev/restinio/async_chain/growable_size.hpp b/dev/restinio/async_chain/growable_size.hpp index 11e04b07..0530afde 100644 --- a/dev/restinio/async_chain/growable_size.hpp +++ b/dev/restinio/async_chain/growable_size.hpp @@ -25,14 +25,15 @@ namespace restinio::async_chain * @brief A holder of variable-size chain of asynchronous handlers. * * @note - * Once a list of handler is filled and an instance of growable_size_chain_t - * is created that instance can't be changed: a new handler can't be added, and - * an old handler can be removed. The creation of growable_size_chain_t + * Once a list of schedulers is filled and an instance of growable_size_chain_t + * is created that instance can't be changed: a new scheduler can't be added, and + * an old scheduler can be removed. The creation of growable_size_chain_t * instance is performed by the help of growable_size_chain_t::builder_t * class. * * Usage example for the case when there is no extra-data in a request object - * (please note that this is simplified example without actual asynchronous code): + * (please note that this is simplified example without actual asynchronous code, + * all schedulers work as synchronous handlers): * @code * struct my_traits : public restinio::default_traits_t { * using request_handler_t = restinio::async_chain::growable_size_chain_t; @@ -90,7 +91,8 @@ namespace restinio::async_chain * * Usage example for the case when some extra-data is incorporated into * a request object: - * (please note that this is simplified example without actual asynchronous code): + * (please note that this is simplified example without actual asynchronous code, + * all schedulers work as synchronous handlers): * @code * struct my_extra_data_factory { * // A data formed by checker of HTTP-fields. @@ -202,20 +204,20 @@ class growable_size_chain_t * @brief Actual implementation of the controller interface. * * @note - * Object of this type holds a copy of the source vector of handlers. + * Object of this type holds a copy of the source vector of schedulers. */ class actual_controller_t final : public async_handling_controller_t< Extra_Data_Factory > { //! The source request. const actual_request_handle_t m_request; - //! Request handlers. + //! Request schedulers. schedulers_vector_t m_schedulers; //! Index of the current scheduler to be used. /*! * @note * May be equal to or greater than m_schedulers.size() in the case - * when all handlers are already processed. + * when all schedulers are already processed. */ std::size_t m_current{}; @@ -261,7 +263,7 @@ class growable_size_chain_t * That instance can be obtained by release() method. * * @note - * New handlers can be added to the chain by add() method until + * New schedulers can be added to the chain by add() method until * release() is called. * * @attention @@ -278,7 +280,7 @@ class growable_size_chain_t {} /*! - * @brief Stop adding of new handlers and acquire the chain instance. + * @brief Stop adding of new schedulers and acquire the chain instance. * * @note * The builder object should not be used after the calling of @@ -314,7 +316,7 @@ class growable_size_chain_t }; private: - //! The vector of request handlers. + //! The vector of schedulers. schedulers_vector_t m_schedulers; /*! @@ -334,7 +336,7 @@ class growable_size_chain_t growable_size_chain_t() = delete; /*! - * Initiates execution of the first request handler in the chain. + * Initiates execution of the first scheduler in the chain. * * @note * Always returns request_handling_status_t::accepted.