[DEV] add v1.76.0

This commit is contained in:
2021-10-05 21:37:46 +02:00
parent a97e9ae7d4
commit d0115b733d
45133 changed files with 4744437 additions and 1026325 deletions

View File

@@ -22,7 +22,10 @@ if (OPENSSL_FOUND)
set_property(TARGET websocket-server-coro-ssl PROPERTY FOLDER "example-websocket-server")
target_link_libraries (websocket-server-coro-ssl
${OPENSSL_LIBRARIES}
OpenSSL::SSL OpenSSL::Crypto
lib-asio
lib-asio-ssl
lib-beast
)
endif()

View File

@@ -7,10 +7,11 @@
# Official repository: https://github.com/boostorg/beast
#
import ac ;
project
: requirements
<library>ssl
<library>crypto
[ ac.check-library /boost/beast//lib-asio-ssl : <library>/boost/beast//lib-asio-ssl/<link>static : <build>no ]
;
exe websocket-server-coro-ssl :
@@ -18,4 +19,5 @@ exe websocket-server-coro-ssl :
:
<variant>coverage:<build>no
<variant>ubasan:<build>no
<library>/boost/coroutine//boost_coroutine
;

View File

@@ -1,5 +1,5 @@
//
// Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -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/spawn.hpp>
#include <boost/asio/ssl/stream.hpp>
#include <algorithm>
#include <cstdlib>
#include <functional>
@@ -30,15 +29,18 @@
#include <thread>
#include <vector>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp>
namespace websocket = boost::beast::websocket; // from <boost/beast/websocket.hpp>
namespace beast = boost::beast; // from <boost/beast.hpp>
namespace http = beast::http; // from <boost/beast/http.hpp>
namespace websocket = beast::websocket; // from <boost/beast/websocket.hpp>
namespace net = boost::asio; // from <boost/asio.hpp>
namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
//------------------------------------------------------------------------------
// Report a failure
void
fail(boost::system::error_code ec, char const* what)
fail(beast::error_code ec, char const* what)
{
std::cerr << what << ": " << ec.message() << "\n";
}
@@ -46,20 +48,38 @@ fail(boost::system::error_code ec, char const* what)
// Echoes back all received WebSocket messages
void
do_session(
tcp::socket& socket,
ssl::context& ctx,
boost::asio::yield_context yield)
websocket::stream<
beast::ssl_stream<beast::tcp_stream>>& ws,
net::yield_context yield)
{
boost::system::error_code ec;
beast::error_code ec;
// Construct the stream by moving in the socket
websocket::stream<ssl::stream<tcp::socket&>> ws{socket, ctx};
// Set the timeout.
beast::get_lowest_layer(ws).expires_after(std::chrono::seconds(30));
// Perform the SSL handshake
ws.next_layer().async_handshake(ssl::stream_base::server, yield[ec]);
if(ec)
return fail(ec, "handshake");
// Turn off the timeout on the tcp_stream, because
// the websocket stream has its own timeout system.
beast::get_lowest_layer(ws).expires_never();
// Set suggested timeout settings for the websocket
ws.set_option(
websocket::stream_base::timeout::suggested(
beast::role_type::server));
// Set a decorator to change the Server of the handshake
ws.set_option(websocket::stream_base::decorator(
[](websocket::response_type& res)
{
res.set(http::field::server,
std::string(BOOST_BEAST_VERSION_STRING) +
" websocket-server-coro-ssl");
}));
// Accept the websocket handshake
ws.async_accept(yield[ec]);
if(ec)
@@ -68,7 +88,7 @@ do_session(
for(;;)
{
// This buffer will hold the incoming message
boost::beast::multi_buffer buffer;
beast::flat_buffer buffer;
// Read a message
ws.async_read(buffer, yield[ec]);
@@ -93,12 +113,12 @@ do_session(
// Accepts incoming connections and launches the sessions
void
do_listen(
boost::asio::io_context& ioc,
net::io_context& ioc,
ssl::context& ctx,
tcp::endpoint endpoint,
boost::asio::yield_context yield)
net::yield_context yield)
{
boost::system::error_code ec;
beast::error_code ec;
// Open the acceptor
tcp::acceptor acceptor(ioc);
@@ -106,13 +126,18 @@ do_listen(
if(ec)
return fail(ec, "open");
// Allow address reuse
acceptor.set_option(net::socket_base::reuse_address(true), ec);
if(ec)
return fail(ec, "set_option");
// Bind to the server address
acceptor.bind(endpoint, ec);
if(ec)
return fail(ec, "bind");
// Start listening for connections
acceptor.listen(boost::asio::socket_base::max_listen_connections, ec);
acceptor.listen(net::socket_base::max_listen_connections, ec);
if(ec)
return fail(ec, "listen");
@@ -124,11 +149,11 @@ do_listen(
fail(ec, "accept");
else
boost::asio::spawn(
acceptor.get_executor().context(),
acceptor.get_executor(),
std::bind(
&do_session,
std::move(socket),
std::ref(ctx),
websocket::stream<beast::ssl_stream<
beast::tcp_stream>>(std::move(socket), ctx),
std::placeholders::_1));
}
}
@@ -144,15 +169,15 @@ int main(int argc, char* argv[])
" websocket-server-coro-ssl 0.0.0.0 8080 1\n";
return EXIT_FAILURE;
}
auto const address = boost::asio::ip::make_address(argv[1]);
auto const address = net::ip::make_address(argv[1]);
auto const port = static_cast<unsigned short>(std::atoi(argv[2]));
auto const threads = std::max<int>(1, std::atoi(argv[3]));
// The io_context is required for all I/O
boost::asio::io_context ioc{threads};
net::io_context ioc{threads};
// The SSL context is required, and holds certificates
ssl::context ctx{ssl::context::sslv23};
ssl::context ctx{ssl::context::tlsv12};
// This holds the self-signed certificate used by the server
load_server_certificate(ctx);