diff --git a/Builds/CMake/FindBoost.cmake b/Builds/CMake/FindBoost.cmake index c02977fbd6..7325eca5ea 100644 --- a/Builds/CMake/FindBoost.cmake +++ b/Builds/CMake/FindBoost.cmake @@ -85,33 +85,33 @@ The following :prop_tgt:`IMPORTED` targets are also defined:: Boost::dynamic_linking - interface target to enable dynamic linking linking with MSVC (adds BOOST_ALL_DYN_LINK) -Implicit dependencies such as Boost::filesystem requiring -Boost::system will be automatically detected and satisfied, even -if system is not specified when using find_package and if -Boost::system is not added to target_link_libraries. If using -Boost::thread, then Threads::Threads will also be added automatically. +Implicit dependencies such as ``Boost::filesystem`` requiring +``Boost::system`` will be automatically detected and satisfied, even +if system is not specified when using :command:`find_package` and if +``Boost::system`` is not added to :command:`target_link_libraries`. If using +``Boost::thread``, then ``Threads::Threads`` will also be added automatically. It is important to note that the imported targets behave differently than variables created by this module: multiple calls to -find_package(Boost) in the same directory or sub-directories with +:command:`find_package(Boost)` in the same directory or sub-directories with different options (e.g. static or shared) will not override the values of the targets created by the first call. -Users may set these hints or results as cache entries. Projects +Users may set these hints or results as ``CACHE`` entries. Projects should not read these entries directly but instead use the above result variables. Note that some hint names start in upper-case "BOOST". One may specify these as environment variables if they are not specified as CMake variables or cache entries. -This module first searches for the Boost header files using the above -hint variables (excluding BOOST_LIBRARYDIR) and saves the result in -Boost_INCLUDE_DIR. Then it searches for requested component libraries -using the above hints (excluding BOOST_INCLUDEDIR and -Boost_ADDITIONAL_VERSIONS), "lib" directories near Boost_INCLUDE_DIR, +This module first searches for the ``Boost`` header files using the above +hint variables (excluding ``BOOST_LIBRARYDIR``) and saves the result in +``Boost_INCLUDE_DIR``. Then it searches for requested component libraries +using the above hints (excluding ``BOOST_INCLUDEDIR`` and +``Boost_ADDITIONAL_VERSIONS``), "lib" directories near ``Boost_INCLUDE_DIR``, and the library name configuration settings below. It saves the -library directories in Boost_LIBRARY_DIR_DEBUG and -Boost_LIBRARY_DIR_RELEASE and individual library -locations in Boost__LIBRARY_DEBUG and Boost__LIBRARY_RELEASE. +library directories in ``Boost_LIBRARY_DIR_DEBUG`` and +``Boost_LIBRARY_DIR_RELEASE`` and individual library +locations in ``Boost__LIBRARY_DEBUG`` and ``Boost__LIBRARY_RELEASE``. When one changes settings used by previous searches in the same build tree (excluding environment variables) this module discards previous search results affected by the changes and searches again. @@ -179,9 +179,9 @@ Other variables one may set to control this module are:: On Visual Studio and Borland compilers Boost headers request automatic linking to corresponding libraries. This requires matching libraries to be linked explicitly or available in the link library search path. -In this case setting Boost_USE_STATIC_LIBS to OFF may not achieve +In this case setting ``Boost_USE_STATIC_LIBS`` to ``OFF`` may not achieve dynamic linking. Boost automatic linking typically requests static -libraries with a few exceptions (such as Boost.Python). Use:: +libraries with a few exceptions (such as ``Boost.Python``). Use:: add_definitions(${Boost_LIB_DIAGNOSTIC_DEFINITIONS}) @@ -230,12 +230,12 @@ Boost CMake If Boost was built using the boost-cmake project it provides a package configuration file for use with find_package's Config mode. This module looks for the package configuration file called -BoostConfig.cmake or boost-config.cmake and stores the result in cache -entry "Boost_DIR". If found, the package configuration file is loaded +``BoostConfig.cmake`` or ``boost-config.cmake`` and stores the result in +``CACHE`` entry "Boost_DIR". If found, the package configuration file is loaded and this module returns with no further action. See documentation of the Boost CMake package configuration for details on what it provides. -Set Boost_NO_BOOST_CMAKE to ON to disable the search for boost-cmake. +Set ``Boost_NO_BOOST_CMAKE`` to ``ON``, to disable the search for boost-cmake. #]=======================================================================] # Save project's policies @@ -465,33 +465,20 @@ function(_Boost_GUESS_COMPILER_PREFIX _ret) endif() elseif (GHSMULTI) set(_boost_COMPILER "-ghs") - elseif("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xMSVC") - #[========================================================[ - NOTE: newer versions of FindBoost from kitware - change this version check to use MSVC_TOOLSET_VERSION. - That variable only exists in make 3.12 or greater, so - until all envs (including bundled visual studio) have - this min version of cmake, stick with this - CMAKE_CXX_COMPILER_VERSION check - #]========================================================] - if(DEFINED MSVC_TOOLSET_VERSION AND MSVC_TOOLSET_VERSION GREATER_EQUAL 141) - set(_boost_COMPILER "-vc141;-vc140") - elseif(DEFINED MSVC_TOOLSET_VERSION AND MSVC_TOOLSET_VERSION GREATER_EQUAL 80) + elseif("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xMSVC" OR "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC") + if(MSVC_TOOLSET_VERSION GREATER_EQUAL 150) + # Not yet known. + set(_boost_COMPILER "") + elseif(MSVC_TOOLSET_VERSION GREATER_EQUAL 140) + # MSVC toolset 14.x versions are forward compatible. + set(_boost_COMPILER "") + foreach(v 9 8 7 6 5 4 3 2 1 0) + if(MSVC_TOOLSET_VERSION GREATER_EQUAL 14${v}) + list(APPEND _boost_COMPILER "-vc14${v}") + endif() + endforeach() + elseif(MSVC_TOOLSET_VERSION GREATER_EQUAL 80) set(_boost_COMPILER "-vc${MSVC_TOOLSET_VERSION}") - elseif (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.10) - set(_boost_COMPILER "-vc141;-vc140") - elseif (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19) - set(_boost_COMPILER "-vc140") - elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18) - set(_boost_COMPILER "-vc120") - elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 17) - set(_boost_COMPILER "-vc110") - elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16) - set(_boost_COMPILER "-vc100") - elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 15) - set(_boost_COMPILER "-vc90") - elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 14) - set(_boost_COMPILER "-vc80") elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 13.10) set(_boost_COMPILER "-vc71") elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 13) # Good luck! @@ -499,6 +486,12 @@ function(_Boost_GUESS_COMPILER_PREFIX _ret) else() # VS 6.0 Good luck! set(_boost_COMPILER "-vc6") # yes, this is correct endif() + + if("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xClang") + string(REPLACE "." ";" VERSION_LIST "${CMAKE_CXX_COMPILER_VERSION}") + list(GET VERSION_LIST 0 CLANG_VERSION_MAJOR) + set(_boost_COMPILER "-clangw${CLANG_VERSION_MAJOR};${_boost_COMPILER}") + endif() elseif (BORLAND) set(_boost_COMPILER "-bcb") elseif(CMAKE_CXX_COMPILER_ID STREQUAL "SunPro") @@ -884,8 +877,22 @@ function(_Boost_COMPONENT_DEPENDENCIES component _ret) set(_Boost_TIMER_DEPENDENCIES chrono system) set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread chrono date_time atomic) set(_Boost_WSERIALIZATION_DEPENDENCIES serialization) + elseif(NOT Boost_VERSION VERSION_LESS 106900 AND Boost_VERSION VERSION_LESS 107000) + set(_Boost_CONTRACT_DEPENDENCIES thread chrono date_time) + set(_Boost_COROUTINE_DEPENDENCIES context) + set(_Boost_FIBER_DEPENDENCIES context) + set(_Boost_IOSTREAMS_DEPENDENCIES regex) + set(_Boost_LOG_DEPENDENCIES date_time log_setup filesystem thread regex chrono atomic) + set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l atomic) + set(_Boost_MPI_DEPENDENCIES serialization) + set(_Boost_MPI_PYTHON_DEPENDENCIES python${component_python_version} mpi serialization) + set(_Boost_NUMPY_DEPENDENCIES python${component_python_version}) + set(_Boost_THREAD_DEPENDENCIES chrono date_time atomic) + set(_Boost_TIMER_DEPENDENCIES chrono system) + set(_Boost_WAVE_DEPENDENCIES filesystem serialization thread chrono date_time atomic) + set(_Boost_WSERIALIZATION_DEPENDENCIES serialization) else() - if(NOT Boost_VERSION VERSION_LESS 106900) + if(NOT Boost_VERSION VERSION_LESS 107000) set(_Boost_CONTRACT_DEPENDENCIES thread chrono date_time) set(_Boost_COROUTINE_DEPENDENCIES context) set(_Boost_FIBER_DEPENDENCIES context) @@ -900,7 +907,7 @@ function(_Boost_COMPONENT_DEPENDENCIES component _ret) set(_Boost_WAVE_DEPENDENCIES filesystem serialization thread chrono date_time atomic) set(_Boost_WSERIALIZATION_DEPENDENCIES serialization) endif() - if(NOT Boost_VERSION VERSION_LESS 107000) + if(NOT Boost_VERSION VERSION_LESS 107100) message(WARNING "New Boost version may have incorrect or missing dependencies and imported targets") endif() endif() @@ -1085,27 +1092,18 @@ function(_Boost_UPDATE_WINDOWS_LIBRARY_SEARCH_DIRS_WITH_PREBUILT_PATHS component else() set(_arch_suffix 32) endif() - if(DEFINED MSVC_TOOLSET_VERSION AND MSVC_TOOLSET_VERSION GREATER_EQUAL 141) - list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-14.1) - list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-14.0) - elseif(DEFINED MSVC_TOOLSET_VERSION AND MSVC_TOOLSET_VERSION GREATER_EQUAL 80) + if(MSVC_TOOLSET_VERSION GREATER_EQUAL 150) + # Not yet known. + elseif(MSVC_TOOLSET_VERSION GREATER_EQUAL 140) + # MSVC toolset 14.x versions are forward compatible. + foreach(v 9 8 7 6 5 4 3 2 1 0) + if(MSVC_TOOLSET_VERSION GREATER_EQUAL 14${v}) + list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-14.${v}) + endif() + endforeach() + elseif(MSVC_TOOLSET_VERSION GREATER_EQUAL 80) math(EXPR _toolset_major_version "${MSVC_TOOLSET_VERSION} / 10") list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-${_toolset_major_version}.0) - elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.10) - list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-14.1) - list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-14.0) - elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19) - list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-14.0) - elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18) - list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-12.0) - elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 17) - list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-11.0) - elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16) - list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-10.0) - elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 15) - list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-9.0) - elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 14) - list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-8.0) endif() set(${componentlibvar} ${${componentlibvar}} PARENT_SCOPE) endif() @@ -1163,7 +1161,7 @@ else() # _Boost_COMPONENT_HEADERS. See the instructions at the top of # _Boost_COMPONENT_DEPENDENCIES. set(_Boost_KNOWN_VERSIONS ${Boost_ADDITIONAL_VERSIONS} - "1.69.0" "1.69" + "1.70.0" "1.70" "1.69.0" "1.69" "1.68.0" "1.68" "1.67.0" "1.67" "1.66.0" "1.66" "1.65.1" "1.65.0" "1.65" "1.64.0" "1.64" "1.63.0" "1.63" "1.62.0" "1.62" "1.61.0" "1.61" "1.60.0" "1.60" "1.59.0" "1.59" "1.58.0" "1.58" "1.57.0" "1.57" "1.56.0" "1.56" "1.55.0" "1.55" @@ -1224,6 +1222,8 @@ if(NOT TARGET Boost::diagnostic_definitions) add_library(Boost::diagnostic_definitions INTERFACE IMPORTED) add_library(Boost::disable_autolinking INTERFACE IMPORTED) add_library(Boost::dynamic_linking INTERFACE IMPORTED) + set_target_properties(Boost::dynamic_linking PROPERTIES + INTERFACE_COMPILE_DEFINITIONS "BOOST_ALL_DYN_LINK") endif() if(WIN32) # In windows, automatic linking is performed, so you do not have @@ -1248,8 +1248,6 @@ if(WIN32) INTERFACE_COMPILE_DEFINITIONS "BOOST_LIB_DIAGNOSTIC") set_target_properties(Boost::disable_autolinking PROPERTIES INTERFACE_COMPILE_DEFINITIONS "BOOST_ALL_NO_LIB") - set_target_properties(Boost::dynamic_linking PROPERTIES - INTERFACE_COMPILE_DEFINITIONS "BOOST_ALL_DYN_LINK") endif() _Boost_CHECK_SPELLING(Boost_ROOT) @@ -1779,7 +1777,7 @@ foreach(COMPONENT ${Boost_FIND_COMPONENTS}) list(APPEND _Boost_FIND_LIBRARY_HINTS_FOR_COMPONENT_NAME "${COMPONENT_UNVERSIONED}${COMPONENT_PYTHON_VERSION_MAJOR}-py${COMPONENT_PYTHON_VERSION_MAJOR}${COMPONENT_PYTHON_VERSION_MINOR}") list(APPEND _Boost_FIND_LIBRARY_HINTS_FOR_COMPONENT_NAME "${COMPONENT_UNVERSIONED}-py${COMPONENT_PYTHON_VERSION_MAJOR}${COMPONENT_PYTHON_VERSION_MINOR}") # Gentoo - list(APPEND _Boost_FIND_LIBRARY_HINTS_FOR_COMPONENT_NAME "${COMPONENT_UNVERSIONED}-${COMPONENT_PYTHON_VERSION_MAJOR}${COMPONENT_PYTHON_VERSION_MINOR}") + list(APPEND _Boost_FIND_LIBRARY_HINTS_FOR_COMPONENT_NAME "${COMPONENT_UNVERSIONED}-${COMPONENT_PYTHON_VERSION_MAJOR}.${COMPONENT_PYTHON_VERSION_MINOR}") # RPMs list(APPEND _Boost_FIND_LIBRARY_HINTS_FOR_COMPONENT_NAME "${COMPONENT_UNVERSIONED}-${COMPONENT_PYTHON_VERSION_MAJOR}${COMPONENT_PYTHON_VERSION_MINOR}") endif() @@ -1830,10 +1828,12 @@ foreach(COMPONENT ${Boost_FIND_COMPONENTS}) foreach(compiler IN LISTS _boost_COMPILER) list(APPEND _boost_RELEASE_NAMES ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG}${_boost_ARCHITECTURE_TAG}-${Boost_LIB_VERSION} + ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG}${_boost_ARCHITECTURE_TAG} ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG} ) endforeach() list(APPEND _boost_RELEASE_NAMES ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG}${_boost_ARCHITECTURE_TAG}-${Boost_LIB_VERSION} + ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG}${_boost_ARCHITECTURE_TAG} ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG} ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED} ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component} ) @@ -1842,10 +1842,12 @@ foreach(COMPONENT ${Boost_FIND_COMPONENTS}) foreach(compiler IN LISTS _boost_COMPILER) list(APPEND _boost_RELEASE_NAMES ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG}${_boost_ARCHITECTURE_TAG}-${Boost_LIB_VERSION} + ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG}${_boost_ARCHITECTURE_TAG} ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG} ) endforeach() list(APPEND _boost_RELEASE_NAMES ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG}${_boost_ARCHITECTURE_TAG}-${Boost_LIB_VERSION} + ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG}${_boost_ARCHITECTURE_TAG} ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG} ) endif() endforeach() @@ -1883,10 +1885,12 @@ foreach(COMPONENT ${Boost_FIND_COMPONENTS}) foreach(compiler IN LISTS _boost_COMPILER) list(APPEND _boost_DEBUG_NAMES ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG}${_boost_ARCHITECTURE_TAG}-${Boost_LIB_VERSION} + ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG}${_boost_ARCHITECTURE_TAG} ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG} ) endforeach() list(APPEND _boost_DEBUG_NAMES ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG}${_boost_ARCHITECTURE_TAG}-${Boost_LIB_VERSION} + ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG}${_boost_ARCHITECTURE_TAG} ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG} ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED} ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component} ) @@ -1895,10 +1899,12 @@ foreach(COMPONENT ${Boost_FIND_COMPONENTS}) foreach(compiler IN LISTS _boost_COMPILER) list(APPEND _boost_DEBUG_NAMES ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG}${_boost_ARCHITECTURE_TAG}-${Boost_LIB_VERSION} + ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG}${_boost_ARCHITECTURE_TAG} ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG} ) endforeach() list(APPEND _boost_DEBUG_NAMES ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG}${_boost_ARCHITECTURE_TAG}-${Boost_LIB_VERSION} + ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG}${_boost_ARCHITECTURE_TAG} ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG} ) endif() endforeach() diff --git a/Builds/CMake/FindBoost.patch b/Builds/CMake/FindBoost.patch deleted file mode 100644 index 34ce952c08..0000000000 --- a/Builds/CMake/FindBoost.patch +++ /dev/null @@ -1,67 +0,0 @@ ---- FindBoost.cmake 2018-12-12 11:15:12.000000000 -0800 -+++ FindBoost_patched.cmake 2018-12-12 11:53:19.000000000 -0800 -@@ -458,10 +458,32 @@ - elseif (GHSMULTI) - set(_boost_COMPILER "-ghs") - elseif("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xMSVC") -- if(MSVC_TOOLSET_VERSION GREATER_EQUAL 141) -+ #[========================================================[ -+ NOTE: newer versions of FindBoost from kitware -+ change this version check to use MSVC_TOOLSET_VERSION. -+ That variable only exists in make 3.12 or greater, so -+ until all envs (including bundled visual studio) have -+ this min version of cmake, stick with this -+ CMAKE_CXX_COMPILER_VERSION check -+ #]========================================================] -+ if(DEFINED MSVC_TOOLSET_VERSION AND MSVC_TOOLSET_VERSION GREATER_EQUAL 141) - set(_boost_COMPILER "-vc141;-vc140") -- elseif(MSVC_TOOLSET_VERSION GREATER_EQUAL 80) -+ elseif(DEFINED MSVC_TOOLSET_VERSION AND MSVC_TOOLSET_VERSION GREATER_EQUAL 80) - set(_boost_COMPILER "-vc${MSVC_TOOLSET_VERSION}") -+ elseif (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.10) -+ set(_boost_COMPILER "-vc141;-vc140") -+ elseif (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19) -+ set(_boost_COMPILER "-vc140") -+ elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18) -+ set(_boost_COMPILER "-vc120") -+ elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 17) -+ set(_boost_COMPILER "-vc110") -+ elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16) -+ set(_boost_COMPILER "-vc100") -+ elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 15) -+ set(_boost_COMPILER "-vc90") -+ elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 14) -+ set(_boost_COMPILER "-vc80") - elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 13.10) - set(_boost_COMPILER "-vc71") - elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 13) # Good luck! -@@ -1018,12 +1040,27 @@ - else() - set(_arch_suffix 32) - endif() -- if(MSVC_TOOLSET_VERSION GREATER_EQUAL 141) -+ if(DEFINED MSVC_TOOLSET_VERSION AND MSVC_TOOLSET_VERSION GREATER_EQUAL 141) - list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-14.1) - list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-14.0) -- elseif(MSVC_TOOLSET_VERSION GREATER_EQUAL 80) -+ elseif(DEFINED MSVC_TOOLSET_VERSION AND MSVC_TOOLSET_VERSION GREATER_EQUAL 80) - math(EXPR _toolset_major_version "${MSVC_TOOLSET_VERSION} / 10") - list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-${_toolset_major_version}.0) -+ elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.10) -+ list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-14.1) -+ list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-14.0) -+ elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19) -+ list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-14.0) -+ elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18) -+ list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-12.0) -+ elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 17) -+ list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-11.0) -+ elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16) -+ list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-10.0) -+ elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 15) -+ list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-9.0) -+ elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 14) -+ list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-8.0) - endif() - set(${componentlibvar} ${${componentlibvar}} PARENT_SCOPE) - endif() diff --git a/Builds/CMake/README.md b/Builds/CMake/README.md index 7c3384f48f..77d6813b65 100644 --- a/Builds/CMake/README.md +++ b/Builds/CMake/README.md @@ -4,19 +4,15 @@ These are modules and sources that support our CMake build. == FindBoost.cmake == In order to facilitate updating to latest releases of boost, we've made a local -copy of this cmake module in our repo. The latest official version can +copy of the FindBoost cmake module in our repo. The latest official version can generally be obtained [here](https://github.com/Kitware/CMake/blob/master/Modules/FindBoost.cmake). The latest version provided by Kitware can be tailored for use with the version of CMake that it ships with (typically the next upcoming CMake -release). Our local version, however, cannot necessarily assume a -specific version of CMake and might need to accommodate older versions, -depending on the min version we support for our project. As such, we need to -patch the stock FindBoost module. There is currently one patch file provided -here to accommodate CMake versions prior to 3.12 on windows. When updating to a -newer FindBoost, apply this patch via `patch < FindBoost.patch` after -downloading the latest `FindBoost.cmake` file. If the patch does not apply, -it's possible the applicable section of the original has changed: more -investigation will be required to resolve such a situation. Any backup files -created by `patch` can be deleted if/when the patch applies cleanly. +release). As such, the latest version from the repository might not work +perfectly with older versions of CMake - for instance, the latest version +might use features or properties only available in the version of CMake that +it ships with. Given this, it's best to test any updates to this module with a few +different versions of cmake. + diff --git a/Builds/macos/README.md b/Builds/macos/README.md index 97f74aa3c2..cad5b3a182 100644 --- a/Builds/macos/README.md +++ b/Builds/macos/README.md @@ -70,7 +70,7 @@ Extract it to a folder, making note of where, open a terminal, then: ``` ./bootstrap.sh -./b2 cxxflags="-std=c++14" +./b2 cxxflags="-std=c++14" visibility=global ``` Create an environment variable `BOOST_ROOT` in one of your `rc` files, pointing diff --git a/CMakeLists.txt b/CMakeLists.txt index 513eb3de64..6790b5ec27 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,9 @@ include (CheckCXXCompilerFlag) if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.11) include (FetchContent) endif () +if (MSVC AND CMAKE_VERSION VERSION_LESS 3.12) + message (FATAL_ERROR "MSVC requires cmake 3.12 or greater for proper boost support") +endif () include (ExternalProject) include (CMakeFuncs) # must come *after* ExternalProject b/c it overrides one function in EP include (ProcessorCount) @@ -1117,6 +1120,7 @@ if (WIN32) # this version in the name might change if/when we change versions of soci set (soci_lib_post "_4_0") endif () +get_target_property (_boost_incs Boost::date_time INTERFACE_INCLUDE_DIRECTORIES) ExternalProject_Add (soci PREFIX ${nih_cache_path} GIT_REPOSITORY https://github.com/SOCI/soci.git @@ -1135,6 +1139,7 @@ ExternalProject_Add (soci -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} $<$:-DCMAKE_VERBOSE_MAKEFILE=ON> -DCMAKE_PREFIX_PATH=${CMAKE_BINARY_DIR}/sqlite3 + -DCMAKE_MODULE_PATH=${CMAKE_CURRENT_SOURCE_DIR}/Builds/CMake -DCMAKE_INCLUDE_PATH=$,::> -DCMAKE_LIBRARY_PATH=${sqlite_BINARY_DIR} -DCMAKE_DEBUG_POSTFIX=_d @@ -1144,7 +1149,12 @@ ExternalProject_Add (soci -DSOCI_LIBDIR=lib -DSOCI_SHARED=OFF -DSOCI_TESTS=OFF - -DBOOST_ROOT=${Boost_DIR} + # hack to workaround the fact that soci doesn't currently use + # boost imported targets in its cmake. If they switch to + # proper imported targets, this next line can be removed + # (as well as the get_property above that sets _boost_incs) + -DBoost_INCLUDE_DIRS=$ + -DBOOST_ROOT=${BOOST_ROOT} -DWITH_BOOST=ON -DSOCI_DB2=OFF -DSOCI_FIREBIRD=OFF diff --git a/src/ripple/beast/asio/waitable_timer.h b/src/ripple/beast/asio/waitable_timer.h new file mode 100644 index 0000000000..f50d4ffe19 --- /dev/null +++ b/src/ripple/beast/asio/waitable_timer.h @@ -0,0 +1,45 @@ +//------------------------------------------------------------------------------ +/* + This file is part of rippled: https://github.com/ripple/rippled + Copyright (c) 2019 Ripple Labs Inc. + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef RIPPLE_BEAST_ASIO_WAITABLETIMER_H_INCLUDED +#define RIPPLE_BEAST_ASIO_WAITABLETIMER_H_INCLUDED + +#include + +namespace beast { + +// Pre boost 1.70, a waitable timer may only be created from an io_context. +// However, post 1.70, the `get_io_service` function is deleted. Post +// boost 1.70, a waitable time may be created from an executor. This functions +// allows a waitable timer to be created from a socket in both pre and post +// boost 1.70 versions +template +T +create_waitable_timer(boost::asio::ip::tcp::socket& socket) +{ +#if BOOST_VERSION >= 107000 + return T{socket.get_executor()}; +#else + return T{socket.get_io_service()}; +#endif +} + +} // namespace ripple + +#endif diff --git a/src/ripple/net/AutoSocket.h b/src/ripple/net/AutoSocket.h index 2ed3e1f7ed..6cafc50261 100644 --- a/src/ripple/net/AutoSocket.h +++ b/src/ripple/net/AutoSocket.h @@ -64,11 +64,6 @@ public: { } - boost::asio::io_service& get_io_service () noexcept - { - return mSocket->get_io_service (); - } - bool isSecure () { return mSecure; @@ -167,8 +162,9 @@ public: { // must be plain mSecure = false; - mSocket->get_io_service ().post ( - boost::beast::bind_handler (cbFunc, error_code())); + post( + mSocket->get_executor(), + boost::beast::bind_handler(cbFunc, error_code())); } else { @@ -200,8 +196,9 @@ public: { ec = e.code(); } - mSocket->get_io_service ().post ( - boost::beast::bind_handler (handler, ec)); + post( + mSocket->get_executor(), + boost::beast::bind_handler(handler, ec)); } } diff --git a/src/ripple/net/impl/SSLHTTPDownloader.cpp b/src/ripple/net/impl/SSLHTTPDownloader.cpp index 092c8325d9..d133c952c1 100644 --- a/src/ripple/net/impl/SSLHTTPDownloader.cpp +++ b/src/ripple/net/impl/SSLHTTPDownloader.cpp @@ -132,14 +132,14 @@ SSLHTTPDownloader::do_session( using namespace boost::beast; boost::system::error_code ec; - ip::tcp::resolver resolver {strand_.get_io_context()}; + ip::tcp::resolver resolver {strand_.context()}; auto const results = resolver.async_resolve(host, port, yield[ec]); if (ec) return fail(dstPath, complete, ec, "async_resolve"); try { - stream_.emplace(strand_.get_io_service(), ctx_); + stream_.emplace(strand_.context(), ctx_); } catch (std::exception const& e) { diff --git a/src/ripple/overlay/impl/PeerImp.cpp b/src/ripple/overlay/impl/PeerImp.cpp index 4261482ea7..40f915d3f1 100644 --- a/src/ripple/overlay/impl/PeerImp.cpp +++ b/src/ripple/overlay/impl/PeerImp.cpp @@ -66,8 +66,8 @@ PeerImp::PeerImp (Application& app, id_t id, endpoint_type remote_endpoint, , ssl_bundle_(std::move(ssl_bundle)) , socket_ (ssl_bundle_->socket) , stream_ (ssl_bundle_->stream) - , strand_ (socket_.get_io_service()) - , timer_ (socket_.get_io_service()) + , strand_ (socket_.get_executor()) + , timer_ (beast::create_waitable_timer(socket_)) , remote_address_ ( beast::IPAddressConversion::from_asio(remote_endpoint)) , overlay_ (overlay) @@ -102,7 +102,7 @@ void PeerImp::run() { if(! strand_.running_in_this_thread()) - return strand_.post(std::bind ( + return post(strand_, std::bind ( &PeerImp::run, shared_from_this())); if (m_inbound) { @@ -145,8 +145,7 @@ void PeerImp::stop() { if(! strand_.running_in_this_thread()) - return strand_.post(std::bind ( - &PeerImp::stop, shared_from_this())); + return post(strand_, std::bind(&PeerImp::stop, shared_from_this())); if (socket_.is_open()) { // The rationale for using different severity levels is that @@ -172,8 +171,7 @@ void PeerImp::send (Message::pointer const& m) { if (! strand_.running_in_this_thread()) - return strand_.post(std::bind ( - &PeerImp::send, shared_from_this(), m)); + return post(strand_, std::bind(&PeerImp::send, shared_from_this(), m)); if(gracefulClose_) return; if(detaching_) @@ -204,11 +202,16 @@ PeerImp::send (Message::pointer const& m) if(sendq_size != 0) return; - boost::asio::async_write (stream_, boost::asio::buffer( - send_queue_.front()->getBuffer()), strand_.wrap(std::bind( - &PeerImp::onWriteMessage, shared_from_this(), + boost::asio::async_write( + stream_, + boost::asio::buffer(send_queue_.front()->getBuffer()), + bind_executor( + strand_, + std::bind( + &PeerImp::onWriteMessage, + shared_from_this(), std::placeholders::_1, - std::placeholders::_2))); + std::placeholders::_2))); } void @@ -438,9 +441,12 @@ void PeerImp::fail(std::string const& reason) { if(! strand_.running_in_this_thread()) - return strand_.post(std::bind ( - (void(Peer::*)(std::string const&))&PeerImp::fail, - shared_from_this(), reason)); + return post( + strand_, + std::bind( + (void (Peer::*)(std::string const&)) & PeerImp::fail, + shared_from_this(), + reason)); if (socket_.is_open()) { JLOG (journal_.warn()) << @@ -498,8 +504,10 @@ PeerImp::gracefulClose() if (send_queue_.size() > 0) return; setTimer(); - stream_.async_shutdown(strand_.wrap(std::bind(&PeerImp::onShutdown, - shared_from_this(), std::placeholders::_1))); + stream_.async_shutdown(bind_executor( + strand_, + std::bind( + &PeerImp::onShutdown, shared_from_this(), std::placeholders::_1))); } void @@ -514,8 +522,10 @@ PeerImp::setTimer() JLOG(journal_.error()) << "setTimer: " << ec.message(); return; } - timer_.async_wait(strand_.wrap(std::bind(&PeerImp::onTimer, - shared_from_this(), std::placeholders::_1))); + timer_.async_wait(bind_executor( + strand_, + std::bind( + &PeerImp::onTimer, shared_from_this(), std::placeholders::_1))); } // convenience for ignoring the error code @@ -709,9 +719,14 @@ PeerImp::onWriteResponse (error_code ec, std::size_t bytes_transferred) if (write_buffer_.size() == 0) return doProtocolStart(); - stream_.async_write_some (write_buffer_.data(), - strand_.wrap (std::bind (&PeerImp::onWriteResponse, - shared_from_this(), std::placeholders::_1, + stream_.async_write_some( + write_buffer_.data(), + bind_executor( + strand_, + std::bind( + &PeerImp::onWriteResponse, + shared_from_this(), + std::placeholders::_1, std::placeholders::_2))); } @@ -785,9 +800,14 @@ PeerImp::onReadMessage (error_code ec, std::size_t bytes_transferred) read_buffer_.consume (bytes_consumed); } // Timeout on writes only - stream_.async_read_some (read_buffer_.prepare (Tuning::readBufferBytes), - strand_.wrap (std::bind (&PeerImp::onReadMessage, - shared_from_this(), std::placeholders::_1, + stream_.async_read_some( + read_buffer_.prepare(Tuning::readBufferBytes), + bind_executor( + strand_, + std::bind( + &PeerImp::onReadMessage, + shared_from_this(), + std::placeholders::_1, std::placeholders::_2))); } @@ -814,17 +834,25 @@ PeerImp::onWriteMessage (error_code ec, std::size_t bytes_transferred) if (! send_queue_.empty()) { // Timeout on writes only - return boost::asio::async_write (stream_, boost::asio::buffer( - send_queue_.front()->getBuffer()), strand_.wrap(std::bind( - &PeerImp::onWriteMessage, shared_from_this(), + return boost::asio::async_write( + stream_, + boost::asio::buffer(send_queue_.front()->getBuffer()), + bind_executor( + strand_, + std::bind( + &PeerImp::onWriteMessage, + shared_from_this(), std::placeholders::_1, - std::placeholders::_2))); + std::placeholders::_2))); } if (gracefulClose_) { - return stream_.async_shutdown(strand_.wrap(std::bind( - &PeerImp::onShutdown, shared_from_this(), + return stream_.async_shutdown(bind_executor( + strand_, + std::bind( + &PeerImp::onShutdown, + shared_from_this(), std::placeholders::_1))); } } @@ -1816,9 +1844,12 @@ void PeerImp::check () if (reject) { overlay_.peerFinder().on_failure (slot_); - strand_.post (std::bind ( - (void (PeerImp::*)(std::string const&)) &PeerImp::fail, - shared_from_this(), "Not useful")); + post( + strand_, + std::bind( + (void (PeerImp::*)(std::string const&)) & PeerImp::fail, + shared_from_this(), + "Not useful")); } } diff --git a/src/ripple/overlay/impl/PeerImp.h b/src/ripple/overlay/impl/PeerImp.h index 7f1645b4c5..69a5a64fb7 100644 --- a/src/ripple/overlay/impl/PeerImp.h +++ b/src/ripple/overlay/impl/PeerImp.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -94,6 +95,7 @@ private: using stream_type = boost::asio::ssl::stream ; using address_type = boost::asio::ip::address; using endpoint_type = boost::asio::ip::tcp::endpoint; + using waitable_timer = boost::asio::basic_waitable_timer; // The length of the smallest valid finished message static const size_t sslMinimumFinishedLength = 12; @@ -107,9 +109,8 @@ private: std::unique_ptr ssl_bundle_; socket_type& socket_; stream_type& stream_; - boost::asio::io_service::strand strand_; - boost::asio::basic_waitable_timer< - std::chrono::steady_clock> timer_; + boost::asio::strand strand_; + waitable_timer timer_; //Type type_ = Type::legacy; @@ -479,6 +480,7 @@ private: beast::Journal journal); }; + //------------------------------------------------------------------------------ template @@ -498,8 +500,8 @@ PeerImp::PeerImp (Application& app, std::unique_ptr&& s , ssl_bundle_(std::move(ssl_bundle)) , socket_ (ssl_bundle_->socket) , stream_ (ssl_bundle_->stream) - , strand_ (socket_.get_io_service()) - , timer_ (socket_.get_io_service()) + , strand_ (socket_.get_executor()) + , timer_ (beast::create_waitable_timer(socket_)) , remote_address_ (slot->remote_endpoint()) , overlay_ (overlay) , m_inbound (false) diff --git a/src/ripple/server/impl/BaseHTTPPeer.h b/src/ripple/server/impl/BaseHTTPPeer.h index f4d6118cc6..2fbae782ed 100644 --- a/src/ripple/server/impl/BaseHTTPPeer.h +++ b/src/ripple/server/impl/BaseHTTPPeer.h @@ -84,8 +84,8 @@ protected: Port const& port_; Handler& handler_; - boost::asio::io_service::work work_; - boost::asio::io_service::strand strand_; + boost::asio::executor_work_guard work_; + boost::asio::strand strand_; waitable_timer timer_; endpoint_type remote_address_; beast::Journal journal_; @@ -109,10 +109,15 @@ protected: //-------------------------------------------------------------------------- public: - template - BaseHTTPPeer(Port const& port, Handler& handler, - boost::asio::io_service& io_service, beast::Journal journal, - endpoint_type remote_address, ConstBufferSequence const& buffers); + template + BaseHTTPPeer( + Port const& port, + Handler& handler, + boost::asio::executor const& executor, + waitable_timer timer, + beast::Journal journal, + endpoint_type remote_address, + ConstBufferSequence const& buffers); virtual ~BaseHTTPPeer(); @@ -208,18 +213,21 @@ protected: //------------------------------------------------------------------------------ -template -template -BaseHTTPPeer:: -BaseHTTPPeer(Port const& port, Handler& handler, - boost::asio::io_service& io_service, beast::Journal journal, - endpoint_type remote_address, - ConstBufferSequence const& buffers) +template +template +BaseHTTPPeer::BaseHTTPPeer( + Port const& port, + Handler& handler, + boost::asio::executor const& executor, + waitable_timer timer, + beast::Journal journal, + endpoint_type remote_address, + ConstBufferSequence const& buffers) : port_(port) , handler_(handler) - , work_(io_service) - , strand_(io_service) - , timer_(io_service) + , work_(executor) + , strand_(executor) + , timer_(std::move(timer)) , remote_address_(remote_address) , journal_(journal) { @@ -248,8 +256,10 @@ BaseHTTPPeer:: close() { if(! strand_.running_in_this_thread()) - return strand_.post(std::bind( - (void(BaseHTTPPeer::*)(void))&BaseHTTPPeer::close, + return post( + strand_, + std::bind( + (void (BaseHTTPPeer::*)(void)) & BaseHTTPPeer::close, impl().shared_from_this())); error_code ec; impl().stream_.lowest_layer().close(ec); @@ -285,8 +295,11 @@ start_timer() ec); if(ec) return fail(ec, "start_timer"); - timer_.async_wait(strand_.wrap(std::bind( - &BaseHTTPPeer::on_timer, impl().shared_from_this(), + timer_.async_wait(bind_executor( + strand_, + std::bind( + &BaseHTTPPeer::on_timer, + impl().shared_from_this(), std::placeholders::_1))); } @@ -359,9 +372,15 @@ on_write(error_code const& ec, for(auto const& b : wq2_) v.emplace_back(b.data.get(), b.bytes); start_timer(); - return boost::asio::async_write(impl().stream_, v, - strand_.wrap(std::bind(&BaseHTTPPeer::on_write, - impl().shared_from_this(), std::placeholders::_1, + return boost::asio::async_write( + impl().stream_, + v, + bind_executor( + strand_, + std::bind( + &BaseHTTPPeer::on_write, + impl().shared_from_this(), + std::placeholders::_1, std::placeholders::_2))); } if(! complete_) @@ -432,10 +451,13 @@ write( }()) { if(! strand_.running_in_this_thread()) - return strand_.post(std::bind( - &BaseHTTPPeer::on_write, + return post( + strand_, + std::bind( + &BaseHTTPPeer::on_write, impl().shared_from_this(), - error_code{}, 0)); + error_code{}, + 0)); else return on_write(error_code{}, 0); } @@ -447,9 +469,14 @@ BaseHTTPPeer:: write(std::shared_ptr const& writer, bool keep_alive) { - boost::asio::spawn(strand_, std::bind( - &BaseHTTPPeer::do_writer, impl().shared_from_this(), - writer, keep_alive, std::placeholders::_1)); + boost::asio::spawn(bind_executor( + strand_, + std::bind( + &BaseHTTPPeer::do_writer, + impl().shared_from_this(), + writer, + keep_alive, + std::placeholders::_1))); } // DEPRECATED @@ -470,8 +497,11 @@ BaseHTTPPeer:: complete() { if(! strand_.running_in_this_thread()) - return strand_.post(std::bind(&BaseHTTPPeer::complete, - impl().shared_from_this())); + return post( + strand_, + std::bind( + &BaseHTTPPeer::complete, + impl().shared_from_this())); message_ = {}; complete_ = true; @@ -483,8 +513,12 @@ complete() } // keep-alive - boost::asio::spawn(strand_, std::bind(&BaseHTTPPeer::do_read, - impl().shared_from_this(), std::placeholders::_1)); + boost::asio::spawn(bind_executor( + strand_, + std::bind( + &BaseHTTPPeer::do_read, + impl().shared_from_this(), + std::placeholders::_1))); } // DEPRECATED @@ -495,9 +529,13 @@ BaseHTTPPeer:: close(bool graceful) { if(! strand_.running_in_this_thread()) - return strand_.post(std::bind( - (void(BaseHTTPPeer::*)(bool))&BaseHTTPPeer::close, - impl().shared_from_this(), graceful)); + return post( + strand_, + std::bind( + (void (BaseHTTPPeer::*)(bool)) & + BaseHTTPPeer::close, + impl().shared_from_this(), + graceful)); complete_ = true; if(graceful) diff --git a/src/ripple/server/impl/BasePeer.h b/src/ripple/server/impl/BasePeer.h index ba4efc6079..c9c4ff501f 100644 --- a/src/ripple/server/impl/BasePeer.h +++ b/src/ripple/server/impl/BasePeer.h @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -48,14 +49,15 @@ protected: beast::WrappedSink sink_; beast::Journal j_; - boost::asio::io_service::work work_; - boost::asio::io_service::strand strand_; - + boost::asio::executor_work_guard work_; + boost::asio::strand strand_; public: - BasePeer(Port const& port, Handler& handler, + BasePeer( + Port const& port, + Handler& handler, + boost::asio::executor const& executor, endpoint_type remote_address, - boost::asio::io_service& io_service, - beast::Journal journal); + beast::Journal journal); void close() override; @@ -70,24 +72,25 @@ private: //------------------------------------------------------------------------------ -template -BasePeer:: -BasePeer(Port const& port, Handler& handler, +template +BasePeer::BasePeer( + Port const& port, + Handler& handler, + boost::asio::executor const& executor, endpoint_type remote_address, - boost::asio::io_service& io_service, - beast::Journal journal) + beast::Journal journal) : port_(port) , handler_(handler) , remote_address_(remote_address) - , sink_(journal.sink(), - [] - { - static std::atomic id{0}; - return "##" + std::to_string(++id) + " "; - }()) + , sink_( + journal.sink(), + [] { + static std::atomic id{0}; + return "##" + std::to_string(++id) + " "; + }()) , j_(sink_) - , work_(io_service) - , strand_(io_service) + , work_(executor) + , strand_(executor) { } @@ -97,10 +100,10 @@ BasePeer:: close() { if (! strand_.running_in_this_thread()) - return strand_.post(std::bind( - &BasePeer::close, impl().shared_from_this())); + return post( + strand_, std::bind(&BasePeer::close, impl().shared_from_this())); error_code ec; - impl().ws_.lowest_layer().close(ec); + ripple::get_lowest_layer(impl().ws_).close(ec); } } // ripple diff --git a/src/ripple/server/impl/BaseWSPeer.h b/src/ripple/server/impl/BaseWSPeer.h index 301d78ace3..135a69fc07 100644 --- a/src/ripple/server/impl/BaseWSPeer.h +++ b/src/ripple/server/impl/BaseWSPeer.h @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -66,9 +67,10 @@ public: BaseWSPeer( Port const& port, Handler& handler, + boost::asio::executor const& executor, + waitable_timer timer, endpoint_type remote_address, boost::beast::http::request&& request, - boost::asio::io_service& io_service, beast::Journal journal); void @@ -156,21 +158,25 @@ protected: //------------------------------------------------------------------------------ -template -template -BaseWSPeer:: -BaseWSPeer( +template +template +BaseWSPeer::BaseWSPeer( Port const& port, Handler& handler, + boost::asio::executor const& executor, + waitable_timer timer, endpoint_type remote_address, boost::beast::http::request&& request, - boost::asio::io_service& io_service, beast::Journal journal) - : BasePeer(port, handler, remote_address, - io_service, journal) + : BasePeer( + port, + handler, + executor, + remote_address, + journal) , request_(std::move(request)) - , timer_(io_service) - , payload_ ("12345678") // ensures size is 8 bytes + , timer_(std::move(timer)) + , payload_("12345678") // ensures size is 8 bytes { } @@ -180,8 +186,8 @@ BaseWSPeer:: run() { if(! strand_.running_in_this_thread()) - return strand_.post(std::bind( - &BaseWSPeer::run, impl().shared_from_this())); + return post( + strand_, std::bind(&BaseWSPeer::run, impl().shared_from_this())); impl().ws_.set_option(port().pmd_options); // Must manage the control callback memory outside of the `control_callback` function control_callback_ = std::bind( @@ -190,14 +196,18 @@ run() impl().ws_.control_callback(control_callback_); start_timer(); close_on_timer_ = true; - impl().ws_.async_accept_ex(request_, - [](auto & res) - { + impl().ws_.async_accept_ex( + request_, + [](auto& res) { res.set(boost::beast::http::field::server, BuildInfo::getFullVersionString()); }, - strand_.wrap(std::bind(&BaseWSPeer::on_ws_handshake, - impl().shared_from_this(), std::placeholders::_1))); + bind_executor( + strand_, + std::bind( + &BaseWSPeer::on_ws_handshake, + impl().shared_from_this(), + std::placeholders::_1))); } template @@ -206,9 +216,10 @@ BaseWSPeer:: send(std::shared_ptr w) { if(! strand_.running_in_this_thread()) - return strand_.post(std::bind( - &BaseWSPeer::send, impl().shared_from_this(), - std::move(w))); + return post( + strand_, + std::bind( + &BaseWSPeer::send, impl().shared_from_this(), std::move(w))); if(do_close_) return; if(wq_.size() > port().ws_queue_limit) @@ -233,13 +244,18 @@ BaseWSPeer:: close() { if(! strand_.running_in_this_thread()) - return strand_.post(std::bind( - &BaseWSPeer::close, impl().shared_from_this())); + return post( + strand_, std::bind(&BaseWSPeer::close, impl().shared_from_this())); do_close_ = true; if(wq_.empty()) - impl().ws_.async_close({}, strand_.wrap(std::bind( - &BaseWSPeer::on_close, impl().shared_from_this(), - std::placeholders::_1))); + impl().ws_.async_close( + {}, + bind_executor( + strand_, + std::bind( + &BaseWSPeer::on_close, + impl().shared_from_this(), + std::placeholders::_1))); } template @@ -248,8 +264,9 @@ BaseWSPeer:: complete() { if(! strand_.running_in_this_thread()) - return strand_.post(std::bind( - &BaseWSPeer::complete, impl().shared_from_this())); + return post( + strand_, + std::bind(&BaseWSPeer::complete, impl().shared_from_this())); do_read(); } @@ -270,8 +287,9 @@ BaseWSPeer:: do_write() { if(! strand_.running_in_this_thread()) - return strand_.post(std::bind( - &BaseWSPeer::do_write, impl().shared_from_this())); + return post( + strand_, + std::bind(&BaseWSPeer::do_write, impl().shared_from_this())); on_write({}); } @@ -293,18 +311,22 @@ on_write(error_code const& ec) impl().ws_.async_write_some( static_cast(result.first), result.second, - strand_.wrap(std::bind( - &BaseWSPeer::on_write, - impl().shared_from_this(), - std::placeholders::_1))); + bind_executor( + strand_, + std::bind( + &BaseWSPeer::on_write, + impl().shared_from_this(), + std::placeholders::_1))); else impl().ws_.async_write_some( static_cast(result.first), result.second, - strand_.wrap(std::bind( - &BaseWSPeer::on_write_fin, - impl().shared_from_this(), - std::placeholders::_1))); + bind_executor( + strand_, + std::bind( + &BaseWSPeer::on_write_fin, + impl().shared_from_this(), + std::placeholders::_1))); } template @@ -316,9 +338,14 @@ on_write_fin(error_code const& ec) return fail(ec, "write_fin"); wq_.pop_front(); if(do_close_) - impl().ws_.async_close(cr_, strand_.wrap(std::bind( - &BaseWSPeer::on_close, impl().shared_from_this(), - std::placeholders::_1))); + impl().ws_.async_close( + cr_, + bind_executor( + strand_, + std::bind( + &BaseWSPeer::on_close, + impl().shared_from_this(), + std::placeholders::_1))); else if(! wq_.empty()) on_write({}); } @@ -329,11 +356,17 @@ BaseWSPeer:: do_read() { if(! strand_.running_in_this_thread()) - return strand_.post(std::bind( - &BaseWSPeer::do_read, impl().shared_from_this())); - impl().ws_.async_read(rb_, strand_.wrap( - std::bind(&BaseWSPeer::on_read, - impl().shared_from_this(), std::placeholders::_1))); + return post( + strand_, + std::bind(&BaseWSPeer::do_read, impl().shared_from_this())); + impl().ws_.async_read( + rb_, + bind_executor( + strand_, + std::bind( + &BaseWSPeer::on_read, + impl().shared_from_this(), + std::placeholders::_1))); } template @@ -376,8 +409,11 @@ start_timer() ec); if(ec) return fail(ec, "start_timer"); - timer_.async_wait(strand_.wrap(std::bind( - &BaseWSPeer::on_timer, impl().shared_from_this(), + timer_.async_wait(bind_executor( + strand_, + std::bind( + &BaseWSPeer::on_timer, + impl().shared_from_this(), std::placeholders::_1))); } @@ -444,11 +480,14 @@ on_timer(error_code ec) // cryptographic is probably overkill.. beast::rngfill(payload_.begin(), payload_.size(), crypto_prng()); - impl().ws_.async_ping(payload_, - strand_.wrap(std::bind( - &BaseWSPeer::on_ping, + impl().ws_.async_ping( + payload_, + bind_executor( + strand_, + std::bind( + &BaseWSPeer::on_ping, impl().shared_from_this(), - std::placeholders::_1))); + std::placeholders::_1))); JLOG(this->j_.trace()) << "sent ping"; return; @@ -474,7 +513,7 @@ fail(error_code ec, String const& what) ec_ = ec; JLOG(this->j_.trace()) << what << ": " << ec.message(); - impl().ws_.lowest_layer().close(ec); + ripple::get_lowest_layer(impl().ws_).close(ec); } } diff --git a/src/ripple/server/impl/Door.h b/src/ripple/server/impl/Door.h index 8ada7a10c7..b04ad0861e 100644 --- a/src/ripple/server/impl/Door.h +++ b/src/ripple/server/impl/Door.h @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include #include @@ -65,16 +65,21 @@ private: private: Port const& port_; Handler& handler_; + boost::asio::io_context& ioc_; socket_type socket_; timer_type timer_; endpoint_type remote_address_; - boost::asio::io_service::strand strand_; + boost::asio::io_context::strand strand_; beast::Journal j_; public: - Detector (Port const& port, Handler& handler, - socket_type&& socket, endpoint_type remote_address, - beast::Journal j); + Detector( + Port const& port, + Handler& handler, + boost::asio::io_context& ioc, + socket_type&& socket, + endpoint_type remote_address, + beast::Journal j); void run(); void close() override; @@ -86,13 +91,14 @@ private: beast::Journal j_; Port const& port_; Handler& handler_; + boost::asio::io_context& ioc_; acceptor_type acceptor_; - boost::asio::io_service::strand strand_; + boost::asio::io_context::strand strand_; bool ssl_; bool plain_; public: - Door(Handler& handler, boost::asio::io_service& io_service, + Door(Handler& handler, boost::asio::io_context& io_context, Port const& port, beast::Journal j); // Work-around because we can't call shared_from_this in ctor @@ -169,17 +175,21 @@ detect_ssl (Socket& socket, StreamBuf& buf, Yield do_yield) return result; } -template -Door::Detector:: -Detector(Port const& port, - Handler& handler, socket_type&& socket, - endpoint_type remote_address, beast::Journal j) +template +Door::Detector::Detector( + Port const& port, + Handler& handler, + boost::asio::io_context& ioc, + socket_type&& socket, + endpoint_type remote_address, + beast::Journal j) : port_(port) , handler_(handler) + , ioc_(ioc) , socket_(std::move(socket)) - , timer_(socket_.get_io_service()) + , timer_(ioc_) , remote_address_(remote_address) - , strand_(socket_.get_io_service()) + , strand_(ioc_) , j_(j) { } @@ -238,15 +248,15 @@ do_detect(boost::asio::yield_context do_yield) { if (ssl) { - if(auto sp = ios().template emplace>( - port_, handler_, j_, remote_address_, - buf.data(), std::move(socket_))) + if (auto sp = ios().template emplace>( + port_, handler_, ioc_, j_, remote_address_, + buf.data(), std::move(socket_))) sp->run(); return; } - if(auto sp = ios().template emplace>( - port_, handler_, j_, remote_address_, - buf.data(), std::move(socket_))) + if (auto sp = ios().template emplace>( + port_, handler_, ioc_, j_, remote_address_, + buf.data(), std::move(socket_))) sp->run(); return; } @@ -262,13 +272,14 @@ do_detect(boost::asio::yield_context do_yield) template Door:: -Door(Handler& handler, boost::asio::io_service& io_service, +Door(Handler& handler, boost::asio::io_context& io_context, Port const& port, beast::Journal j) : j_(j) , port_(port) , handler_(handler) - , acceptor_(io_service) - , strand_(io_service) + , ioc_(io_context) + , acceptor_(io_context) + , strand_(io_context) , ssl_( port_.protocol.count("https") > 0 || port_.protocol.count("wss") > 0 || @@ -352,15 +363,15 @@ create(bool ssl, ConstBufferSequence const& buffers, { if (ssl) { - if(auto sp = ios().template emplace>( - port_, handler_, j_, remote_address, - buffers, std::move(socket))) + if (auto sp = ios().template emplace>( + port_, handler_, ioc_, j_, remote_address, + buffers, std::move(socket))) sp->run(); return; } - if(auto sp = ios().template emplace>( - port_, handler_, j_, remote_address, - buffers, std::move(socket))) + if (auto sp = ios().template emplace>( + port_, handler_, ioc_, j_, remote_address, + buffers, std::move(socket))) sp->run(); } @@ -373,7 +384,7 @@ do_accept(boost::asio::yield_context do_yield) { error_code ec; endpoint_type remote_address; - socket_type socket (acceptor_.get_io_service()); + socket_type socket (ioc_); acceptor_.async_accept (socket, remote_address, do_yield[ec]); if (ec && ec != boost::asio::error::operation_aborted) { @@ -387,9 +398,9 @@ do_accept(boost::asio::yield_context do_yield) if (ssl_ && plain_) { - if(auto sp = ios().template emplace( - port_, handler_, std::move(socket), - remote_address, j_)) + if (auto sp = ios().template emplace( + port_, handler_, ioc_, std::move(socket), + remote_address, j_)) sp->run(); } else if (ssl_ || plain_) diff --git a/src/ripple/server/impl/LowestLayer.h b/src/ripple/server/impl/LowestLayer.h new file mode 100644 index 0000000000..abc6904179 --- /dev/null +++ b/src/ripple/server/impl/LowestLayer.h @@ -0,0 +1,46 @@ + +//------------------------------------------------------------------------------ +/* + This file is part of rippled: https://github.com/ripple/rippled + Copyright (c) 2019 Ripple Labs Inc. + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef RIPPLE_SERVER_LOWESTLAYER_H_INCLUDED +#define RIPPLE_SERVER_LOWESTLAYER_H_INCLUDED + +#if BOOST_VERSION >= 107000 +#include +#else +#include +#endif + +namespace ripple { + +// Before boost 1.70, get_lowest_layer required an explicit templat parameter +template +decltype(auto) +get_lowest_layer(T& t) noexcept +{ +#if BOOST_VERSION >= 107000 + return boost::beast::get_lowest_layer(t); +#else + return t.lowest_layer(); +#endif +} + +} // namespace ripple + +#endif diff --git a/src/ripple/server/impl/PlainHTTPPeer.h b/src/ripple/server/impl/PlainHTTPPeer.h index 5c2984c0e6..9f249dacfb 100644 --- a/src/ripple/server/impl/PlainHTTPPeer.h +++ b/src/ripple/server/impl/PlainHTTPPeer.h @@ -34,19 +34,24 @@ class PlainHTTPPeer { private: friend class BaseHTTPPeer; + using waitable_timer = typename BaseHTTPPeer::waitable_timer; using socket_type = boost::asio::ip::tcp::socket; using endpoint_type = boost::asio::ip::tcp::endpoint; socket_type stream_; public: - template - PlainHTTPPeer(Port const& port, Handler& handler, - beast::Journal journal, endpoint_type remote_address, - ConstBufferSequence const& buffers, socket_type&& socket); + template + PlainHTTPPeer( + Port const& port, + Handler& handler, + boost::asio::io_context& ioc, + beast::Journal journal, + endpoint_type remote_address, + ConstBufferSequence const& buffers, + socket_type&& socket); - void - run(); + void run(); std::shared_ptr websocketUpgrade() override; @@ -61,14 +66,24 @@ private: //------------------------------------------------------------------------------ -template -template -PlainHTTPPeer:: -PlainHTTPPeer(Port const& port, Handler& handler, - beast::Journal journal, endpoint_type remote_endpoint, - ConstBufferSequence const& buffers, socket_type&& socket) - : BaseHTTPPeer(port, handler, - socket.get_io_service(), journal, remote_endpoint, buffers) +template +template +PlainHTTPPeer::PlainHTTPPeer( + Port const& port, + Handler& handler, + boost::asio::io_context& ioc, + beast::Journal journal, + endpoint_type remote_endpoint, + ConstBufferSequence const& buffers, + socket_type&& socket) + : BaseHTTPPeer( + port, + handler, + ioc.get_executor(), + waitable_timer{ioc}, + journal, + remote_endpoint, + buffers) , stream_(std::move(socket)) { // Set TCP_NODELAY on loopback interfaces, diff --git a/src/ripple/server/impl/PlainWSPeer.h b/src/ripple/server/impl/PlainWSPeer.h index d06f612ec2..18e608dbff 100644 --- a/src/ripple/server/impl/PlainWSPeer.h +++ b/src/ripple/server/impl/PlainWSPeer.h @@ -21,6 +21,7 @@ #define RIPPLE_SERVER_PLAINWSPEER_H_INCLUDED #include +#include #include namespace ripple { @@ -54,18 +55,23 @@ public: //------------------------------------------------------------------------------ -template -template -PlainWSPeer:: -PlainWSPeer( +template +template +PlainWSPeer::PlainWSPeer( Port const& port, Handler& handler, endpoint_type remote_address, boost::beast::http::request&& request, socket_type&& socket, beast::Journal journal) - : BaseWSPeer(port, handler, remote_address, - std::move(request), socket.get_io_service(), journal) + : BaseWSPeer( + port, + handler, + socket.get_executor(), + beast::create_waitable_timer(socket), + remote_address, + std::move(request), + journal) , ws_(std::move(socket)) { } diff --git a/src/ripple/server/impl/SSLHTTPPeer.h b/src/ripple/server/impl/SSLHTTPPeer.h index e7dd7fef20..1d30b6b48a 100644 --- a/src/ripple/server/impl/SSLHTTPPeer.h +++ b/src/ripple/server/impl/SSLHTTPPeer.h @@ -23,6 +23,7 @@ #include #include #include +#include #include namespace ripple { @@ -34,6 +35,7 @@ class SSLHTTPPeer { private: friend class BaseHTTPPeer; + using waitable_timer = typename BaseHTTPPeer::waitable_timer; using socket_type = boost::asio::ip::tcp::socket; using stream_type = boost::asio::ssl::stream ; using endpoint_type = boost::asio::ip::tcp::endpoint; @@ -44,10 +46,15 @@ private: stream_type& stream_; public: - template - SSLHTTPPeer(Port const& port, Handler& handler, - beast::Journal journal, endpoint_type remote_address, - ConstBufferSequence const& buffers, socket_type&& socket); + template + SSLHTTPPeer( + Port const& port, + Handler& handler, + boost::asio::io_context& ioc, + beast::Journal journal, + endpoint_type remote_address, + ConstBufferSequence const& buffers, + socket_type&& socket); void run(); @@ -71,14 +78,24 @@ private: //------------------------------------------------------------------------------ -template -template -SSLHTTPPeer:: -SSLHTTPPeer(Port const& port, Handler& handler, - beast::Journal journal, endpoint_type remote_address, - ConstBufferSequence const& buffers, socket_type&& socket) - : BaseHTTPPeer(port, handler, - socket.get_io_service(), journal, remote_address, buffers) +template +template +SSLHTTPPeer::SSLHTTPPeer( + Port const& port, + Handler& handler, + boost::asio::io_context& ioc, + beast::Journal journal, + endpoint_type remote_address, + ConstBufferSequence const& buffers, + socket_type&& socket) + : BaseHTTPPeer( + port, + handler, + ioc.get_executor(), + waitable_timer{ioc}, + journal, + remote_address, + buffers) , ssl_bundle_(std::make_unique( port.context, std::move(socket))) , stream_(ssl_bundle_->stream) @@ -168,8 +185,11 @@ SSLHTTPPeer:: do_close() { this->start_timer(); - stream_.async_shutdown(this->strand_.wrap(std::bind ( - &SSLHTTPPeer::on_shutdown, this->shared_from_this(), + stream_.async_shutdown(bind_executor( + this->strand_, + std::bind( + &SSLHTTPPeer::on_shutdown, + this->shared_from_this(), std::placeholders::_1))); } diff --git a/src/ripple/server/impl/SSLWSPeer.h b/src/ripple/server/impl/SSLWSPeer.h index 3b662ff471..0ed8397dd6 100644 --- a/src/ripple/server/impl/SSLWSPeer.h +++ b/src/ripple/server/impl/SSLWSPeer.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -60,20 +61,23 @@ public: //------------------------------------------------------------------------------ -template -template -SSLWSPeer:: -SSLWSPeer( +template +template +SSLWSPeer::SSLWSPeer( Port const& port, Handler& handler, endpoint_type remote_endpoint, boost::beast::http::request&& request, - std::unique_ptr< - beast::asio::ssl_bundle>&& ssl_bundle, + std::unique_ptr&& ssl_bundle, beast::Journal journal) - : BaseWSPeer(port, handler, - remote_endpoint, std::move(request), - ssl_bundle->socket.get_io_service(), journal) + : BaseWSPeer( + port, + handler, + ssl_bundle->socket.get_executor(), + beast::create_waitable_timer(ssl_bundle->socket), + remote_endpoint, + std::move(request), + journal) , ssl_bundle_(std::move(ssl_bundle)) , ws_(ssl_bundle_->stream) { diff --git a/src/test/jtx/TrustedPublisherServer.h b/src/test/jtx/TrustedPublisherServer.h index 11f548ad20..993450c420 100644 --- a/src/test/jtx/TrustedPublisherServer.h +++ b/src/test/jtx/TrustedPublisherServer.h @@ -58,14 +58,14 @@ public: }; TrustedPublisherServer( - boost::asio::io_service& ios, + boost::asio::io_context& ioc, std::pair keys, std::string const& manifest, int sequence, NetClock::time_point expiration, int version, std::vector const& validators) - : sock_(ios), acceptor_(ios) + : sock_(ioc), acceptor_(ioc) { endpoint_type const& ep { beast::IP::Address::from_string (ripple::test::getEnvLocalhostAddr()), @@ -124,13 +124,13 @@ private: int id; TrustedPublisherServer& self; socket_type sock; - boost::asio::io_service::work work; + boost::asio::executor_work_guard work; lambda(int id_, TrustedPublisherServer& self_, socket_type&& sock_) : id(id_) , self(self_) , sock(std::move(sock_)) - , work(sock.get_io_service()) + , work(sock_.get_executor()) { } diff --git a/src/test/overlay/short_read_test.cpp b/src/test/overlay/short_read_test.cpp index 1dcf303ac3..d02fcfaf75 100644 --- a/src/test/overlay/short_read_test.cpp +++ b/src/test/overlay/short_read_test.cpp @@ -48,8 +48,8 @@ will complete with eof. class short_read_test : public beast::unit_test::suite { private: - using io_service_type = boost::asio::io_service; - using strand_type = io_service_type::strand; + using io_context_type = boost::asio::io_context; + using strand_type = boost::asio::io_context::strand; using timer_type = boost::asio::basic_waitable_timer< std::chrono::steady_clock>; using acceptor_type = boost::asio::ip::tcp::acceptor; @@ -59,8 +59,8 @@ private: using endpoint_type = boost::asio::ip::tcp::endpoint; using address_type = boost::asio::ip::address; - io_service_type io_service_; - boost::optional work_; + io_context_type io_context_; + boost::optional> work_; std::thread thread_; std::shared_ptr context_; @@ -183,11 +183,11 @@ private: : Child(server) , server_(server) , test_(server_.test_) - , acceptor_(test_.io_service_, + , acceptor_(test_.io_context_, endpoint_type(beast::IP::Address::from_string( test::getEnvLocalhostAddr()), 0)) - , socket_(test_.io_service_) - , strand_(socket_.get_io_service()) + , socket_(test_.io_context_) + , strand_(test_.io_context_) { acceptor_.listen(); server_.endpoint_ = acceptor_.local_endpoint(); @@ -199,7 +199,7 @@ private: close() override { if(! strand_.running_in_this_thread()) - return strand_.post(std::bind(&Acceptor::close, + return post(strand_, std::bind(&Acceptor::close, shared_from_this())); acceptor_.close(); } @@ -207,9 +207,14 @@ private: void run() { - acceptor_.async_accept(socket_, strand_.wrap(std::bind( - &Acceptor::on_accept, shared_from_this(), - std::placeholders::_1))); + acceptor_.async_accept( + socket_, + bind_executor( + strand_, + std::bind( + &Acceptor::on_accept, + shared_from_this(), + std::placeholders::_1))); } void @@ -233,9 +238,14 @@ private: server_, std::move(socket_)); server_.add(p); p->run(); - acceptor_.async_accept(socket_, strand_.wrap(std::bind( - &Acceptor::on_accept, shared_from_this(), - std::placeholders::_1))); + acceptor_.async_accept( + socket_, + bind_executor( + strand_, + std::bind( + &Acceptor::on_accept, + shared_from_this(), + std::placeholders::_1))); } }; @@ -256,8 +266,8 @@ private: , test_(server_.test_) , socket_(std::move(socket)) , stream_(socket_, *test_.context_) - , strand_(socket_.get_io_service()) - , timer_(socket_.get_io_service()) + , strand_(test_.io_context_) + , timer_(test_.io_context_) { } @@ -265,7 +275,7 @@ private: close() override { if(! strand_.running_in_this_thread()) - return strand_.post(std::bind(&Connection::close, + return post(strand_, std::bind(&Connection::close, shared_from_this())); if (socket_.is_open()) { @@ -278,11 +288,20 @@ private: run() { timer_.expires_from_now(std::chrono::seconds(3)); - timer_.async_wait(strand_.wrap(std::bind(&Connection::on_timer, - shared_from_this(), std::placeholders::_1))); - stream_.async_handshake(stream_type::server, strand_.wrap( - std::bind(&Connection::on_handshake, shared_from_this(), + timer_.async_wait(bind_executor( + strand_, + std::bind( + &Connection::on_timer, + shared_from_this(), std::placeholders::_1))); + stream_.async_handshake( + stream_type::server, + bind_executor( + strand_, + std::bind( + &Connection::on_handshake, + shared_from_this(), + std::placeholders::_1))); } void @@ -315,9 +334,16 @@ private: if (ec) return fail("handshake", ec); #if 1 - boost::asio::async_read_until(stream_, buf_, "\n", strand_.wrap( - std::bind(&Connection::on_read, shared_from_this(), - std::placeholders::_1, + boost::asio::async_read_until( + stream_, + buf_, + "\n", + bind_executor( + strand_, + std::bind( + &Connection::on_read, + shared_from_this(), + std::placeholders::_1, std::placeholders::_2))); #else close(); @@ -330,8 +356,11 @@ private: if (ec == boost::asio::error::eof) { server_.test_.log << "[server] read: EOF" << std::endl; - return stream_.async_shutdown(strand_.wrap(std::bind( - &Connection::on_shutdown, shared_from_this(), + return stream_.async_shutdown(bind_executor( + strand_, + std::bind( + &Connection::on_shutdown, + shared_from_this(), std::placeholders::_1))); } if (ec) @@ -340,9 +369,15 @@ private: buf_.commit(bytes_transferred); buf_.consume(bytes_transferred); write(buf_, "BYE\n"); - boost::asio::async_write(stream_, buf_.data(), strand_.wrap( - std::bind(&Connection::on_write, shared_from_this(), - std::placeholders::_1, + boost::asio::async_write( + stream_, + buf_.data(), + bind_executor( + strand_, + std::bind( + &Connection::on_write, + shared_from_this(), + std::placeholders::_1, std::placeholders::_2))); } @@ -352,8 +387,11 @@ private: buf_.consume(bytes_transferred); if (ec) return fail("write", ec); - stream_.async_shutdown(strand_.wrap(std::bind( - &Connection::on_shutdown, shared_from_this(), + stream_.async_shutdown(bind_executor( + strand_, + std::bind( + &Connection::on_shutdown, + shared_from_this(), std::placeholders::_1))); } @@ -412,10 +450,10 @@ private: : Child(client) , client_(client) , test_(client_.test_) - , socket_(test_.io_service_) + , socket_(test_.io_context_) , stream_(socket_, *test_.context_) - , strand_(socket_.get_io_service()) - , timer_(socket_.get_io_service()) + , strand_(test_.io_context_) + , timer_(test_.io_context_) , ep_(ep) { } @@ -424,8 +462,9 @@ private: close() override { if(! strand_.running_in_this_thread()) - return strand_.post(std::bind(&Connection::close, - shared_from_this())); + return post( + strand_, + std::bind(&Connection::close, shared_from_this())); if (socket_.is_open()) { socket_.close(); @@ -437,11 +476,20 @@ private: run(endpoint_type const& ep) { timer_.expires_from_now(std::chrono::seconds(3)); - timer_.async_wait(strand_.wrap(std::bind(&Connection::on_timer, - shared_from_this(), std::placeholders::_1))); - socket_.async_connect(ep, strand_.wrap(std::bind( - &Connection::on_connect, shared_from_this(), + timer_.async_wait(bind_executor( + strand_, + std::bind( + &Connection::on_timer, + shared_from_this(), std::placeholders::_1))); + socket_.async_connect( + ep, + bind_executor( + strand_, + std::bind( + &Connection::on_connect, + shared_from_this(), + std::placeholders::_1))); } void @@ -473,9 +521,14 @@ private: { if (ec) return fail("connect", ec); - stream_.async_handshake(stream_type::client, strand_.wrap( - std::bind(&Connection::on_handshake, shared_from_this(), - std::placeholders::_1))); + stream_.async_handshake( + stream_type::client, + bind_executor( + strand_, + std::bind( + &Connection::on_handshake, + shared_from_this(), + std::placeholders::_1))); } void @@ -486,13 +539,22 @@ private: write(buf_, "HELLO\n"); #if 1 - boost::asio::async_write(stream_, buf_.data(), strand_.wrap( - std::bind(&Connection::on_write, shared_from_this(), - std::placeholders::_1, + boost::asio::async_write( + stream_, + buf_.data(), + bind_executor( + strand_, + std::bind( + &Connection::on_write, + shared_from_this(), + std::placeholders::_1, std::placeholders::_2))); #else - stream_.async_shutdown(strand_.wrap(std::bind( - &Connection::on_shutdown, shared_from_this(), + stream_.async_shutdown(bind_executor( + strand_, + std::bind( + &Connection::on_shutdown, + shared_from_this(), std::placeholders::_1))); #endif } @@ -504,13 +566,23 @@ private: if (ec) return fail("write", ec); #if 1 - boost::asio::async_read_until(stream_, buf_, "\n", strand_.wrap( - std::bind(&Connection::on_read, shared_from_this(), - std::placeholders::_1, + boost::asio::async_read_until( + stream_, + buf_, + "\n", + bind_executor( + strand_, + std::bind( + &Connection::on_read, + shared_from_this(), + std::placeholders::_1, std::placeholders::_2))); #else - stream_.async_shutdown(strand_.wrap(std::bind( - &Connection::on_shutdown, shared_from_this(), + stream_.async_shutdown(bind_executor( + strand_, + std::bind( + &Connection::on_shutdown, + shared_from_this(), std::placeholders::_1))); #endif } @@ -521,8 +593,11 @@ private: if (ec) return fail("read", ec); buf_.commit(bytes_transferred); - stream_.async_shutdown(strand_.wrap(std::bind( - &Connection::on_shutdown, shared_from_this(), + stream_.async_shutdown(bind_executor( + strand_, + std::bind( + &Connection::on_shutdown, + shared_from_this(), std::placeholders::_1))); } @@ -555,12 +630,11 @@ private: public: short_read_test() - : work_(boost::in_place(std::ref(io_service_))) - , thread_(std::thread([this]() - { - beast::setCurrentThreadName("io_service"); - this->io_service_.run(); - })) + : work_(io_context_.get_executor()) + , thread_(std::thread([this]() { + beast::setCurrentThreadName("io_context"); + this->io_context_.run(); + })) , context_(make_SSLContext("")) { }