examples & tests use context instead of coroutine.

This commit is contained in:
Klemens authored and Klemens Morgenstern committed 2023-02-02 23:27:49 +08:00
1 parent 1841a592d6
commit 99bceb5bff
24 files changed
+156 -37

No files matched your search

+1 -1
View File
@@ -19,5 +19,5 @@ exe http-server-coro-ssl :
:
<variant>coverage:<build>no
<variant>ubasan:<build>no
<library>/boost/coroutine//boost_coroutine
<library>/boost/context//boost_context
;
@@ -19,6 +19,7 @@
#include <boost/beast/http.hpp>
#include <boost/beast/ssl.hpp>
#include <boost/beast/version.hpp>
#include <boost/asio/detached.hpp>
#include <boost/asio/spawn.hpp>
#include <boost/config.hpp>
#include <algorithm>
@@ -344,7 +345,10 @@ do_listen(
beast::ssl_stream<beast::tcp_stream>(
std::move(socket), ctx),
doc_root,
std::placeholders::_1));
std::placeholders::_1),
// we ignore the result of the session,
// most errors are handled with error_code
boost::asio::detached);
}
}
@@ -381,7 +385,18 @@ int main(int argc, char* argv[])
std::ref(ctx),
tcp::endpoint{address, port},
doc_root,
std::placeholders::_1));
std::placeholders::_1),
// on completion, spawn will call this function
[](std::exception_ptr ex)
{
// if an exception occurred in the coroutine,
// it's something critical, e.g. out of memory
// we capture normal errors in the ec
// so we just rethrow the exception here,
// which will cause `ioc.run()` to throw
if (ex)
std::rethrow_exception(ex);
});
// Run the I/O service on the requested number of threads
std::vector<std::thread> v;