From 7ce6980042833e3ab87e320164679ef2f1a2064a Mon Sep 17 00:00:00 2001 From: Richard Hodges Date: Sun, 26 Jan 2020 12:33:50 +0100 Subject: [PATCH] fix strand use in example fixes #1822 close #1823 --- CHANGELOG.md | 1 + .../client/async-ssl/http_client_async_ssl.cpp | 17 +++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09fa6f88..93a4bbdd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ Version XXX: +* examples use strands correctly * update root certificates in examples * clarify end-of-file behaviour in File::read docs * file_body returns short_read on eof during read diff --git a/example/http/client/async-ssl/http_client_async_ssl.cpp b/example/http/client/async-ssl/http_client_async_ssl.cpp index 6248c33f..2a5f95bd 100644 --- a/example/http/client/async-ssl/http_client_async_ssl.cpp +++ b/example/http/client/async-ssl/http_client_async_ssl.cpp @@ -51,12 +51,12 @@ class session : public std::enable_shared_from_this http::response res_; public: - // Objects are constructed with a strand to - // ensure that handlers do not execute concurrently. explicit - session(net::io_context& ioc, ssl::context& ctx) - : resolver_(net::make_strand(ioc)) - , stream_(net::make_strand(ioc), ctx) + session( + net::executor ex, + ssl::context& ctx) + : resolver_(ex) + , stream_(ex, ctx) { } @@ -229,7 +229,12 @@ int main(int argc, char** argv) ctx.set_verify_mode(ssl::verify_peer); // Launch the asynchronous operation - std::make_shared(ioc, ctx)->run(host, port, target, version); + // The session is constructed with a strand to + // ensure that handlers do not execute concurrently. + std::make_shared( + net::make_strand(ioc), + ctx + )->run(host, port, target, version); // Run the I/O service. The call will return when // the get operation is complete.