forked from boostorg/beast
role_type is in boost/beast/core/role.hpp (API Change):
This enumeration is now part of the library core and not specific to websocket.
This commit is contained in:
@@ -26,6 +26,7 @@ add_executable (tests-doc
|
||||
http_10_custom_parser.cpp
|
||||
http_examples.cpp
|
||||
http_snippets.cpp
|
||||
websocket.cpp
|
||||
websocket_3_handshake.cpp
|
||||
websocket_snippets.cpp
|
||||
exemplars.cpp
|
||||
|
||||
@@ -24,6 +24,7 @@ alias run-tests :
|
||||
[ run core_4_layers.cpp $(TEST_MAIN) ]
|
||||
[ run http_10_custom_parser.cpp $(TEST_MAIN) ]
|
||||
[ run http_examples.cpp $(TEST_MAIN) ]
|
||||
[ run websocket.cpp $(TEST_MAIN) ]
|
||||
[ run websocket_3_handshake.cpp $(TEST_MAIN) ]
|
||||
;
|
||||
|
||||
@@ -34,6 +35,7 @@ exe fat-tests :
|
||||
core_4_layers.cpp
|
||||
http_10_custom_parser.cpp
|
||||
http_examples.cpp
|
||||
websocket.cpp
|
||||
websocket_3_handshake.cpp
|
||||
;
|
||||
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
// Official repository: https://github.com/boostorg/beast
|
||||
//
|
||||
|
||||
#include "snippets.hpp"
|
||||
|
||||
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 4459) // declaration hides global declaration
|
||||
#endif
|
||||
|
||||
//[code_websocket_1a
|
||||
#include <boost/beast/core.hpp>
|
||||
#include <boost/beast/http.hpp>
|
||||
#include <boost/beast/ssl.hpp>
|
||||
#include <boost/beast/websocket.hpp>
|
||||
//]
|
||||
|
||||
namespace {
|
||||
|
||||
//[code_websocket_1b
|
||||
namespace net = boost::asio;
|
||||
using namespace boost::beast;
|
||||
using namespace boost::beast::websocket;
|
||||
|
||||
net::io_context ioc;
|
||||
net::ssl::context ctx(net::ssl::context::sslv23);
|
||||
|
||||
//]
|
||||
|
||||
void
|
||||
websocket_snippets()
|
||||
{
|
||||
{
|
||||
//[code_websocket_1f
|
||||
|
||||
// This newly constructed WebSocket stream will use the specified
|
||||
// I/O context and have support for the permessage-deflate extension.
|
||||
|
||||
stream<tcp_stream> ws(ioc);
|
||||
|
||||
//]
|
||||
}
|
||||
|
||||
{
|
||||
//[code_websocket_2f
|
||||
|
||||
// The `tcp_stream` will be constructed with a new strand which
|
||||
// uses the specified I/O context.
|
||||
|
||||
stream<tcp_stream> ws(make_strand(ioc));
|
||||
|
||||
//]
|
||||
}
|
||||
|
||||
{
|
||||
//[code_websocket_3f
|
||||
|
||||
// The WebSocket stream will use SSL and a new strand
|
||||
stream<ssl_stream<tcp_stream>> wss(make_strand(ioc), ctx);
|
||||
|
||||
//
|
||||
//]
|
||||
}
|
||||
}
|
||||
|
||||
} // (anon)
|
||||
|
||||
namespace boost {
|
||||
namespace beast {
|
||||
|
||||
struct websocket_snippets_test
|
||||
: public beast::unit_test::suite
|
||||
{
|
||||
void
|
||||
run() override
|
||||
{
|
||||
BEAST_EXPECT(&websocket_snippets);
|
||||
pass();
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(beast,doc,websocket_snippets);
|
||||
|
||||
} // beast
|
||||
} // boost
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
@@ -10,18 +10,17 @@
|
||||
#include <boost/beast/core.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/asio/spawn.hpp>
|
||||
#include <boost/asio/ssl.hpp>
|
||||
#include <boost/asio/use_future.hpp>
|
||||
#include <algorithm>
|
||||
#include <future>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
//[ws_snippet_1
|
||||
using namespace boost::beast;
|
||||
|
||||
#include <boost/beast/websocket.hpp>
|
||||
using namespace boost::beast::websocket;
|
||||
//]
|
||||
|
||||
using namespace boost::beast;
|
||||
|
||||
namespace doc_ws_snippets {
|
||||
|
||||
@@ -34,12 +33,6 @@ error_code ec;
|
||||
net::ip::tcp::socket sock{ioc};
|
||||
boost::ignore_unused(ec);
|
||||
|
||||
{
|
||||
//[ws_snippet_2
|
||||
stream<net::ip::tcp::socket> ws{ioc};
|
||||
//]
|
||||
}
|
||||
|
||||
{
|
||||
//[ws_snippet_3
|
||||
stream<net::ip::tcp::socket> ws{std::move(sock)};
|
||||
@@ -277,25 +270,10 @@ struct custom_wrapper
|
||||
|
||||
//]
|
||||
|
||||
//[ws_snippet_26
|
||||
|
||||
// A WebSocket stream
|
||||
template<
|
||||
class NextLayer,
|
||||
bool deflateSupported = true>
|
||||
class stream;
|
||||
|
||||
//]
|
||||
|
||||
} // doc_ws_snippets
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//[wss_snippet_1
|
||||
#include <boost/beast/websocket/ssl.hpp>
|
||||
#include <boost/asio/ssl.hpp>
|
||||
//]
|
||||
|
||||
namespace doc_wss_snippets {
|
||||
|
||||
void fxx() {
|
||||
@@ -306,13 +284,6 @@ std::thread t{[&](){ ioc.run(); }};
|
||||
error_code ec;
|
||||
net::ip::tcp::socket sock{ioc};
|
||||
|
||||
{
|
||||
//[wss_snippet_2
|
||||
net::ssl::context ctx{net::ssl::context::sslv23};
|
||||
stream<net::ssl::stream<net::ip::tcp::socket>> wss{ioc, ctx};
|
||||
//]
|
||||
}
|
||||
|
||||
{
|
||||
//[wss_snippet_3
|
||||
net::ip::tcp::endpoint ep;
|
||||
|
||||
Reference in New Issue
Block a user