net::ssl::stream is canonical in examples

We no longer need to use beast::ssl_stream to improve write performance, as
Asio now linearizes scatter/gather I/O in ssl::stream:
https://github.com/chriskohlhoff/asio/commit/17637a48ccbfa2f63941d8393a7c8316a8df4a79
This commit is contained in:
Mohammad Nejati
2024-05-31 16:45:52 +03:30
committed by Mohammad Nejati
parent bd804b6520
commit 03b792faac
20 changed files with 63 additions and 90 deletions
@@ -16,13 +16,12 @@
#include "example/common/root_certificates.hpp"
#include <boost/beast/core.hpp>
#include <boost/beast/ssl.hpp>
#include <boost/beast/websocket.hpp>
#include <boost/beast/websocket/ssl.hpp>
#include <boost/asio/ssl.hpp>
#include <boost/asio/strand.hpp>
#include <boost/asio/system_executor.hpp>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <memory>
#include <string>
@@ -47,8 +46,7 @@ fail(beast::error_code ec, char const* what)
class session : public std::enable_shared_from_this<session>
{
tcp::resolver resolver_;
websocket::stream<
beast::ssl_stream<beast::tcp_stream>> ws_;
websocket::stream<ssl::stream<beast::tcp_stream>> ws_;
beast::flat_buffer buffer_;
std::string host_;
std::string text_;
@@ -16,12 +16,11 @@
#include "example/common/root_certificates.hpp"
#include <boost/beast/core.hpp>
#include <boost/beast/ssl.hpp>
#include <boost/beast/websocket.hpp>
#include <boost/beast/websocket/ssl.hpp>
#include <boost/asio/ssl.hpp>
#include <boost/asio/strand.hpp>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <memory>
#include <string>
@@ -46,8 +45,7 @@ fail(beast::error_code ec, char const* what)
class session : public std::enable_shared_from_this<session>
{
tcp::resolver resolver_;
websocket::stream<
beast::ssl_stream<beast::tcp_stream>> ws_;
websocket::stream<ssl::stream<beast::tcp_stream>> ws_;
beast::flat_buffer buffer_;
std::string host_;
std::string text_;
@@ -16,10 +16,10 @@
#include "example/common/root_certificates.hpp"
#include <boost/beast/core.hpp>
#include <boost/beast/ssl.hpp>
#include <boost/beast/websocket.hpp>
#include <boost/beast/websocket/ssl.hpp>
#include <boost/asio/spawn.hpp>
#include <boost/asio/ssl.hpp>
#include <cstdlib>
#include <functional>
#include <iostream>
@@ -55,8 +55,7 @@ do_session(
// These objects perform our I/O
tcp::resolver resolver(ioc);
websocket::stream<
beast::ssl_stream<beast::tcp_stream>> ws(ioc, ctx);
websocket::stream<ssl::stream<beast::tcp_stream>> ws(ioc, ctx);
// Look up the domain name
auto const results = resolver.async_resolve(host, port, yield[ec]);
@@ -16,12 +16,11 @@
#include "example/common/root_certificates.hpp"
#include <boost/beast/core.hpp>
#include <boost/beast/ssl.hpp>
#include <boost/beast/websocket.hpp>
#include <boost/beast/websocket/ssl.hpp>
#include <boost/asio/connect.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/ssl/stream.hpp>
#include <boost/asio/ssl.hpp>
#include <cstdlib>
#include <iostream>
#include <string>
@@ -62,13 +61,13 @@ int main(int argc, char** argv)
// These objects perform our I/O
tcp::resolver resolver{ioc};
websocket::stream<beast::ssl_stream<tcp::socket>> ws{ioc, ctx};
websocket::stream<ssl::stream<tcp::socket>> ws{ioc, ctx};
// Look up the domain name
auto const results = resolver.resolve(host, port);
// Make the connection on the IP address we get from a lookup
auto ep = net::connect(get_lowest_layer(ws), results);
auto ep = net::connect(beast::get_lowest_layer(ws), results);
// Set SNI Hostname (many hosts need this to handshake successfully)
if(! SSL_set_tlsext_host_name(ws.next_layer().native_handle(), host.c_str()))
@@ -16,14 +16,13 @@
#include "example/common/server_certificate.hpp"
#include <boost/beast/core.hpp>
#include <boost/beast/ssl.hpp>
#include <boost/beast/websocket.hpp>
#include <boost/beast/websocket/ssl.hpp>
#include <boost/asio/strand.hpp>
#include <boost/asio/dispatch.hpp>
#include <boost/asio/ssl.hpp>
#include <boost/asio/strand.hpp>
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <memory>
#include <string>
@@ -49,8 +48,7 @@ fail(beast::error_code ec, char const* what)
// Echoes back all received WebSocket messages
class session : public std::enable_shared_from_this<session>
{
websocket::stream<
beast::ssl_stream<beast::tcp_stream>> ws_;
websocket::stream<ssl::stream<beast::tcp_stream>> ws_;
beast::flat_buffer buffer_;
public:
@@ -16,16 +16,15 @@
#include "example/common/server_certificate.hpp"
#include <boost/beast/core.hpp>
#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 <boost/asio/ssl.hpp>
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <memory>
#include <string>
#include <thread>
#include <vector>
@@ -49,8 +48,7 @@ fail(beast::error_code ec, char const* what)
// Echoes back all received WebSocket messages
void
do_session(
websocket::stream<
beast::ssl_stream<beast::tcp_stream>>& ws,
websocket::stream<ssl::stream<beast::tcp_stream>>& ws,
net::yield_context yield)
{
beast::error_code ec;
@@ -153,7 +151,7 @@ do_listen(
acceptor.get_executor(),
std::bind(
&do_session,
websocket::stream<beast::ssl_stream<
websocket::stream<ssl::stream<
beast::tcp_stream>>(std::move(socket), ctx),
std::placeholders::_1),
// we ignore the result of the session,
@@ -16,12 +16,12 @@
#include "example/common/server_certificate.hpp"
#include <boost/beast/core.hpp>
#include <boost/beast/ssl.hpp>
#include <boost/beast/websocket.hpp>
#include <boost/beast/websocket/ssl.hpp>
#include <boost/asio/coroutine.hpp>
#include <boost/asio/strand.hpp>
#include <boost/asio/dispatch.hpp>
#include <boost/asio/ssl.hpp>
#include <boost/asio/strand.hpp>
#include <algorithm>
#include <cstdlib>
#include <functional>
@@ -52,7 +52,7 @@ class session
: public boost::asio::coroutine
, public std::enable_shared_from_this<session>
{
websocket::stream<beast::ssl_stream<beast::tcp_stream>> ws_;
websocket::stream<ssl::stream<beast::tcp_stream>> ws_;
beast::flat_buffer buffer_;
public:
@@ -16,11 +16,10 @@
#include "example/common/server_certificate.hpp"
#include <boost/beast/core.hpp>
#include <boost/beast/ssl.hpp>
#include <boost/beast/websocket.hpp>
#include <boost/beast/websocket/ssl.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/ssl/stream.hpp>
#include <boost/asio/ssl.hpp>
#include <cstdlib>
#include <functional>
#include <iostream>
@@ -43,7 +42,7 @@ do_session(tcp::socket socket, ssl::context& ctx)
try
{
// Construct the websocket stream around the socket
websocket::stream<beast::ssl_stream<tcp::socket&>> ws{socket, ctx};
websocket::stream<ssl::stream<tcp::socket&>> ws{socket, ctx};
// Perform the SSL handshake
ws.next_layer().handshake(ssl::stream_base::server);