forked from boostorg/beast
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:
@@ -27,15 +27,18 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
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>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// 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";
|
||||
}
|
||||
@@ -45,14 +48,14 @@ class session : public std::enable_shared_from_this<session>
|
||||
{
|
||||
tcp::resolver resolver_;
|
||||
websocket::stream<ssl::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, ssl::context& ctx)
|
||||
session(net::io_context& ioc, ssl::context& ctx)
|
||||
: resolver_(ioc)
|
||||
, ws_(ioc, ctx)
|
||||
{
|
||||
@@ -82,14 +85,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().next_layer(),
|
||||
results.begin(),
|
||||
results.end(),
|
||||
@@ -100,7 +103,7 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
on_connect(boost::system::error_code ec)
|
||||
on_connect(beast::error_code ec)
|
||||
{
|
||||
if(ec)
|
||||
return fail(ec, "connect");
|
||||
@@ -115,7 +118,7 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
on_ssl_handshake(boost::system::error_code ec)
|
||||
on_ssl_handshake(beast::error_code ec)
|
||||
{
|
||||
if(ec)
|
||||
return fail(ec, "ssl_handshake");
|
||||
@@ -129,14 +132,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(),
|
||||
@@ -146,7 +149,7 @@ public:
|
||||
|
||||
void
|
||||
on_write(
|
||||
boost::system::error_code ec,
|
||||
beast::error_code ec,
|
||||
std::size_t bytes_transferred)
|
||||
{
|
||||
boost::ignore_unused(bytes_transferred);
|
||||
@@ -166,7 +169,7 @@ public:
|
||||
|
||||
void
|
||||
on_read(
|
||||
boost::system::error_code ec,
|
||||
beast::error_code ec,
|
||||
std::size_t bytes_transferred)
|
||||
{
|
||||
boost::ignore_unused(bytes_transferred);
|
||||
@@ -183,7 +186,7 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
on_close(boost::system::error_code ec)
|
||||
on_close(beast::error_code ec)
|
||||
{
|
||||
if(ec)
|
||||
return fail(ec, "close");
|
||||
@@ -191,7 +194,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;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -213,7 +216,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;
|
||||
|
||||
// The SSL context is required, and holds certificates
|
||||
ssl::context ctx{ssl::context::sslv23_client};
|
||||
|
||||
Reference in New Issue
Block a user