mirror of
https://github.com/boostorg/beast.git
synced 2025-07-29 20:37:31 +02:00
Add make_strand
This commit is contained in:
@ -3,6 +3,7 @@ Version 216:
|
||||
* Refactor websocket::stream operations
|
||||
* Add websocket::stream timeouts
|
||||
* Use suggested timeouts in Websocket examples
|
||||
* Add make_strand
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
@ -65,12 +65,12 @@
|
||||
<member><link linkend="beast.ref.boost__beast__beast_close_socket">beast_close_socket</link> <emphasis role="green">🞲</emphasis></member>
|
||||
<member><link linkend="beast.ref.boost__beast__bind_front_handler">bind_front_handler</link> <emphasis role="green">🞲</emphasis></member>
|
||||
<member><link linkend="beast.ref.boost__beast__bind_handler">bind_handler</link></member>
|
||||
<member><link linkend="beast.ref.boost__beast__buffer_size">buffer_size</link> <emphasis role="green">🞲</emphasis></member>
|
||||
<member><link linkend="beast.ref.boost__beast__close_socket">close_socket</link> <emphasis role="green">🞲</emphasis></member>
|
||||
<member><link linkend="beast.ref.boost__beast__connect">connect</link> <emphasis role="green">🞲</emphasis></member>
|
||||
<member><link linkend="beast.ref.boost__beast__generic_category">generic_category</link></member>
|
||||
<member><link linkend="beast.ref.boost__beast__get_lowest_layer">get_lowest_layer</link> <emphasis role="green">🞲</emphasis></member>
|
||||
<member><link linkend="beast.ref.boost__beast__iequals">iequals</link></member>
|
||||
<member><link linkend="beast.ref.boost__beast__make_strand">make_strand</link> <emphasis role="green">🞲</emphasis></member>
|
||||
<member><link linkend="beast.ref.boost__beast__to_static_string">to_static_string</link></member>
|
||||
</simplelist>
|
||||
</entry>
|
||||
@ -123,6 +123,7 @@
|
||||
<simplelist type="vert" columns="1">
|
||||
<member><link linkend="beast.ref.boost__beast__basic_flat_buffer">basic_flat_buffer</link></member>
|
||||
<member><link linkend="beast.ref.boost__beast__basic_multi_buffer">basic_multi_buffer</link></member>
|
||||
<member><link linkend="beast.ref.boost__beast__buffer_size">buffer_size</link> <emphasis role="green">🞲</emphasis></member>
|
||||
<member><link linkend="beast.ref.boost__beast__buffered_read_stream">buffered_read_stream</link></member>
|
||||
<member><link linkend="beast.ref.boost__beast__buffers_adaptor">buffers_adaptor</link></member>
|
||||
<member><link linkend="beast.ref.boost__beast__buffers_cat_view">buffers_cat_view</link></member>
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include <boost/beast/core/flat_stream.hpp>
|
||||
#include <boost/beast/core/handler_ptr.hpp>
|
||||
#include <boost/beast/core/make_printable.hpp>
|
||||
#include <boost/beast/core/make_strand.hpp>
|
||||
#include <boost/beast/core/multi_buffer.hpp>
|
||||
#include <boost/beast/core/ostream.hpp>
|
||||
#include <boost/beast/core/read_size.hpp>
|
||||
|
60
include/boost/beast/core/make_strand.hpp
Normal file
60
include/boost/beast/core/make_strand.hpp
Normal file
@ -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 <boost/beast/core/detail/config.hpp>
|
||||
#include <boost/beast/core/stream_traits.hpp>
|
||||
#include <boost/asio/is_executor.hpp>
|
||||
#include <boost/asio/strand.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
namespace boost {
|
||||
namespace beast {
|
||||
|
||||
/** Return a strand usable with the specified execution context.
|
||||
*/
|
||||
#if BOOST_BEAST_DOXYGEN
|
||||
template<class ExecutionContext>
|
||||
__see_below__
|
||||
#else
|
||||
template<class ExecutionContext
|
||||
,class = typename std::enable_if<
|
||||
has_get_executor<ExecutionContext>::value &&
|
||||
std::is_convertible<
|
||||
ExecutionContext&,
|
||||
net::execution_context&>::value>::type
|
||||
>
|
||||
net::strand<executor_type<ExecutionContext>>
|
||||
#endif
|
||||
make_strand(ExecutionContext& context)
|
||||
{
|
||||
return net::strand<executor_type<
|
||||
ExecutionContext>>{context.get_executor()};
|
||||
}
|
||||
|
||||
/** Return a strand usable with the specified executor.
|
||||
*/
|
||||
template<class Executor
|
||||
#if ! BOOST_BEAST_DOXYGEN
|
||||
, class = typename
|
||||
net::is_executor<Executor>::type
|
||||
#endif
|
||||
>
|
||||
net::strand<Executor>
|
||||
make_strand(Executor const& ex)
|
||||
{
|
||||
return net::strand<Executor>{ex};
|
||||
}
|
||||
|
||||
} // beast
|
||||
} // boost
|
||||
|
||||
#endif
|
@ -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
|
||||
|
@ -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
|
||||
|
49
test/beast/core/make_strand.cpp
Normal file
49
test/beast/core/make_strand.cpp
Normal file
@ -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 <boost/beast/core/make_strand.hpp>
|
||||
|
||||
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
||||
#include <boost/asio/executor.hpp>
|
||||
#include <boost/asio/io_context.hpp>
|
||||
|
||||
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
|
Reference in New Issue
Block a user