Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / beast / example / http / server / async-ssl / http_server_async_ssl.cpp
index f51d445..f6c66c9 100644 (file)
@@ -19,6 +19,7 @@
 #include <boost/beast/http.hpp>
 #include <boost/beast/ssl.hpp>
 #include <boost/beast/version.hpp>
+#include <boost/asio/dispatch.hpp>
 #include <boost/asio/strand.hpp>
 #include <boost/config.hpp>
 #include <algorithm>
@@ -299,8 +300,23 @@ public:
     void
     run()
     {
+        // We need to be executing within a strand to perform async operations
+        // on the I/O objects in this session. Although not strictly necessary
+        // for single-threaded contexts, this example code is written to be
+        // thread-safe by default.
+        net::dispatch(
+            stream_.get_executor(),
+            beast::bind_front_handler(
+                &session::on_run,
+                shared_from_this()));
+    }
+
+    void
+    on_run()
+    {
         // Set the timeout.
-        beast::get_lowest_layer(stream_).expires_after(std::chrono::seconds(30));
+        beast::get_lowest_layer(stream_).expires_after(
+            std::chrono::seconds(30));
 
         // Perform the SSL handshake
         stream_.async_handshake(