I am using beast for implementation of HTTPS Client. In order to make the handshake I call async_handshake
. But if I try to shutdown the stream via async_shutdown
, I receive the following assert: boost::beast::detail::stream_base::pending_guard::pending_guard(bool&): Assertion `. b_' failed.
boost::beast::detail::stream_base::pending_guard::pending_guard(bool&): Assertion `. b_' failed.
Is there a way to correctly shutdown the stream during the handshake?
As far as I can tell the assertion means that a read/write operation is in progress. Make sure you synchronize access to the stream object using a (implicit) strand.
If you have only one thread, you should already have it. Otherwise, post to the strand executor, eg instead of
stream_.async_shutdown(handler);
Do something like
boost::asio::post(stream_.get_executor(),
[self] { self->stream_.async_shutdown(handler); });
If the containing class has shared ownership you would have auto self = shared_from_this();
. Otherwise self
could just be this
.
More background on where and why of strands: Asio docs and Why do I need strand per connection when using boost::asio?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.