Support Boost 1.70:

This patch removes calls to several deprecated asio functions.

* `io_service::post` becomes `post` (free function)
* `io_service::work` becomes `executor_work_guard`
* `io_service::wrap` becomes `bind_executor`
* `get_io_context`   becomes `get_executor` or `get_executor().context()`

This patch was tested with boost 1.69 and 1.70. The functions
`ripple::get_lowest_layer` and `beast::create_waitable_timer` are required to
handle a breaking difference between these versions. When rippled no longer
needs to support pre 1.70 boost versions, both of these functions may be
removed, and the waitable timer injections may also be removed.
This commit is contained in:
seelabs
2019-04-11 20:39:53 -04:00
committed by Manoj doshi
parent b39b0fef39
commit 6f9e8dc720
21 changed files with 727 additions and 451 deletions

View File

@@ -85,33 +85,33 @@ The following :prop_tgt:`IMPORTED` targets are also defined::
Boost::dynamic_linking - interface target to enable dynamic linking Boost::dynamic_linking - interface target to enable dynamic linking
linking with MSVC (adds BOOST_ALL_DYN_LINK) linking with MSVC (adds BOOST_ALL_DYN_LINK)
Implicit dependencies such as Boost::filesystem requiring Implicit dependencies such as ``Boost::filesystem`` requiring
Boost::system will be automatically detected and satisfied, even ``Boost::system`` will be automatically detected and satisfied, even
if system is not specified when using find_package and if if system is not specified when using :command:`find_package` and if
Boost::system is not added to target_link_libraries. If using ``Boost::system`` is not added to :command:`target_link_libraries`. If using
Boost::thread, then Threads::Threads will also be added automatically. ``Boost::thread``, then ``Threads::Threads`` will also be added automatically.
It is important to note that the imported targets behave differently It is important to note that the imported targets behave differently
than variables created by this module: multiple calls to 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 different options (e.g. static or shared) will not override the
values of the targets created by the first call. 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 should not read these entries directly but instead use the above
result variables. Note that some hint names start in upper-case result variables. Note that some hint names start in upper-case
"BOOST". One may specify these as environment variables if they are "BOOST". One may specify these as environment variables if they are
not specified as CMake variables or cache entries. not specified as CMake variables or cache entries.
This module first searches for the Boost header files using the above This module first searches for the ``Boost`` header files using the above
hint variables (excluding BOOST_LIBRARYDIR) and saves the result in hint variables (excluding ``BOOST_LIBRARYDIR``) and saves the result in
Boost_INCLUDE_DIR. Then it searches for requested component libraries ``Boost_INCLUDE_DIR``. Then it searches for requested component libraries
using the above hints (excluding BOOST_INCLUDEDIR and using the above hints (excluding ``BOOST_INCLUDEDIR`` and
Boost_ADDITIONAL_VERSIONS), "lib" directories near Boost_INCLUDE_DIR, ``Boost_ADDITIONAL_VERSIONS``), "lib" directories near ``Boost_INCLUDE_DIR``,
and the library name configuration settings below. It saves the and the library name configuration settings below. It saves the
library directories in Boost_LIBRARY_DIR_DEBUG and library directories in ``Boost_LIBRARY_DIR_DEBUG`` and
Boost_LIBRARY_DIR_RELEASE and individual library ``Boost_LIBRARY_DIR_RELEASE`` and individual library
locations in Boost_<C>_LIBRARY_DEBUG and Boost_<C>_LIBRARY_RELEASE. locations in ``Boost_<C>_LIBRARY_DEBUG`` and ``Boost_<C>_LIBRARY_RELEASE``.
When one changes settings used by previous searches in the same build When one changes settings used by previous searches in the same build
tree (excluding environment variables) this module discards previous tree (excluding environment variables) this module discards previous
search results affected by the changes and searches again. 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 On Visual Studio and Borland compilers Boost headers request automatic
linking to corresponding libraries. This requires matching libraries linking to corresponding libraries. This requires matching libraries
to be linked explicitly or available in the link library search path. 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 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}) 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 If Boost was built using the boost-cmake project it provides a package
configuration file for use with find_package's Config mode. This configuration file for use with find_package's Config mode. This
module looks for the package configuration file called module looks for the package configuration file called
BoostConfig.cmake or boost-config.cmake and stores the result in cache ``BoostConfig.cmake`` or ``boost-config.cmake`` and stores the result in
entry "Boost_DIR". If found, the package configuration file is loaded ``CACHE`` entry "Boost_DIR". If found, the package configuration file is loaded
and this module returns with no further action. See documentation of and this module returns with no further action. See documentation of
the Boost CMake package configuration for details on what it provides. 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 # Save project's policies
@@ -465,33 +465,20 @@ function(_Boost_GUESS_COMPILER_PREFIX _ret)
endif() endif()
elseif (GHSMULTI) elseif (GHSMULTI)
set(_boost_COMPILER "-ghs") set(_boost_COMPILER "-ghs")
elseif("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xMSVC") elseif("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xMSVC" OR "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
#[========================================================[ if(MSVC_TOOLSET_VERSION GREATER_EQUAL 150)
NOTE: newer versions of FindBoost from kitware # Not yet known.
change this version check to use MSVC_TOOLSET_VERSION. set(_boost_COMPILER "")
That variable only exists in make 3.12 or greater, so elseif(MSVC_TOOLSET_VERSION GREATER_EQUAL 140)
until all envs (including bundled visual studio) have # MSVC toolset 14.x versions are forward compatible.
this min version of cmake, stick with this set(_boost_COMPILER "")
CMAKE_CXX_COMPILER_VERSION check foreach(v 9 8 7 6 5 4 3 2 1 0)
#]========================================================] if(MSVC_TOOLSET_VERSION GREATER_EQUAL 14${v})
if(DEFINED MSVC_TOOLSET_VERSION AND MSVC_TOOLSET_VERSION GREATER_EQUAL 141) list(APPEND _boost_COMPILER "-vc14${v}")
set(_boost_COMPILER "-vc141;-vc140") endif()
elseif(DEFINED MSVC_TOOLSET_VERSION AND MSVC_TOOLSET_VERSION GREATER_EQUAL 80) endforeach()
elseif(MSVC_TOOLSET_VERSION GREATER_EQUAL 80)
set(_boost_COMPILER "-vc${MSVC_TOOLSET_VERSION}") 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) elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 13.10)
set(_boost_COMPILER "-vc71") set(_boost_COMPILER "-vc71")
elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 13) # Good luck! 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! else() # VS 6.0 Good luck!
set(_boost_COMPILER "-vc6") # yes, this is correct set(_boost_COMPILER "-vc6") # yes, this is correct
endif() 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) elseif (BORLAND)
set(_boost_COMPILER "-bcb") set(_boost_COMPILER "-bcb")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "SunPro") 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_TIMER_DEPENDENCIES chrono system)
set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread chrono date_time atomic) set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread chrono date_time atomic)
set(_Boost_WSERIALIZATION_DEPENDENCIES serialization) 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() 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_CONTRACT_DEPENDENCIES thread chrono date_time)
set(_Boost_COROUTINE_DEPENDENCIES context) set(_Boost_COROUTINE_DEPENDENCIES context)
set(_Boost_FIBER_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_WAVE_DEPENDENCIES filesystem serialization thread chrono date_time atomic)
set(_Boost_WSERIALIZATION_DEPENDENCIES serialization) set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
endif() 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") message(WARNING "New Boost version may have incorrect or missing dependencies and imported targets")
endif() endif()
endif() endif()
@@ -1085,27 +1092,18 @@ function(_Boost_UPDATE_WINDOWS_LIBRARY_SEARCH_DIRS_WITH_PREBUILT_PATHS component
else() else()
set(_arch_suffix 32) set(_arch_suffix 32)
endif() endif()
if(DEFINED MSVC_TOOLSET_VERSION AND MSVC_TOOLSET_VERSION GREATER_EQUAL 141) if(MSVC_TOOLSET_VERSION GREATER_EQUAL 150)
list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-14.1) # Not yet known.
list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-14.0) elseif(MSVC_TOOLSET_VERSION GREATER_EQUAL 140)
elseif(DEFINED MSVC_TOOLSET_VERSION AND MSVC_TOOLSET_VERSION GREATER_EQUAL 80) # 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") math(EXPR _toolset_major_version "${MSVC_TOOLSET_VERSION} / 10")
list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-${_toolset_major_version}.0) 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() endif()
set(${componentlibvar} ${${componentlibvar}} PARENT_SCOPE) set(${componentlibvar} ${${componentlibvar}} PARENT_SCOPE)
endif() endif()
@@ -1163,7 +1161,7 @@ else()
# _Boost_COMPONENT_HEADERS. See the instructions at the top of # _Boost_COMPONENT_HEADERS. See the instructions at the top of
# _Boost_COMPONENT_DEPENDENCIES. # _Boost_COMPONENT_DEPENDENCIES.
set(_Boost_KNOWN_VERSIONS ${Boost_ADDITIONAL_VERSIONS} 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.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.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" "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::diagnostic_definitions INTERFACE IMPORTED)
add_library(Boost::disable_autolinking INTERFACE IMPORTED) add_library(Boost::disable_autolinking INTERFACE IMPORTED)
add_library(Boost::dynamic_linking INTERFACE IMPORTED) add_library(Boost::dynamic_linking INTERFACE IMPORTED)
set_target_properties(Boost::dynamic_linking PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "BOOST_ALL_DYN_LINK")
endif() endif()
if(WIN32) if(WIN32)
# In windows, automatic linking is performed, so you do not have # In windows, automatic linking is performed, so you do not have
@@ -1248,8 +1248,6 @@ if(WIN32)
INTERFACE_COMPILE_DEFINITIONS "BOOST_LIB_DIAGNOSTIC") INTERFACE_COMPILE_DEFINITIONS "BOOST_LIB_DIAGNOSTIC")
set_target_properties(Boost::disable_autolinking PROPERTIES set_target_properties(Boost::disable_autolinking PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "BOOST_ALL_NO_LIB") INTERFACE_COMPILE_DEFINITIONS "BOOST_ALL_NO_LIB")
set_target_properties(Boost::dynamic_linking PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "BOOST_ALL_DYN_LINK")
endif() endif()
_Boost_CHECK_SPELLING(Boost_ROOT) _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}${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}") list(APPEND _Boost_FIND_LIBRARY_HINTS_FOR_COMPONENT_NAME "${COMPONENT_UNVERSIONED}-py${COMPONENT_PYTHON_VERSION_MAJOR}${COMPONENT_PYTHON_VERSION_MINOR}")
# Gentoo # 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 # RPMs
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}")
endif() endif()
@@ -1830,10 +1828,12 @@ foreach(COMPONENT ${Boost_FIND_COMPONENTS})
foreach(compiler IN LISTS _boost_COMPILER) foreach(compiler IN LISTS _boost_COMPILER)
list(APPEND _boost_RELEASE_NAMES 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_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} ) ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG} )
endforeach() endforeach()
list(APPEND _boost_RELEASE_NAMES 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_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_RELEASE_ABI_TAG}
${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED} ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}
${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component} ) ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component} )
@@ -1842,10 +1842,12 @@ foreach(COMPONENT ${Boost_FIND_COMPONENTS})
foreach(compiler IN LISTS _boost_COMPILER) foreach(compiler IN LISTS _boost_COMPILER)
list(APPEND _boost_RELEASE_NAMES 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_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} ) ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG} )
endforeach() endforeach()
list(APPEND _boost_RELEASE_NAMES 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_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} ) ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG} )
endif() endif()
endforeach() endforeach()
@@ -1883,10 +1885,12 @@ foreach(COMPONENT ${Boost_FIND_COMPONENTS})
foreach(compiler IN LISTS _boost_COMPILER) foreach(compiler IN LISTS _boost_COMPILER)
list(APPEND _boost_DEBUG_NAMES 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_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} ) ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG} )
endforeach() endforeach()
list(APPEND _boost_DEBUG_NAMES 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_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_DEBUG_ABI_TAG}
${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED} ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}
${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component} ) ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component} )
@@ -1895,10 +1899,12 @@ foreach(COMPONENT ${Boost_FIND_COMPONENTS})
foreach(compiler IN LISTS _boost_COMPILER) foreach(compiler IN LISTS _boost_COMPILER)
list(APPEND _boost_DEBUG_NAMES 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_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} ) ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG} )
endforeach() endforeach()
list(APPEND _boost_DEBUG_NAMES 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_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} ) ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG} )
endif() endif()
endforeach() endforeach()

View File

@@ -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()

View File

@@ -4,19 +4,15 @@ These are modules and sources that support our CMake build.
== FindBoost.cmake == == FindBoost.cmake ==
In order to facilitate updating to latest releases of boost, we've made a local 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 generally be obtained
[here](https://github.com/Kitware/CMake/blob/master/Modules/FindBoost.cmake). [here](https://github.com/Kitware/CMake/blob/master/Modules/FindBoost.cmake).
The latest version provided by Kitware can be tailored for use with the 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 version of CMake that it ships with (typically the next upcoming CMake
release). Our local version, however, cannot necessarily assume a release). As such, the latest version from the repository might not work
specific version of CMake and might need to accommodate older versions, perfectly with older versions of CMake - for instance, the latest version
depending on the min version we support for our project. As such, we need to might use features or properties only available in the version of CMake that
patch the stock FindBoost module. There is currently one patch file provided it ships with. Given this, it's best to test any updates to this module with a few
here to accommodate CMake versions prior to 3.12 on windows. When updating to a different versions of cmake.
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.

View File

@@ -70,7 +70,7 @@ Extract it to a folder, making note of where, open a terminal, then:
``` ```
./bootstrap.sh ./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 Create an environment variable `BOOST_ROOT` in one of your `rc` files, pointing

View File

@@ -5,6 +5,9 @@ include (CheckCXXCompilerFlag)
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.11) if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.11)
include (FetchContent) include (FetchContent)
endif () 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 (ExternalProject)
include (CMakeFuncs) # must come *after* ExternalProject b/c it overrides one function in EP include (CMakeFuncs) # must come *after* ExternalProject b/c it overrides one function in EP
include (ProcessorCount) include (ProcessorCount)
@@ -1117,6 +1120,7 @@ if (WIN32)
# this version in the name might change if/when we change versions of soci # this version in the name might change if/when we change versions of soci
set (soci_lib_post "_4_0") set (soci_lib_post "_4_0")
endif () endif ()
get_target_property (_boost_incs Boost::date_time INTERFACE_INCLUDE_DIRECTORIES)
ExternalProject_Add (soci ExternalProject_Add (soci
PREFIX ${nih_cache_path} PREFIX ${nih_cache_path}
GIT_REPOSITORY https://github.com/SOCI/soci.git GIT_REPOSITORY https://github.com/SOCI/soci.git
@@ -1135,6 +1139,7 @@ ExternalProject_Add (soci
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:-DCMAKE_VERBOSE_MAKEFILE=ON> $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:-DCMAKE_VERBOSE_MAKEFILE=ON>
-DCMAKE_PREFIX_PATH=${CMAKE_BINARY_DIR}/sqlite3 -DCMAKE_PREFIX_PATH=${CMAKE_BINARY_DIR}/sqlite3
-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_SOURCE_DIR}/Builds/CMake
-DCMAKE_INCLUDE_PATH=$<JOIN:$<TARGET_PROPERTY:sqlite,INTERFACE_INCLUDE_DIRECTORIES>,::> -DCMAKE_INCLUDE_PATH=$<JOIN:$<TARGET_PROPERTY:sqlite,INTERFACE_INCLUDE_DIRECTORIES>,::>
-DCMAKE_LIBRARY_PATH=${sqlite_BINARY_DIR} -DCMAKE_LIBRARY_PATH=${sqlite_BINARY_DIR}
-DCMAKE_DEBUG_POSTFIX=_d -DCMAKE_DEBUG_POSTFIX=_d
@@ -1144,7 +1149,12 @@ ExternalProject_Add (soci
-DSOCI_LIBDIR=lib -DSOCI_LIBDIR=lib
-DSOCI_SHARED=OFF -DSOCI_SHARED=OFF
-DSOCI_TESTS=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=$<JOIN:${_boost_incs},::>
-DBOOST_ROOT=${BOOST_ROOT}
-DWITH_BOOST=ON -DWITH_BOOST=ON
-DSOCI_DB2=OFF -DSOCI_DB2=OFF
-DSOCI_FIREBIRD=OFF -DSOCI_FIREBIRD=OFF

View File

@@ -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 <boost/asio/ip/tcp.hpp>
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 <class T>
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

View File

@@ -64,11 +64,6 @@ public:
{ {
} }
boost::asio::io_service& get_io_service () noexcept
{
return mSocket->get_io_service ();
}
bool isSecure () bool isSecure ()
{ {
return mSecure; return mSecure;
@@ -167,7 +162,8 @@ public:
{ {
// must be plain // must be plain
mSecure = false; mSecure = false;
mSocket->get_io_service ().post ( post(
mSocket->get_executor(),
boost::beast::bind_handler(cbFunc, error_code())); boost::beast::bind_handler(cbFunc, error_code()));
} }
else else
@@ -200,7 +196,8 @@ public:
{ {
ec = e.code(); ec = e.code();
} }
mSocket->get_io_service ().post ( post(
mSocket->get_executor(),
boost::beast::bind_handler(handler, ec)); boost::beast::bind_handler(handler, ec));
} }
} }

View File

@@ -132,14 +132,14 @@ SSLHTTPDownloader::do_session(
using namespace boost::beast; using namespace boost::beast;
boost::system::error_code ec; 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]); auto const results = resolver.async_resolve(host, port, yield[ec]);
if (ec) if (ec)
return fail(dstPath, complete, ec, "async_resolve"); return fail(dstPath, complete, ec, "async_resolve");
try try
{ {
stream_.emplace(strand_.get_io_service(), ctx_); stream_.emplace(strand_.context(), ctx_);
} }
catch (std::exception const& e) catch (std::exception const& e)
{ {

View File

@@ -66,8 +66,8 @@ PeerImp::PeerImp (Application& app, id_t id, endpoint_type remote_endpoint,
, ssl_bundle_(std::move(ssl_bundle)) , ssl_bundle_(std::move(ssl_bundle))
, socket_ (ssl_bundle_->socket) , socket_ (ssl_bundle_->socket)
, stream_ (ssl_bundle_->stream) , stream_ (ssl_bundle_->stream)
, strand_ (socket_.get_io_service()) , strand_ (socket_.get_executor())
, timer_ (socket_.get_io_service()) , timer_ (beast::create_waitable_timer<waitable_timer>(socket_))
, remote_address_ ( , remote_address_ (
beast::IPAddressConversion::from_asio(remote_endpoint)) beast::IPAddressConversion::from_asio(remote_endpoint))
, overlay_ (overlay) , overlay_ (overlay)
@@ -102,7 +102,7 @@ void
PeerImp::run() PeerImp::run()
{ {
if(! strand_.running_in_this_thread()) if(! strand_.running_in_this_thread())
return strand_.post(std::bind ( return post(strand_, std::bind (
&PeerImp::run, shared_from_this())); &PeerImp::run, shared_from_this()));
if (m_inbound) if (m_inbound)
{ {
@@ -145,8 +145,7 @@ void
PeerImp::stop() PeerImp::stop()
{ {
if(! strand_.running_in_this_thread()) if(! strand_.running_in_this_thread())
return strand_.post(std::bind ( return post(strand_, std::bind(&PeerImp::stop, shared_from_this()));
&PeerImp::stop, shared_from_this()));
if (socket_.is_open()) if (socket_.is_open())
{ {
// The rationale for using different severity levels is that // The rationale for using different severity levels is that
@@ -172,8 +171,7 @@ void
PeerImp::send (Message::pointer const& m) PeerImp::send (Message::pointer const& m)
{ {
if (! strand_.running_in_this_thread()) if (! strand_.running_in_this_thread())
return strand_.post(std::bind ( return post(strand_, std::bind(&PeerImp::send, shared_from_this(), m));
&PeerImp::send, shared_from_this(), m));
if(gracefulClose_) if(gracefulClose_)
return; return;
if(detaching_) if(detaching_)
@@ -204,9 +202,14 @@ PeerImp::send (Message::pointer const& m)
if(sendq_size != 0) if(sendq_size != 0)
return; return;
boost::asio::async_write (stream_, boost::asio::buffer( boost::asio::async_write(
send_queue_.front()->getBuffer()), strand_.wrap(std::bind( stream_,
&PeerImp::onWriteMessage, shared_from_this(), boost::asio::buffer(send_queue_.front()->getBuffer()),
bind_executor(
strand_,
std::bind(
&PeerImp::onWriteMessage,
shared_from_this(),
std::placeholders::_1, std::placeholders::_1,
std::placeholders::_2))); std::placeholders::_2)));
} }
@@ -438,9 +441,12 @@ void
PeerImp::fail(std::string const& reason) PeerImp::fail(std::string const& reason)
{ {
if(! strand_.running_in_this_thread()) if(! strand_.running_in_this_thread())
return strand_.post(std::bind ( return post(
strand_,
std::bind(
(void (Peer::*)(std::string const&)) & PeerImp::fail, (void (Peer::*)(std::string const&)) & PeerImp::fail,
shared_from_this(), reason)); shared_from_this(),
reason));
if (socket_.is_open()) if (socket_.is_open())
{ {
JLOG (journal_.warn()) << JLOG (journal_.warn()) <<
@@ -498,8 +504,10 @@ PeerImp::gracefulClose()
if (send_queue_.size() > 0) if (send_queue_.size() > 0)
return; return;
setTimer(); setTimer();
stream_.async_shutdown(strand_.wrap(std::bind(&PeerImp::onShutdown, stream_.async_shutdown(bind_executor(
shared_from_this(), std::placeholders::_1))); strand_,
std::bind(
&PeerImp::onShutdown, shared_from_this(), std::placeholders::_1)));
} }
void void
@@ -514,8 +522,10 @@ PeerImp::setTimer()
JLOG(journal_.error()) << "setTimer: " << ec.message(); JLOG(journal_.error()) << "setTimer: " << ec.message();
return; return;
} }
timer_.async_wait(strand_.wrap(std::bind(&PeerImp::onTimer, timer_.async_wait(bind_executor(
shared_from_this(), std::placeholders::_1))); strand_,
std::bind(
&PeerImp::onTimer, shared_from_this(), std::placeholders::_1)));
} }
// convenience for ignoring the error code // 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) if (write_buffer_.size() == 0)
return doProtocolStart(); return doProtocolStart();
stream_.async_write_some (write_buffer_.data(), stream_.async_write_some(
strand_.wrap (std::bind (&PeerImp::onWriteResponse, write_buffer_.data(),
shared_from_this(), std::placeholders::_1, bind_executor(
strand_,
std::bind(
&PeerImp::onWriteResponse,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2))); std::placeholders::_2)));
} }
@@ -785,9 +800,14 @@ PeerImp::onReadMessage (error_code ec, std::size_t bytes_transferred)
read_buffer_.consume (bytes_consumed); read_buffer_.consume (bytes_consumed);
} }
// Timeout on writes only // Timeout on writes only
stream_.async_read_some (read_buffer_.prepare (Tuning::readBufferBytes), stream_.async_read_some(
strand_.wrap (std::bind (&PeerImp::onReadMessage, read_buffer_.prepare(Tuning::readBufferBytes),
shared_from_this(), std::placeholders::_1, bind_executor(
strand_,
std::bind(
&PeerImp::onReadMessage,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2))); std::placeholders::_2)));
} }
@@ -814,17 +834,25 @@ PeerImp::onWriteMessage (error_code ec, std::size_t bytes_transferred)
if (! send_queue_.empty()) if (! send_queue_.empty())
{ {
// Timeout on writes only // Timeout on writes only
return boost::asio::async_write (stream_, boost::asio::buffer( return boost::asio::async_write(
send_queue_.front()->getBuffer()), strand_.wrap(std::bind( stream_,
&PeerImp::onWriteMessage, shared_from_this(), boost::asio::buffer(send_queue_.front()->getBuffer()),
bind_executor(
strand_,
std::bind(
&PeerImp::onWriteMessage,
shared_from_this(),
std::placeholders::_1, std::placeholders::_1,
std::placeholders::_2))); std::placeholders::_2)));
} }
if (gracefulClose_) if (gracefulClose_)
{ {
return stream_.async_shutdown(strand_.wrap(std::bind( return stream_.async_shutdown(bind_executor(
&PeerImp::onShutdown, shared_from_this(), strand_,
std::bind(
&PeerImp::onShutdown,
shared_from_this(),
std::placeholders::_1))); std::placeholders::_1)));
} }
} }
@@ -1816,9 +1844,12 @@ void PeerImp::check ()
if (reject) if (reject)
{ {
overlay_.peerFinder().on_failure (slot_); overlay_.peerFinder().on_failure (slot_);
strand_.post (std::bind ( post(
strand_,
std::bind(
(void (PeerImp::*)(std::string const&)) & PeerImp::fail, (void (PeerImp::*)(std::string const&)) & PeerImp::fail,
shared_from_this(), "Not useful")); shared_from_this(),
"Not useful"));
} }
} }

View File

@@ -23,6 +23,7 @@
#include <ripple/app/consensus/RCLCxPeerPos.h> #include <ripple/app/consensus/RCLCxPeerPos.h>
#include <ripple/basics/Log.h> #include <ripple/basics/Log.h>
#include <ripple/basics/RangeSet.h> #include <ripple/basics/RangeSet.h>
#include <ripple/beast/asio/waitable_timer.h>
#include <ripple/beast/utility/WrappedSink.h> #include <ripple/beast/utility/WrappedSink.h>
#include <ripple/overlay/impl/ProtocolMessage.h> #include <ripple/overlay/impl/ProtocolMessage.h>
#include <ripple/overlay/impl/OverlayImpl.h> #include <ripple/overlay/impl/OverlayImpl.h>
@@ -94,6 +95,7 @@ private:
using stream_type = boost::asio::ssl::stream <socket_type&>; using stream_type = boost::asio::ssl::stream <socket_type&>;
using address_type = boost::asio::ip::address; using address_type = boost::asio::ip::address;
using endpoint_type = boost::asio::ip::tcp::endpoint; using endpoint_type = boost::asio::ip::tcp::endpoint;
using waitable_timer = boost::asio::basic_waitable_timer<std::chrono::steady_clock>;
// The length of the smallest valid finished message // The length of the smallest valid finished message
static const size_t sslMinimumFinishedLength = 12; static const size_t sslMinimumFinishedLength = 12;
@@ -107,9 +109,8 @@ private:
std::unique_ptr<beast::asio::ssl_bundle> ssl_bundle_; std::unique_ptr<beast::asio::ssl_bundle> ssl_bundle_;
socket_type& socket_; socket_type& socket_;
stream_type& stream_; stream_type& stream_;
boost::asio::io_service::strand strand_; boost::asio::strand<boost::asio::executor> strand_;
boost::asio::basic_waitable_timer< waitable_timer timer_;
std::chrono::steady_clock> timer_;
//Type type_ = Type::legacy; //Type type_ = Type::legacy;
@@ -479,6 +480,7 @@ private:
beast::Journal journal); beast::Journal journal);
}; };
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
template <class Buffers> template <class Buffers>
@@ -498,8 +500,8 @@ PeerImp::PeerImp (Application& app, std::unique_ptr<beast::asio::ssl_bundle>&& s
, ssl_bundle_(std::move(ssl_bundle)) , ssl_bundle_(std::move(ssl_bundle))
, socket_ (ssl_bundle_->socket) , socket_ (ssl_bundle_->socket)
, stream_ (ssl_bundle_->stream) , stream_ (ssl_bundle_->stream)
, strand_ (socket_.get_io_service()) , strand_ (socket_.get_executor())
, timer_ (socket_.get_io_service()) , timer_ (beast::create_waitable_timer<waitable_timer>(socket_))
, remote_address_ (slot->remote_endpoint()) , remote_address_ (slot->remote_endpoint())
, overlay_ (overlay) , overlay_ (overlay)
, m_inbound (false) , m_inbound (false)

View File

@@ -84,8 +84,8 @@ protected:
Port const& port_; Port const& port_;
Handler& handler_; Handler& handler_;
boost::asio::io_service::work work_; boost::asio::executor_work_guard<boost::asio::executor> work_;
boost::asio::io_service::strand strand_; boost::asio::strand<boost::asio::executor> strand_;
waitable_timer timer_; waitable_timer timer_;
endpoint_type remote_address_; endpoint_type remote_address_;
beast::Journal journal_; beast::Journal journal_;
@@ -110,9 +110,14 @@ protected:
public: public:
template <class ConstBufferSequence> template <class ConstBufferSequence>
BaseHTTPPeer(Port const& port, Handler& handler, BaseHTTPPeer(
boost::asio::io_service& io_service, beast::Journal journal, Port const& port,
endpoint_type remote_address, ConstBufferSequence const& buffers); Handler& handler,
boost::asio::executor const& executor,
waitable_timer timer,
beast::Journal journal,
endpoint_type remote_address,
ConstBufferSequence const& buffers);
virtual virtual
~BaseHTTPPeer(); ~BaseHTTPPeer();
@@ -210,16 +215,19 @@ protected:
template <class Handler, class Impl> template <class Handler, class Impl>
template <class ConstBufferSequence> template <class ConstBufferSequence>
BaseHTTPPeer<Handler, Impl>:: BaseHTTPPeer<Handler, Impl>::BaseHTTPPeer(
BaseHTTPPeer(Port const& port, Handler& handler, Port const& port,
boost::asio::io_service& io_service, beast::Journal journal, Handler& handler,
boost::asio::executor const& executor,
waitable_timer timer,
beast::Journal journal,
endpoint_type remote_address, endpoint_type remote_address,
ConstBufferSequence const& buffers) ConstBufferSequence const& buffers)
: port_(port) : port_(port)
, handler_(handler) , handler_(handler)
, work_(io_service) , work_(executor)
, strand_(io_service) , strand_(executor)
, timer_(io_service) , timer_(std::move(timer))
, remote_address_(remote_address) , remote_address_(remote_address)
, journal_(journal) , journal_(journal)
{ {
@@ -248,7 +256,9 @@ BaseHTTPPeer<Handler, Impl>::
close() close()
{ {
if(! strand_.running_in_this_thread()) if(! strand_.running_in_this_thread())
return strand_.post(std::bind( return post(
strand_,
std::bind(
(void (BaseHTTPPeer::*)(void)) & BaseHTTPPeer::close, (void (BaseHTTPPeer::*)(void)) & BaseHTTPPeer::close,
impl().shared_from_this())); impl().shared_from_this()));
error_code ec; error_code ec;
@@ -285,8 +295,11 @@ start_timer()
ec); ec);
if(ec) if(ec)
return fail(ec, "start_timer"); return fail(ec, "start_timer");
timer_.async_wait(strand_.wrap(std::bind( timer_.async_wait(bind_executor(
&BaseHTTPPeer<Handler, Impl>::on_timer, impl().shared_from_this(), strand_,
std::bind(
&BaseHTTPPeer<Handler, Impl>::on_timer,
impl().shared_from_this(),
std::placeholders::_1))); std::placeholders::_1)));
} }
@@ -359,9 +372,15 @@ on_write(error_code const& ec,
for(auto const& b : wq2_) for(auto const& b : wq2_)
v.emplace_back(b.data.get(), b.bytes); v.emplace_back(b.data.get(), b.bytes);
start_timer(); start_timer();
return boost::asio::async_write(impl().stream_, v, return boost::asio::async_write(
strand_.wrap(std::bind(&BaseHTTPPeer::on_write, impl().stream_,
impl().shared_from_this(), std::placeholders::_1, v,
bind_executor(
strand_,
std::bind(
&BaseHTTPPeer::on_write,
impl().shared_from_this(),
std::placeholders::_1,
std::placeholders::_2))); std::placeholders::_2)));
} }
if(! complete_) if(! complete_)
@@ -432,10 +451,13 @@ write(
}()) }())
{ {
if(! strand_.running_in_this_thread()) if(! strand_.running_in_this_thread())
return strand_.post(std::bind( return post(
strand_,
std::bind(
&BaseHTTPPeer::on_write, &BaseHTTPPeer::on_write,
impl().shared_from_this(), impl().shared_from_this(),
error_code{}, 0)); error_code{},
0));
else else
return on_write(error_code{}, 0); return on_write(error_code{}, 0);
} }
@@ -447,9 +469,14 @@ BaseHTTPPeer<Handler, Impl>::
write(std::shared_ptr <Writer> const& writer, write(std::shared_ptr <Writer> const& writer,
bool keep_alive) bool keep_alive)
{ {
boost::asio::spawn(strand_, std::bind( boost::asio::spawn(bind_executor(
&BaseHTTPPeer<Handler, Impl>::do_writer, impl().shared_from_this(), strand_,
writer, keep_alive, std::placeholders::_1)); std::bind(
&BaseHTTPPeer<Handler, Impl>::do_writer,
impl().shared_from_this(),
writer,
keep_alive,
std::placeholders::_1)));
} }
// DEPRECATED // DEPRECATED
@@ -470,7 +497,10 @@ BaseHTTPPeer<Handler, Impl>::
complete() complete()
{ {
if(! strand_.running_in_this_thread()) if(! strand_.running_in_this_thread())
return strand_.post(std::bind(&BaseHTTPPeer<Handler, Impl>::complete, return post(
strand_,
std::bind(
&BaseHTTPPeer<Handler, Impl>::complete,
impl().shared_from_this())); impl().shared_from_this()));
message_ = {}; message_ = {};
@@ -483,8 +513,12 @@ complete()
} }
// keep-alive // keep-alive
boost::asio::spawn(strand_, std::bind(&BaseHTTPPeer<Handler, Impl>::do_read, boost::asio::spawn(bind_executor(
impl().shared_from_this(), std::placeholders::_1)); strand_,
std::bind(
&BaseHTTPPeer<Handler, Impl>::do_read,
impl().shared_from_this(),
std::placeholders::_1)));
} }
// DEPRECATED // DEPRECATED
@@ -495,9 +529,13 @@ BaseHTTPPeer<Handler, Impl>::
close(bool graceful) close(bool graceful)
{ {
if(! strand_.running_in_this_thread()) if(! strand_.running_in_this_thread())
return strand_.post(std::bind( return post(
(void(BaseHTTPPeer::*)(bool))&BaseHTTPPeer<Handler, Impl>::close, strand_,
impl().shared_from_this(), graceful)); std::bind(
(void (BaseHTTPPeer::*)(bool)) &
BaseHTTPPeer<Handler, Impl>::close,
impl().shared_from_this(),
graceful));
complete_ = true; complete_ = true;
if(graceful) if(graceful)

View File

@@ -22,6 +22,7 @@
#include <ripple/server/Port.h> #include <ripple/server/Port.h>
#include <ripple/server/impl/io_list.h> #include <ripple/server/impl/io_list.h>
#include <ripple/server/impl/LowestLayer.h>
#include <ripple/beast/utility/WrappedSink.h> #include <ripple/beast/utility/WrappedSink.h>
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include <atomic> #include <atomic>
@@ -48,13 +49,14 @@ protected:
beast::WrappedSink sink_; beast::WrappedSink sink_;
beast::Journal j_; beast::Journal j_;
boost::asio::io_service::work work_; boost::asio::executor_work_guard<boost::asio::executor> work_;
boost::asio::io_service::strand strand_; boost::asio::strand<boost::asio::executor> strand_;
public: public:
BasePeer(Port const& port, Handler& handler, BasePeer(
Port const& port,
Handler& handler,
boost::asio::executor const& executor,
endpoint_type remote_address, endpoint_type remote_address,
boost::asio::io_service& io_service,
beast::Journal journal); beast::Journal journal);
void void
@@ -71,23 +73,24 @@ private:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
template <class Handler, class Impl> template <class Handler, class Impl>
BasePeer<Handler, Impl>:: BasePeer<Handler, Impl>::BasePeer(
BasePeer(Port const& port, Handler& handler, Port const& port,
Handler& handler,
boost::asio::executor const& executor,
endpoint_type remote_address, endpoint_type remote_address,
boost::asio::io_service& io_service,
beast::Journal journal) beast::Journal journal)
: port_(port) : port_(port)
, handler_(handler) , handler_(handler)
, remote_address_(remote_address) , remote_address_(remote_address)
, sink_(journal.sink(), , sink_(
[] journal.sink(),
{ [] {
static std::atomic<unsigned> id{0}; static std::atomic<unsigned> id{0};
return "##" + std::to_string(++id) + " "; return "##" + std::to_string(++id) + " ";
}()) }())
, j_(sink_) , j_(sink_)
, work_(io_service) , work_(executor)
, strand_(io_service) , strand_(executor)
{ {
} }
@@ -97,10 +100,10 @@ BasePeer<Handler, Impl>::
close() close()
{ {
if (! strand_.running_in_this_thread()) if (! strand_.running_in_this_thread())
return strand_.post(std::bind( return post(
&BasePeer::close, impl().shared_from_this())); strand_, std::bind(&BasePeer::close, impl().shared_from_this()));
error_code ec; error_code ec;
impl().ws_.lowest_layer().close(ec); ripple::get_lowest_layer(impl().ws_).close(ec);
} }
} // ripple } // ripple

View File

@@ -22,6 +22,7 @@
#include <ripple/basics/safe_cast.h> #include <ripple/basics/safe_cast.h>
#include <ripple/server/impl/BasePeer.h> #include <ripple/server/impl/BasePeer.h>
#include <ripple/server/impl/LowestLayer.h>
#include <ripple/protocol/BuildInfo.h> #include <ripple/protocol/BuildInfo.h>
#include <ripple/beast/utility/rngfill.h> #include <ripple/beast/utility/rngfill.h>
#include <ripple/crypto/csprng.h> #include <ripple/crypto/csprng.h>
@@ -66,9 +67,10 @@ public:
BaseWSPeer( BaseWSPeer(
Port const& port, Port const& port,
Handler& handler, Handler& handler,
boost::asio::executor const& executor,
waitable_timer timer,
endpoint_type remote_address, endpoint_type remote_address,
boost::beast::http::request<Body, Headers>&& request, boost::beast::http::request<Body, Headers>&& request,
boost::asio::io_service& io_service,
beast::Journal journal); beast::Journal journal);
void void
@@ -158,18 +160,22 @@ protected:
template <class Handler, class Impl> template <class Handler, class Impl>
template <class Body, class Headers> template <class Body, class Headers>
BaseWSPeer<Handler, Impl>:: BaseWSPeer<Handler, Impl>::BaseWSPeer(
BaseWSPeer(
Port const& port, Port const& port,
Handler& handler, Handler& handler,
boost::asio::executor const& executor,
waitable_timer timer,
endpoint_type remote_address, endpoint_type remote_address,
boost::beast::http::request<Body, Headers>&& request, boost::beast::http::request<Body, Headers>&& request,
boost::asio::io_service& io_service,
beast::Journal journal) beast::Journal journal)
: BasePeer<Handler, Impl>(port, handler, remote_address, : BasePeer<Handler, Impl>(
io_service, journal) port,
handler,
executor,
remote_address,
journal)
, request_(std::move(request)) , request_(std::move(request))
, timer_(io_service) , timer_(std::move(timer))
, payload_("12345678") // ensures size is 8 bytes , payload_("12345678") // ensures size is 8 bytes
{ {
} }
@@ -180,8 +186,8 @@ BaseWSPeer<Handler, Impl>::
run() run()
{ {
if(! strand_.running_in_this_thread()) if(! strand_.running_in_this_thread())
return strand_.post(std::bind( return post(
&BaseWSPeer::run, impl().shared_from_this())); strand_, std::bind(&BaseWSPeer::run, impl().shared_from_this()));
impl().ws_.set_option(port().pmd_options); impl().ws_.set_option(port().pmd_options);
// Must manage the control callback memory outside of the `control_callback` function // Must manage the control callback memory outside of the `control_callback` function
control_callback_ = std::bind( control_callback_ = std::bind(
@@ -190,14 +196,18 @@ run()
impl().ws_.control_callback(control_callback_); impl().ws_.control_callback(control_callback_);
start_timer(); start_timer();
close_on_timer_ = true; close_on_timer_ = true;
impl().ws_.async_accept_ex(request_, impl().ws_.async_accept_ex(
[](auto & res) request_,
{ [](auto& res) {
res.set(boost::beast::http::field::server, res.set(boost::beast::http::field::server,
BuildInfo::getFullVersionString()); BuildInfo::getFullVersionString());
}, },
strand_.wrap(std::bind(&BaseWSPeer::on_ws_handshake, bind_executor(
impl().shared_from_this(), std::placeholders::_1))); strand_,
std::bind(
&BaseWSPeer::on_ws_handshake,
impl().shared_from_this(),
std::placeholders::_1)));
} }
template<class Handler, class Impl> template<class Handler, class Impl>
@@ -206,9 +216,10 @@ BaseWSPeer<Handler, Impl>::
send(std::shared_ptr<WSMsg> w) send(std::shared_ptr<WSMsg> w)
{ {
if(! strand_.running_in_this_thread()) if(! strand_.running_in_this_thread())
return strand_.post(std::bind( return post(
&BaseWSPeer::send, impl().shared_from_this(), strand_,
std::move(w))); std::bind(
&BaseWSPeer::send, impl().shared_from_this(), std::move(w)));
if(do_close_) if(do_close_)
return; return;
if(wq_.size() > port().ws_queue_limit) if(wq_.size() > port().ws_queue_limit)
@@ -233,12 +244,17 @@ BaseWSPeer<Handler, Impl>::
close() close()
{ {
if(! strand_.running_in_this_thread()) if(! strand_.running_in_this_thread())
return strand_.post(std::bind( return post(
&BaseWSPeer::close, impl().shared_from_this())); strand_, std::bind(&BaseWSPeer::close, impl().shared_from_this()));
do_close_ = true; do_close_ = true;
if(wq_.empty()) if(wq_.empty())
impl().ws_.async_close({}, strand_.wrap(std::bind( impl().ws_.async_close(
&BaseWSPeer::on_close, impl().shared_from_this(), {},
bind_executor(
strand_,
std::bind(
&BaseWSPeer::on_close,
impl().shared_from_this(),
std::placeholders::_1))); std::placeholders::_1)));
} }
@@ -248,8 +264,9 @@ BaseWSPeer<Handler, Impl>::
complete() complete()
{ {
if(! strand_.running_in_this_thread()) if(! strand_.running_in_this_thread())
return strand_.post(std::bind( return post(
&BaseWSPeer::complete, impl().shared_from_this())); strand_,
std::bind(&BaseWSPeer::complete, impl().shared_from_this()));
do_read(); do_read();
} }
@@ -270,8 +287,9 @@ BaseWSPeer<Handler, Impl>::
do_write() do_write()
{ {
if(! strand_.running_in_this_thread()) if(! strand_.running_in_this_thread())
return strand_.post(std::bind( return post(
&BaseWSPeer::do_write, impl().shared_from_this())); strand_,
std::bind(&BaseWSPeer::do_write, impl().shared_from_this()));
on_write({}); on_write({});
} }
@@ -293,7 +311,9 @@ on_write(error_code const& ec)
impl().ws_.async_write_some( impl().ws_.async_write_some(
static_cast<bool>(result.first), static_cast<bool>(result.first),
result.second, result.second,
strand_.wrap(std::bind( bind_executor(
strand_,
std::bind(
&BaseWSPeer::on_write, &BaseWSPeer::on_write,
impl().shared_from_this(), impl().shared_from_this(),
std::placeholders::_1))); std::placeholders::_1)));
@@ -301,7 +321,9 @@ on_write(error_code const& ec)
impl().ws_.async_write_some( impl().ws_.async_write_some(
static_cast<bool>(result.first), static_cast<bool>(result.first),
result.second, result.second,
strand_.wrap(std::bind( bind_executor(
strand_,
std::bind(
&BaseWSPeer::on_write_fin, &BaseWSPeer::on_write_fin,
impl().shared_from_this(), impl().shared_from_this(),
std::placeholders::_1))); std::placeholders::_1)));
@@ -316,8 +338,13 @@ on_write_fin(error_code const& ec)
return fail(ec, "write_fin"); return fail(ec, "write_fin");
wq_.pop_front(); wq_.pop_front();
if(do_close_) if(do_close_)
impl().ws_.async_close(cr_, strand_.wrap(std::bind( impl().ws_.async_close(
&BaseWSPeer::on_close, impl().shared_from_this(), cr_,
bind_executor(
strand_,
std::bind(
&BaseWSPeer::on_close,
impl().shared_from_this(),
std::placeholders::_1))); std::placeholders::_1)));
else if(! wq_.empty()) else if(! wq_.empty())
on_write({}); on_write({});
@@ -329,11 +356,17 @@ BaseWSPeer<Handler, Impl>::
do_read() do_read()
{ {
if(! strand_.running_in_this_thread()) if(! strand_.running_in_this_thread())
return strand_.post(std::bind( return post(
&BaseWSPeer::do_read, impl().shared_from_this())); strand_,
impl().ws_.async_read(rb_, strand_.wrap( std::bind(&BaseWSPeer::do_read, impl().shared_from_this()));
std::bind(&BaseWSPeer::on_read, impl().ws_.async_read(
impl().shared_from_this(), std::placeholders::_1))); rb_,
bind_executor(
strand_,
std::bind(
&BaseWSPeer::on_read,
impl().shared_from_this(),
std::placeholders::_1)));
} }
template<class Handler, class Impl> template<class Handler, class Impl>
@@ -376,8 +409,11 @@ start_timer()
ec); ec);
if(ec) if(ec)
return fail(ec, "start_timer"); return fail(ec, "start_timer");
timer_.async_wait(strand_.wrap(std::bind( timer_.async_wait(bind_executor(
&BaseWSPeer<Handler, Impl>::on_timer, impl().shared_from_this(), strand_,
std::bind(
&BaseWSPeer<Handler, Impl>::on_timer,
impl().shared_from_this(),
std::placeholders::_1))); std::placeholders::_1)));
} }
@@ -444,8 +480,11 @@ on_timer(error_code ec)
// cryptographic is probably overkill.. // cryptographic is probably overkill..
beast::rngfill(payload_.begin(), beast::rngfill(payload_.begin(),
payload_.size(), crypto_prng()); payload_.size(), crypto_prng());
impl().ws_.async_ping(payload_, impl().ws_.async_ping(
strand_.wrap(std::bind( payload_,
bind_executor(
strand_,
std::bind(
&BaseWSPeer::on_ping, &BaseWSPeer::on_ping,
impl().shared_from_this(), impl().shared_from_this(),
std::placeholders::_1))); std::placeholders::_1)));
@@ -474,7 +513,7 @@ fail(error_code ec, String const& what)
ec_ = ec; ec_ = ec;
JLOG(this->j_.trace()) << JLOG(this->j_.trace()) <<
what << ": " << ec.message(); what << ": " << ec.message();
impl().ws_.lowest_layer().close(ec); ripple::get_lowest_layer(impl().ws_).close(ec);
} }
} }

View File

@@ -29,7 +29,7 @@
#include <boost/beast/core/multi_buffer.hpp> #include <boost/beast/core/multi_buffer.hpp>
#include <boost/asio/basic_waitable_timer.hpp> #include <boost/asio/basic_waitable_timer.hpp>
#include <boost/asio/buffer.hpp> #include <boost/asio/buffer.hpp>
#include <boost/asio/io_service.hpp> #include <boost/asio/io_context.hpp>
#include <boost/asio/ip/tcp.hpp> #include <boost/asio/ip/tcp.hpp>
#include <boost/asio/spawn.hpp> #include <boost/asio/spawn.hpp>
#include <boost/container/flat_map.hpp> #include <boost/container/flat_map.hpp>
@@ -65,15 +65,20 @@ private:
private: private:
Port const& port_; Port const& port_;
Handler& handler_; Handler& handler_;
boost::asio::io_context& ioc_;
socket_type socket_; socket_type socket_;
timer_type timer_; timer_type timer_;
endpoint_type remote_address_; endpoint_type remote_address_;
boost::asio::io_service::strand strand_; boost::asio::io_context::strand strand_;
beast::Journal j_; beast::Journal j_;
public: public:
Detector (Port const& port, Handler& handler, Detector(
socket_type&& socket, endpoint_type remote_address, Port const& port,
Handler& handler,
boost::asio::io_context& ioc,
socket_type&& socket,
endpoint_type remote_address,
beast::Journal j); beast::Journal j);
void run(); void run();
void close() override; void close() override;
@@ -86,13 +91,14 @@ private:
beast::Journal j_; beast::Journal j_;
Port const& port_; Port const& port_;
Handler& handler_; Handler& handler_;
boost::asio::io_context& ioc_;
acceptor_type acceptor_; acceptor_type acceptor_;
boost::asio::io_service::strand strand_; boost::asio::io_context::strand strand_;
bool ssl_; bool ssl_;
bool plain_; bool plain_;
public: 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); Port const& port, beast::Journal j);
// Work-around because we can't call shared_from_this in ctor // Work-around because we can't call shared_from_this in ctor
@@ -170,16 +176,20 @@ detect_ssl (Socket& socket, StreamBuf& buf, Yield do_yield)
} }
template <class Handler> template <class Handler>
Door<Handler>::Detector:: Door<Handler>::Detector::Detector(
Detector(Port const& port, Port const& port,
Handler& handler, socket_type&& socket, Handler& handler,
endpoint_type remote_address, beast::Journal j) boost::asio::io_context& ioc,
socket_type&& socket,
endpoint_type remote_address,
beast::Journal j)
: port_(port) : port_(port)
, handler_(handler) , handler_(handler)
, ioc_(ioc)
, socket_(std::move(socket)) , socket_(std::move(socket))
, timer_(socket_.get_io_service()) , timer_(ioc_)
, remote_address_(remote_address) , remote_address_(remote_address)
, strand_(socket_.get_io_service()) , strand_(ioc_)
, j_(j) , j_(j)
{ {
} }
@@ -239,13 +249,13 @@ do_detect(boost::asio::yield_context do_yield)
if (ssl) if (ssl)
{ {
if (auto sp = ios().template emplace<SSLHTTPPeer<Handler>>( if (auto sp = ios().template emplace<SSLHTTPPeer<Handler>>(
port_, handler_, j_, remote_address_, port_, handler_, ioc_, j_, remote_address_,
buf.data(), std::move(socket_))) buf.data(), std::move(socket_)))
sp->run(); sp->run();
return; return;
} }
if (auto sp = ios().template emplace<PlainHTTPPeer<Handler>>( if (auto sp = ios().template emplace<PlainHTTPPeer<Handler>>(
port_, handler_, j_, remote_address_, port_, handler_, ioc_, j_, remote_address_,
buf.data(), std::move(socket_))) buf.data(), std::move(socket_)))
sp->run(); sp->run();
return; return;
@@ -262,13 +272,14 @@ do_detect(boost::asio::yield_context do_yield)
template<class Handler> template<class Handler>
Door<Handler>:: Door<Handler>::
Door(Handler& handler, boost::asio::io_service& io_service, Door(Handler& handler, boost::asio::io_context& io_context,
Port const& port, beast::Journal j) Port const& port, beast::Journal j)
: j_(j) : j_(j)
, port_(port) , port_(port)
, handler_(handler) , handler_(handler)
, acceptor_(io_service) , ioc_(io_context)
, strand_(io_service) , acceptor_(io_context)
, strand_(io_context)
, ssl_( , ssl_(
port_.protocol.count("https") > 0 || port_.protocol.count("https") > 0 ||
port_.protocol.count("wss") > 0 || port_.protocol.count("wss") > 0 ||
@@ -353,13 +364,13 @@ create(bool ssl, ConstBufferSequence const& buffers,
if (ssl) if (ssl)
{ {
if (auto sp = ios().template emplace<SSLHTTPPeer<Handler>>( if (auto sp = ios().template emplace<SSLHTTPPeer<Handler>>(
port_, handler_, j_, remote_address, port_, handler_, ioc_, j_, remote_address,
buffers, std::move(socket))) buffers, std::move(socket)))
sp->run(); sp->run();
return; return;
} }
if (auto sp = ios().template emplace<PlainHTTPPeer<Handler>>( if (auto sp = ios().template emplace<PlainHTTPPeer<Handler>>(
port_, handler_, j_, remote_address, port_, handler_, ioc_, j_, remote_address,
buffers, std::move(socket))) buffers, std::move(socket)))
sp->run(); sp->run();
} }
@@ -373,7 +384,7 @@ do_accept(boost::asio::yield_context do_yield)
{ {
error_code ec; error_code ec;
endpoint_type remote_address; endpoint_type remote_address;
socket_type socket (acceptor_.get_io_service()); socket_type socket (ioc_);
acceptor_.async_accept (socket, remote_address, do_yield[ec]); acceptor_.async_accept (socket, remote_address, do_yield[ec]);
if (ec && ec != boost::asio::error::operation_aborted) if (ec && ec != boost::asio::error::operation_aborted)
{ {
@@ -388,7 +399,7 @@ do_accept(boost::asio::yield_context do_yield)
if (ssl_ && plain_) if (ssl_ && plain_)
{ {
if (auto sp = ios().template emplace<Detector>( if (auto sp = ios().template emplace<Detector>(
port_, handler_, std::move(socket), port_, handler_, ioc_, std::move(socket),
remote_address, j_)) remote_address, j_))
sp->run(); sp->run();
} }

View File

@@ -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 <boost/beast/core/stream_traits.hpp>
#else
#include <boost/beast/core/type_traits.hpp>
#endif
namespace ripple {
// Before boost 1.70, get_lowest_layer required an explicit templat parameter
template <class T>
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

View File

@@ -34,6 +34,7 @@ class PlainHTTPPeer
{ {
private: private:
friend class BaseHTTPPeer<Handler, PlainHTTPPeer>; friend class BaseHTTPPeer<Handler, PlainHTTPPeer>;
using waitable_timer = typename BaseHTTPPeer<Handler, PlainHTTPPeer>::waitable_timer;
using socket_type = boost::asio::ip::tcp::socket; using socket_type = boost::asio::ip::tcp::socket;
using endpoint_type = boost::asio::ip::tcp::endpoint; using endpoint_type = boost::asio::ip::tcp::endpoint;
@@ -41,12 +42,16 @@ private:
public: public:
template <class ConstBufferSequence> template <class ConstBufferSequence>
PlainHTTPPeer(Port const& port, Handler& handler, PlainHTTPPeer(
beast::Journal journal, endpoint_type remote_address, Port const& port,
ConstBufferSequence const& buffers, socket_type&& socket); Handler& handler,
boost::asio::io_context& ioc,
beast::Journal journal,
endpoint_type remote_address,
ConstBufferSequence const& buffers,
socket_type&& socket);
void void run();
run();
std::shared_ptr<WSSession> std::shared_ptr<WSSession>
websocketUpgrade() override; websocketUpgrade() override;
@@ -63,12 +68,22 @@ private:
template <class Handler> template <class Handler>
template <class ConstBufferSequence> template <class ConstBufferSequence>
PlainHTTPPeer<Handler>:: PlainHTTPPeer<Handler>::PlainHTTPPeer(
PlainHTTPPeer(Port const& port, Handler& handler, Port const& port,
beast::Journal journal, endpoint_type remote_endpoint, Handler& handler,
ConstBufferSequence const& buffers, socket_type&& socket) boost::asio::io_context& ioc,
: BaseHTTPPeer<Handler, PlainHTTPPeer>(port, handler, beast::Journal journal,
socket.get_io_service(), journal, remote_endpoint, buffers) endpoint_type remote_endpoint,
ConstBufferSequence const& buffers,
socket_type&& socket)
: BaseHTTPPeer<Handler, PlainHTTPPeer>(
port,
handler,
ioc.get_executor(),
waitable_timer{ioc},
journal,
remote_endpoint,
buffers)
, stream_(std::move(socket)) , stream_(std::move(socket))
{ {
// Set TCP_NODELAY on loopback interfaces, // Set TCP_NODELAY on loopback interfaces,

View File

@@ -21,6 +21,7 @@
#define RIPPLE_SERVER_PLAINWSPEER_H_INCLUDED #define RIPPLE_SERVER_PLAINWSPEER_H_INCLUDED
#include <ripple/server/impl/BaseWSPeer.h> #include <ripple/server/impl/BaseWSPeer.h>
#include <ripple/beast/asio/waitable_timer.h>
#include <memory> #include <memory>
namespace ripple { namespace ripple {
@@ -56,16 +57,21 @@ public:
template <class Handler> template <class Handler>
template <class Body, class Headers> template <class Body, class Headers>
PlainWSPeer<Handler>:: PlainWSPeer<Handler>::PlainWSPeer(
PlainWSPeer(
Port const& port, Port const& port,
Handler& handler, Handler& handler,
endpoint_type remote_address, endpoint_type remote_address,
boost::beast::http::request<Body, Headers>&& request, boost::beast::http::request<Body, Headers>&& request,
socket_type&& socket, socket_type&& socket,
beast::Journal journal) beast::Journal journal)
: BaseWSPeer<Handler, PlainWSPeer>(port, handler, remote_address, : BaseWSPeer<Handler, PlainWSPeer>(
std::move(request), socket.get_io_service(), journal) port,
handler,
socket.get_executor(),
beast::create_waitable_timer<waitable_timer>(socket),
remote_address,
std::move(request),
journal)
, ws_(std::move(socket)) , ws_(std::move(socket))
{ {
} }

View File

@@ -23,6 +23,7 @@
#include <ripple/server/impl/BaseHTTPPeer.h> #include <ripple/server/impl/BaseHTTPPeer.h>
#include <ripple/server/impl/SSLWSPeer.h> #include <ripple/server/impl/SSLWSPeer.h>
#include <ripple/beast/asio/ssl_bundle.h> #include <ripple/beast/asio/ssl_bundle.h>
#include <ripple/beast/asio/waitable_timer.h>
#include <memory> #include <memory>
namespace ripple { namespace ripple {
@@ -34,6 +35,7 @@ class SSLHTTPPeer
{ {
private: private:
friend class BaseHTTPPeer<Handler, SSLHTTPPeer>; friend class BaseHTTPPeer<Handler, SSLHTTPPeer>;
using waitable_timer = typename BaseHTTPPeer<Handler, SSLHTTPPeer>::waitable_timer;
using socket_type = boost::asio::ip::tcp::socket; using socket_type = boost::asio::ip::tcp::socket;
using stream_type = boost::asio::ssl::stream <socket_type&>; using stream_type = boost::asio::ssl::stream <socket_type&>;
using endpoint_type = boost::asio::ip::tcp::endpoint; using endpoint_type = boost::asio::ip::tcp::endpoint;
@@ -45,9 +47,14 @@ private:
public: public:
template <class ConstBufferSequence> template <class ConstBufferSequence>
SSLHTTPPeer(Port const& port, Handler& handler, SSLHTTPPeer(
beast::Journal journal, endpoint_type remote_address, Port const& port,
ConstBufferSequence const& buffers, socket_type&& socket); Handler& handler,
boost::asio::io_context& ioc,
beast::Journal journal,
endpoint_type remote_address,
ConstBufferSequence const& buffers,
socket_type&& socket);
void void
run(); run();
@@ -73,12 +80,22 @@ private:
template <class Handler> template <class Handler>
template <class ConstBufferSequence> template <class ConstBufferSequence>
SSLHTTPPeer<Handler>:: SSLHTTPPeer<Handler>::SSLHTTPPeer(
SSLHTTPPeer(Port const& port, Handler& handler, Port const& port,
beast::Journal journal, endpoint_type remote_address, Handler& handler,
ConstBufferSequence const& buffers, socket_type&& socket) boost::asio::io_context& ioc,
: BaseHTTPPeer<Handler, SSLHTTPPeer>(port, handler, beast::Journal journal,
socket.get_io_service(), journal, remote_address, buffers) endpoint_type remote_address,
ConstBufferSequence const& buffers,
socket_type&& socket)
: BaseHTTPPeer<Handler, SSLHTTPPeer>(
port,
handler,
ioc.get_executor(),
waitable_timer{ioc},
journal,
remote_address,
buffers)
, ssl_bundle_(std::make_unique<beast::asio::ssl_bundle>( , ssl_bundle_(std::make_unique<beast::asio::ssl_bundle>(
port.context, std::move(socket))) port.context, std::move(socket)))
, stream_(ssl_bundle_->stream) , stream_(ssl_bundle_->stream)
@@ -168,8 +185,11 @@ SSLHTTPPeer<Handler>::
do_close() do_close()
{ {
this->start_timer(); this->start_timer();
stream_.async_shutdown(this->strand_.wrap(std::bind ( stream_.async_shutdown(bind_executor(
&SSLHTTPPeer::on_shutdown, this->shared_from_this(), this->strand_,
std::bind(
&SSLHTTPPeer::on_shutdown,
this->shared_from_this(),
std::placeholders::_1))); std::placeholders::_1)));
} }

View File

@@ -23,6 +23,7 @@
#include <ripple/server/impl/BaseHTTPPeer.h> #include <ripple/server/impl/BaseHTTPPeer.h>
#include <ripple/server/WSSession.h> #include <ripple/server/WSSession.h>
#include <ripple/beast/asio/ssl_bundle.h> #include <ripple/beast/asio/ssl_bundle.h>
#include <ripple/beast/asio/waitable_timer.h>
#include <boost/beast/websocket/ssl.hpp> #include <boost/beast/websocket/ssl.hpp>
#include <memory> #include <memory>
@@ -62,18 +63,21 @@ public:
template <class Handler> template <class Handler>
template <class Body, class Headers> template <class Body, class Headers>
SSLWSPeer<Handler>:: SSLWSPeer<Handler>::SSLWSPeer(
SSLWSPeer(
Port const& port, Port const& port,
Handler& handler, Handler& handler,
endpoint_type remote_endpoint, endpoint_type remote_endpoint,
boost::beast::http::request<Body, Headers>&& request, boost::beast::http::request<Body, Headers>&& request,
std::unique_ptr< std::unique_ptr<beast::asio::ssl_bundle>&& ssl_bundle,
beast::asio::ssl_bundle>&& ssl_bundle,
beast::Journal journal) beast::Journal journal)
: BaseWSPeer<Handler, SSLWSPeer>(port, handler, : BaseWSPeer<Handler, SSLWSPeer>(
remote_endpoint, std::move(request), port,
ssl_bundle->socket.get_io_service(), journal) handler,
ssl_bundle->socket.get_executor(),
beast::create_waitable_timer<waitable_timer>(ssl_bundle->socket),
remote_endpoint,
std::move(request),
journal)
, ssl_bundle_(std::move(ssl_bundle)) , ssl_bundle_(std::move(ssl_bundle))
, ws_(ssl_bundle_->stream) , ws_(ssl_bundle_->stream)
{ {

View File

@@ -58,14 +58,14 @@ public:
}; };
TrustedPublisherServer( TrustedPublisherServer(
boost::asio::io_service& ios, boost::asio::io_context& ioc,
std::pair<PublicKey, SecretKey> keys, std::pair<PublicKey, SecretKey> keys,
std::string const& manifest, std::string const& manifest,
int sequence, int sequence,
NetClock::time_point expiration, NetClock::time_point expiration,
int version, int version,
std::vector<Validator> const& validators) std::vector<Validator> const& validators)
: sock_(ios), acceptor_(ios) : sock_(ioc), acceptor_(ioc)
{ {
endpoint_type const& ep { endpoint_type const& ep {
beast::IP::Address::from_string (ripple::test::getEnvLocalhostAddr()), beast::IP::Address::from_string (ripple::test::getEnvLocalhostAddr()),
@@ -124,13 +124,13 @@ private:
int id; int id;
TrustedPublisherServer& self; TrustedPublisherServer& self;
socket_type sock; socket_type sock;
boost::asio::io_service::work work; boost::asio::executor_work_guard<boost::asio::executor> work;
lambda(int id_, TrustedPublisherServer& self_, socket_type&& sock_) lambda(int id_, TrustedPublisherServer& self_, socket_type&& sock_)
: id(id_) : id(id_)
, self(self_) , self(self_)
, sock(std::move(sock_)) , sock(std::move(sock_))
, work(sock.get_io_service()) , work(sock_.get_executor())
{ {
} }

View File

@@ -48,8 +48,8 @@ will complete with eof.
class short_read_test : public beast::unit_test::suite class short_read_test : public beast::unit_test::suite
{ {
private: private:
using io_service_type = boost::asio::io_service; using io_context_type = boost::asio::io_context;
using strand_type = io_service_type::strand; using strand_type = boost::asio::io_context::strand;
using timer_type = boost::asio::basic_waitable_timer< using timer_type = boost::asio::basic_waitable_timer<
std::chrono::steady_clock>; std::chrono::steady_clock>;
using acceptor_type = boost::asio::ip::tcp::acceptor; using acceptor_type = boost::asio::ip::tcp::acceptor;
@@ -59,8 +59,8 @@ private:
using endpoint_type = boost::asio::ip::tcp::endpoint; using endpoint_type = boost::asio::ip::tcp::endpoint;
using address_type = boost::asio::ip::address; using address_type = boost::asio::ip::address;
io_service_type io_service_; io_context_type io_context_;
boost::optional<io_service_type::work> work_; boost::optional<boost::asio::executor_work_guard<boost::asio::executor>> work_;
std::thread thread_; std::thread thread_;
std::shared_ptr<boost::asio::ssl::context> context_; std::shared_ptr<boost::asio::ssl::context> context_;
@@ -183,11 +183,11 @@ private:
: Child(server) : Child(server)
, server_(server) , server_(server)
, test_(server_.test_) , test_(server_.test_)
, acceptor_(test_.io_service_, , acceptor_(test_.io_context_,
endpoint_type(beast::IP::Address::from_string( endpoint_type(beast::IP::Address::from_string(
test::getEnvLocalhostAddr()), 0)) test::getEnvLocalhostAddr()), 0))
, socket_(test_.io_service_) , socket_(test_.io_context_)
, strand_(socket_.get_io_service()) , strand_(test_.io_context_)
{ {
acceptor_.listen(); acceptor_.listen();
server_.endpoint_ = acceptor_.local_endpoint(); server_.endpoint_ = acceptor_.local_endpoint();
@@ -199,7 +199,7 @@ private:
close() override close() override
{ {
if(! strand_.running_in_this_thread()) if(! strand_.running_in_this_thread())
return strand_.post(std::bind(&Acceptor::close, return post(strand_, std::bind(&Acceptor::close,
shared_from_this())); shared_from_this()));
acceptor_.close(); acceptor_.close();
} }
@@ -207,8 +207,13 @@ private:
void void
run() run()
{ {
acceptor_.async_accept(socket_, strand_.wrap(std::bind( acceptor_.async_accept(
&Acceptor::on_accept, shared_from_this(), socket_,
bind_executor(
strand_,
std::bind(
&Acceptor::on_accept,
shared_from_this(),
std::placeholders::_1))); std::placeholders::_1)));
} }
@@ -233,8 +238,13 @@ private:
server_, std::move(socket_)); server_, std::move(socket_));
server_.add(p); server_.add(p);
p->run(); p->run();
acceptor_.async_accept(socket_, strand_.wrap(std::bind( acceptor_.async_accept(
&Acceptor::on_accept, shared_from_this(), socket_,
bind_executor(
strand_,
std::bind(
&Acceptor::on_accept,
shared_from_this(),
std::placeholders::_1))); std::placeholders::_1)));
} }
}; };
@@ -256,8 +266,8 @@ private:
, test_(server_.test_) , test_(server_.test_)
, socket_(std::move(socket)) , socket_(std::move(socket))
, stream_(socket_, *test_.context_) , stream_(socket_, *test_.context_)
, strand_(socket_.get_io_service()) , strand_(test_.io_context_)
, timer_(socket_.get_io_service()) , timer_(test_.io_context_)
{ {
} }
@@ -265,7 +275,7 @@ private:
close() override close() override
{ {
if(! strand_.running_in_this_thread()) if(! strand_.running_in_this_thread())
return strand_.post(std::bind(&Connection::close, return post(strand_, std::bind(&Connection::close,
shared_from_this())); shared_from_this()));
if (socket_.is_open()) if (socket_.is_open())
{ {
@@ -278,10 +288,19 @@ private:
run() run()
{ {
timer_.expires_from_now(std::chrono::seconds(3)); timer_.expires_from_now(std::chrono::seconds(3));
timer_.async_wait(strand_.wrap(std::bind(&Connection::on_timer, timer_.async_wait(bind_executor(
shared_from_this(), std::placeholders::_1))); strand_,
stream_.async_handshake(stream_type::server, strand_.wrap( std::bind(
std::bind(&Connection::on_handshake, shared_from_this(), &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))); std::placeholders::_1)));
} }
@@ -315,8 +334,15 @@ private:
if (ec) if (ec)
return fail("handshake", ec); return fail("handshake", ec);
#if 1 #if 1
boost::asio::async_read_until(stream_, buf_, "\n", strand_.wrap( boost::asio::async_read_until(
std::bind(&Connection::on_read, shared_from_this(), stream_,
buf_,
"\n",
bind_executor(
strand_,
std::bind(
&Connection::on_read,
shared_from_this(),
std::placeholders::_1, std::placeholders::_1,
std::placeholders::_2))); std::placeholders::_2)));
#else #else
@@ -330,8 +356,11 @@ private:
if (ec == boost::asio::error::eof) if (ec == boost::asio::error::eof)
{ {
server_.test_.log << "[server] read: EOF" << std::endl; server_.test_.log << "[server] read: EOF" << std::endl;
return stream_.async_shutdown(strand_.wrap(std::bind( return stream_.async_shutdown(bind_executor(
&Connection::on_shutdown, shared_from_this(), strand_,
std::bind(
&Connection::on_shutdown,
shared_from_this(),
std::placeholders::_1))); std::placeholders::_1)));
} }
if (ec) if (ec)
@@ -340,8 +369,14 @@ private:
buf_.commit(bytes_transferred); buf_.commit(bytes_transferred);
buf_.consume(bytes_transferred); buf_.consume(bytes_transferred);
write(buf_, "BYE\n"); write(buf_, "BYE\n");
boost::asio::async_write(stream_, buf_.data(), strand_.wrap( boost::asio::async_write(
std::bind(&Connection::on_write, shared_from_this(), stream_,
buf_.data(),
bind_executor(
strand_,
std::bind(
&Connection::on_write,
shared_from_this(),
std::placeholders::_1, std::placeholders::_1,
std::placeholders::_2))); std::placeholders::_2)));
} }
@@ -352,8 +387,11 @@ private:
buf_.consume(bytes_transferred); buf_.consume(bytes_transferred);
if (ec) if (ec)
return fail("write", ec); return fail("write", ec);
stream_.async_shutdown(strand_.wrap(std::bind( stream_.async_shutdown(bind_executor(
&Connection::on_shutdown, shared_from_this(), strand_,
std::bind(
&Connection::on_shutdown,
shared_from_this(),
std::placeholders::_1))); std::placeholders::_1)));
} }
@@ -412,10 +450,10 @@ private:
: Child(client) : Child(client)
, client_(client) , client_(client)
, test_(client_.test_) , test_(client_.test_)
, socket_(test_.io_service_) , socket_(test_.io_context_)
, stream_(socket_, *test_.context_) , stream_(socket_, *test_.context_)
, strand_(socket_.get_io_service()) , strand_(test_.io_context_)
, timer_(socket_.get_io_service()) , timer_(test_.io_context_)
, ep_(ep) , ep_(ep)
{ {
} }
@@ -424,8 +462,9 @@ private:
close() override close() override
{ {
if(! strand_.running_in_this_thread()) if(! strand_.running_in_this_thread())
return strand_.post(std::bind(&Connection::close, return post(
shared_from_this())); strand_,
std::bind(&Connection::close, shared_from_this()));
if (socket_.is_open()) if (socket_.is_open())
{ {
socket_.close(); socket_.close();
@@ -437,10 +476,19 @@ private:
run(endpoint_type const& ep) run(endpoint_type const& ep)
{ {
timer_.expires_from_now(std::chrono::seconds(3)); timer_.expires_from_now(std::chrono::seconds(3));
timer_.async_wait(strand_.wrap(std::bind(&Connection::on_timer, timer_.async_wait(bind_executor(
shared_from_this(), std::placeholders::_1))); strand_,
socket_.async_connect(ep, strand_.wrap(std::bind( std::bind(
&Connection::on_connect, shared_from_this(), &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))); std::placeholders::_1)));
} }
@@ -473,8 +521,13 @@ private:
{ {
if (ec) if (ec)
return fail("connect", ec); return fail("connect", ec);
stream_.async_handshake(stream_type::client, strand_.wrap( stream_.async_handshake(
std::bind(&Connection::on_handshake, shared_from_this(), stream_type::client,
bind_executor(
strand_,
std::bind(
&Connection::on_handshake,
shared_from_this(),
std::placeholders::_1))); std::placeholders::_1)));
} }
@@ -486,13 +539,22 @@ private:
write(buf_, "HELLO\n"); write(buf_, "HELLO\n");
#if 1 #if 1
boost::asio::async_write(stream_, buf_.data(), strand_.wrap( boost::asio::async_write(
std::bind(&Connection::on_write, shared_from_this(), stream_,
buf_.data(),
bind_executor(
strand_,
std::bind(
&Connection::on_write,
shared_from_this(),
std::placeholders::_1, std::placeholders::_1,
std::placeholders::_2))); std::placeholders::_2)));
#else #else
stream_.async_shutdown(strand_.wrap(std::bind( stream_.async_shutdown(bind_executor(
&Connection::on_shutdown, shared_from_this(), strand_,
std::bind(
&Connection::on_shutdown,
shared_from_this(),
std::placeholders::_1))); std::placeholders::_1)));
#endif #endif
} }
@@ -504,13 +566,23 @@ private:
if (ec) if (ec)
return fail("write", ec); return fail("write", ec);
#if 1 #if 1
boost::asio::async_read_until(stream_, buf_, "\n", strand_.wrap( boost::asio::async_read_until(
std::bind(&Connection::on_read, shared_from_this(), stream_,
buf_,
"\n",
bind_executor(
strand_,
std::bind(
&Connection::on_read,
shared_from_this(),
std::placeholders::_1, std::placeholders::_1,
std::placeholders::_2))); std::placeholders::_2)));
#else #else
stream_.async_shutdown(strand_.wrap(std::bind( stream_.async_shutdown(bind_executor(
&Connection::on_shutdown, shared_from_this(), strand_,
std::bind(
&Connection::on_shutdown,
shared_from_this(),
std::placeholders::_1))); std::placeholders::_1)));
#endif #endif
} }
@@ -521,8 +593,11 @@ private:
if (ec) if (ec)
return fail("read", ec); return fail("read", ec);
buf_.commit(bytes_transferred); buf_.commit(bytes_transferred);
stream_.async_shutdown(strand_.wrap(std::bind( stream_.async_shutdown(bind_executor(
&Connection::on_shutdown, shared_from_this(), strand_,
std::bind(
&Connection::on_shutdown,
shared_from_this(),
std::placeholders::_1))); std::placeholders::_1)));
} }
@@ -555,11 +630,10 @@ private:
public: public:
short_read_test() short_read_test()
: work_(boost::in_place(std::ref(io_service_))) : work_(io_context_.get_executor())
, thread_(std::thread([this]() , thread_(std::thread([this]() {
{ beast::setCurrentThreadName("io_context");
beast::setCurrentThreadName("io_service"); this->io_context_.run();
this->io_service_.run();
})) }))
, context_(make_SSLContext("")) , context_(make_SSLContext(""))
{ {