[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-sync-ssl PROPERTY FOLDER "example-websocket-server")
target_link_libraries (websocket-server-sync-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-sync-ssl :

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,6 +16,7 @@
#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>
@@ -26,31 +27,43 @@
#include <string>
#include <thread>
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>
//------------------------------------------------------------------------------
// Echoes back all received WebSocket messages
void
do_session(tcp::socket& socket, ssl::context& ctx)
do_session(tcp::socket socket, ssl::context& ctx)
{
try
{
// Construct the websocket stream around the socket
websocket::stream<ssl::stream<tcp::socket&>> ws{socket, ctx};
websocket::stream<beast::ssl_stream<tcp::socket&>> ws{socket, ctx};
// Perform the SSL handshake
ws.next_layer().handshake(ssl::stream_base::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-sync-ssl");
}));
// Accept the websocket handshake
ws.accept();
for(;;)
{
// This buffer will hold the incoming message
boost::beast::multi_buffer buffer;
beast::flat_buffer buffer;
// Read a message
ws.read(buffer);
@@ -60,7 +73,7 @@ do_session(tcp::socket& socket, ssl::context& ctx)
ws.write(buffer.data());
}
}
catch(boost::system::system_error const& se)
catch(beast::system_error const& se)
{
// This indicates that the session was closed
if(se.code() != websocket::error::closed)
@@ -87,14 +100,14 @@ int main(int argc, char* argv[])
" websocket-server-sync-ssl 0.0.0.0 8080\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]));
// The io_context is required for all I/O
boost::asio::io_context ioc{1};
net::io_context ioc{1};
// 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);
@@ -110,10 +123,10 @@ int main(int argc, char* argv[])
acceptor.accept(socket);
// Launch the session, transferring ownership of the socket
std::thread{std::bind(
std::thread(
&do_session,
std::move(socket),
std::ref(ctx))}.detach();
std::ref(ctx)).detach();
}
}
catch (const std::exception& e)