Documentation work

This commit is contained in:
Vinnie Falco committed 2019-02-19 16:23:30 -08:00
1 parent 3f50efa138
commit bc436da9c5
6 files changed
+105 -115

No files matched your search

+1
View File
@@ -34,6 +34,7 @@ add_executable (tests-beast-websocket
rfc6455.cpp
role.cpp
stream.cpp
stream_base.cpp
stream_explicit.cpp
stream_fwd.cpp
teardown.cpp
+1
View File
@@ -24,6 +24,7 @@ local SOURCES =
rfc6455.cpp
role.cpp
stream.cpp
stream_base.cpp
stream_explicit.cpp
stream_fwd.cpp
teardown.cpp
+38
View File
@@ -0,0 +1,38 @@
//
// Copyright (c) 2016-2017 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
//
// Test that header file is self-contained.
#include <boost/beast/websocket/stream_base.hpp>
#include <boost/beast/_experimental/unit_test/suite.hpp>
namespace boost {
namespace beast {
namespace websocket {
class stream_base_test : public unit_test::suite
{
public:
void
testJavadoc()
{
}
void
run() override
{
testJavadoc();
}
};
BEAST_DEFINE_TESTSUITE(beast,websocket,stream_base);
} // websocket
} // beast
} // boost
+4 -80
View File
@@ -60,96 +60,20 @@ boost::ignore_unused(ec);
//[ws_snippet_6
std::string const host = "example.com";
net::ip::tcp::resolver r{ioc};
stream<net::ip::tcp::socket> ws{ioc};
stream<tcp_stream<net::io_context::executor_type>> ws{ioc};
auto const results = r.resolve(host, "ws");
net::connect(ws.next_layer(), results.begin(), results.end());
connect(get_lowest_layer(ws), results.begin(), results.end());
//]
}
{
//[ws_snippet_7
net::ip::tcp::acceptor acceptor{ioc};
stream<net::ip::tcp::socket> ws{acceptor.get_executor().context()};
acceptor.accept(ws.next_layer());
stream<tcp_stream<net::io_context::executor_type>> ws{acceptor.get_executor().context()};
acceptor.accept(get_lowest_layer(ws).socket());
//]
}
{
stream<net::ip::tcp::socket> ws{ioc};
//[ws_snippet_8
ws.handshake("localhost", "/");
//]
//[ws_snippet_9
ws.handshake_ex("localhost", "/",
[](request_type& m)
{
m.insert(http::field::sec_websocket_protocol, "xmpp;ws-chat");
});
//]
//[ws_snippet_10
response_type res;
ws.handshake(res, "localhost", "/");
if(! res.count(http::field::sec_websocket_protocol))
throw std::invalid_argument("missing subprotocols");
//]
//[ws_snippet_11
ws.accept();
//]
//[ws_snippet_12
ws.accept_ex(
[](response_type& m)
{
m.insert(http::field::server, "MyServer");
});
//]
}
{
//[ws_snippet_13]
// Buffer required for reading HTTP messages
flat_buffer buffer;
// Read the HTTP request ourselves
http::request<http::string_body> req;
http::read(sock, buffer, req);
// See if its a WebSocket upgrade request
if(websocket::is_upgrade(req))
{
// Construct the stream, transferring ownership of the socket
stream<net::ip::tcp::socket> ws{std::move(sock)};
// Clients SHOULD NOT begin sending WebSocket
// frames until the server has provided a response.
BOOST_ASSERT(buffer.size() == 0);
// Accept the upgrade request
ws.accept(req);
}
else
{
// Its not a WebSocket upgrade, so
// handle it like a normal HTTP request.
}
//]
}
{
stream<net::ip::tcp::socket> ws{ioc};
//[ws_snippet_14
// Read into our buffer until we reach the end of the HTTP request.
// No parsing takes place here, we are just accumulating data.
net::streambuf buffer;
net::read_until(sock, buffer, "\r\n\r\n");
// Now accept the connection, using the buffered data.
ws.accept(buffer.data());
//]
}
{
stream<net::ip::tcp::socket> ws{ioc};
//[ws_snippet_15