Skip to content

get_executor() works on initiation objects #2895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -221,24 +221,26 @@ jobs:
container: ${{ matrix.container }}

steps:
- name: Check if running in container
if: matrix.container != ''
run: echo "GHA_CONTAINER=${{ matrix.container }}" >> $GITHUB_ENV
- name: If running in container, upgrade packages
- name: Setup container environment
if: matrix.container != ''
run: |
apt-get -o Acquire::Retries=3 update && DEBIAN_FRONTEND=noninteractive apt-get -y install tzdata && apt-get -o Acquire::Retries=3 install -y sudo software-properties-common wget curl apt-transport-https make apt-file sudo unzip libssl-dev build-essential autotools-dev autoconf automake g++ libc++-helpers python ruby cpio gcc-multilib g++-multilib pkgconf python3 ccache libpython-dev locales
sudo apt-add-repository ppa:git-core/ppa
sudo apt-get -o Acquire::Retries=3 update && apt-get -o Acquire::Retries=3 -y install git
python_version=$(python3 -c 'import sys; print("{0.major}.{0.minor}".format(sys.version_info))')
if [[ ${python_version} =~ ^3\.[0-5]$ ]]; then
true
else
apt-get install -y python3-distutils
fi
sudo wget https://bootstrap.pypa.io/pip/$python_version/get-pip.py
sudo python3 get-pip.py
sudo /usr/local/bin/pip install cmake
apt-get -o Acquire::Retries=3 update && DEBIAN_FRONTEND=noninteractive apt-get -y install tzdata && apt-get -o Acquire::Retries=3 install -y sudo software-properties-common wget curl apt-transport-https make apt-file sudo unzip libssl-dev build-essential autotools-dev autoconf automake g++ libc++-helpers python ruby cpio gcc-multilib g++-multilib pkgconf python3 ccache libpython-dev locales
sudo apt-add-repository ppa:git-core/ppa
sudo apt-get -o Acquire::Retries=3 update && apt-get -o Acquire::Retries=3 -y install git
python_version=$(python3 -c 'import sys; print("{0.major}.{0.minor}".format(sys.version_info))')
if [[ ${python_version} =~ ^3\.[0-5]$ ]]; then
true
else
apt-get install -y python3-distutils
fi
sudo wget https://bootstrap.pypa.io/pip/$python_version/get-pip.py
sudo python3 get-pip.py
sudo /usr/local/bin/pip install cmake

if [[ "${{matrix.container}}" == "ubuntu:16.04" ]] || [[ "${{matrix.container}}" == "ubuntu:18.04" ]]; then
echo "ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION=true" >> $GITHUB_ENV
fi

- uses: actions/checkout@v3

- name: Install packages
Expand Down
16 changes: 12 additions & 4 deletions include/boost/beast/_experimental/http/impl/icy_stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,20 @@ class read_op

struct run_read_op
{
icy_stream* self;

using executor_type = typename icy_stream::executor_type;

executor_type
get_executor() const noexcept
{
return self->get_executor();
}

template<class ReadHandler, class Buffers>
void
operator()(
ReadHandler&& h,
icy_stream* s,
Buffers const& b)
{
// If you get an error on the following line it means
Expand All @@ -186,7 +195,7 @@ struct run_read_op
read_op<
Buffers,
typename std::decay<ReadHandler>::type>(
std::forward<ReadHandler>(h), *s, b);
std::forward<ReadHandler>(h), *self, b);
}
};

Expand Down Expand Up @@ -292,9 +301,8 @@ async_read_some(
return net::async_initiate<
ReadHandler,
void(error_code, std::size_t)>(
typename ops::run_read_op{},
typename ops::run_read_op{this},
handler,
this,
buffers);
}

Expand Down
72 changes: 43 additions & 29 deletions include/boost/beast/_experimental/test/impl/stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,27 @@ namespace boost {
namespace beast {
namespace test {

//------------------------------------------------------------------------------
namespace detail
{
template<class To>
struct extract_executor_op
{
To operator()(net::any_io_executor& ex) const
{
assert(ex.template target<To>());
return *ex.template target<To>();
}
};

template<>
struct extract_executor_op<net::any_io_executor>
{
net::any_io_executor operator()(net::any_io_executor& ex) const
{
return ex;
}
};
} // detail

template<class Executor>
template<class Handler, class Buffers>
Expand Down Expand Up @@ -163,13 +183,22 @@ class basic_stream<Executor>::read_op : public detail::stream_read_op_base
template<class Executor>
struct basic_stream<Executor>::run_read_op
{
boost::shared_ptr<detail::stream_state> const& in;

using executor_type = typename basic_stream::executor_type;

executor_type
get_executor() const noexcept
{
return detail::extract_executor_op<Executor>()(in->exec);
}

template<
class ReadHandler,
class MutableBufferSequence>
void
operator()(
ReadHandler&& h,
boost::shared_ptr<detail::stream_state> const& in,
MutableBufferSequence const& buffers)
{
// If you get an error on the following line it means
Expand Down Expand Up @@ -197,13 +226,22 @@ struct basic_stream<Executor>::run_read_op
template<class Executor>
struct basic_stream<Executor>::run_write_op
{
boost::shared_ptr<detail::stream_state> const& in_;

using executor_type = typename basic_stream::executor_type;

executor_type
get_executor() const noexcept
{
return detail::extract_executor_op<Executor>()(in_->exec);
}

template<
class WriteHandler,
class ConstBufferSequence>
void
operator()(
WriteHandler&& h,
boost::shared_ptr<detail::stream_state> in_,
boost::weak_ptr<detail::stream_state> out_,
ConstBufferSequence const& buffers)
{
Expand Down Expand Up @@ -336,9 +374,8 @@ async_read_some(
return net::async_initiate<
ReadHandler,
void(error_code, std::size_t)>(
run_read_op{},
run_read_op{in_},
handler,
in_,
buffers);
}

Expand Down Expand Up @@ -420,9 +457,8 @@ async_write_some(
return net::async_initiate<
WriteHandler,
void(error_code, std::size_t)>(
run_write_op{},
run_write_op{in_},
handler,
in_,
out_,
buffers);
}
Expand Down Expand Up @@ -467,28 +503,6 @@ connect(stream& to, Arg1&& arg1, ArgN&&... argn)
return from;
}

namespace detail
{
template<class To>
struct extract_executor_op
{
To operator()(net::any_io_executor& ex) const
{
assert(ex.template target<To>());
return *ex.template target<To>();
}
};

template<>
struct extract_executor_op<net::any_io_executor>
{
net::any_io_executor operator()(net::any_io_executor& ex) const
{
return ex;
}
};
}

template<class Executor>
auto basic_stream<Executor>::get_executor() noexcept -> executor_type
{
Expand Down
18 changes: 13 additions & 5 deletions include/boost/beast/core/detail/impl/read.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,26 @@ class read_op

//------------------------------------------------------------------------------

template <typename AsyncReadStream>
struct run_read_op
{
AsyncReadStream* stream;

using executor_type = typename AsyncReadStream::executor_type;

executor_type
get_executor() const noexcept
{
return stream->get_executor();
}

template<
class AsyncReadStream,
class DynamicBuffer,
class Condition,
class ReadHandler>
void
operator()(
ReadHandler&& h,
AsyncReadStream* s,
DynamicBuffer* b,
Condition&& c)
{
Expand All @@ -133,7 +142,7 @@ struct run_read_op
typename std::decay<Condition>::type,
typename std::decay<ReadHandler>::type>(
std::forward<ReadHandler>(h),
*s,
*stream,
*b,
std::forward<Condition>(c));
}
Expand Down Expand Up @@ -234,9 +243,8 @@ async_read(
return net::async_initiate<
ReadHandler,
void(error_code, std::size_t)>(
typename dynamic_read_ops::run_read_op{},
typename dynamic_read_ops::run_read_op<AsyncReadStream>{&stream},
handler,
&stream,
&buffer,
std::forward<CompletionCondition>(cond));
}
Expand Down
21 changes: 15 additions & 6 deletions include/boost/beast/core/detect_ssl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ class detect_ssl_op;
// authors of composed operations need to write it this way to get the
// very best performance, for example when using Coroutines TS (`co_await`).

template <typename AsyncReadStream>
struct run_detect_ssl_op
{
// The implementation of `net::async_initiate` captures the
Expand All @@ -361,20 +362,29 @@ struct run_detect_ssl_op
// token into the "real handler" which must have the correct
// signature, in this case `void(error_code, boost::tri_bool)`.

AsyncReadStream* stream;

using executor_type = typename AsyncReadStream::executor_type;

executor_type
get_executor() const noexcept
{
return stream->get_executor();
}

template<
class DetectHandler,
class AsyncReadStream,
class DynamicBuffer>
void operator()(
void
operator()(
DetectHandler&& h,
AsyncReadStream* s, // references are passed as pointers
DynamicBuffer* b)
{
detect_ssl_op<
typename std::decay<DetectHandler>::type,
AsyncReadStream,
DynamicBuffer>(
std::forward<DetectHandler>(h), *s, *b);
std::forward<DetectHandler>(h), *stream, *b);
}
};

Expand Down Expand Up @@ -423,9 +433,8 @@ async_detect_ssl(
return net::async_initiate<
CompletionToken,
void(error_code, bool)>(
detail::run_detect_ssl_op{},
detail::run_detect_ssl_op<AsyncReadStream>{&stream},
token,
&stream, // pass the reference by pointer
&buffer);
}

Expand Down
Loading
Loading