├── .clang-format ├── .clang-tidy ├── .github ├── python │ └── requirements.txt ├── vcpkg │ ├── linux-clang-latest.cmake │ ├── linux-clang13.cmake │ ├── x64-linux-clang-latest-release.cmake │ ├── x64-linux-clang13-release.cmake │ ├── x64-linux-gcc10-release.cmake │ └── x64-osx-custom-release.cmake └── workflows │ ├── build.yml │ └── mdsnippets.yml ├── .gitignore ├── CMakeLists.txt ├── CMakePresets.json ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── asio-grpc.natvis ├── cmake-format.yaml ├── cmake ├── AsioGrpcCheckBoostVersion.cmake ├── AsioGrpcCheckStdPmr.cmake ├── AsioGrpcCompileOptions.cmake ├── AsioGrpcCoverage.cmake ├── AsioGrpcFindPackages.cmake ├── AsioGrpcGitHooksInstaller.cmake ├── AsioGrpcHunter.cmake ├── AsioGrpcInstallGitHooks.cmake ├── AsioGrpcInstallation.cmake ├── AsioGrpcOptionDefaults.cmake ├── AsioGrpcProjectTopLevel.cmake ├── AsioGrpcProtobufGenerator.cmake ├── asio-grpcConfig.cmake.in ├── check_boost_asio_has_co_await.cpp ├── check_std_pmr.cpp └── hooks │ ├── AsioGrpcPreCommit.cmake.in │ └── pre-commit.in ├── deps ├── abseil │ ├── chord.patch │ ├── portfile.cmake │ └── vcpkg.json ├── asio │ ├── CMakeLists.txt │ ├── asio-config.cmake │ ├── portfile.cmake │ └── vcpkg.json ├── protobuf │ ├── compare.patch │ ├── fix-arm64-msvc.patch │ ├── fix-default-proto-file-path.patch │ ├── fix-install-dirs.patch │ ├── fix-static-build.patch │ ├── fix-utf8-range.patch │ ├── portfile.cmake │ ├── protobuf-targets-vcpkg-protoc.cmake │ ├── static-assert.patch │ ├── vcpkg-cmake-wrapper.cmake │ └── vcpkg.json └── stdexec │ ├── fix-version.patch │ ├── portfile.cmake │ └── vcpkg.json ├── doc ├── CMakeLists.txt ├── client_rpc_cheat_sheet.md ├── cmake_protobuf_generate.md ├── completion_token.md ├── custom.css ├── doxygen-awesome-darkmode-toggle.js ├── doxygen-awesome-sidebar-only-darkmode-toggle.css ├── doxygen-awesome-sidebar-only.css ├── doxygen-awesome.css ├── header.html ├── index.md ├── server_rpc_cheat_sheet.md ├── using_asio_io_context.md └── v3_migration.md ├── example ├── CMakeLists.txt ├── README.md ├── async-generator-client.cpp ├── async-generator-server.cpp ├── generic-client.cpp ├── generic-server.cpp ├── hello-world-client.cpp ├── hello-world-server-arena.cpp ├── hello-world-server.cpp ├── helper │ ├── coro_traits.hpp │ ├── helper.hpp │ ├── notify_when_done_server_rpc.hpp │ ├── rethrow_first_arg.hpp │ ├── scope_guard.hpp │ ├── server_shutdown_asio.hpp │ ├── server_shutdown_unifex.hpp │ └── yield_helper.hpp ├── main-io-context-server.cpp ├── multi-threaded-alternative-client.cpp ├── multi-threaded-alternative-server.cpp ├── multi-threaded-client.cpp ├── multi-threaded-server.cpp ├── proto │ ├── CMakeLists.txt │ ├── example │ │ └── v1 │ │ │ ├── example.proto │ │ │ └── example_ext.proto │ ├── grpc │ │ └── health │ │ │ └── v1 │ │ │ └── health.proto │ └── helloworld │ │ └── helloworld.proto ├── share-io-context-client.cpp ├── share-io-context-server.cpp ├── snippets │ ├── CMakeLists.txt │ ├── README.md │ ├── alarm.cpp │ ├── client.cpp │ ├── client_callback.cpp │ ├── client_rpc.cpp │ ├── io_context.cpp │ ├── rpc_cheat_sheet.cpp │ ├── server.cpp │ ├── server_callback.cpp │ ├── server_rpc.cpp │ ├── unifex_client.cpp │ └── unifex_server.cpp ├── streaming-client.cpp ├── streaming-server.cpp ├── unifex-client.cpp └── unifex-server.cpp ├── mdsnippets.json ├── sonar-project.properties ├── src ├── CMakeLists.txt └── agrpc │ ├── alarm.hpp │ ├── asio_grpc.hpp │ ├── client_callback.hpp │ ├── client_rpc.hpp │ ├── default_server_rpc_traits.hpp │ ├── detail │ ├── alarm.hpp │ ├── algorithm.hpp │ ├── allocate.hpp │ ├── allocate_operation.hpp │ ├── allocation_type.hpp │ ├── asio_forward.hpp │ ├── asio_macros.hpp │ ├── asio_utils.hpp │ ├── association.hpp │ ├── association_asio.hpp │ ├── association_execution.hpp │ ├── atomic_bool_stop_context.hpp │ ├── atomic_intrusive_queue.hpp │ ├── awaitable.hpp │ ├── backoff.hpp │ ├── basic_sender.hpp │ ├── bind_allocator.hpp │ ├── client_callback.hpp │ ├── client_rpc_base.hpp │ ├── client_rpc_context_base.hpp │ ├── client_rpc_sender.hpp │ ├── co_spawn.hpp │ ├── config.hpp │ ├── coroutine_traits.hpp │ ├── create_and_submit_no_arg_operation.hpp │ ├── deallocate_on_complete.hpp │ ├── default_completion_token.hpp │ ├── epilogue.hpp │ ├── execution.hpp │ ├── execution_asio.hpp │ ├── execution_stdexec.hpp │ ├── execution_unifex.hpp │ ├── executor_with_default.hpp │ ├── forward.hpp │ ├── functional.hpp │ ├── grpc_completion_queue_event.hpp │ ├── grpc_context_definition.hpp │ ├── grpc_context_implementation.hpp │ ├── grpc_context_implementation_definition.hpp │ ├── grpc_context_local_allocator.hpp │ ├── grpc_executor_base.hpp │ ├── grpc_executor_options.hpp │ ├── grpc_sender.hpp │ ├── health_check_repeatedly_request.hpp │ ├── health_check_service.hpp │ ├── initiate_sender_implementation.hpp │ ├── intrusive_list.hpp │ ├── intrusive_list_hook.hpp │ ├── intrusive_queue.hpp │ ├── intrusive_slist.hpp │ ├── intrusive_stack.hpp │ ├── listable_pool_resource.hpp │ ├── manual_reset_event.hpp │ ├── manual_reset_event_offset_storage.hpp │ ├── manual_reset_event_operation.hpp │ ├── math.hpp │ ├── memory.hpp │ ├── name.hpp │ ├── no_arg_operation.hpp │ ├── notify_on_state_change.hpp │ ├── notify_when_done_event.hpp │ ├── offset_manual_reset_event.hpp │ ├── operation_base.hpp │ ├── operation_handle.hpp │ ├── operation_implementation.hpp │ ├── operation_initiation.hpp │ ├── pool_resource.hpp │ ├── pool_resource_allocator.hpp │ ├── prepend_error_code.hpp │ ├── query_grpc_context.hpp │ ├── reactor_client_context_base.hpp │ ├── reactor_executor_base.hpp │ ├── reactor_ptr.hpp │ ├── reactor_ptr_type.hpp │ ├── ref_counted_reactor.hpp │ ├── register_callback_rpc_handler.hpp │ ├── register_coroutine_rpc_handler.hpp │ ├── register_rpc_handler_asio_base.hpp │ ├── register_rpc_handler_base.hpp │ ├── register_sender_rpc_handler.hpp │ ├── register_yield_rpc_handler.hpp │ ├── rethrow_first_arg.hpp │ ├── rpc_executor_base.hpp │ ├── rpc_type.hpp │ ├── schedule_sender.hpp │ ├── sender_implementation.hpp │ ├── sender_implementation_operation.hpp │ ├── sender_of.hpp │ ├── server_callback.hpp │ ├── server_callback_coroutine.hpp │ ├── server_rpc_base.hpp │ ├── server_rpc_context_base.hpp │ ├── server_rpc_notify_when_done_base.hpp │ ├── server_rpc_notify_when_done_mixin.hpp │ ├── server_rpc_request_message.hpp │ ├── server_rpc_sender.hpp │ ├── server_rpc_starter.hpp │ ├── server_rpc_with_request.hpp │ ├── server_write_reactor.hpp │ ├── serving_status.hpp │ ├── stop_callback_lifetime.hpp │ ├── submit.hpp │ ├── test.hpp │ ├── tuple.hpp │ ├── use_sender.hpp │ ├── utility.hpp │ ├── waiter.hpp │ └── work_tracking_completion_handler.hpp │ ├── grpc_context.hpp │ ├── grpc_executor.hpp │ ├── health_check_service.hpp │ ├── notify_on_state_change.hpp │ ├── reactor_ptr.hpp │ ├── read.hpp │ ├── register_awaitable_rpc_handler.hpp │ ├── register_callback_rpc_handler.hpp │ ├── register_coroutine_rpc_handler.hpp │ ├── register_sender_rpc_handler.hpp │ ├── register_yield_rpc_handler.hpp │ ├── rpc_type.hpp │ ├── run.hpp │ ├── server_callback.hpp │ ├── server_callback_coroutine.hpp │ ├── server_rpc.hpp │ ├── server_rpc_ptr.hpp │ ├── test.hpp │ ├── use_sender.hpp │ └── waiter.hpp ├── test ├── CMakeLists.txt ├── cmake │ ├── CMakeLists.txt │ ├── subdirectory │ │ ├── CMakeLists.txt.in │ │ └── src │ │ │ ├── CMakeLists.txt │ │ │ ├── main.cpp │ │ │ ├── proto │ │ │ └── target.proto │ │ │ └── vcpkg.json │ └── superbuild │ │ ├── CMakeLists.txt.in │ │ └── src │ │ ├── CMakeLists.txt │ │ ├── descriptor.cpp │ │ ├── main.cpp │ │ ├── out_var.cpp │ │ ├── proto │ │ ├── descriptor.proto │ │ ├── out_var │ │ │ ├── msg │ │ │ │ └── message.proto │ │ │ ├── subdir │ │ │ │ └── other.1.proto │ │ │ └── v1 │ │ │ │ └── out_var.proto │ │ └── target.proto │ │ ├── target.cpp │ │ └── vcpkg.json ├── example │ ├── CMakeLists.txt │ └── test_examples.cpp ├── proto │ ├── CMakeLists.txt │ ├── grpc │ │ └── health │ │ │ └── v1 │ │ │ └── health.proto │ └── test │ │ ├── msg │ │ └── message.proto │ │ └── v1 │ │ └── test.proto ├── src │ ├── CMakeLists.txt │ ├── test_alarm_17.cpp │ ├── test_alarm_20.cpp │ ├── test_asio_grpc_17.cpp │ ├── test_bind_allocator_17.cpp │ ├── test_bind_allocator_20.cpp │ ├── test_callback_17.cpp │ ├── test_callback_20.cpp │ ├── test_client_rpc_17.cpp │ ├── test_execution.cpp │ ├── test_grpc_context_17.cpp │ ├── test_grpc_context_20.cpp │ ├── test_health_check_service_17.cpp │ ├── test_run_17.cpp │ ├── test_server_rpc_17.cpp │ ├── test_server_rpc_20.cpp │ ├── test_test_17.cpp │ ├── test_unifex_20.cpp │ └── test_waiter_17.cpp ├── syntax │ └── CMakeLists.txt └── utils │ ├── CMakeLists.txt │ └── utils │ ├── asio_forward.hpp │ ├── asio_separate_compilation.cpp │ ├── asio_utils.cpp │ ├── asio_utils.hpp │ ├── client_context.cpp │ ├── client_context.hpp │ ├── client_rpc.hpp │ ├── client_rpc_test.hpp │ ├── delete_guard.hpp │ ├── doctest.hpp │ ├── exception.hpp │ ├── execution_test.hpp │ ├── execution_utils.hpp │ ├── free_port.cpp │ ├── free_port.hpp │ ├── future.hpp │ ├── grpc_client_server_callback_test.cpp │ ├── grpc_client_server_callback_test.hpp │ ├── grpc_client_server_test.cpp │ ├── grpc_client_server_test.hpp │ ├── grpc_client_server_test_base.cpp │ ├── grpc_client_server_test_base.hpp │ ├── grpc_client_server_test_impl.hpp │ ├── grpc_context_test.cpp │ ├── grpc_context_test.hpp │ ├── grpc_format.cpp │ ├── grpc_format.hpp │ ├── grpc_generic_client_server_test.cpp │ ├── grpc_generic_client_server_test.hpp │ ├── introspect_rpc.hpp │ ├── io_context_test.cpp │ ├── io_context_test.hpp │ ├── main.cpp │ ├── precompiled_header.hpp │ ├── protobuf.hpp │ ├── requestMessageFactory.hpp │ ├── rpc.cpp │ ├── rpc.hpp │ ├── server_callback_test.hpp │ ├── server_rpc.hpp │ ├── server_shutdown_initiator.cpp │ ├── server_shutdown_initiator.hpp │ ├── test.cpp │ ├── test.hpp │ ├── throwing_allocator.hpp │ ├── time.cpp │ ├── time.hpp │ ├── tracking_allocator.hpp │ ├── unassignable_allocator.hpp │ └── utility.hpp └── vcpkg.json /.github/python/requirements.txt: -------------------------------------------------------------------------------- 1 | gcovr==8.3 -------------------------------------------------------------------------------- /.github/vcpkg/linux-clang-latest.cmake: -------------------------------------------------------------------------------- 1 | if(NOT _VCPKG_LINUX_CLANG_TOOLCHAIN) 2 | set(_VCPKG_LINUX_CLANG_TOOLCHAIN 1) 3 | set(CMAKE_C_COMPILER "clang") 4 | set(CMAKE_CXX_COMPILER "clang++") 5 | 6 | set(CMAKE_CROSSCOMPILING 7 | OFF 8 | CACHE BOOL "") 9 | set(CMAKE_SYSTEM_NAME 10 | Linux 11 | CACHE STRING "") 12 | set(CMAKE_SYSTEM_PROCESSOR 13 | x86_64 14 | CACHE STRING "") 15 | 16 | get_property(_CMAKE_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE) 17 | if(NOT _CMAKE_IN_TRY_COMPILE) 18 | string(APPEND CMAKE_C_FLAGS_INIT " -fPIC ${VCPKG_C_FLAGS} ") 19 | string(APPEND CMAKE_CXX_FLAGS_INIT " -fPIC ${VCPKG_CXX_FLAGS} -Wno-error -stdlib=libc++ ") 20 | string(APPEND CMAKE_C_FLAGS_DEBUG_INIT " ${VCPKG_C_FLAGS_DEBUG} ") 21 | string(APPEND CMAKE_CXX_FLAGS_DEBUG_INIT " ${VCPKG_CXX_FLAGS_DEBUG} ") 22 | string(APPEND CMAKE_C_FLAGS_RELEASE_INIT " ${VCPKG_C_FLAGS_RELEASE} ") 23 | string(APPEND CMAKE_CXX_FLAGS_RELEASE_INIT " ${VCPKG_CXX_FLAGS_RELEASE} ") 24 | 25 | string(APPEND CMAKE_SHARED_LINKER_FLAGS_INIT " ${VCPKG_LINKER_FLAGS} ") 26 | string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT " ${VCPKG_LINKER_FLAGS} ") 27 | if(VCPKG_CRT_LINKAGE STREQUAL "static") 28 | string(APPEND CMAKE_SHARED_LINKER_FLAGS_INIT "-static ") 29 | string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT "-static ") 30 | endif() 31 | string(APPEND CMAKE_SHARED_LINKER_FLAGS_DEBUG_INIT " ${VCPKG_LINKER_FLAGS_DEBUG} ") 32 | string(APPEND CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT " ${VCPKG_LINKER_FLAGS_DEBUG} ") 33 | string(APPEND CMAKE_SHARED_LINKER_FLAGS_RELEASE_INIT " ${VCPKG_LINKER_FLAGS_RELEASE} ") 34 | string(APPEND CMAKE_EXE_LINKER_FLAGS_RELEASE_INIT " ${VCPKG_LINKER_FLAGS_RELEASE} ") 35 | endif() 36 | endif() 37 | -------------------------------------------------------------------------------- /.github/vcpkg/linux-clang13.cmake: -------------------------------------------------------------------------------- 1 | if(NOT _VCPKG_LINUX_CLANG_TOOLCHAIN) 2 | set(_VCPKG_LINUX_CLANG_TOOLCHAIN 1) 3 | set(CMAKE_C_COMPILER "clang-13") 4 | set(CMAKE_CXX_COMPILER "clang++-13") 5 | 6 | set(CMAKE_CROSSCOMPILING 7 | OFF 8 | CACHE BOOL "") 9 | set(CMAKE_SYSTEM_NAME 10 | Linux 11 | CACHE STRING "") 12 | set(CMAKE_SYSTEM_PROCESSOR 13 | x86_64 14 | CACHE STRING "") 15 | 16 | get_property(_CMAKE_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE) 17 | if(NOT _CMAKE_IN_TRY_COMPILE) 18 | string(APPEND CMAKE_C_FLAGS_INIT " -fPIC ${VCPKG_C_FLAGS} ") 19 | string( 20 | APPEND CMAKE_CXX_FLAGS_INIT 21 | " -fPIC ${VCPKG_CXX_FLAGS} -Wno-error -stdlib=libc++ -stdlib++-isystem /usr/lib/llvm-13/include/c++/v1/ ") 22 | string(APPEND CMAKE_C_FLAGS_DEBUG_INIT " ${VCPKG_C_FLAGS_DEBUG} ") 23 | string(APPEND CMAKE_CXX_FLAGS_DEBUG_INIT " ${VCPKG_CXX_FLAGS_DEBUG} ") 24 | string(APPEND CMAKE_C_FLAGS_RELEASE_INIT " ${VCPKG_C_FLAGS_RELEASE} ") 25 | string(APPEND CMAKE_CXX_FLAGS_RELEASE_INIT " ${VCPKG_CXX_FLAGS_RELEASE} ") 26 | 27 | string(APPEND CMAKE_SHARED_LINKER_FLAGS_INIT " ${VCPKG_LINKER_FLAGS} -fuse-ld=lld ") 28 | string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT " ${VCPKG_LINKER_FLAGS} -fuse-ld=lld ") 29 | if(VCPKG_CRT_LINKAGE STREQUAL "static") 30 | string(APPEND CMAKE_SHARED_LINKER_FLAGS_INIT "-static ") 31 | string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT "-static ") 32 | endif() 33 | string(APPEND CMAKE_SHARED_LINKER_FLAGS_DEBUG_INIT " ${VCPKG_LINKER_FLAGS_DEBUG} ") 34 | string(APPEND CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT " ${VCPKG_LINKER_FLAGS_DEBUG} ") 35 | string(APPEND CMAKE_SHARED_LINKER_FLAGS_RELEASE_INIT " ${VCPKG_LINKER_FLAGS_RELEASE} ") 36 | string(APPEND CMAKE_EXE_LINKER_FLAGS_RELEASE_INIT " ${VCPKG_LINKER_FLAGS_RELEASE} ") 37 | endif() 38 | endif() 39 | -------------------------------------------------------------------------------- /.github/vcpkg/x64-linux-clang-latest-release.cmake: -------------------------------------------------------------------------------- 1 | set(VCPKG_TARGET_ARCHITECTURE x64) 2 | set(VCPKG_CRT_LINKAGE dynamic) 3 | set(VCPKG_LIBRARY_LINKAGE static) 4 | set(VCPKG_BUILD_TYPE release) 5 | 6 | set(VCPKG_CMAKE_SYSTEM_NAME Linux) 7 | set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${CMAKE_CURRENT_LIST_DIR}/linux-clang-latest.cmake") 8 | -------------------------------------------------------------------------------- /.github/vcpkg/x64-linux-clang13-release.cmake: -------------------------------------------------------------------------------- 1 | set(VCPKG_TARGET_ARCHITECTURE x64) 2 | set(VCPKG_CRT_LINKAGE dynamic) 3 | set(VCPKG_LIBRARY_LINKAGE static) 4 | set(VCPKG_BUILD_TYPE release) 5 | 6 | set(VCPKG_CMAKE_SYSTEM_NAME Linux) 7 | 8 | if(PORT MATCHES "(boost-cobalt)") 9 | set(VCPKG_C_FLAGS "") 10 | set(VCPKG_CXX_FLAGS "-std=c++20 -fcoroutines-ts") 11 | endif() 12 | 13 | set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${CMAKE_CURRENT_LIST_DIR}/linux-clang13.cmake") 14 | -------------------------------------------------------------------------------- /.github/vcpkg/x64-linux-gcc10-release.cmake: -------------------------------------------------------------------------------- 1 | set(VCPKG_TARGET_ARCHITECTURE x64) 2 | set(VCPKG_CRT_LINKAGE dynamic) 3 | set(VCPKG_LIBRARY_LINKAGE static) 4 | 5 | set(VCPKG_CMAKE_SYSTEM_NAME Linux) 6 | set(VCPKG_BUILD_TYPE release) 7 | 8 | if(PORT MATCHES "(boost-cobalt)") 9 | set(VCPKG_C_FLAGS "") 10 | set(VCPKG_CXX_FLAGS "-std=c++20 -fcoroutines") 11 | endif() 12 | -------------------------------------------------------------------------------- /.github/vcpkg/x64-osx-custom-release.cmake: -------------------------------------------------------------------------------- 1 | set(VCPKG_TARGET_ARCHITECTURE x64) 2 | set(VCPKG_CRT_LINKAGE dynamic) 3 | set(VCPKG_LIBRARY_LINKAGE static) 4 | 5 | set(VCPKG_CMAKE_SYSTEM_NAME Darwin) 6 | set(VCPKG_OSX_ARCHITECTURES x86_64) 7 | set(VCPKG_BUILD_TYPE release) 8 | 9 | if(PORT MATCHES "(boost-cobalt)") 10 | set(VCPKG_C_FLAGS "-DBOOST_COBALT_NO_PMR") 11 | set(VCPKG_CXX_FLAGS "-BOOST_COBALT_NO_PMR") 12 | endif() 13 | -------------------------------------------------------------------------------- /.github/workflows/mdsnippets.yml: -------------------------------------------------------------------------------- 1 | name: Run MarkdownSnippets 2 | 3 | on: 4 | push: 5 | 6 | jobs: 7 | docs: 8 | runs-on: windows-latest 9 | 10 | steps: 11 | - uses: actions/checkout@v2 12 | 13 | - name: Run MarkdownSnippets 14 | run: | 15 | dotnet tool install --global MarkdownSnippets.Tool 16 | mdsnippets 17 | working-directory: ${{ github.workspace }} 18 | 19 | - name: Push changes 20 | run: | 21 | git config --local user.email "action@github.com" 22 | git config --local user.name "GitHub Action" 23 | git commit -m "Re-generate mdsnippets" -a || echo "nothing to commit" 24 | remote="https://${GITHUB_ACTOR}:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git" 25 | branch="${GITHUB_REF:11}" 26 | git push "${remote}" ${branch} || echo "nothing to push" 27 | shell: bash 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | 34 | # Visual Studio 35 | *.db 36 | /project/msvc/ 37 | /tests/project/msvc/ 38 | .vs 39 | CMakeSettings.json 40 | 41 | # Visual Studio Code 42 | .vscode 43 | cmake-variants.yaml 44 | CMakeUserPresets.json 45 | 46 | # Codeblocks 47 | *.layout 48 | *.depend 49 | 50 | # QT Creator 51 | *.user 52 | *.autosave 53 | 54 | # Clion 55 | .idea/ 56 | .clion.source.upload.marker 57 | 58 | # Gedit backup files 59 | *.txt~ 60 | *.cmake~ 61 | *.cpp~ 62 | *.h~ 63 | *.hpp~ 64 | 65 | # Build folders 66 | /*build*/ 67 | 68 | # SonarQube 69 | sonar-cfamily-reproducer.zip 70 | .scannerwork 71 | 72 | # https://github.com/aras-p/ClangBuildAnalyzer 73 | ClangBuildAnalyzer.ini 74 | 75 | # asio-grpc specific 76 | docs/ 77 | test/cmake/superbuild/CMakeLists.txt 78 | test/cmake/subdirectory/CMakeLists.txt -------------------------------------------------------------------------------- /CMakePresets.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 10, 3 | "cmakeMinimumRequired": { 4 | "major": 3, 5 | "minor": 19, 6 | "patch": 0 7 | }, 8 | "configurePresets": [ 9 | { 10 | "name": "default", 11 | "displayName": "Default Config", 12 | "binaryDir": "${sourceDir}/build", 13 | "toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", 14 | "cacheVariables": { 15 | "CMAKE_BUILD_TYPE": "Debug", 16 | "VCPKG_OVERLAY_PORTS": "${sourceDir}/deps", 17 | "VCPKG_INSTALL_OPTIONS": "--no-print-usage", 18 | "CMAKE_INSTALL_PREFIX": "out", 19 | "ASIO_GRPC_BUILD_TESTS": "TRUE", 20 | "ASIO_GRPC_DISCOVER_TESTS": "TRUE" 21 | } 22 | } 23 | ], 24 | "buildPresets": [ 25 | { 26 | "name": "default", 27 | "configurePreset": "default", 28 | "configuration": "Debug" 29 | } 30 | ], 31 | "testPresets": [ 32 | { 33 | "name": "default", 34 | "configurePreset": "default", 35 | "configuration": "Debug", 36 | "output": { 37 | "outputOnFailure": true, 38 | "outputJUnitFile": "${sourceDir}/build/junit.xml" 39 | }, 40 | "execution": { 41 | "noTestsAction": "error", 42 | "timeout": 180, 43 | "jobs": 10 44 | } 45 | } 46 | ] 47 | } -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to asio-grpc 2 | 3 | **Thank you for considering to contribute to this project!** 4 | 5 | If you encountered a bug or want to make a feature request then do not hesitate to create a new issue. I am happy to look into it. 6 | 7 | If you intend to work on the code then please follow the steps below. 8 | 9 | ## Prerequisites 10 | 11 | You will need a C++ compiler, CMake (3.19+) and a way of installing this project's dependencies: gRPC, Boost, standalone Asio, libunifex and doctest. I recommend [vcpkg](https://github.com/microsoft/vcpkg). 12 | Head over to their github repository for more details, but in general the following should get you started: 13 | 14 | ```sh 15 | git clone https://github.com/microsoft/vcpkg 16 | ./vcpkg/bootstrap-vcpkg.bat # or bootstrap-vcpkg.sh on Linux 17 | ``` 18 | 19 | ## Build and run tests 20 | 21 | From the root of the repository run: 22 | 23 | ```sh 24 | # Make sure the VCPKG_ROOT env variable points to the cloned vcpkg repository 25 | cmake --preset default 26 | ``` 27 | 28 | It might take a while until vcpkg has installed all dependencies. 29 | 30 | Compile the tests and examples with: 31 | 32 | ```sh 33 | cmake --build --preset default 34 | ``` 35 | 36 | And run all tests: 37 | 38 | ```sh 39 | ctest --preset default 40 | ``` 41 | 42 | ## Install git hooks 43 | 44 | Before making a commit, install the latest version of [clang-format](https://github.com/llvm/llvm-project/releases) (part of clang-tools-extra) and [cmake-format](https://pypi.org/project/cmake-format/). 45 | Re-run the CMake configure step and finally run: 46 | 47 | ```sh 48 | cmake --build --preset default --target asio-grpc-init-git-hooks 49 | ``` 50 | -------------------------------------------------------------------------------- /cmake-format.yaml: -------------------------------------------------------------------------------- 1 | additional_commands: 2 | asio_grpc_protobuf_generate: 3 | flags: 4 | - GENERATE_GRPC 5 | - GENERATE_DESCRIPTORS 6 | - GENERATE_MOCK_CODE 7 | kwargs: 8 | OUT_VAR: '1' 9 | OUT_DIR: '1' 10 | TARGET: '1' 11 | USAGE_REQUIREMENT: '1' 12 | PROTOS: '*' 13 | IMPORT_DIRS: '*' 14 | EXTRA_ARGS: '*' 15 | doxygen_add_docs: 16 | kwargs: 17 | WORKING_DIRECTORY: '1' 18 | always_wrap: [] 19 | command_case: lower 20 | dangle_parens: false 21 | enable_markup: true 22 | first_comment_is_literal: true 23 | keyword_case: upper 24 | line_ending: unix 25 | line_width: 120 26 | literal_comment_pattern: null 27 | separate_ctrl_name_with_space: false 28 | separate_fn_name_with_space: false 29 | tab_size: 4 30 | autosort: true 31 | -------------------------------------------------------------------------------- /cmake/AsioGrpcCheckBoostVersion.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Dennis Hezel 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | if(NOT DEFINED ASIO_GRPC_BOOST_ASIO_HAS_CO_AWAIT) 16 | try_compile( 17 | ASIO_GRPC_BOOST_ASIO_HAS_CO_AWAIT "${CMAKE_CURRENT_BINARY_DIR}" 18 | "${CMAKE_CURRENT_LIST_DIR}/check_boost_asio_has_co_await.cpp" 19 | CMAKE_FLAGS "-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}" 20 | LINK_LIBRARIES Boost::headers CXX_STANDARD 20 CXX_STANDARD_REQUIRED on) 21 | endif() 22 | 23 | message(STATUS "ASIO_GRPC_BOOST_ASIO_HAS_CO_AWAIT: ${ASIO_GRPC_BOOST_ASIO_HAS_CO_AWAIT}") 24 | -------------------------------------------------------------------------------- /cmake/AsioGrpcCheckStdPmr.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Dennis Hezel 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | if(NOT DEFINED ASIO_GRPC_HAS_STD_PMR) 16 | try_compile( 17 | ASIO_GRPC_HAS_STD_PMR "${CMAKE_CURRENT_BINARY_DIR}" 18 | "${CMAKE_CURRENT_LIST_DIR}/check_std_pmr.cpp" 19 | CMAKE_FLAGS "-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}" CXX_STANDARD 17 CXX_STANDARD_REQUIRED on) 20 | endif() 21 | 22 | message(STATUS "ASIO_GRPC_HAS_STD_PMR: ${ASIO_GRPC_HAS_STD_PMR}") 23 | -------------------------------------------------------------------------------- /cmake/AsioGrpcGitHooksInstaller.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Dennis Hezel 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | file( 16 | COPY "${GIT_HOOKS_SOURCE_DIR}/pre-commit" "${GIT_HOOKS_SOURCE_DIR}/AsioGrpcPreCommit.cmake" 17 | DESTINATION "${GIT_HOOKS_TARGET_DIR}" 18 | FILE_PERMISSIONS 19 | OWNER_READ 20 | GROUP_READ 21 | WORLD_READ 22 | OWNER_WRITE 23 | OWNER_EXECUTE 24 | GROUP_EXECUTE 25 | WORLD_EXECUTE) 26 | -------------------------------------------------------------------------------- /cmake/AsioGrpcHunter.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Dennis Hezel 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | set(HUNTER_PACKAGES gRPC) 16 | 17 | if(ASIO_GRPC_HUNTER_BACKEND_BOOST_ASIO OR ASIO_GRPC_BUILD_TESTS) 18 | list(APPEND HUNTER_PACKAGES Boost) 19 | endif() 20 | 21 | if(ASIO_GRPC_HUNTER_BACKEND_STANDALONE_ASIO OR ASIO_GRPC_BUILD_TESTS) 22 | list(APPEND HUNTER_PACKAGES asio) 23 | endif() 24 | 25 | if(ASIO_GRPC_BUILD_TESTS) 26 | list(APPEND HUNTER_PACKAGES doctest) 27 | list(APPEND HUNTER_Boost_COMPONENTS coroutine thread filesystem) 28 | endif() 29 | 30 | include(FetchContent) 31 | fetchcontent_declare(SetupHunter GIT_REPOSITORY https://github.com/cpp-pm/gate) 32 | fetchcontent_makeavailable(SetupHunter) 33 | -------------------------------------------------------------------------------- /cmake/AsioGrpcInstallation.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Dennis Hezel 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/asio-grpcConfig.cmake.in" 16 | "${CMAKE_CURRENT_BINARY_DIR}/generated/${PROJECT_NAME}Config.cmake" @ONLY) 17 | 18 | include(CMakePackageConfigHelpers) 19 | write_basic_package_version_file( 20 | "${CMAKE_CURRENT_BINARY_DIR}/generated/${PROJECT_NAME}ConfigVersion.cmake" ARCH_INDEPENDENT 21 | VERSION "${PROJECT_VERSION}" 22 | COMPATIBILITY SameMajorVersion) 23 | 24 | install( 25 | FILES "${CMAKE_CURRENT_BINARY_DIR}/generated/${PROJECT_NAME}ConfigVersion.cmake" 26 | "${CMAKE_CURRENT_BINARY_DIR}/generated/${PROJECT_NAME}Config.cmake" 27 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake/AsioGrpcProtobufGenerator.cmake" 28 | DESTINATION "${ASIO_GRPC_CMAKE_CONFIG_INSTALL_DIR}") 29 | 30 | install( 31 | FILES "${ASIO_GRPC_PROJECT_ROOT}/asio-grpc.natvis" 32 | DESTINATION "${ASIO_GRPC_CMAKE_CONFIG_INSTALL_DIR}" 33 | RENAME "${PROJECT_NAME}.natvis") 34 | 35 | install(TARGETS asio-grpc asio-grpc-standalone-asio asio-grpc-unifex asio-grpc-stdexec EXPORT ${PROJECT_NAME}Targets) 36 | 37 | install( 38 | EXPORT ${PROJECT_NAME}Targets 39 | NAMESPACE ${PROJECT_NAME}:: 40 | DESTINATION "${ASIO_GRPC_CMAKE_CONFIG_INSTALL_DIR}") 41 | 42 | install( 43 | DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src/agrpc" 44 | TYPE INCLUDE 45 | FILES_MATCHING 46 | PATTERN "*.hpp") 47 | -------------------------------------------------------------------------------- /cmake/AsioGrpcOptionDefaults.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Dennis Hezel 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND "${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS "9") 16 | set(ASIO_GRPC_DEFAULT_ENABLE_CPP20_TESTS_AND_EXAMPLES off) 17 | else() 18 | set(ASIO_GRPC_DEFAULT_ENABLE_CPP20_TESTS_AND_EXAMPLES on) 19 | endif() 20 | -------------------------------------------------------------------------------- /cmake/AsioGrpcProjectTopLevel.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Dennis Hezel 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.21) 16 | set(ASIO_GRPC_PROJECT_IS_TOP_LEVEL ${PROJECT_IS_TOP_LEVEL}) 17 | else() 18 | get_directory_property(_asio_grpc_parent_dir PARENT_DIRECTORY) 19 | if(_asio_grpc_parent_dir) 20 | set(ASIO_GRPC_PROJECT_IS_TOP_LEVEL off) 21 | else() 22 | set(ASIO_GRPC_PROJECT_IS_TOP_LEVEL on) 23 | endif() 24 | endif() 25 | -------------------------------------------------------------------------------- /cmake/asio-grpcConfig.cmake.in: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Dennis Hezel 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") 16 | include("${CMAKE_CURRENT_LIST_DIR}/AsioGrpcProtobufGenerator.cmake") 17 | 18 | if("${CMAKE_GENERATOR}" STRGREATER_EQUAL "Visual Studio") 19 | target_sources(@PROJECT_NAME@::asio-grpc INTERFACE "${CMAKE_CURRENT_LIST_DIR}/asio-grpc.natvis") 20 | target_sources(@PROJECT_NAME@::asio-grpc-standalone-asio INTERFACE "${CMAKE_CURRENT_LIST_DIR}/asio-grpc.natvis") 21 | target_sources(@PROJECT_NAME@::asio-grpc-unifex INTERFACE "${CMAKE_CURRENT_LIST_DIR}/asio-grpc.natvis") 22 | target_sources(@PROJECT_NAME@::asio-grpc-stdexec INTERFACE "${CMAKE_CURRENT_LIST_DIR}/asio-grpc.natvis") 23 | endif() 24 | 25 | if(ASIO_GRPC_DISABLE_AUTOLINK) 26 | return() 27 | endif() 28 | 29 | include(CMakeFindDependencyMacro) 30 | 31 | find_dependency(gRPC) 32 | if(TARGET "gRPC::grpc++") 33 | set_target_properties(@PROJECT_NAME@::asio-grpc PROPERTIES INTERFACE_LINK_LIBRARIES "gRPC::grpc++") 34 | set_target_properties(@PROJECT_NAME@::asio-grpc-standalone-asio PROPERTIES INTERFACE_LINK_LIBRARIES "gRPC::grpc++") 35 | set_target_properties(@PROJECT_NAME@::asio-grpc-unifex PROPERTIES INTERFACE_LINK_LIBRARIES "gRPC::grpc++") 36 | set_target_properties(@PROJECT_NAME@::asio-grpc-stdexec PROPERTIES INTERFACE_LINK_LIBRARIES "gRPC::grpc++") 37 | endif() 38 | -------------------------------------------------------------------------------- /cmake/check_boost_asio_has_co_await.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | int main() 18 | { 19 | #ifndef BOOST_ASIO_HAS_CO_AWAIT 20 | static_assert(false, ""); 21 | #endif 22 | } -------------------------------------------------------------------------------- /cmake/check_std_pmr.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | int main() { (void)std::pmr::new_delete_resource(); } -------------------------------------------------------------------------------- /cmake/hooks/AsioGrpcPreCommit.cmake.in: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Dennis Hezel 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Do not ignore empty list items 16 | cmake_policy(SET CMP0007 NEW) 17 | 18 | execute_process( 19 | COMMAND "@GIT_EXECUTABLE@" "diff-index" "--cached" "--name-only" "--diff-filter=ACMRT" "HEAD" 20 | OUTPUT_VARIABLE _git_output 21 | WORKING_DIRECTORY "@CMAKE_SOURCE_DIR@") 22 | 23 | string(REPLACE "\r" "" _git_output_no_carriage "${_git_output}") 24 | string(REPLACE "\n" ";" _git_output_list "${_git_output_no_carriage}") 25 | list(REMOVE_ITEM _git_output_list "") 26 | 27 | # process CMake files 28 | foreach(_git_out IN LISTS _git_output_list) 29 | string(REGEX MATCHALL ".*\\.cmake\\.in\$|.*\\.cmake\$|.*CMakeLists.txt\$" _file "${_git_out}") 30 | 31 | if(NOT "${_file}" STREQUAL "") 32 | execute_process(COMMAND "@ASIO_GRPC_CMAKE_FORMAT_PROGRAM@" "-i" "${_file}" 33 | WORKING_DIRECTORY "@CMAKE_SOURCE_DIR@") 34 | 35 | execute_process(COMMAND "@GIT_EXECUTABLE@" "add" "${_file}" WORKING_DIRECTORY "@CMAKE_SOURCE_DIR@") 36 | endif() 37 | endforeach() 38 | 39 | # process cpp files 40 | foreach(_git_out IN LISTS _git_output_list) 41 | string(REGEX MATCHALL ".*\\.tpp\$|.*\\.hpp\$|.*\\.cpp\$|.*\\.proto\$|.*\\.h\$|.*\\.c\$" _file "${_git_out}") 42 | 43 | if(NOT "${_file}" STREQUAL "") 44 | execute_process(COMMAND "@ASIO_GRPC_CLANG_FORMAT_PROGRAM@" "-i" "-style=file" "${_file}" 45 | WORKING_DIRECTORY "@CMAKE_SOURCE_DIR@") 46 | 47 | execute_process(COMMAND "@GIT_EXECUTABLE@" "add" "${_file}" WORKING_DIRECTORY "@CMAKE_SOURCE_DIR@") 48 | endif() 49 | endforeach() 50 | -------------------------------------------------------------------------------- /cmake/hooks/pre-commit.in: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | "@CMAKE_COMMAND@" -P "@ASIO_GRPC_GIT_HOOKS_TARGET_DIR@/AsioGrpcPreCommit.cmake" -------------------------------------------------------------------------------- /deps/abseil/chord.patch: -------------------------------------------------------------------------------- 1 | diff --git a/absl/strings/cord.h b/absl/strings/cord.h 2 | index 1d8fcd37..2e8fd500 100644 3 | --- a/absl/strings/cord.h 4 | +++ b/absl/strings/cord.h 5 | @@ -849,8 +849,8 @@ class Cord { 6 | friend bool operator==(const Cord& lhs, const Cord& rhs); 7 | friend bool operator==(const Cord& lhs, absl::string_view rhs); 8 | 9 | -#ifdef __cpp_impl_three_way_comparison 10 | - 11 | +#if defined(__cpp_impl_three_way_comparison) && \ 12 | + defined(__cpp_lib_three_way_comparison) 13 | // Cords support comparison with other Cords and string_views via operator< 14 | // and others; here we provide a wrapper for the C++20 three-way comparison 15 | // <=> operator. 16 | -------------------------------------------------------------------------------- /deps/abseil/vcpkg.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "abseil", 3 | "version": "20240722.0", 4 | "port-version": 1, 5 | "description": [ 6 | "Abseil is an open-source collection of C++ library code designed to augment the C++ standard library. The Abseil library code is collected from Google's own C++ code base, has been extensively tested and used in production, and is the same code we depend on in our daily coding lives.", 7 | "In some cases, Abseil provides pieces missing from the C++ standard; in others, Abseil provides alternatives to the standard for special needs we've found through usage in the Google code base. We denote those cases clearly within the library code we provide you.", 8 | "Abseil is not meant to be a competitor to the standard library; we've just found that many of these utilities serve a purpose within our code base, and we now want to provide those resources to the C++ community as a whole." 9 | ], 10 | "homepage": "https://github.com/abseil/abseil-cpp", 11 | "license": "Apache-2.0", 12 | "dependencies": [ 13 | { 14 | "name": "vcpkg-cmake", 15 | "host": true 16 | }, 17 | { 18 | "name": "vcpkg-cmake-config", 19 | "host": true 20 | } 21 | ], 22 | "features": { 23 | "cxx17": { 24 | "description": "Enable compiler C++17." 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /deps/asio/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.8) 2 | project(asio) 3 | 4 | add_library(asio INTERFACE) 5 | 6 | # Export target 7 | install( 8 | TARGETS asio 9 | EXPORT asio 10 | INCLUDES 11 | DESTINATION include/) 12 | 13 | install( 14 | EXPORT asio 15 | DESTINATION "share/asio" 16 | FILE asio-targets.cmake) 17 | 18 | install( 19 | DIRECTORY asio/include/asio 20 | DESTINATION include/ 21 | FILES_MATCHING 22 | PATTERN "*.hpp" 23 | PATTERN "*.ipp") 24 | 25 | install(FILES asio/include/asio.hpp DESTINATION include/) 26 | -------------------------------------------------------------------------------- /deps/asio/asio-config.cmake: -------------------------------------------------------------------------------- 1 | include("${CMAKE_CURRENT_LIST_DIR}/asio-targets.cmake") 2 | 3 | if(NOT TARGET asio::asio) 4 | add_library(asio::asio INTERFACE IMPORTED) 5 | target_link_libraries(asio::asio INTERFACE asio) 6 | endif() 7 | 8 | get_target_property(_ASIO_INCLUDE_DIR asio INTERFACE_INCLUDE_DIRECTORIES) 9 | set(ASIO_INCLUDE_DIR "${_ASIO_INCLUDE_DIR}") 10 | -------------------------------------------------------------------------------- /deps/asio/portfile.cmake: -------------------------------------------------------------------------------- 1 | #header-only library 2 | 3 | vcpkg_from_github( 4 | OUT_SOURCE_PATH 5 | SOURCE_PATH 6 | REPO 7 | chriskohlhoff/asio 8 | REF 9 | asio-1-17-0 10 | SHA512 11 | d99bbf2c4628e0ce43b21ccf5d4f75180c05e5fd84e394dd800f340b1c607f663b43f442253f5cac53394aee3b6bd17aa2082cd10637ac952a83f154ffab332e 12 | HEAD_REF 13 | master) 14 | 15 | # Always use "ASIO_STANDALONE" to avoid boost dependency 16 | vcpkg_replace_string("${SOURCE_PATH}/asio/include/asio/detail/config.hpp" "defined(ASIO_STANDALONE)" 17 | "!defined(VCPKG_DISABLE_ASIO_STANDALONE)") 18 | 19 | # CMake install 20 | file(COPY "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt" DESTINATION "${SOURCE_PATH}") 21 | vcpkg_cmake_configure(SOURCE_PATH "${SOURCE_PATH}") 22 | vcpkg_cmake_install() 23 | 24 | vcpkg_cmake_config_fixup() 25 | file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/asio-config.cmake" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}") 26 | file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug") 27 | 28 | # Handle copyright 29 | vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/asio/LICENSE_1_0.txt") 30 | -------------------------------------------------------------------------------- /deps/asio/vcpkg.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "asio", 3 | "version": "1.17.0", 4 | "description": "Asio is a cross-platform C++ library for network and low-level I/O programming that provides developers with a consistent asynchronous model using a modern C++ approach.", 5 | "homepage": "https://github.com/chriskohlhoff/asio", 6 | "documentation": "https://think-async.com/Asio/asio-1.17.0/doc/", 7 | "license": "BSL-1.0", 8 | "dependencies": [ 9 | { 10 | "name": "vcpkg-cmake", 11 | "host": true 12 | }, 13 | { 14 | "name": "vcpkg-cmake-config", 15 | "host": true 16 | } 17 | ], 18 | "features": { 19 | "coroutine": { 20 | "description": "Boost.Coroutine (optional) if you use spawn() to launch coroutines", 21 | "dependencies": [ 22 | "boost-coroutine" 23 | ] 24 | }, 25 | "openssl": { 26 | "description": "OpenSSL (optional) if you use Asio's SSL support.", 27 | "dependencies": [ 28 | "openssl" 29 | ] 30 | }, 31 | "regex": { 32 | "description": "Boost.Regex (optional) if you use any of the read_until() or async_read_until() overloads that take a boost::regex parameter.", 33 | "dependencies": [ 34 | "boost-regex" 35 | ] 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /deps/protobuf/compare.patch: -------------------------------------------------------------------------------- 1 | diff --git a/src/google/protobuf/message_lite.h b/src/google/protobuf/message_lite.h 2 | index cae4e6bbe..ab5da650c 100644 3 | --- a/src/google/protobuf/message_lite.h 4 | +++ b/src/google/protobuf/message_lite.h 5 | @@ -22,6 +22,9 @@ 6 | #include 7 | #include 8 | #include 9 | +#if defined(__cpp_lib_three_way_comparison) 10 | +#include 11 | +#endif 12 | 13 | #include "absl/base/attributes.h" 14 | #include "absl/log/absl_check.h" 15 | @@ -907,7 +910,7 @@ class TypeId { 16 | return a.data_ >= b.data_; 17 | } 18 | 19 | -#if defined(__cpp_impl_three_way_comparison) && \ 20 | +#if defined (__cpp_lib_three_way_comparison) && defined(__cpp_impl_three_way_comparison) && \ 21 | __cpp_impl_three_way_comparison >= 201907L 22 | friend constexpr auto operator<=>(TypeId a, TypeId b) { 23 | return a.data_ <=> b.data_; 24 | -------------------------------------------------------------------------------- /deps/protobuf/fix-arm64-msvc.patch: -------------------------------------------------------------------------------- 1 | diff --git a/src/google/protobuf/parse_context.h b/src/google/protobuf/parse_context.h 2 | index d40e71c1d..22ed8212d 100644 3 | --- a/src/google/protobuf/parse_context.h 4 | +++ b/src/google/protobuf/parse_context.h 5 | @@ -635,7 +635,7 @@ inline const char* VarintParseSlow(const char* p, uint32_t res, uint64_t* out) { 6 | return tmp.first; 7 | } 8 | 9 | -#ifdef __aarch64__ 10 | +#if defined(__aarch64__) && !defined(_MSC_VER) 11 | // Generally, speaking, the ARM-optimized Varint decode algorithm is to extract 12 | // and concatenate all potentially valid data bits, compute the actual length 13 | // of the Varint, and mask off the data bits which are not actually part of the 14 | @@ -866,7 +866,7 @@ static const char* VarintParseSlowArm(const char* p, uint64_t* out, 15 | // The caller must ensure that p points to at least 10 valid bytes. 16 | template 17 | PROTOBUF_NODISCARD const char* VarintParse(const char* p, T* out) { 18 | -#if defined(__aarch64__) && defined(ABSL_IS_LITTLE_ENDIAN) 19 | +#if defined(__aarch64__) && defined(ABSL_IS_LITTLE_ENDIAN) && !defined(_MSC_VER) 20 | // This optimization is not supported in big endian mode 21 | uint64_t first8; 22 | std::memcpy(&first8, p, sizeof(first8)); 23 | -------------------------------------------------------------------------------- /deps/protobuf/fix-default-proto-file-path.patch: -------------------------------------------------------------------------------- 1 | diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc 2 | index cd95c8b41..d4825180d 100644 3 | --- a/src/google/protobuf/compiler/command_line_interface.cc 4 | +++ b/src/google/protobuf/compiler/command_line_interface.cc 5 | @@ -272,12 +272,15 @@ void AddDefaultProtoPaths( 6 | paths->emplace_back("", std::move(include_path)); 7 | return; 8 | } 9 | - // Check if the upper level directory has an "include" subdirectory. 10 | + // change "'$/bin' is next to 'include'" assumption to "'$/bin/tools' is next to 'include'" 11 | + for (int i = 0; i < 2; i++) 12 | + { 13 | pos = path.find_last_of("/\\"); 14 | if (pos == std::string::npos || pos == 0) { 15 | return; 16 | } 17 | path = path.substr(0, pos); 18 | + } 19 | include_path = absl::StrCat(path, "/include"); 20 | if (IsInstalledProtoPath(include_path)) { 21 | paths->emplace_back("", std::move(include_path)); 22 | -------------------------------------------------------------------------------- /deps/protobuf/fix-install-dirs.patch: -------------------------------------------------------------------------------- 1 | diff --git a/CMakeLists.txt b/CMakeLists.txt 2 | index 540c12253..320aaf72d 100644 3 | --- a/CMakeLists.txt 4 | +++ b/CMakeLists.txt 5 | @@ -13,6 +13,7 @@ endif() 6 | 7 | # Project 8 | project(protobuf C CXX) 9 | +include(GNUInstallDirs) 10 | 11 | if(protobuf_DEPRECATED_CMAKE_SUBDIRECTORY_USAGE) 12 | if(CMAKE_PROJECT_NAME STREQUAL "protobuf") 13 | -------------------------------------------------------------------------------- /deps/protobuf/fix-static-build.patch: -------------------------------------------------------------------------------- 1 | diff --git a/cmake/install.cmake b/cmake/install.cmake 2 | index 65765ca29..f5ad69102 100644 3 | --- a/cmake/install.cmake 4 | +++ b/cmake/install.cmake 5 | @@ -61,7 +61,7 @@ if (protobuf_BUILD_PROTOC_BINARIES) 6 | endforeach () 7 | endif () 8 | foreach (binary IN LISTS _protobuf_binaries) 9 | - if (UNIX AND NOT APPLE) 10 | + if (UNIX AND NOT APPLE AND NOT protobuf_MSVC_STATIC_RUNTIME) 11 | set_property(TARGET ${binary} 12 | PROPERTY INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}") 13 | elseif (APPLE) 14 | @@ -81,7 +81,6 @@ set(protobuf_HEADERS 15 | ${cpp_features_proto_proto_srcs} 16 | ${descriptor_proto_proto_srcs} 17 | ${plugin_proto_proto_srcs} 18 | - ${java_features_proto_proto_srcs} 19 | ) 20 | if (protobuf_BUILD_LIBUPB) 21 | list(APPEND protobuf_HEADERS ${libupb_hdrs}) 22 | -------------------------------------------------------------------------------- /deps/protobuf/protobuf-targets-vcpkg-protoc.cmake: -------------------------------------------------------------------------------- 1 | # Create imported target protobuf::protoc 2 | add_executable(protobuf::protoc IMPORTED) 3 | 4 | # Import target "protobuf::protoc" for configuration "Release" 5 | set_property( 6 | TARGET protobuf::protoc 7 | APPEND 8 | PROPERTY IMPORTED_CONFIGURATIONS RELEASE) 9 | set_target_properties(protobuf::protoc PROPERTIES IMPORTED_LOCATION_RELEASE "${Protobuf_PROTOC_EXECUTABLE}") 10 | -------------------------------------------------------------------------------- /deps/protobuf/static-assert.patch: -------------------------------------------------------------------------------- 1 | diff --git a/src/google/protobuf/port.h b/src/google/protobuf/port.h 2 | index 182f5786f..a6f292f15 100644 3 | --- a/src/google/protobuf/port.h 4 | +++ b/src/google/protobuf/port.h 5 | @@ -173,10 +173,6 @@ void AssertDownCast(From* from) { 6 | #if defined(__cpp_concepts) 7 | // Check that this function is not used to downcast message types. 8 | // For those we should use {Down,Dynamic}CastTo{Message,Generated}. 9 | - static_assert(!requires { 10 | - std::derived_from, 11 | - typename std::remove_pointer_t::MessageLite>; 12 | - }); 13 | #endif 14 | 15 | #if PROTOBUF_RTTI 16 | -------------------------------------------------------------------------------- /deps/protobuf/vcpkg-cmake-wrapper.cmake: -------------------------------------------------------------------------------- 1 | find_program( 2 | Protobuf_PROTOC_EXECUTABLE 3 | NAMES protoc 4 | PATHS "${CMAKE_CURRENT_LIST_DIR}/../../../@HOST_TRIPLET@/tools/protobuf" 5 | NO_DEFAULT_PATH) 6 | 7 | _find_package(${ARGS} CONFIG) 8 | -------------------------------------------------------------------------------- /deps/protobuf/vcpkg.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "protobuf", 3 | "version": "5.28.3", 4 | "port-version": 1, 5 | "description": "Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data.", 6 | "homepage": "https://github.com/protocolbuffers/protobuf", 7 | "license": "BSD-3-Clause", 8 | "dependencies": [ 9 | "abseil", 10 | { 11 | "name": "protobuf", 12 | "host": true 13 | }, 14 | "utf8-range", 15 | { 16 | "name": "vcpkg-cmake", 17 | "host": true 18 | }, 19 | { 20 | "name": "vcpkg-cmake-config", 21 | "host": true 22 | } 23 | ], 24 | "features": { 25 | "zlib": { 26 | "description": "ZLib based features like Gzip streams", 27 | "dependencies": [ 28 | "zlib" 29 | ] 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /deps/stdexec/fix-version.patch: -------------------------------------------------------------------------------- 1 | diff --git a/CMakeLists.txt b/CMakeLists.txt 2 | index 8e29cfed..f2ac5c01 100644 3 | --- a/CMakeLists.txt 4 | +++ b/CMakeLists.txt 5 | @@ -42,7 +42,7 @@ if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/execution.bs) 6 | ${CMAKE_CURRENT_BINARY_DIR}/execution.bs) 7 | endif() 8 | file(STRINGS "${CMAKE_CURRENT_BINARY_DIR}/execution.bs" STD_EXECUTION_BS_REVISION_LINE REGEX "Revision: [0-9]+") 9 | -string(REGEX REPLACE "Revision: ([0-9]+)" "\\1" STD_EXECUTION_BS_REVISION ${STD_EXECUTION_BS_REVISION_LINE}) 10 | +string(REGEX REPLACE "Revision: ([0-9]+).*" "\\1" STD_EXECUTION_BS_REVISION ${STD_EXECUTION_BS_REVISION_LINE}) 11 | 12 | # nvc++ isn't supported by (s)ccache yet, so unset these before the `project()` 13 | # call so CMake's CXX compiler detection doesn't throw attempting to use it 14 | @@ -543,7 +543,7 @@ endif() 15 | 16 | include(CPack) 17 | 18 | -install(TARGETS stdexec system_context 19 | +install(TARGETS stdexec 20 | EXPORT stdexec-exports 21 | FILE_SET headers 22 | FILE_SET version_config) 23 | -------------------------------------------------------------------------------- /deps/stdexec/vcpkg.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "stdexec", 3 | "version-date": "2025-04-08", 4 | "description": "stdexec is an experimental reference implementation of the Senders model of asynchronous programming proposed by P2300 - std::execution for adoption into the C++ Standard.", 5 | "homepage": "https://github.com/NVIDIA/stdexec", 6 | "license": "Apache-2.0", 7 | "dependencies": [ 8 | { 9 | "name": "vcpkg-cmake", 10 | "host": true 11 | }, 12 | { 13 | "name": "vcpkg-cmake-config", 14 | "host": true 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /doc/client_rpc_cheat_sheet.md: -------------------------------------------------------------------------------- 1 | # Client rpc cheat sheet 2 | 3 | @tableofcontents 4 | 5 | The code below is based on [example.proto](https://github.com/Tradias/asio-grpc/blob/d4bdcc0a06389127bb649ae4ea68185b928a5264/example/proto/example/v1/example.proto). 6 | 7 | A single-threaded gRPC client: 8 | 9 | @snippet client.cpp client-main-cheat-sheet 10 | 11 | ## Unary rpc 12 | 13 | @snippet client_rpc.cpp client-rpc-unary 14 | 15 | ## Client-streaming rpc 16 | 17 | @snippet client_rpc.cpp client-rpc-client-streaming 18 | 19 | ## Server-streaming rpc 20 | 21 | @snippet client_rpc.cpp client-rpc-server-streaming 22 | 23 | ## Bidirectional-streaming rpc 24 | 25 | @snippet client_rpc.cpp client-rpc-bidirectional-streaming 26 | -------------------------------------------------------------------------------- /doc/cmake_protobuf_generate.md: -------------------------------------------------------------------------------- 1 | # CMake protobuf generate 2 | 3 | @snippet{doc} AsioGrpcProtobufGenerator.cmake asio_grpc_protobuf_generate 4 | 5 | ### Example 6 | 7 | Given a CMake target called `target-option`: 8 | 9 | @snippet test/cmake/superbuild/src/CMakeLists.txt asio_grpc_protobuf_generate-example 10 | 11 | Compiling `target-option` will cause the generation and compilation of: 12 | 13 | * `${CMAKE_CURRENT_BINARY_DIR}/target/target.pb.h` 14 | * `${CMAKE_CURRENT_BINARY_DIR}/target/target.pb.cc` 15 | * `${CMAKE_CURRENT_BINARY_DIR}/target/target.grpc.pb.h` 16 | * `${CMAKE_CURRENT_BINARY_DIR}/target/target.grpc.pb.cc` 17 | * `${CMAKE_CURRENT_BINARY_DIR}/target/target_mock.grpc.pb.h` 18 | 19 | whenever `${CMAKE_CURRENT_SOURCE_DIR}/proto/target.proto` has been modified. 20 | -------------------------------------------------------------------------------- /doc/completion_token.md: -------------------------------------------------------------------------------- 1 | # Completion token 2 | 3 | The last argument to all async functions in this library is a [CompletionToken](https://www.boost.org/doc/libs/1_86_0/doc/html/boost_asio/reference/asynchronous_operations.html#boost_asio.reference.asynchronous_operations.completion_tokens_and_handlers). It can be used to customize how to receive notification of the completion of the asynchronous operation. Some examples: 4 | 5 | ## Callback 6 | 7 | @snippet alarm.cpp alarm-with-callback 8 | 9 | ## Boost.Coroutine 10 | 11 | @snippet alarm.cpp alarm-with-spawn 12 | 13 | ## use_sender 14 | 15 | `agrpc::use_sender` causes functions in this library to return a [Sender](https://github.com/facebookexperimental/libunifex/blob/main/doc/concepts.md#typedsender-concept). They can for example be combined with `unifex::task` to asynchronously process RPCs using `co_await`. Note when using libunifex or stdexec exclusively then `agrpc::use_sender` is already the default completion token: 16 | 17 | @snippet unifex_client.cpp unifex-server-streaming-client-side 18 | 19 | ## Custom allocator 20 | 21 | Asio-grpc attempts to get the completion handler's associated allocator by calling [asio::get_associated_allocator](https://www.boost.org/doc/libs/1_86_0/doc/html/boost_asio/reference/get_associated_allocator.html) and uses to allocate intermediate storage, typically for the completion handler itself. Prior to invocation of the completion handler all storage is deallocated. 22 | 23 | The associated allocator can be customized using [asio::bind_allocator](https://www.boost.org/doc/libs/1_86_0/doc/html/boost_asio/reference/bind_allocator.html) (since Boost.Asio 1.79): 24 | 25 | @snippet alarm.cpp alarm-with-allocator-aware-awaitable 26 | -------------------------------------------------------------------------------- /doc/custom.css: -------------------------------------------------------------------------------- 1 | html { 2 | --content-maxwidth: 95%; 3 | } -------------------------------------------------------------------------------- /doc/doxygen-awesome-sidebar-only-darkmode-toggle.css: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | 4 | Doxygen Awesome 5 | https://github.com/jothepro/doxygen-awesome-css 6 | 7 | MIT License 8 | 9 | Copyright (c) 2021 - 2023 jothepro 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in all 19 | copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 27 | SOFTWARE. 28 | 29 | */ 30 | 31 | @media screen and (min-width: 768px) { 32 | 33 | #MSearchBox { 34 | width: calc(var(--side-nav-fixed-width) - calc(2 * var(--spacing-medium)) - var(--searchbar-height) - 1px); 35 | } 36 | 37 | #MSearchField { 38 | width: calc(var(--side-nav-fixed-width) - calc(2 * var(--spacing-medium)) - 66px - var(--searchbar-height)); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /doc/index.md: -------------------------------------------------------------------------------- 1 | # asio-grpc 2 | 3 | ## Overview 4 | 5 | Feature overview, installation and performance benchmark can be found on [github](https://github.com/Tradias/asio-grpc). 6 | 7 | * View of the entire API: [agrpc namespace](namespaceagrpc.html) 8 | * (New) Asio'nized gRPC callback API: `agrpc::BasicServerUnaryReactor`, `agrpc::BasicServerReadReactor`, `agrpc::BasicClientUnaryReactor`, `agrpc::BasicClientWriteReactor` 9 | * Main workhorses of this library: `agrpc::GrpcContext`, `agrpc::GrpcExecutor`. 10 | * Asynchronous gRPC clients: [cheat sheet](md_doc_2client__rpc__cheat__sheet.html), `agrpc::ClientRPC`, 11 | * Asynchronous gRPC servers: [cheat sheet](md_doc_2server__rpc__cheat__sheet.html), `agrpc::ServerRPC`, `agrpc::register_awaitable_rpc_handler`, 12 | `agrpc::register_yield_rpc_handler`, `agrpc::register_sender_rpc_handler`, `agrpc::register_callback_rpc_handler`, `agrpc::register_coroutine_rpc_handler` 13 | * GRPC Timer: `agrpc::Alarm` 14 | * Combining GrpcContext and `asio::io_context`: `agrpc::run`, `agrpc::run_completion_queue` 15 | * Faster, drop-in replacement for gRPC's [DefaultHealthCheckService](https://github.com/grpc/grpc/blob/v1.50.1/src/cpp/server/health/default_health_check_service.h): `agrpc::HealthCheckService` 16 | * Writing Rust/Golang [select](https://go.dev/ref/spec#Select_statements)-style code: `agrpc::Waiter` 17 | * Customizing asynchronous completion: [Completion token](md_doc_2completion__token.html) 18 | * Running `protoc` from CMake to generate gRPC source files: [CMake protobuf generate](md_doc_2cmake__protobuf__generate.html) 19 | -------------------------------------------------------------------------------- /doc/server_rpc_cheat_sheet.md: -------------------------------------------------------------------------------- 1 | # Server rpc cheat sheet 2 | 3 | @tableofcontents 4 | 5 | The code below is based on [example.proto](https://github.com/Tradias/asio-grpc/blob/d4bdcc0a06389127bb649ae4ea68185b928a5264/example/proto/example/v1/example.proto). 6 | 7 | A single-threaded gRPC server: 8 | 9 | @snippet server.cpp server-main-cheat-sheet 10 | 11 | ## Unary rpc 12 | 13 | @snippet server_rpc.cpp server-rpc-unary 14 | 15 | ## Client-streaming rpc 16 | 17 | @snippet server_rpc.cpp server-rpc-client-streaming 18 | 19 | ## Server-streaming rpc 20 | 21 | @snippet server_rpc.cpp server-rpc-server-streaming 22 | 23 | ## Bidirectional-streaming rpc 24 | 25 | @snippet server_rpc.cpp server-rpc-bidirectional-streaming 26 | -------------------------------------------------------------------------------- /example/hello-world-client.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "helloworld/helloworld.grpc.pb.h" 16 | #include "helper.hpp" 17 | #include "rethrow_first_arg.hpp" 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | namespace asio = boost::asio; 25 | 26 | int main(int argc, const char** argv) 27 | { 28 | const char* port = argc >= 2 ? argv[1] : "50051"; 29 | const auto host = std::string("localhost:") + port; 30 | 31 | grpc::Status status; 32 | 33 | helloworld::Greeter::Stub stub{grpc::CreateChannel(host, grpc::InsecureChannelCredentials())}; 34 | agrpc::GrpcContext grpc_context; 35 | 36 | asio::co_spawn( 37 | grpc_context, 38 | [&]() -> asio::awaitable 39 | { 40 | using RPC = agrpc::ClientRPC<&helloworld::Greeter::Stub::PrepareAsyncSayHello>; 41 | grpc::ClientContext client_context; 42 | helloworld::HelloRequest request; 43 | request.set_name("world"); 44 | helloworld::HelloReply response; 45 | status = co_await RPC::request(grpc_context, stub, client_context, request, response); 46 | std::cout << status.ok() << " response: " << response.message() << std::endl; 47 | }, 48 | example::RethrowFirstArg{}); 49 | 50 | grpc_context.run(); 51 | 52 | abort_if_not(status.ok()); 53 | } -------------------------------------------------------------------------------- /example/hello-world-server.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "helloworld/helloworld.grpc.pb.h" 16 | #include "rethrow_first_arg.hpp" 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | namespace asio = boost::asio; 23 | 24 | // begin-snippet: server-side-helloworld 25 | 26 | // Server-side hello world which handles exactly one request from the client before shutting down. 27 | 28 | // end-snippet 29 | int main(int argc, const char** argv) 30 | { 31 | const char* port = argc >= 2 ? argv[1] : "50051"; 32 | const auto host = std::string("0.0.0.0:") + port; 33 | 34 | helloworld::Greeter::AsyncService service; 35 | std::unique_ptr server; 36 | 37 | grpc::ServerBuilder builder; 38 | agrpc::GrpcContext grpc_context{builder.AddCompletionQueue()}; 39 | builder.AddListeningPort(host, grpc::InsecureServerCredentials()); 40 | builder.RegisterService(&service); 41 | server = builder.BuildAndStart(); 42 | 43 | using RPC = agrpc::ServerRPC<&helloworld::Greeter::AsyncService::RequestSayHello>; 44 | agrpc::register_awaitable_rpc_handler( 45 | grpc_context, service, 46 | [&](RPC& rpc, helloworld::HelloRequest& request) -> asio::awaitable 47 | { 48 | helloworld::HelloReply response; 49 | response.set_message("Hello " + request.name()); 50 | co_await rpc.finish(response, grpc::Status::OK); 51 | server->Shutdown(); 52 | }, 53 | example::RethrowFirstArg{}); 54 | 55 | grpc_context.run(); 56 | } -------------------------------------------------------------------------------- /example/helper/coro_traits.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef AGRPC_HELPER_CORO_TRAITS_HPP 16 | #define AGRPC_HELPER_CORO_TRAITS_HPP 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | namespace example 23 | { 24 | /* [asio-coro-traits] */ 25 | template > 26 | struct AsioCoroTraits 27 | { 28 | using ReturnType = boost::asio::experimental::coro; 29 | 30 | template 31 | static boost::asio::deferred_t completion_token(RPCHandler&, CompletionHandler&) 32 | { 33 | return {}; 34 | } 35 | 36 | template 37 | static void co_spawn(const IoExecutor& io_executor, RPCHandler&, CompletionHandler& completion_handler, 38 | Function&& function) 39 | { 40 | boost::asio::experimental::co_spawn( 41 | static_cast(function)(boost::asio::get_associated_executor(completion_handler, io_executor)), 42 | boost::asio::detached); 43 | } 44 | }; 45 | /* [asio-coro-traits] */ 46 | } // namespace example 47 | 48 | #endif // AGRPC_HELPER_CORO_TRAITS_HPP 49 | -------------------------------------------------------------------------------- /example/helper/helper.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef AGRPC_EXAMPLE_HELPER_H 16 | #define AGRPC_EXAMPLE_HELPER_H 17 | 18 | #include 19 | #include 20 | 21 | inline void abort_if_not_impl(bool condition, const char* condition_string, const char* file, const long line) 22 | { 23 | if (!condition) 24 | { 25 | std::printf("[%s:%li] Assertion failed: %s\n", file, line, condition_string); 26 | std::abort(); 27 | } 28 | } 29 | 30 | #define abort_if_not(condition) ::abort_if_not_impl((condition), #condition, __FILE__, __LINE__) 31 | 32 | template 33 | void silence_unused(Args&&... args) 34 | { 35 | ((void)args, ...); 36 | } 37 | 38 | #endif // AGRPC_EXAMPLE_HELPER_H 39 | -------------------------------------------------------------------------------- /example/helper/notify_when_done_server_rpc.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef AGRPC_HELPER_NOTIFY_WHEN_DONE_SERVER_RPC_HPP 16 | #define AGRPC_HELPER_NOTIFY_WHEN_DONE_SERVER_RPC_HPP 17 | 18 | #include 19 | 20 | namespace example 21 | { 22 | struct ServerRPCNotifyWhenDoneTraits : agrpc::DefaultServerRPCTraits 23 | { 24 | static constexpr bool NOTIFY_WHEN_DONE = true; 25 | }; 26 | 27 | template 28 | using NotifyWhenDoneServerRPC = agrpc::ServerRPC; 29 | } 30 | 31 | #endif // AGRPC_HELPER_NOTIFY_WHEN_DONE_SERVER_RPC_HPP 32 | -------------------------------------------------------------------------------- /example/helper/rethrow_first_arg.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef AGRPC_HELPER_RETHROW_FIRST_ARG_HPP 16 | #define AGRPC_HELPER_RETHROW_FIRST_ARG_HPP 17 | 18 | #include 19 | 20 | namespace example 21 | { 22 | // Using this as the completion token to functions like asio::co_spawn ensures that exceptions thrown by the coroutine 23 | // are rethrown from grpc_context.run(). 24 | struct RethrowFirstArg 25 | { 26 | template 27 | void operator()(std::exception_ptr ep, T&&...) 28 | { 29 | if (ep) 30 | { 31 | std::rethrow_exception(ep); 32 | } 33 | } 34 | 35 | template 36 | void operator()(T&&...) 37 | { 38 | } 39 | }; 40 | } // namespace example 41 | 42 | #endif // AGRPC_HELPER_RETHROW_FIRST_ARG_HPP 43 | -------------------------------------------------------------------------------- /example/helper/scope_guard.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef AGRPC_HELPER_SCOPE_GUARD_HPP 16 | #define AGRPC_HELPER_SCOPE_GUARD_HPP 17 | 18 | namespace example 19 | { 20 | template 21 | struct ScopeGuard 22 | { 23 | OnExit on_exit; 24 | 25 | explicit ScopeGuard(OnExit on_exit) : on_exit(std::move(on_exit)) {} 26 | 27 | ~ScopeGuard() { on_exit(); } 28 | }; 29 | } // namespace example 30 | 31 | #endif // AGRPC_HELPER_SCOPE_GUARD_HPP 32 | -------------------------------------------------------------------------------- /example/proto/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Dennis Hezel 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | asio_grpc_protobuf_generate( 16 | GENERATE_GRPC GENERATE_MOCK_CODE 17 | OUT_VAR "ASIO_GRPC_EXAMPLE_PROTO_SOURCES" 18 | OUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated" 19 | IMPORT_DIRS "${CMAKE_CURRENT_LIST_DIR}" 20 | PROTOS "${CMAKE_CURRENT_LIST_DIR}/helloworld/helloworld.proto" 21 | "${CMAKE_CURRENT_LIST_DIR}/grpc/health/v1/health.proto" "${CMAKE_CURRENT_LIST_DIR}/example/v1/example.proto" 22 | "${CMAKE_CURRENT_LIST_DIR}/example/v1/example_ext.proto") 23 | 24 | function(asio_grpc_add_example_proto_target _asio_grpc_name) 25 | add_library(${_asio_grpc_name} OBJECT) 26 | 27 | target_sources(${_asio_grpc_name} PRIVATE ${ASIO_GRPC_EXAMPLE_PROTO_SOURCES}) 28 | 29 | target_link_libraries(${_asio_grpc_name} PUBLIC protobuf::libprotobuf asio-grpc-compile-options) 30 | 31 | target_include_directories(${_asio_grpc_name} SYSTEM 32 | PUBLIC "$") 33 | endfunction() 34 | 35 | asio_grpc_add_example_proto_target(asio-grpc-example-protos) 36 | 37 | if(ASIO_GRPC_BOOST_ASIO_HAS_CO_AWAIT AND ASIO_GRPC_ENABLE_CPP20_TESTS_AND_EXAMPLES) 38 | asio_grpc_add_example_proto_target(asio-grpc-example-protos-cpp20) 39 | target_link_libraries(asio-grpc-example-protos-cpp20 PUBLIC asio-grpc-compile-options-cpp20) 40 | endif() 41 | -------------------------------------------------------------------------------- /example/proto/example/v1/example.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /* [example-proto] */ 16 | syntax = "proto3"; 17 | 18 | package example.v1; 19 | 20 | service Example { 21 | rpc ServerStreaming(Request) returns (stream Response) {} 22 | 23 | rpc ClientStreaming(stream Request) returns (Response) {} 24 | 25 | rpc BidirectionalStreaming(stream Request) returns (stream Response) {} 26 | 27 | rpc Unary(Request) returns (Response) {} 28 | } 29 | 30 | message Request { 31 | int32 integer = 1; 32 | } 33 | 34 | message Response { 35 | int32 integer = 1; 36 | } 37 | /* [example-proto] */ 38 | -------------------------------------------------------------------------------- /example/proto/example/v1/example_ext.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package example.v1; 18 | 19 | import "google/protobuf/empty.proto"; 20 | import "example/v1/example.proto"; 21 | 22 | service ExampleExt { 23 | rpc SlowUnary(SlowRequest) returns (google.protobuf.Empty) {} 24 | 25 | rpc Shutdown(google.protobuf.Empty) returns (google.protobuf.Empty) {} 26 | 27 | rpc SendFile(stream SendFileRequest) returns (google.protobuf.Empty) {} 28 | 29 | rpc ServerStreamingNotifyWhenDone(Request) returns (stream Response) {} 30 | } 31 | 32 | message SlowRequest { 33 | int32 delay = 1; 34 | } 35 | 36 | message SendFileRequest { 37 | bytes content = 1; 38 | } -------------------------------------------------------------------------------- /example/proto/helloworld/helloworld.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2015 gRPC authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | option java_multiple_files = true; 18 | option java_package = "io.grpc.examples.helloworld"; 19 | option java_outer_classname = "HelloWorldProto"; 20 | option objc_class_prefix = "HLW"; 21 | 22 | package helloworld; 23 | 24 | // The greeting service definition. 25 | service Greeter { 26 | // Sends a greeting 27 | rpc SayHello(HelloRequest) returns (HelloReply) {} 28 | } 29 | 30 | // The request message containing the user's name. 31 | message HelloRequest { 32 | string name = 1; 33 | } 34 | 35 | // The response message containing the greetings 36 | message HelloReply { 37 | string message = 1; 38 | } -------------------------------------------------------------------------------- /example/snippets/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2024 Dennis Hezel 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | function(asio_grpc_add_documentation _asio_grpc_name) 16 | add_library(${_asio_grpc_name} OBJECT) 17 | 18 | target_sources(${_asio_grpc_name} PRIVATE ${ARGN}) 19 | 20 | target_link_libraries(${_asio_grpc_name} PRIVATE asio-grpc-example-helper asio-grpc-example-protos-cpp20 21 | asio-grpc-compile-options-cpp20) 22 | endfunction() 23 | 24 | if(ASIO_GRPC_BOOST_ASIO_HAS_CO_AWAIT AND ASIO_GRPC_ENABLE_CPP20_TESTS_AND_EXAMPLES) 25 | asio_grpc_add_documentation( 26 | asio-grpc-documentation-boost-asio 27 | "alarm.cpp" 28 | "client.cpp" 29 | "client_callback.cpp" 30 | "client_rpc.cpp" 31 | "server.cpp" 32 | "server_callback.cpp" 33 | "server_rpc.cpp" 34 | "io_context.cpp") 35 | target_link_libraries(asio-grpc-documentation-boost-asio PRIVATE asio-grpc::asio-grpc) 36 | 37 | asio_grpc_add_documentation(asio-grpc-documentation-unifex "unifex_client.cpp" "unifex_server.cpp") 38 | target_link_libraries(asio-grpc-documentation-unifex PRIVATE asio-grpc::asio-grpc-unifex) 39 | endif() 40 | -------------------------------------------------------------------------------- /example/snippets/README.md: -------------------------------------------------------------------------------- 1 | # About this directory 2 | 3 | The examples in this directory act primarily as a template for writing documentation and for you to copy code snippets out of. 4 | They outline all features of the API of asio-grpc, but are not intended to be run as is. 5 | -------------------------------------------------------------------------------- /example/snippets/unifex_client.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "example/v1/example.grpc.pb.h" 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | /* [unifex-server-streaming-client-side] */ 26 | unifex::task server_streaming_example(agrpc::GrpcContext& grpc_context, example::v1::Example::Stub& stub) 27 | { 28 | using RPC = agrpc::ClientRPC<&example::v1::Example::Stub::PrepareAsyncServerStreaming>; 29 | grpc::ClientContext client_context; 30 | RPC::Request request; 31 | RPC rpc{grpc_context}; 32 | co_await rpc.start(stub, request, agrpc::use_sender); 33 | RPC::Response response; 34 | co_await rpc.read(response, agrpc::use_sender); 35 | co_await rpc.finish(agrpc::use_sender); 36 | } 37 | /* [unifex-server-streaming-client-side] */ 38 | 39 | int main() 40 | { 41 | auto stub = 42 | example::v1::Example::NewStub(grpc::CreateChannel("localhost:50051", grpc::InsecureChannelCredentials())); 43 | agrpc::GrpcContext grpc_context; 44 | 45 | unifex::sync_wait(unifex::when_all(server_streaming_example(grpc_context, *stub), 46 | [&]() -> unifex::task 47 | { 48 | grpc_context.run(); 49 | co_return; 50 | }())); 51 | } -------------------------------------------------------------------------------- /example/snippets/unifex_server.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "example/v1/example.grpc.pb.h" 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | /* [server-rpc-unary-sender] */ 23 | auto server_rpc_unary_sender(agrpc::GrpcContext& grpc_context, example::v1::Example::AsyncService& service) 24 | { 25 | using RPC = agrpc::ServerRPC<&example::v1::Example::AsyncService::RequestUnary>; 26 | return agrpc::register_sender_rpc_handler(grpc_context, service, 27 | [](RPC& rpc, RPC::Request& request) 28 | { 29 | return unifex::let_value_with( 30 | [] 31 | { 32 | return RPC::Response{}; 33 | }, 34 | [&](auto& response) 35 | { 36 | response.set_integer(request.integer()); 37 | return rpc.finish(response, grpc::Status::OK); 38 | }); 39 | }); 40 | } 41 | /* [server-rpc-unary-sender] */ 42 | -------------------------------------------------------------------------------- /mdsnippets.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/SimonCropp/MarkdownSnippets/master/schema.json", 3 | "Convention": "InPlaceOverwrite", 4 | "WriteHeader": false, 5 | "ReadOnly": false, 6 | "LinkFormat": "GitHub", 7 | "ExcludeDirectories": [ 8 | "build", 9 | "src" 10 | ], 11 | "MaxWidth": 150 12 | } -------------------------------------------------------------------------------- /sonar-project.properties: -------------------------------------------------------------------------------- 1 | sonar.projectKey=Tradias_asio-grpc 2 | sonar.organization=tradias 3 | 4 | sonar.host.url=https://sonarcloud.io 5 | 6 | # This is the name and version displayed in the SonarCloud UI. 7 | sonar.projectName=asio-grpc 8 | sonar.projectVersion=3.4.3 9 | 10 | # Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. 11 | sonar.sources=src 12 | sonar.tests=test 13 | 14 | # Encoding of the source code. Default is default system encoding 15 | sonar.sourceEncoding=UTF-8 16 | 17 | sonar.cfamily.compile-commands=/github/workspace/build/compile_commands.json 18 | sonar.cfamily.threads=2 19 | sonar.cfamily.cpp20=true 20 | sonar.c.file.suffixes=.c, .h 21 | sonar.cpp.file.suffixes=.cpp, .hpp, ipp 22 | sonar.cfamily.gcov.reportsPath=/github/workspace/build 23 | sonar.coverageReportPaths=/github/workspace/build/sonarqube-coverage.xml 24 | -------------------------------------------------------------------------------- /src/agrpc/asio_grpc.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @file asio_grpc.hpp 17 | * @brief Convenience header 18 | */ 19 | 20 | /** 21 | * @namespace agrpc 22 | * @brief Public namespace 23 | */ 24 | 25 | #ifndef AGRPC_AGRPC_ASIO_GRPC_HPP 26 | #define AGRPC_AGRPC_ASIO_GRPC_HPP 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | 46 | #endif // AGRPC_AGRPC_ASIO_GRPC_HPP 47 | -------------------------------------------------------------------------------- /src/agrpc/default_server_rpc_traits.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef AGRPC_AGRPC_DEFAULT_SERVER_RPC_TRAITS_HPP 16 | #define AGRPC_AGRPC_DEFAULT_SERVER_RPC_TRAITS_HPP 17 | 18 | #include 19 | 20 | AGRPC_NAMESPACE_BEGIN() 21 | 22 | /** 23 | * @brief Default ServerRPC traits 24 | * 25 | * Users that intend to customize ServerRPC traits should publicly inherit from this type to ensure forwards 26 | * compatibility. 27 | * 28 | * Example showing how to enable `ServerRPC::wait_for_done()`: 29 | * 30 | * @code{cpp} 31 | * struct MyTraits : agrpc::DefaultServerRPCTraits 32 | * { 33 | * static constexpr bool NOTIFY_WHEN_DONE = true; 34 | * }; 35 | * 36 | * template 37 | * using MyServerRPC = agrpc::ServerRPC; 38 | * @endcode 39 | */ 40 | struct DefaultServerRPCTraits 41 | { 42 | /** 43 | * @brief Whether the ServerRPC should support `wait_for_done` 44 | */ 45 | static constexpr bool NOTIFY_WHEN_DONE = false; 46 | }; 47 | 48 | AGRPC_NAMESPACE_END 49 | 50 | #include 51 | 52 | #endif // AGRPC_AGRPC_DEFAULT_SERVER_RPC_TRAITS_HPP 53 | -------------------------------------------------------------------------------- /src/agrpc/detail/allocation_type.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef AGRPC_DETAIL_ALLOCATION_TYPE_HPP 16 | #define AGRPC_DETAIL_ALLOCATION_TYPE_HPP 17 | 18 | #include 19 | 20 | AGRPC_NAMESPACE_BEGIN() 21 | 22 | namespace detail 23 | { 24 | enum class AllocationType 25 | { 26 | NONE, 27 | LOCAL, 28 | CUSTOM 29 | }; 30 | } 31 | 32 | AGRPC_NAMESPACE_END 33 | 34 | #endif // AGRPC_DETAIL_ALLOCATION_TYPE_HPP 35 | -------------------------------------------------------------------------------- /src/agrpc/detail/asio_macros.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #if !defined(AGRPC_ASIO_HAS_CANCELLATION_SLOT) && !defined(AGRPC_ASIO_HAS_NEW_SPAWN) && \ 16 | !defined(AGRPC_ASIO_HAS_IMMEDIATE_EXECUTOR) 17 | 18 | #ifdef AGRPC_STANDALONE_ASIO // standalone Asio 19 | #include 20 | 21 | #if (ASIO_VERSION >= 101900) 22 | #define AGRPC_ASIO_HAS_CANCELLATION_SLOT 23 | #endif 24 | 25 | #if (ASIO_VERSION >= 102400) 26 | #define AGRPC_ASIO_HAS_NEW_SPAWN 27 | #endif 28 | 29 | #if (ASIO_VERSION >= 102700) 30 | #define AGRPC_ASIO_HAS_IMMEDIATE_EXECUTOR 31 | #endif 32 | #elif defined(AGRPC_BOOST_ASIO) // Boost.Asio 33 | #include 34 | 35 | #if (BOOST_VERSION >= 107700) 36 | #define AGRPC_ASIO_HAS_CANCELLATION_SLOT 37 | #endif 38 | 39 | #if (BOOST_VERSION >= 108000) 40 | #define AGRPC_ASIO_HAS_NEW_SPAWN 41 | #endif 42 | 43 | #if (BOOST_VERSION >= 108200) 44 | #define AGRPC_ASIO_HAS_IMMEDIATE_EXECUTOR 45 | #endif 46 | #endif 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /src/agrpc/detail/association.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef AGRPC_DETAIL_ASSOCIATION_HPP 16 | #define AGRPC_DETAIL_ASSOCIATION_HPP 17 | 18 | #include 19 | 20 | #if defined(AGRPC_STANDALONE_ASIO) || defined(AGRPC_BOOST_ASIO) 21 | #include 22 | #else 23 | #include 24 | #endif 25 | 26 | #endif // AGRPC_DETAIL_ASSOCIATION_HPP 27 | -------------------------------------------------------------------------------- /src/agrpc/detail/association_asio.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef AGRPC_DETAIL_ASSOCIATION_ASIO_HPP 16 | #define AGRPC_DETAIL_ASSOCIATION_ASIO_HPP 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | AGRPC_NAMESPACE_BEGIN() 25 | 26 | namespace detail 27 | { 28 | struct UncancellableSlot 29 | { 30 | }; 31 | 32 | template 33 | inline constexpr bool IS_CANCELLATION_SLOT = !exec::stoppable_token; 34 | 35 | template 36 | inline constexpr bool IS_STOP_EVER_POSSIBLE_V = !exec::unstoppable_token; 37 | 38 | template <> 39 | inline constexpr bool IS_STOP_EVER_POSSIBLE_V = false; 40 | 41 | template 42 | inline constexpr bool IS_EXECUTOR = asio::is_executor::value || asio::execution::is_executor_v; 43 | 44 | template 45 | using AssociatedExecutorT = asio::associated_executor_t; 46 | 47 | template > 48 | using AssociatedAllocatorT = asio::associated_allocator_t; 49 | 50 | template 51 | decltype(auto) get_executor(const Object& object) noexcept 52 | { 53 | return asio::get_associated_executor(object); 54 | } 55 | 56 | template 57 | decltype(auto) get_allocator(const Object& object) noexcept 58 | { 59 | return asio::get_associated_allocator(object); 60 | } 61 | } // namespace detail 62 | 63 | AGRPC_NAMESPACE_END 64 | 65 | #endif // AGRPC_DETAIL_ASSOCIATION_ASIO_HPP 66 | -------------------------------------------------------------------------------- /src/agrpc/detail/association_execution.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef AGRPC_DETAIL_ASSOCIATION_EXECUTION_HPP 16 | #define AGRPC_DETAIL_ASSOCIATION_EXECUTION_HPP 17 | 18 | #include 19 | 20 | #include 21 | 22 | AGRPC_NAMESPACE_BEGIN() 23 | 24 | namespace detail 25 | { 26 | template 27 | inline constexpr bool IS_CANCELLATION_SLOT = false; 28 | 29 | template 30 | inline constexpr bool IS_STOP_EVER_POSSIBLE_V = !exec::unstoppable_token; 31 | 32 | template 33 | inline constexpr bool IS_EXECUTOR = exec::scheduler; 34 | 35 | template 36 | using AssociatedExecutorT = decltype(exec::get_scheduler(std::declval())); 37 | 38 | template 39 | using AssociatedAllocatorT = decltype(exec::get_allocator(std::declval())); 40 | 41 | inline const auto& get_executor = exec::get_scheduler; 42 | 43 | using exec::get_allocator; 44 | } // namespace detail 45 | 46 | AGRPC_NAMESPACE_END 47 | 48 | #endif // AGRPC_DETAIL_ASSOCIATION_EXECUTION_HPP 49 | -------------------------------------------------------------------------------- /src/agrpc/detail/awaitable.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef AGRPC_ASIO_HAS_CO_AWAIT 16 | 17 | #ifdef AGRPC_STANDALONE_ASIO 18 | #include 19 | 20 | #ifdef ASIO_HAS_CO_AWAIT 21 | #define AGRPC_ASIO_HAS_CO_AWAIT 22 | #endif 23 | #elif defined(AGRPC_BOOST_ASIO) 24 | #include 25 | 26 | #ifdef BOOST_ASIO_HAS_CO_AWAIT 27 | #define AGRPC_ASIO_HAS_CO_AWAIT 28 | #endif 29 | #endif 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/agrpc/detail/backoff.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef AGRPC_DETAIL_BACKOFF_HPP 16 | #define AGRPC_DETAIL_BACKOFF_HPP 17 | 18 | #include 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | AGRPC_NAMESPACE_BEGIN() 26 | 27 | namespace detail 28 | { 29 | using BackoffDelay = std::chrono::nanoseconds; 30 | 31 | template 32 | class Backoff 33 | { 34 | private: 35 | using Delay = detail::BackoffDelay; 36 | using Iteration = std::ptrdiff_t; 37 | 38 | public: 39 | static constexpr Delay MAX_DELAY{MaxDelay}; 40 | static constexpr Iteration ITERATIONS_PER_DELAY{5}; 41 | 42 | Delay next() noexcept 43 | { 44 | ++iterations_; 45 | if (ITERATIONS_PER_DELAY == iterations_) 46 | { 47 | iterations_ = Iteration{}; 48 | increase_delay(); 49 | } 50 | return delay_; 51 | } 52 | 53 | auto reset() noexcept 54 | { 55 | iterations_ = Iteration{}; 56 | delay_ = Delay::zero(); 57 | return delay_; 58 | } 59 | 60 | private: 61 | static constexpr Delay INCREMENT{detail::maximum(Delay::rep{1}, MaxDelay)}; 62 | 63 | void increase_delay() noexcept 64 | { 65 | if (MAX_DELAY > delay_) 66 | { 67 | delay_ += INCREMENT; 68 | } 69 | } 70 | 71 | Delay delay_{Delay::zero()}; 72 | Iteration iterations_{}; 73 | }; 74 | } 75 | 76 | AGRPC_NAMESPACE_END 77 | 78 | #endif // AGRPC_DETAIL_BACKOFF_HPP 79 | -------------------------------------------------------------------------------- /src/agrpc/detail/co_spawn.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef AGRPC_DETAIL_CO_SPAWN_HPP 16 | #define AGRPC_DETAIL_CO_SPAWN_HPP 17 | 18 | #ifdef AGRPC_STANDALONE_ASIO 19 | #include 20 | #include 21 | #elif defined(AGRPC_BOOST_ASIO) 22 | #include 23 | #include 24 | #endif 25 | 26 | #endif // AGRPC_DETAIL_CO_SPAWN_HPP 27 | -------------------------------------------------------------------------------- /src/agrpc/detail/coroutine_traits.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef AGRPC_DETAIL_COROUTINE_TRAITS_HPP 16 | #define AGRPC_DETAIL_COROUTINE_TRAITS_HPP 17 | 18 | #include 19 | 20 | #ifdef AGRPC_ASIO_HAS_CO_AWAIT 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | AGRPC_NAMESPACE_BEGIN() 29 | 30 | namespace detail 31 | { 32 | template 33 | struct CoroutineTraits; 34 | 35 | template 36 | struct CoroutineTraits> 37 | { 38 | using ReturnType = asio::awaitable; 39 | 40 | template 41 | static asio::use_awaitable_t completion_token(RPCHandler&, CompletionHandler&) 42 | { 43 | return {}; 44 | } 45 | 46 | template 47 | static void co_spawn(const IoExecutor& io_executor, RPCHandler&, CompletionHandler& completion_handler, 48 | Function&& function) 49 | { 50 | asio::co_spawn(asio::get_associated_executor(completion_handler, io_executor), 51 | static_cast(function), detail::RethrowFirstArg{}); 52 | } 53 | }; 54 | } 55 | 56 | AGRPC_NAMESPACE_END 57 | 58 | #endif 59 | 60 | #endif // AGRPC_DETAIL_COROUTINE_TRAITS_HPP 61 | -------------------------------------------------------------------------------- /src/agrpc/detail/deallocate_on_complete.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef AGRPC_DETAIL_DEALLOCATE_ON_COMPLETE_HPP 16 | #define AGRPC_DETAIL_DEALLOCATE_ON_COMPLETE_HPP 17 | 18 | #include 19 | 20 | AGRPC_NAMESPACE_BEGIN() 21 | 22 | namespace detail 23 | { 24 | enum class DeallocateOnComplete 25 | { 26 | NO_, 27 | YES_ 28 | }; 29 | } 30 | 31 | AGRPC_NAMESPACE_END 32 | 33 | #endif // AGRPC_DETAIL_DEALLOCATE_ON_COMPLETE_HPP 34 | -------------------------------------------------------------------------------- /src/agrpc/detail/default_completion_token.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef AGRPC_DETAIL_DEFAULT_COMPLETION_TOKEN_HPP 16 | #define AGRPC_DETAIL_DEFAULT_COMPLETION_TOKEN_HPP 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | AGRPC_NAMESPACE_BEGIN() 25 | 26 | namespace detail 27 | { 28 | #if defined(AGRPC_STANDALONE_ASIO) || defined(AGRPC_BOOST_ASIO) 29 | #if defined(AGRPC_UNIFEX) || defined(AGRPC_STDEXEC) 30 | template 31 | using DefaultCompletionTokenT = detail::ConditionalT>, 32 | agrpc::UseSender, asio::default_completion_token_t>; 33 | #else 34 | template 35 | using DefaultCompletionTokenT = asio::default_completion_token_t; 36 | #endif 37 | #else 38 | template 39 | using DefaultCompletionTokenT = agrpc::UseSender; 40 | #endif 41 | } 42 | 43 | AGRPC_NAMESPACE_END 44 | 45 | #endif // AGRPC_DETAIL_DEFAULT_COMPLETION_TOKEN_HPP 46 | -------------------------------------------------------------------------------- /src/agrpc/detail/epilogue.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef AGRPC_GENERATING_DOCUMENTATION 16 | 17 | // config.hpp 18 | #undef AGRPC_UNLIKELY 19 | #undef AGRPC_LIKELY 20 | 21 | #undef AGRPC_TRY 22 | #undef AGRPC_CATCH 23 | 24 | #undef AGRPC_NAMESPACE_BEGIN 25 | 26 | #undef AGRPC_NAMESPACE_END 27 | 28 | // asio_macros.hpp 29 | #undef AGRPC_ASIO_HAS_CANCELLATION_SLOT 30 | #undef AGRPC_ASIO_HAS_NEW_SPAWN 31 | #undef AGRPC_ASIO_HAS_IMMEDIATE_EXECUTOR 32 | 33 | // awaitable.hpp 34 | #undef AGRPC_ASIO_HAS_CO_AWAIT 35 | 36 | #endif -------------------------------------------------------------------------------- /src/agrpc/detail/execution.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef AGRPC_DETAIL_EXECUTION_HPP 16 | #define AGRPC_DETAIL_EXECUTION_HPP 17 | 18 | #include 19 | 20 | #ifdef AGRPC_UNIFEX 21 | #include 22 | #elif defined(AGRPC_STDEXEC) 23 | #include 24 | #elif defined(AGRPC_STANDALONE_ASIO) || defined(AGRPC_BOOST_ASIO) 25 | #include 26 | #endif 27 | 28 | #endif // AGRPC_DETAIL_EXECUTION_HPP 29 | -------------------------------------------------------------------------------- /src/agrpc/detail/functional.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef AGRPC_DETAIL_FUNCTIONAL_HPP 16 | #define AGRPC_DETAIL_FUNCTIONAL_HPP 17 | 18 | #include 19 | 20 | #include 21 | 22 | #include 23 | 24 | AGRPC_NAMESPACE_BEGIN() 25 | 26 | namespace detail 27 | { 28 | template 29 | decltype(auto) invoke(Function&& function, Args&&... args) 30 | { 31 | if constexpr (std::is_same_v(function), 32 | static_cast(args)...))>) 33 | { 34 | std::invoke(static_cast(function), static_cast(args)...); 35 | return detail::Empty{}; 36 | } 37 | else 38 | { 39 | return std::invoke(static_cast(function), static_cast(args)...); 40 | } 41 | } 42 | } 43 | 44 | AGRPC_NAMESPACE_END 45 | 46 | #endif // AGRPC_DETAIL_FUNCTIONAL_HPP 47 | -------------------------------------------------------------------------------- /src/agrpc/detail/grpc_completion_queue_event.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef AGRPC_DETAIL_GRPC_COMPLETION_QUEUE_EVENT_HPP 16 | #define AGRPC_DETAIL_GRPC_COMPLETION_QUEUE_EVENT_HPP 17 | 18 | #include 19 | 20 | AGRPC_NAMESPACE_BEGIN() 21 | 22 | namespace detail 23 | { 24 | struct GrpcCompletionQueueEvent 25 | { 26 | void* tag_; 27 | bool ok_; 28 | }; 29 | } 30 | 31 | AGRPC_NAMESPACE_END 32 | 33 | #endif // AGRPC_DETAIL_GRPC_COMPLETION_QUEUE_EVENT_HPP 34 | -------------------------------------------------------------------------------- /src/agrpc/detail/grpc_context_local_allocator.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef AGRPC_DETAIL_GRPC_CONTEXT_HPP 16 | #define AGRPC_DETAIL_GRPC_CONTEXT_HPP 17 | 18 | #include 19 | 20 | #include 21 | 22 | AGRPC_NAMESPACE_BEGIN() 23 | 24 | namespace detail 25 | { 26 | using GrpcContextLocalAllocator = detail::PoolResourceAllocator; 27 | 28 | detail::GrpcContextLocalAllocator get_local_allocator() noexcept; 29 | } 30 | 31 | AGRPC_NAMESPACE_END 32 | 33 | #endif // AGRPC_DETAIL_GRPC_CONTEXT_HPP 34 | -------------------------------------------------------------------------------- /src/agrpc/detail/grpc_sender.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef AGRPC_DETAIL_GRPC_SENDER_HPP 16 | #define AGRPC_DETAIL_GRPC_SENDER_HPP 17 | 18 | #include 19 | #include 20 | 21 | #include 22 | 23 | AGRPC_NAMESPACE_BEGIN() 24 | 25 | namespace detail 26 | { 27 | struct GrpcSenderImplementationBase 28 | { 29 | static constexpr bool NEEDS_ON_COMPLETE = false; 30 | 31 | using BaseType = detail::GrpcTagOperationBase; 32 | using Signature = void(bool); 33 | using StopFunction = detail::Empty; 34 | 35 | static void complete(const agrpc::GrpcContext&, bool) noexcept {} 36 | }; 37 | 38 | template 39 | struct GrpcSenderImplementation : detail::GrpcSenderImplementationBase 40 | { 41 | using StopFunction = StopFunctionT; 42 | }; 43 | 44 | template 45 | struct GrpcSenderInitiation 46 | { 47 | auto& stop_function_arg() const noexcept { return initiating_function_; } 48 | 49 | void initiate(agrpc::GrpcContext& grpc_context, void* tag) const { initiating_function_(grpc_context, tag); } 50 | 51 | InitiatingFunction initiating_function_; 52 | }; 53 | } 54 | 55 | AGRPC_NAMESPACE_END 56 | 57 | #endif // AGRPC_DETAIL_GRPC_SENDER_HPP 58 | -------------------------------------------------------------------------------- /src/agrpc/detail/health_check_repeatedly_request.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef AGRPC_DETAIL_HEALTH_CHECK_REPEATEDLY_REQUEST_HPP 16 | #define AGRPC_DETAIL_HEALTH_CHECK_REPEATEDLY_REQUEST_HPP 17 | 18 | #include 19 | #include 20 | 21 | #include 22 | 23 | AGRPC_NAMESPACE_BEGIN() 24 | 25 | namespace detail 26 | { 27 | template 28 | class HealthCheckRepeatedlyRequest : public detail::OperationBase 29 | { 30 | private: 31 | using Base = detail::OperationBase; 32 | 33 | public: 34 | explicit HealthCheckRepeatedlyRequest(agrpc::HealthCheckService& service); 35 | 36 | void start(); 37 | 38 | private: 39 | static void do_request_complete(Base* op, detail::OperationResult result, agrpc::GrpcContext&); 40 | 41 | agrpc::HealthCheckService& service_; 42 | Implementation* impl_; 43 | }; 44 | 45 | using HealthCheckRepeatedlyRequestWatch = detail::HealthCheckRepeatedlyRequest; 46 | 47 | using HealthCheckRepeatedlyRequestCheck = detail::HealthCheckRepeatedlyRequest; 48 | } 49 | 50 | AGRPC_NAMESPACE_END 51 | 52 | #endif // AGRPC_DETAIL_HEALTH_CHECK_REPEATEDLY_REQUEST_HPP 53 | -------------------------------------------------------------------------------- /src/agrpc/detail/intrusive_list_hook.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef AGRPC_DETAIL_INTRUSIVE_LIST_HOOK_HPP 16 | #define AGRPC_DETAIL_INTRUSIVE_LIST_HOOK_HPP 17 | 18 | #include 19 | 20 | AGRPC_NAMESPACE_BEGIN() 21 | 22 | namespace detail 23 | { 24 | template 25 | struct IntrusiveListHook 26 | { 27 | Derived* list_next_; 28 | Derived* list_prev_; 29 | }; 30 | } 31 | 32 | AGRPC_NAMESPACE_END 33 | 34 | #endif // AGRPC_DETAIL_INTRUSIVE_LIST_HOOK_HPP 35 | -------------------------------------------------------------------------------- /src/agrpc/detail/intrusive_stack.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef AGRPC_DETAIL_INTRUSIVE_STACK_HPP 16 | #define AGRPC_DETAIL_INTRUSIVE_STACK_HPP 17 | 18 | #include 19 | 20 | #include 21 | 22 | AGRPC_NAMESPACE_BEGIN() 23 | 24 | namespace detail 25 | { 26 | template 27 | class IntrusiveStack 28 | { 29 | public: 30 | IntrusiveStack() = default; 31 | 32 | IntrusiveStack(const IntrusiveStack&) = delete; 33 | 34 | IntrusiveStack(IntrusiveStack&& other) noexcept : head_(std::exchange(other.head_, nullptr)) {} 35 | 36 | ~IntrusiveStack() = default; 37 | 38 | IntrusiveStack& operator=(const IntrusiveStack&) = delete; 39 | IntrusiveStack& operator=(IntrusiveStack&&) = delete; 40 | 41 | [[nodiscard]] bool empty() const noexcept { return head_ == nullptr; } 42 | 43 | void push_front(T& item) noexcept 44 | { 45 | item.next_ = head_; 46 | head_ = &item; 47 | } 48 | 49 | [[nodiscard]] T& pop_front() noexcept 50 | { 51 | T* item = head_; 52 | head_ = item->next_; 53 | return *item; 54 | } 55 | 56 | private: 57 | T* head_{}; 58 | }; 59 | } 60 | 61 | AGRPC_NAMESPACE_END 62 | 63 | #endif // AGRPC_DETAIL_INTRUSIVE_STACK_HPP 64 | -------------------------------------------------------------------------------- /src/agrpc/detail/listable_pool_resource.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef AGRPC_DETAIL_LISTABLE_POOL_RESOURCE_HPP 16 | #define AGRPC_DETAIL_LISTABLE_POOL_RESOURCE_HPP 17 | 18 | #include 19 | 20 | #include 21 | 22 | AGRPC_NAMESPACE_BEGIN() 23 | 24 | namespace detail 25 | { 26 | struct ListablePoolResource 27 | { 28 | ListablePoolResource* next_; 29 | detail::PoolResource resource_; 30 | }; 31 | } 32 | 33 | AGRPC_NAMESPACE_END 34 | 35 | #endif // AGRPC_DETAIL_LISTABLE_POOL_RESOURCE_HPP 36 | -------------------------------------------------------------------------------- /src/agrpc/detail/manual_reset_event_offset_storage.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef AGRPC_DETAIL_MANUAL_RESET_EVENT_OFFSET_STORAGE_HPP 16 | #define AGRPC_DETAIL_MANUAL_RESET_EVENT_OFFSET_STORAGE_HPP 17 | 18 | #include 19 | #include 20 | 21 | #include 22 | 23 | #include 24 | 25 | AGRPC_NAMESPACE_BEGIN() 26 | 27 | namespace detail 28 | { 29 | template 30 | class ManualResetEventOffsetStorage 31 | { 32 | public: 33 | static constexpr auto OFFSET = Offset; 34 | 35 | void set_value(T&& arg) { value() = static_cast(arg); } 36 | 37 | auto get_value() && noexcept { return detail::Tuple{static_cast(value())}; } 38 | 39 | private: 40 | T& value() noexcept { return *reinterpret_cast(reinterpret_cast(this) + Offset); } 41 | }; 42 | } 43 | 44 | AGRPC_NAMESPACE_END 45 | 46 | #endif // AGRPC_DETAIL_MANUAL_RESET_EVENT_OFFSET_STORAGE_HPP 47 | -------------------------------------------------------------------------------- /src/agrpc/detail/memory.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef AGRPC_DETAIL_MEMORY_HPP 16 | #define AGRPC_DETAIL_MEMORY_HPP 17 | 18 | #include 19 | #include 20 | 21 | #include 22 | 23 | AGRPC_NAMESPACE_BEGIN() 24 | 25 | namespace detail 26 | { 27 | inline constexpr auto MAX_ALIGN = alignof(std::max_align_t); 28 | 29 | struct MaxAlignedData 30 | { 31 | alignas(std::max_align_t) std::byte data_[MAX_ALIGN]; 32 | }; 33 | 34 | inline void* allocate_already_max_aligned(std::size_t size) 35 | { 36 | return std::allocator{}.allocate(size / MAX_ALIGN); 37 | } 38 | 39 | inline void deallocate_already_max_aligned(void* p, std::size_t size) 40 | { 41 | std::allocator{}.deallocate(static_cast(p), size / MAX_ALIGN); 42 | } 43 | 44 | [[nodiscard]] constexpr auto align(std::size_t position, std::size_t alignment) noexcept 45 | { 46 | return (position + alignment - 1u) & ~(alignment - 1u); 47 | } 48 | } 49 | 50 | AGRPC_NAMESPACE_END 51 | 52 | #endif // AGRPC_DETAIL_MEMORY_HPP 53 | -------------------------------------------------------------------------------- /src/agrpc/detail/notify_on_state_change.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef AGRPC_DETAIL_NOTIFY_ON_STATE_CHANGE_HPP 16 | #define AGRPC_DETAIL_NOTIFY_ON_STATE_CHANGE_HPP 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | AGRPC_NAMESPACE_BEGIN() 25 | 26 | namespace detail 27 | { 28 | template 29 | struct NotifyOnStateChangeInitFunction 30 | { 31 | grpc::ChannelInterface& channel_; 32 | Deadline deadline_; 33 | ::grpc_connectivity_state last_observed_; 34 | 35 | void operator()(agrpc::GrpcContext& grpc_context, void* tag) const 36 | { 37 | channel_.NotifyOnStateChange(last_observed_, deadline_, grpc_context.get_completion_queue(), tag); 38 | } 39 | }; 40 | } 41 | 42 | AGRPC_NAMESPACE_END 43 | 44 | #endif // AGRPC_DETAIL_NOTIFY_ON_STATE_CHANGE_HPP 45 | -------------------------------------------------------------------------------- /src/agrpc/detail/offset_manual_reset_event.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef AGRPC_DETAIL_OFFSET_MANUAL_RESET_EVENT_HPP 16 | #define AGRPC_DETAIL_OFFSET_MANUAL_RESET_EVENT_HPP 17 | 18 | #include 19 | #include 20 | 21 | AGRPC_NAMESPACE_BEGIN() 22 | 23 | namespace detail 24 | { 25 | template 26 | struct ManualResetEventOffsetStorageTemplate 27 | { 28 | template 29 | using Type = ManualResetEventOffsetStorage; 30 | }; 31 | 32 | template 33 | using OffsetManualResetEvent = 34 | detail::BasicManualResetEvent::template Type>; 35 | 36 | inline constexpr auto OFFSET_MANUAL_RESET_EVENT_SIZE = sizeof(detail::OffsetManualResetEvent); 37 | } 38 | 39 | AGRPC_NAMESPACE_END 40 | 41 | #endif // AGRPC_DETAIL_OFFSET_MANUAL_RESET_EVENT_HPP 42 | -------------------------------------------------------------------------------- /src/agrpc/detail/pool_resource_allocator.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef AGRPC_DETAIL_POOL_RESOURCE_ALLOCATOR_HPP 16 | #define AGRPC_DETAIL_POOL_RESOURCE_ALLOCATOR_HPP 17 | 18 | #include 19 | 20 | #include 21 | 22 | AGRPC_NAMESPACE_BEGIN() 23 | 24 | namespace detail 25 | { 26 | template 27 | class PoolResourceAllocator 28 | { 29 | public: 30 | using value_type = T; 31 | 32 | PoolResourceAllocator() = default; 33 | 34 | PoolResourceAllocator(const PoolResourceAllocator&) = default; 35 | 36 | template 37 | PoolResourceAllocator(const detail::PoolResourceAllocator&) noexcept 38 | { 39 | } 40 | 41 | PoolResourceAllocator& operator=(const PoolResourceAllocator& other) = default; 42 | 43 | PoolResourceAllocator& operator=(PoolResourceAllocator&& other) = default; 44 | 45 | [[nodiscard]] static T* allocate(std::size_t n); 46 | 47 | static void deallocate(T* p, std::size_t n) noexcept; 48 | 49 | template 50 | friend bool operator==(const PoolResourceAllocator&, const detail::PoolResourceAllocator&) noexcept 51 | { 52 | return true; 53 | } 54 | 55 | template 56 | friend bool operator!=(const PoolResourceAllocator&, const detail::PoolResourceAllocator&) noexcept 57 | { 58 | return false; 59 | } 60 | }; 61 | } 62 | 63 | AGRPC_NAMESPACE_END 64 | 65 | #endif // AGRPC_DETAIL_POOL_RESOURCE_ALLOCATOR_HPP 66 | -------------------------------------------------------------------------------- /src/agrpc/detail/reactor_client_context_base.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef AGRPC_DETAIL_REACTOR_CLIENT_CONTEXT_BASE_HPP 16 | #define AGRPC_DETAIL_REACTOR_CLIENT_CONTEXT_BASE_HPP 17 | 18 | #include 19 | 20 | #include 21 | 22 | AGRPC_NAMESPACE_BEGIN() 23 | 24 | namespace detail 25 | { 26 | class ReactorClientContextBase 27 | { 28 | public: 29 | /** 30 | * @brief Get the underlying `grpc::ClientContext` 31 | */ 32 | [[nodiscard]] grpc::ClientContext& context() noexcept { return client_context_; } 33 | 34 | /** 35 | * @brief Get the underlying `grpc::ClientContext` (const overload) 36 | */ 37 | [[nodiscard]] const grpc::ClientContext& context() const noexcept { return client_context_; } 38 | 39 | private: 40 | grpc::ClientContext client_context_; 41 | }; 42 | } 43 | 44 | AGRPC_NAMESPACE_END 45 | 46 | #endif // AGRPC_DETAIL_REACTOR_CLIENT_CONTEXT_BASE_HPP 47 | -------------------------------------------------------------------------------- /src/agrpc/detail/reactor_executor_base.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef AGRPC_DETAIL_REACTOR_EXECUTOR_BASE_HPP 16 | #define AGRPC_DETAIL_REACTOR_EXECUTOR_BASE_HPP 17 | 18 | #include 19 | 20 | #include 21 | 22 | AGRPC_NAMESPACE_BEGIN() 23 | 24 | namespace detail 25 | { 26 | /** 27 | * @brief Reactor's executor base 28 | * 29 | * @since 3.5.0 30 | */ 31 | template 32 | class ReactorExecutorBase 33 | { 34 | public: 35 | /** 36 | * @brief The executor type 37 | */ 38 | using executor_type = Executor; 39 | 40 | ReactorExecutorBase() {} 41 | 42 | ~ReactorExecutorBase() {} 43 | 44 | /** 45 | * @brief Get the executor 46 | * 47 | * Thread-safe 48 | */ 49 | [[nodiscard]] const Executor& get_executor() const noexcept { return executor_; } 50 | 51 | private: 52 | friend detail::ReactorAccess; 53 | 54 | union 55 | { 56 | Executor executor_; 57 | }; 58 | }; 59 | 60 | template <> 61 | class ReactorExecutorBase 62 | { 63 | }; 64 | 65 | struct ReactorExecutorType 66 | { 67 | template 68 | static Executor get(ReactorExecutorBase*); 69 | }; 70 | 71 | template 72 | using ReactorExecutorTypeT = decltype(ReactorExecutorType::get(static_cast(nullptr))); 73 | } 74 | 75 | AGRPC_NAMESPACE_END 76 | 77 | #endif // AGRPC_DETAIL_REACTOR_EXECUTOR_BASE_HPP 78 | -------------------------------------------------------------------------------- /src/agrpc/detail/reactor_ptr_type.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef AGRPC_DETAIL_REACTOR_PTR_TYPE_HPP 16 | #define AGRPC_DETAIL_REACTOR_PTR_TYPE_HPP 17 | 18 | #include 19 | 20 | #include 21 | 22 | AGRPC_NAMESPACE_BEGIN() 23 | 24 | namespace detail 25 | { 26 | template 27 | struct RefCountedReactorType 28 | { 29 | using Type = Reactor; 30 | }; 31 | 32 | template 33 | struct RefCountedReactorType> 34 | { 35 | using Type = RefCountedServerReactor>; 36 | }; 37 | 38 | template 39 | struct RefCountedReactorType> 40 | { 41 | using Type = RefCountedServerReactor>; 42 | }; 43 | 44 | template 45 | struct RefCountedReactorType> 46 | { 47 | using Type = RefCountedClientReactor>; 48 | }; 49 | 50 | template 51 | struct RefCountedReactorType> 52 | { 53 | using Type = RefCountedClientReactor>; 54 | }; 55 | 56 | template 57 | using RefCountedReactorTypeT = typename RefCountedReactorType::Type; 58 | } 59 | 60 | AGRPC_NAMESPACE_END 61 | 62 | #endif // AGRPC_DETAIL_REACTOR_PTR_TYPE_HPP 63 | -------------------------------------------------------------------------------- /src/agrpc/detail/rethrow_first_arg.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef AGRPC_DETAIL_RETHROW_FIRST_ARG_HPP 16 | #define AGRPC_DETAIL_RETHROW_FIRST_ARG_HPP 17 | 18 | #include 19 | 20 | #include 21 | 22 | AGRPC_NAMESPACE_BEGIN() 23 | 24 | namespace detail 25 | { 26 | struct RethrowFirstArg 27 | { 28 | template 29 | void operator()(const std::exception_ptr& ep, Args&&...) const 30 | { 31 | if AGRPC_UNLIKELY (ep) 32 | { 33 | std::rethrow_exception(ep); 34 | } 35 | } 36 | }; 37 | } 38 | 39 | AGRPC_NAMESPACE_END 40 | 41 | #endif // AGRPC_DETAIL_RETHROW_FIRST_ARG_HPP 42 | -------------------------------------------------------------------------------- /src/agrpc/detail/schedule_sender.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef AGRPC_DETAIL_SCHEDULE_SENDER_HPP 16 | #define AGRPC_DETAIL_SCHEDULE_SENDER_HPP 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | AGRPC_NAMESPACE_BEGIN() 25 | 26 | namespace detail 27 | { 28 | struct ScheduleSenderImplementation 29 | { 30 | static constexpr bool NEEDS_ON_COMPLETE = false; 31 | 32 | using BaseType = detail::NoArgOperationBase; 33 | using Signature = void(); 34 | using StopFunction = detail::Empty; 35 | 36 | static void complete(const agrpc::GrpcContext&) noexcept {} 37 | }; 38 | 39 | struct ScheduleSenderInitiation 40 | { 41 | static void initiate(agrpc::GrpcContext& grpc_context, detail::QueueableOperationBase* operation) noexcept 42 | { 43 | detail::GrpcContextImplementation::add_operation(grpc_context, operation); 44 | } 45 | }; 46 | 47 | using ScheduleSender = detail::BasicSender; 48 | } 49 | 50 | AGRPC_NAMESPACE_END 51 | 52 | #endif // AGRPC_DETAIL_SCHEDULE_SENDER_HPP 53 | -------------------------------------------------------------------------------- /src/agrpc/detail/sender_implementation.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef AGRPC_DETAIL_SENDER_IMPLEMENTATION_HPP 16 | #define AGRPC_DETAIL_SENDER_IMPLEMENTATION_HPP 17 | 18 | #include 19 | 20 | AGRPC_NAMESPACE_BEGIN() 21 | 22 | namespace detail 23 | { 24 | template 25 | auto get_stop_function_arg(const Initiation& initiation, Implementation& implementation) 26 | -> decltype(initiation.stop_function_arg(implementation)) 27 | { 28 | return initiation.stop_function_arg(implementation); 29 | } 30 | 31 | template 32 | auto get_stop_function_arg(const Initiation& initiation, const Implementation&) 33 | -> decltype(initiation.stop_function_arg()) 34 | { 35 | return initiation.stop_function_arg(); 36 | } 37 | } 38 | 39 | AGRPC_NAMESPACE_END 40 | 41 | #endif // AGRPC_DETAIL_SENDER_IMPLEMENTATION_HPP 42 | -------------------------------------------------------------------------------- /src/agrpc/detail/sender_of.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 Dennis Hezel 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef AGRPC_DETAIL_SENDER_OF_HPP 16 | #define AGRPC_DETAIL_SENDER_OF_HPP 17 | 18 | #include 19 | 20 | #include 21 | 22 | #include 23 | 24 | AGRPC_NAMESPACE_BEGIN() 25 | 26 | namespace detail 27 | { 28 | template 29 | struct SenderOf; 30 | 31 | template 32 | struct SenderOf 33 | { 34 | template