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
2018-12-02 17:51:43 -08:00
parent a5739c3ea0
commit f995fd41a3
185 changed files with 2486 additions and 2392 deletions
@@ -23,14 +23,17 @@
#include <memory>
#include <string>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.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>
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";
}
@@ -40,14 +43,14 @@ class session : public std::enable_shared_from_this<session>
{
tcp::resolver resolver_;
websocket::stream<tcp::socket> ws_;
boost::beast::multi_buffer buffer_;
beast::multi_buffer buffer_;
std::string host_;
std::string text_;
public:
// Resolver and socket require an io_context
explicit
session(boost::asio::io_context& ioc)
session(net::io_context& ioc)
: resolver_(ioc)
, ws_(ioc)
{
@@ -77,14 +80,14 @@ public:
void
on_resolve(
boost::system::error_code ec,
beast::error_code ec,
tcp::resolver::results_type results)
{
if(ec)
return fail(ec, "resolve");
// Make the connection on the IP address we get from a lookup
boost::asio::async_connect(
net::async_connect(
ws_.next_layer(),
results.begin(),
results.end(),
@@ -95,7 +98,7 @@ public:
}
void
on_connect(boost::system::error_code ec)
on_connect(beast::error_code ec)
{
if(ec)
return fail(ec, "connect");
@@ -109,14 +112,14 @@ public:
}
void
on_handshake(boost::system::error_code ec)
on_handshake(beast::error_code ec)
{
if(ec)
return fail(ec, "handshake");
// Send the message
ws_.async_write(
boost::asio::buffer(text_),
net::buffer(text_),
std::bind(
&session::on_write,
shared_from_this(),
@@ -126,7 +129,7 @@ public:
void
on_write(
boost::system::error_code ec,
beast::error_code ec,
std::size_t bytes_transferred)
{
boost::ignore_unused(bytes_transferred);
@@ -146,7 +149,7 @@ public:
void
on_read(
boost::system::error_code ec,
beast::error_code ec,
std::size_t bytes_transferred)
{
boost::ignore_unused(bytes_transferred);
@@ -163,7 +166,7 @@ public:
}
void
on_close(boost::system::error_code ec)
on_close(beast::error_code ec)
{
if(ec)
return fail(ec, "close");
@@ -171,7 +174,7 @@ public:
// If we get here then the connection is closed gracefully
// The buffers() function helps print a ConstBufferSequence
std::cout << boost::beast::buffers(buffer_.data()) << std::endl;
std::cout << beast::buffers(buffer_.data()) << std::endl;
}
};
@@ -193,7 +196,7 @@ int main(int argc, char** argv)
auto const text = argv[3];
// The io_context is required for all I/O
boost::asio::io_context ioc;
net::io_context ioc;
// Launch the asynchronous operation
std::make_shared<session>(ioc)->run(host, port, text);