diff --git a/CHANGELOG.md b/CHANGELOG.md index e3e9c9a4..d2179672 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Version 216: * Refactor websocket::stream operations * Add websocket::stream timeouts * Use suggested timeouts in Websocket examples +* Add make_strand -------------------------------------------------------------------------------- diff --git a/doc/qbk/quickref.xml b/doc/qbk/quickref.xml index 6c1b8a8f..2fa9a50f 100644 --- a/doc/qbk/quickref.xml +++ b/doc/qbk/quickref.xml @@ -65,12 +65,12 @@ beast_close_socket 🞲 bind_front_handler 🞲 bind_handler - buffer_size 🞲 close_socket 🞲 connect 🞲 generic_category get_lowest_layer 🞲 iequals + make_strand 🞲 to_static_string @@ -123,6 +123,7 @@ basic_flat_buffer basic_multi_buffer + buffer_size 🞲 buffered_read_stream buffers_adaptor buffers_cat_view diff --git a/include/boost/beast/core.hpp b/include/boost/beast/core.hpp index e286690a..10b4d894 100644 --- a/include/boost/beast/core.hpp +++ b/include/boost/beast/core.hpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include diff --git a/include/boost/beast/core/make_strand.hpp b/include/boost/beast/core/make_strand.hpp new file mode 100644 index 00000000..ce87d5fc --- /dev/null +++ b/include/boost/beast/core/make_strand.hpp @@ -0,0 +1,60 @@ +// +// Copyright (c) 2019 Vinnie Falco (vinnie dot falco at gmail dot com) +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// Official repository: https://github.com/boostorg/beast +// + +#ifndef BOOST_BEAST_MAKE_STRAND_HPP +#define BOOST_BEAST_MAKE_STRAND_HPP + +#include +#include +#include +#include +#include + +namespace boost { +namespace beast { + +/** Return a strand usable with the specified execution context. +*/ +#if BOOST_BEAST_DOXYGEN +template +__see_below__ +#else +template::value && + std::is_convertible< + ExecutionContext&, + net::execution_context&>::value>::type +> +net::strand> +#endif +make_strand(ExecutionContext& context) +{ + return net::strand>{context.get_executor()}; +} + +/** Return a strand usable with the specified executor. +*/ +template::type +#endif +> +net::strand +make_strand(Executor const& ex) +{ + return net::strand{ex}; +} + +} // beast +} // boost + +#endif diff --git a/test/beast/core/CMakeLists.txt b/test/beast/core/CMakeLists.txt index 3885f08e..4f7957cd 100644 --- a/test/beast/core/CMakeLists.txt +++ b/test/beast/core/CMakeLists.txt @@ -55,6 +55,7 @@ add_executable (tests-beast-core flat_stream.cpp handler_ptr.cpp make_printable.cpp + make_strand.cpp multi_buffer.cpp ostream.cpp read_size.cpp diff --git a/test/beast/core/Jamfile b/test/beast/core/Jamfile index bda57c47..fca43e0a 100644 --- a/test/beast/core/Jamfile +++ b/test/beast/core/Jamfile @@ -43,6 +43,7 @@ local SOURCES = flat_stream.cpp handler_ptr.cpp make_printable.cpp + make_strand.cpp multi_buffer.cpp ostream.cpp read_size.cpp diff --git a/test/beast/core/make_strand.cpp b/test/beast/core/make_strand.cpp new file mode 100644 index 00000000..53bc7e69 --- /dev/null +++ b/test/beast/core/make_strand.cpp @@ -0,0 +1,49 @@ +// +// Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com) +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// Official repository: https://github.com/boostorg/beast +// + +// Test that header file is self-contained. +#include + +#include +#include +#include + +namespace boost { +namespace beast { + +class make_strand_test : public beast::unit_test::suite +{ +public: + void + testFunction() + { + net::io_context ioc; + make_strand(ioc); + make_strand(ioc.get_executor()); + make_strand(make_strand(ioc)); + + net::executor ex(ioc.get_executor()); + make_strand(ex); + + // this *should-not* compile + //make_strand(ex.context()); + } + + void + run() override + { + testFunction(); + pass(); + } +}; + +BEAST_DEFINE_TESTSUITE(beast,core,make_strand); + +} // beast +} // boost