boostorg / boostorg/beast

Compile error when any_io_executor based websocket stream with bind_executor strand

Open
#2,775 10 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
4.8k
Forks
694
Avg merge
12h 48m
Merged PRs (30d)
1

Description

### Version of Beast

- My local:
- Boost 1.84.0,
- Beast 351
- Godbolt
- Boost 1.83.0
- Beast 347

### Steps necessary to reproduce the problem

Compile the following code:

```cpp
#include
#include

namespace net = boost::asio;
namespace bs = boost::beast;

using tcp = net::basic_stream_socket;
using ws = bs::websocket::stream;

void tcp_test() {
net::io_context ioc;
net::any_io_executor exe = ioc.get_executor();

std::string buf;
tcp socket{exe};
auto str = net::make_strand(exe);
socket.async_write_some(
net::buffer(buf),
net::bind_executor( // on tcp socket with any_io_executor, no error happens
str,
[](auto, auto){}
)
);
}

void ws_test() {
net::io_context ioc;
net::any_io_executor exe = ioc.get_executor();

std::string buf;
ws web_socket{exe};
auto str = net::make_strand(exe);
web_socket.async_write(
net::buffer(buf),
#if 1 // If you set 0 (remove bind_executor), then error is disappeared
net::bind_executor(
str,
[](auto, auto){}
)
#else
[](auto, auto){}
#endif
);
}

int main() {}
```

Got the following compile error:

```
explorer/libs/boost_1_83_0/boost/asio.hpp:188:
/opt/compiler-explorer/libs/boost_1_83_0/boost/asio/strand.hpp:260:15: error: no member named 'on_work_finished' in 'boost::asio::any_io_executor'
260 | executor_.on_work_finished();
| ~~~~~~~~~ ^
```

godbolt link(x86-64 clang 17.0.1) : https://godbolt.org/z/nocj654EK

### All relevant compiler information
- x86-64 clang 17.0.1
- x86-64 gcc 13.2

### What I noticed
- `tcp` doesn't cause the error.
- The error happens only the combination of `ws` with `bind_executor` strand.
- `ws` contains `tcp` as the next layer. `tcp` has `any_io_executor`.
- The strand `str` is created by `make_strand` and `any_io_executor` `exe` is passed.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.