mirror of
https://github.com/boostorg/beast.git
synced 2025-07-29 20:37:31 +02:00
examples & tests use context instead of coroutine.
This commit is contained in:
committed by
Klemens Morgenstern
parent
1841a592d6
commit
99bceb5bff
@ -19,5 +19,5 @@ exe http-client-coro-ssl :
|
||||
:
|
||||
<variant>coverage:<build>no
|
||||
<variant>ubasan:<build>no
|
||||
<library>/boost/coroutine//boost_coroutine
|
||||
<library>/boost/context//boost_context
|
||||
;
|
||||
|
@ -163,14 +163,25 @@ int main(int argc, char** argv)
|
||||
|
||||
// Launch the asynchronous operation
|
||||
boost::asio::spawn(ioc, std::bind(
|
||||
&do_session,
|
||||
std::string(host),
|
||||
std::string(port),
|
||||
std::string(target),
|
||||
version,
|
||||
std::ref(ioc),
|
||||
std::ref(ctx),
|
||||
std::placeholders::_1));
|
||||
&do_session,
|
||||
std::string(host),
|
||||
std::string(port),
|
||||
std::string(target),
|
||||
version,
|
||||
std::ref(ioc),
|
||||
std::ref(ctx),
|
||||
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. The call will return when
|
||||
// the get operation is complete.
|
||||
|
@ -12,5 +12,5 @@ exe http-client-coro :
|
||||
:
|
||||
<variant>coverage:<build>no
|
||||
<variant>ubasan:<build>no
|
||||
<library>/boost/coroutine//boost_coroutine
|
||||
<library>/boost/context//boost_context
|
||||
;
|
||||
|
@ -134,7 +134,18 @@ int main(int argc, char** argv)
|
||||
std::string(target),
|
||||
version,
|
||||
std::ref(ioc),
|
||||
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. The call will return when
|
||||
// the get operation is complete.
|
||||
|
@ -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;
|
||||
|
@ -12,5 +12,5 @@ exe http-server-coro :
|
||||
:
|
||||
<variant>coverage:<build>no
|
||||
<variant>ubasan:<build>no
|
||||
<library>/boost/coroutine//boost_coroutine
|
||||
<library>/boost/context//boost_context
|
||||
;
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include <boost/beast/http.hpp>
|
||||
#include <boost/beast/version.hpp>
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
#include <boost/asio/detached.hpp>
|
||||
#include <boost/asio/spawn.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <algorithm>
|
||||
@ -308,7 +309,10 @@ do_listen(
|
||||
&do_session,
|
||||
beast::tcp_stream(std::move(socket)),
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -338,7 +342,18 @@ int main(int argc, char* argv[])
|
||||
std::ref(ioc),
|
||||
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;
|
||||
|
@ -19,5 +19,5 @@ exe websocket-client-coro-ssl :
|
||||
:
|
||||
<variant>coverage:<build>no
|
||||
<variant>ubasan:<build>no
|
||||
<library>/boost/coroutine//boost_coroutine
|
||||
<library>/boost/context//boost_context
|
||||
;
|
||||
|
@ -175,7 +175,18 @@ int main(int argc, char** argv)
|
||||
std::string(text),
|
||||
std::ref(ioc),
|
||||
std::ref(ctx),
|
||||
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. The call will return when
|
||||
// the socket is closed.
|
||||
|
@ -12,5 +12,5 @@ exe websocket-client-coro :
|
||||
:
|
||||
<variant>coverage:<build>no
|
||||
<variant>ubasan:<build>no
|
||||
<library>/boost/coroutine//boost_coroutine
|
||||
<library>/boost/context//boost_context
|
||||
;
|
||||
|
@ -143,7 +143,18 @@ int main(int argc, char** argv)
|
||||
std::string(port),
|
||||
std::string(text),
|
||||
std::ref(ioc),
|
||||
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. The call will return when
|
||||
// the socket is closed.
|
||||
|
@ -19,5 +19,5 @@ exe websocket-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/ssl.hpp>
|
||||
#include <boost/beast/websocket.hpp>
|
||||
#include <boost/beast/websocket/ssl.hpp>
|
||||
#include <boost/asio/detached.hpp>
|
||||
#include <boost/asio/spawn.hpp>
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
@ -154,7 +155,10 @@ do_listen(
|
||||
&do_session,
|
||||
websocket::stream<beast::ssl_stream<
|
||||
beast::tcp_stream>>(std::move(socket), ctx),
|
||||
std::placeholders::_1));
|
||||
std::placeholders::_1),
|
||||
// we ignore the result of the session,
|
||||
// most errors are handled with error_code
|
||||
boost::asio::detached);
|
||||
}
|
||||
}
|
||||
|
||||
@ -189,7 +193,18 @@ int main(int argc, char* argv[])
|
||||
std::ref(ioc),
|
||||
std::ref(ctx),
|
||||
tcp::endpoint{address, port},
|
||||
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;
|
||||
|
@ -12,5 +12,5 @@ exe websocket-server-coro :
|
||||
:
|
||||
<variant>coverage:<build>no
|
||||
<variant>ubasan:<build>no
|
||||
<library>/boost/coroutine//boost_coroutine
|
||||
<library>/boost/context//boost_context
|
||||
;
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
#include <boost/beast/core.hpp>
|
||||
#include <boost/beast/websocket.hpp>
|
||||
#include <boost/asio/detached.hpp>
|
||||
#include <boost/asio/spawn.hpp>
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
@ -135,7 +136,10 @@ do_listen(
|
||||
&do_session,
|
||||
websocket::stream<
|
||||
beast::tcp_stream>(std::move(socket)),
|
||||
std::placeholders::_1));
|
||||
std::placeholders::_1),
|
||||
// we ignore the result of the session,
|
||||
// most errors are handled with error_code
|
||||
boost::asio::detached);
|
||||
}
|
||||
}
|
||||
|
||||
@ -163,7 +167,18 @@ int main(int argc, char* argv[])
|
||||
&do_listen,
|
||||
std::ref(ioc),
|
||||
tcp::endpoint{address, port},
|
||||
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;
|
||||
|
@ -12,5 +12,5 @@ exe websocket-server-fast :
|
||||
:
|
||||
<variant>coverage:<build>no
|
||||
<variant>ubasan:<build>no
|
||||
<library>/boost/coroutine//boost_coroutine
|
||||
<library>/boost/context//boost_context
|
||||
;
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include <boost/beast/http.hpp>
|
||||
#include <boost/beast/version.hpp>
|
||||
#include <boost/beast/websocket.hpp>
|
||||
#include <boost/asio/detached.hpp>
|
||||
#include <boost/asio/spawn.hpp>
|
||||
#include <boost/asio/strand.hpp>
|
||||
#include <algorithm>
|
||||
@ -411,7 +412,7 @@ do_coro_listen(
|
||||
&do_coro_session,
|
||||
websocket::stream<
|
||||
beast::tcp_stream>(std::move(socket)),
|
||||
std::placeholders::_1));
|
||||
std::placeholders::_1), boost::asio::detached);
|
||||
}
|
||||
}
|
||||
|
||||
@ -463,7 +464,7 @@ int main(int argc, char* argv[])
|
||||
tcp::endpoint{
|
||||
address,
|
||||
static_cast<unsigned short>(port + 2u)},
|
||||
std::placeholders::_1));
|
||||
std::placeholders::_1), boost::asio::detached);
|
||||
|
||||
// Run the I/O service on the requested number of threads
|
||||
std::vector<std::thread> v;
|
||||
|
Reference in New Issue
Block a user