net is a namespace alias for boost::asio:

The namespace alias beast::net replaces boost::asio in all code
and documentation.
This commit is contained in:
Vinnie Falco committed 2018-12-02 17:51:43 -08:00
1 parent a5739c3ea0
commit f995fd41a3
185 files changed
+2486 -2392

No files matched your search

+6 -6
View File
@@ -32,18 +32,18 @@ public:
buf[2] = 0;
buf[3] = 0;
BEAST_EXPECT(boost::indeterminate(is_ssl_handshake(
boost::asio::buffer(buf, 0))));
net::buffer(buf, 0))));
BEAST_EXPECT(boost::indeterminate(is_ssl_handshake(
boost::asio::buffer(buf, 1))));
net::buffer(buf, 1))));
BEAST_EXPECT(boost::indeterminate(is_ssl_handshake(
boost::asio::buffer(buf, 2))));
net::buffer(buf, 2))));
BEAST_EXPECT(boost::indeterminate(is_ssl_handshake(
boost::asio::buffer(buf, 3))));
net::buffer(buf, 3))));
BEAST_EXPECT(is_ssl_handshake(
boost::asio::buffer(buf, 4)));
net::buffer(buf, 4)));
buf[0] = 0;
BEAST_EXPECT(! is_ssl_handshake(
boost::asio::buffer(buf, 1)));
net::buffer(buf, 1)));
}
void
+7 -7
View File
@@ -26,12 +26,12 @@ void fxx()
//
using namespace boost::beast;
boost::asio::io_context ioc;
auto work = boost::asio::make_work_guard(ioc);
net::io_context ioc;
auto work = net::make_work_guard(ioc);
std::thread t{[&](){ ioc.run(); }};
error_code ec;
boost::asio::ip::tcp::socket sock{ioc};
net::ip::tcp::socket sock{ioc};
//]
boost::ignore_unused(ec);
@@ -40,10 +40,10 @@ boost::asio::ip::tcp::socket sock{ioc};
//[snippet_core_2
char const* const host = "www.example.com";
boost::asio::ip::tcp::resolver r{ioc};
boost::asio::ip::tcp::socket stream{ioc};
net::ip::tcp::resolver r{ioc};
net::ip::tcp::socket stream{ioc};
auto const results = r.resolve(host, "http");
boost::asio::connect(stream, results.begin(), results.end());
net::connect(stream, results.begin(), results.end());
// At this point `stream` is a connected to a remote
// host and may be used to perform stream operations.
@@ -62,7 +62,7 @@ void write_string(SyncWriteStream& stream, string_view s)
{
static_assert(is_sync_write_stream<SyncWriteStream>::value,
"SyncWriteStream requirements not met");
boost::asio::write(stream, boost::asio::const_buffer(s.data(), s.size()));
net::write(stream, net::const_buffer(s.data(), s.size()));
}
//]
+2 -2
View File
@@ -53,7 +53,7 @@ struct BodyWriter
{
public:
/// The type of buffer returned by `get`.
using const_buffers_type = boost::asio::const_buffer;
using const_buffers_type = net::const_buffer;
/** Construct the writer.
@@ -164,7 +164,7 @@ struct BodyReader
// The specification requires this to indicate "no error"
ec = {};
return boost::asio::buffer_size(buffers);
return net::buffer_size(buffers);
}
/** Called when the body is complete.
+8 -8
View File
@@ -201,7 +201,7 @@ public:
};
error_code ec;
custom_parser<true> p;
p.put(boost::asio::buffer(
p.put(net::buffer(
s.data(), s.size()), ec);
BEAST_EXPECTS(! ec, ec.message());
}
@@ -218,7 +218,7 @@ public:
};
error_code ec;
custom_parser<false> p;
p.put(boost::asio::buffer(
p.put(net::buffer(
s.data(), s.size()), ec);
BEAST_EXPECTS(! ec, ec.message());
}
@@ -309,7 +309,7 @@ public:
auto const buf =
[](string_view s)
{
return boost::asio::const_buffer{
return net::const_buffer{
s.data(), s.size()};
};
test::stream ts{ioc_}, tr{ioc_};
@@ -326,22 +326,22 @@ public:
chunk_extensions exts;
boost::asio::write(ts,
net::write(ts,
make_chunk(buf("First")), ec);
exts.insert("quality", "1.0");
boost::asio::write(ts,
net::write(ts,
make_chunk(buf("Hello, world!"), exts), ec);
exts.clear();
exts.insert("file", "abc.txt");
exts.insert("quality", "0.7");
boost::asio::write(ts,
net::write(ts,
make_chunk(buf("The Next Chunk"), std::move(exts)), ec);
exts.clear();
exts.insert("last");
boost::asio::write(ts,
net::write(ts,
make_chunk(buf("Last one"), std::move(exts),
std::allocator<double>{}), ec);
@@ -349,7 +349,7 @@ public:
trailers.set(field::expires, "never");
trailers.set(field::content_md5, "f4a5c16584f03d90");
boost::asio::write(ts,
net::write(ts,
make_chunk_last(
trailers,
std::allocator<double>{}
+30 -30
View File
@@ -26,20 +26,20 @@ namespace doc_http_snippets {
//[http_snippet_17
// This function returns the buffer containing the next chunk body
boost::asio::const_buffer get_next_chunk_body();
net::const_buffer get_next_chunk_body();
//]
boost::asio::const_buffer get_next_chunk_body()
net::const_buffer get_next_chunk_body()
{
return {nullptr, 0};
}
void fxx() {
boost::asio::io_context ioc;
auto work = boost::asio::make_work_guard(ioc);
net::io_context ioc;
auto work = net::make_work_guard(ioc);
std::thread t{[&](){ ioc.run(); }};
boost::asio::ip::tcp::socket sock{ioc};
net::ip::tcp::socket sock{ioc};
{
//[http_snippet_2
@@ -160,12 +160,12 @@ void fxx() {
write_header(sock, sr);
// Now manually emit three chunks:
boost::asio::write(sock, make_chunk(get_next_chunk_body()));
boost::asio::write(sock, make_chunk(get_next_chunk_body()));
boost::asio::write(sock, make_chunk(get_next_chunk_body()));
net::write(sock, make_chunk(get_next_chunk_body()));
net::write(sock, make_chunk(get_next_chunk_body()));
net::write(sock, make_chunk(get_next_chunk_body()));
// We are responsible for sending the last chunk:
boost::asio::write(sock, make_chunk_last());
net::write(sock, make_chunk_last());
//]
}
@@ -180,18 +180,18 @@ void fxx() {
// Write the next chunk with the chunk extensions
// The implementation will make a copy of the extensions object,
// so the caller does not need to manage lifetime issues.
boost::asio::write(sock, make_chunk(get_next_chunk_body(), ext));
net::write(sock, make_chunk(get_next_chunk_body(), ext));
// Write the next chunk with the chunk extensions
// The implementation will make a copy of the extensions object, storing the copy
// using the custom allocator, so the caller does not need to manage lifetime issues.
boost::asio::write(sock, make_chunk(get_next_chunk_body(), ext, std::allocator<char>{}));
net::write(sock, make_chunk(get_next_chunk_body(), ext, std::allocator<char>{}));
// Write the next chunk with the chunk extensions
// The implementation allocates memory using the default allocator and takes ownership
// of the extensions object, so the caller does not need to manage lifetime issues.
// Note: ext is moved
boost::asio::write(sock, make_chunk(get_next_chunk_body(), std::move(ext)));
net::write(sock, make_chunk(get_next_chunk_body(), std::move(ext)));
//]
}
@@ -199,7 +199,7 @@ void fxx() {
//[http_snippet_20
// Manually specify the chunk extensions.
// Some of the strings contain spaces and a period and must be quoted
boost::asio::write(sock, make_chunk(get_next_chunk_body(),
net::write(sock, make_chunk(get_next_chunk_body(),
";mp3"
";title=\"Danny Boy\""
";artist=\"Fred E. Weatherly\""
@@ -221,8 +221,8 @@ void fxx() {
// Serialize the header and two chunks
response_serializer<empty_body> sr{res};
write_header(sock, sr);
boost::asio::write(sock, make_chunk(get_next_chunk_body()));
boost::asio::write(sock, make_chunk(get_next_chunk_body()));
net::write(sock, make_chunk(get_next_chunk_body()));
net::write(sock, make_chunk(get_next_chunk_body()));
// Prepare the trailer
fields trailer;
@@ -232,7 +232,7 @@ void fxx() {
// Emit the trailer in the last chunk.
// The implementation will use the default allocator to create the storage for holding
// the serialized fields.
boost::asio::write(sock, make_chunk_last(trailer));
net::write(sock, make_chunk_last(trailer));
//]
}
@@ -241,7 +241,7 @@ void fxx() {
// Use a custom allocator for serializing the last chunk
fields trailer;
trailer.set(field::approved, "yes");
boost::asio::write(sock, make_chunk_last(trailer, std::allocator<char>{}));
net::write(sock, make_chunk_last(trailer, std::allocator<char>{}));
//]
}
@@ -253,7 +253,7 @@ void fxx() {
"Content-MD5: f4a5c16584f03d90\r\n"
"Expires: never\r\n"
"\r\n";
boost::asio::write(sock, make_chunk_last(boost::asio::const_buffer{ext.data(), ext.size()}));
net::write(sock, make_chunk_last(net::const_buffer{ext.data(), ext.size()}));
//]
}
@@ -272,18 +272,18 @@ void fxx() {
auto const cb3 = get_next_chunk_body();
// Manually emit a chunk by first writing the chunk-size header with the correct size
boost::asio::write(sock, chunk_header{
boost::asio::buffer_size(cb1) +
boost::asio::buffer_size(cb2) +
boost::asio::buffer_size(cb3)});
net::write(sock, chunk_header{
net::buffer_size(cb1) +
net::buffer_size(cb2) +
net::buffer_size(cb3)});
// And then output the chunk body in three pieces ("chunk the chunk")
boost::asio::write(sock, cb1);
boost::asio::write(sock, cb2);
boost::asio::write(sock, cb3);
net::write(sock, cb1);
net::write(sock, cb2);
net::write(sock, cb3);
// When we go this deep, we are also responsible for the terminating CRLF
boost::asio::write(sock, chunk_crlf{});
net::write(sock, chunk_crlf{});
//]
}
@@ -367,7 +367,7 @@ print_cxx14(message<isRequest, Body, Fields> const& m)
{
ec.assign(0, ec.category());
std::cout << buffers(buffer);
sr.consume(boost::asio::buffer_size(buffer));
sr.consume(net::buffer_size(buffer));
});
}
while(! ec && ! sr.is_done());
@@ -394,7 +394,7 @@ struct lambda
{
ec.assign(0, ec.category());
std::cout << buffers(buffer);
sr.consume(boost::asio::buffer_size(buffer));
sr.consume(net::buffer_size(buffer));
}
};
@@ -435,7 +435,7 @@ split_print_cxx14(message<isRequest, Body, Fields> const& m)
{
ec.assign(0, ec.category());
std::cout << buffers(buffer);
sr.consume(boost::asio::buffer_size(buffer));
sr.consume(net::buffer_size(buffer));
});
}
while(! sr.is_header_done());
@@ -449,7 +449,7 @@ split_print_cxx14(message<isRequest, Body, Fields> const& m)
{
ec.assign(0, ec.category());
std::cout << buffers(buffer);
sr.consume(boost::asio::buffer_size(buffer));
sr.consume(net::buffer_size(buffer));
});
}
while(! ec && ! sr.is_done());
+33 -33
View File
@@ -27,55 +27,55 @@ namespace doc_ws_snippets {
void fxx() {
boost::asio::io_context ioc;
auto work = boost::asio::make_work_guard(ioc);
net::io_context ioc;
auto work = net::make_work_guard(ioc);
std::thread t{[&](){ ioc.run(); }};
error_code ec;
boost::asio::ip::tcp::socket sock{ioc};
net::ip::tcp::socket sock{ioc};
boost::ignore_unused(ec);
{
//[ws_snippet_2
stream<boost::asio::ip::tcp::socket> ws{ioc};
stream<net::ip::tcp::socket> ws{ioc};
//]
}
{
//[ws_snippet_3
stream<boost::asio::ip::tcp::socket> ws{std::move(sock)};
stream<net::ip::tcp::socket> ws{std::move(sock)};
//]
}
{
//[ws_snippet_4
stream<boost::asio::ip::tcp::socket&> ws{sock};
stream<net::ip::tcp::socket&> ws{sock};
//]
//[ws_snippet_5
ws.next_layer().shutdown(boost::asio::ip::tcp::socket::shutdown_send);
ws.next_layer().shutdown(net::ip::tcp::socket::shutdown_send);
//]
}
{
//[ws_snippet_6
std::string const host = "example.com";
boost::asio::ip::tcp::resolver r{ioc};
stream<boost::asio::ip::tcp::socket> ws{ioc};
net::ip::tcp::resolver r{ioc};
stream<net::ip::tcp::socket> ws{ioc};
auto const results = r.resolve(host, "ws");
boost::asio::connect(ws.next_layer(), results.begin(), results.end());
net::connect(ws.next_layer(), results.begin(), results.end());
//]
}
{
//[ws_snippet_7
boost::asio::ip::tcp::acceptor acceptor{ioc};
stream<boost::asio::ip::tcp::socket> ws{acceptor.get_executor().context()};
net::ip::tcp::acceptor acceptor{ioc};
stream<net::ip::tcp::socket> ws{acceptor.get_executor().context()};
acceptor.accept(ws.next_layer());
//]
}
{
stream<boost::asio::ip::tcp::socket> ws{ioc};
stream<net::ip::tcp::socket> ws{ioc};
//[ws_snippet_8
ws.handshake("localhost", "/");
//]
@@ -121,7 +121,7 @@ boost::ignore_unused(ec);
if(websocket::is_upgrade(req))
{
// Construct the stream, transferring ownership of the socket
stream<boost::asio::ip::tcp::socket> ws{std::move(sock)};
stream<net::ip::tcp::socket> ws{std::move(sock)};
// Clients SHOULD NOT begin sending WebSocket
// frames until the server has provided a response.
@@ -139,19 +139,19 @@ boost::ignore_unused(ec);
}
{
stream<boost::asio::ip::tcp::socket> ws{ioc};
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.
boost::asio::streambuf buffer;
boost::asio::read_until(sock, buffer, "\r\n\r\n");
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<boost::asio::ip::tcp::socket> ws{ioc};
stream<net::ip::tcp::socket> ws{ioc};
//[ws_snippet_15
// This DynamicBuffer will hold the received message
multi_buffer buffer;
@@ -176,7 +176,7 @@ boost::ignore_unused(ec);
}
{
stream<boost::asio::ip::tcp::socket> ws{ioc};
stream<net::ip::tcp::socket> ws{ioc};
//[ws_snippet_16
// This DynamicBuffer will hold the received message
multi_buffer buffer;
@@ -202,7 +202,7 @@ boost::ignore_unused(ec);
// This will cause the message to be broken up into multiple frames.
for(;;)
{
using boost::asio::buffer_size;
using net::buffer_size;
if(buffer_size(cb) > 512)
{
// There are more than 512 bytes left to send, just
@@ -232,7 +232,7 @@ boost::ignore_unused(ec);
}
{
stream<boost::asio::ip::tcp::socket> ws{ioc};
stream<net::ip::tcp::socket> ws{ioc};
//[ws_snippet_17
ws.control_callback(
[](frame_type kind, string_view payload)
@@ -285,12 +285,12 @@ boost::ignore_unused(ec);
// workaround for https://github.com/chriskohlhoff/asio/issues/112
#ifdef BOOST_MSVC
//[ws_snippet_21
void echo(stream<boost::asio::ip::tcp::socket>& ws,
multi_buffer& buffer, boost::asio::yield_context yield)
void echo(stream<net::ip::tcp::socket>& ws,
multi_buffer& buffer, net::yield_context yield)
{
ws.async_read(buffer, yield);
std::future<std::size_t> fut =
ws.async_write(buffer.data(), boost::asio::use_future);
ws.async_write(buffer.data(), net::use_future);
}
//]
#endif
@@ -379,30 +379,30 @@ namespace doc_wss_snippets {
void fxx() {
boost::asio::io_context ioc;
auto work = boost::asio::make_work_guard(ioc);
net::io_context ioc;
auto work = net::make_work_guard(ioc);
std::thread t{[&](){ ioc.run(); }};
error_code ec;
boost::asio::ip::tcp::socket sock{ioc};
net::ip::tcp::socket sock{ioc};
{
//[wss_snippet_2
boost::asio::ssl::context ctx{boost::asio::ssl::context::sslv23};
stream<boost::asio::ssl::stream<boost::asio::ip::tcp::socket>> wss{ioc, ctx};
net::ssl::context ctx{net::ssl::context::sslv23};
stream<net::ssl::stream<net::ip::tcp::socket>> wss{ioc, ctx};
//]
}
{
//[wss_snippet_3
boost::asio::ip::tcp::endpoint ep;
boost::asio::ssl::context ctx{boost::asio::ssl::context::sslv23};
stream<boost::asio::ssl::stream<boost::asio::ip::tcp::socket>> ws{ioc, ctx};
net::ip::tcp::endpoint ep;
net::ssl::context ctx{net::ssl::context::sslv23};
stream<net::ssl::stream<net::ip::tcp::socket>> ws{ioc, ctx};
// connect the underlying TCP/IP socket
ws.next_layer().next_layer().connect(ep);
// perform SSL handshake
ws.next_layer().handshake(boost::asio::ssl::stream_base::client);
ws.next_layer().handshake(net::ssl::stream_base::client);
// perform WebSocket handshake
ws.handshake("localhost", "/");