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};
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -27,15 +27,18 @@
|
||||
#include <iostream>
|
||||
#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";
|
||||
}
|
||||
@@ -46,11 +49,11 @@ do_session(
|
||||
std::string const& host,
|
||||
std::string const& port,
|
||||
std::string const& text,
|
||||
boost::asio::io_context& ioc,
|
||||
net::io_context& ioc,
|
||||
ssl::context& ctx,
|
||||
boost::asio::yield_context yield)
|
||||
net::yield_context yield)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
beast::error_code ec;
|
||||
|
||||
// These objects perform our I/O
|
||||
tcp::resolver resolver{ioc};
|
||||
@@ -62,7 +65,7 @@ do_session(
|
||||
return fail(ec, "resolve");
|
||||
|
||||
// Make the connection on the IP address we get from a lookup
|
||||
boost::asio::async_connect(ws.next_layer().next_layer(), results.begin(), results.end(), yield[ec]);
|
||||
net::async_connect(ws.next_layer().next_layer(), results.begin(), results.end(), yield[ec]);
|
||||
if(ec)
|
||||
return fail(ec, "connect");
|
||||
|
||||
@@ -77,12 +80,12 @@ do_session(
|
||||
return fail(ec, "handshake");
|
||||
|
||||
// Send the message
|
||||
ws.async_write(boost::asio::buffer(std::string(text)), yield[ec]);
|
||||
ws.async_write(net::buffer(std::string(text)), yield[ec]);
|
||||
if(ec)
|
||||
return fail(ec, "write");
|
||||
|
||||
// This buffer will hold the incoming message
|
||||
boost::beast::multi_buffer b;
|
||||
beast::multi_buffer b;
|
||||
|
||||
// Read a message into our buffer
|
||||
ws.async_read(b, yield[ec]);
|
||||
@@ -97,7 +100,7 @@ do_session(
|
||||
// If we get here then the connection is closed gracefully
|
||||
|
||||
// The buffers() function helps print a ConstBufferSequence
|
||||
std::cout << boost::beast::buffers(b.data()) << std::endl;
|
||||
std::cout << beast::buffers(b.data()) << std::endl;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -118,7 +121,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};
|
||||
@@ -127,7 +130,7 @@ int main(int argc, char** argv)
|
||||
load_root_certificates(ctx);
|
||||
|
||||
// Launch the asynchronous operation
|
||||
boost::asio::spawn(ioc, std::bind(
|
||||
net::spawn(ioc, std::bind(
|
||||
&do_session,
|
||||
std::string(host),
|
||||
std::string(port),
|
||||
|
||||
@@ -23,14 +23,17 @@
|
||||
#include <iostream>
|
||||
#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";
|
||||
}
|
||||
@@ -41,10 +44,10 @@ do_session(
|
||||
std::string const& host,
|
||||
std::string const& port,
|
||||
std::string const& text,
|
||||
boost::asio::io_context& ioc,
|
||||
boost::asio::yield_context yield)
|
||||
net::io_context& ioc,
|
||||
net::yield_context yield)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
beast::error_code ec;
|
||||
|
||||
// These objects perform our I/O
|
||||
tcp::resolver resolver{ioc};
|
||||
@@ -56,7 +59,7 @@ do_session(
|
||||
return fail(ec, "resolve");
|
||||
|
||||
// Make the connection on the IP address we get from a lookup
|
||||
boost::asio::async_connect(ws.next_layer(), results.begin(), results.end(), yield[ec]);
|
||||
net::async_connect(ws.next_layer(), results.begin(), results.end(), yield[ec]);
|
||||
if(ec)
|
||||
return fail(ec, "connect");
|
||||
|
||||
@@ -66,12 +69,12 @@ do_session(
|
||||
return fail(ec, "handshake");
|
||||
|
||||
// Send the message
|
||||
ws.async_write(boost::asio::buffer(std::string(text)), yield[ec]);
|
||||
ws.async_write(net::buffer(std::string(text)), yield[ec]);
|
||||
if(ec)
|
||||
return fail(ec, "write");
|
||||
|
||||
// This buffer will hold the incoming message
|
||||
boost::beast::multi_buffer b;
|
||||
beast::multi_buffer b;
|
||||
|
||||
// Read a message into our buffer
|
||||
ws.async_read(b, yield[ec]);
|
||||
@@ -86,7 +89,7 @@ do_session(
|
||||
// If we get here then the connection is closed gracefully
|
||||
|
||||
// The buffers() function helps print a ConstBufferSequence
|
||||
std::cout << boost::beast::buffers(b.data()) << std::endl;
|
||||
std::cout << beast::buffers(b.data()) << std::endl;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -107,10 +110,10 @@ 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
|
||||
boost::asio::spawn(ioc, std::bind(
|
||||
net::spawn(ioc, std::bind(
|
||||
&do_session,
|
||||
std::string(host),
|
||||
std::string(port),
|
||||
|
||||
@@ -25,9 +25,12 @@
|
||||
#include <iostream>
|
||||
#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>
|
||||
|
||||
// Sends a WebSocket message and prints the response
|
||||
int main(int argc, char** argv)
|
||||
@@ -48,7 +51,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};
|
||||
@@ -64,7 +67,7 @@ int main(int argc, char** argv)
|
||||
auto const results = resolver.resolve(host, port);
|
||||
|
||||
// Make the connection on the IP address we get from a lookup
|
||||
boost::asio::connect(ws.next_layer().next_layer(), results.begin(), results.end());
|
||||
net::connect(ws.next_layer().next_layer(), results.begin(), results.end());
|
||||
|
||||
// Perform the SSL handshake
|
||||
ws.next_layer().handshake(ssl::stream_base::client);
|
||||
@@ -73,10 +76,10 @@ int main(int argc, char** argv)
|
||||
ws.handshake(host, "/");
|
||||
|
||||
// Send the message
|
||||
ws.write(boost::asio::buffer(std::string(text)));
|
||||
ws.write(net::buffer(std::string(text)));
|
||||
|
||||
// This buffer will hold the incoming message
|
||||
boost::beast::multi_buffer b;
|
||||
beast::multi_buffer b;
|
||||
|
||||
// Read a message into our buffer
|
||||
ws.read(b);
|
||||
@@ -87,7 +90,7 @@ int main(int argc, char** argv)
|
||||
// If we get here then the connection is closed gracefully
|
||||
|
||||
// The buffers() function helps print a ConstBufferSequence
|
||||
std::cout << boost::beast::buffers(b.data()) << std::endl;
|
||||
std::cout << beast::buffers(b.data()) << std::endl;
|
||||
}
|
||||
catch(std::exception const& e)
|
||||
{
|
||||
|
||||
@@ -23,8 +23,11 @@
|
||||
#include <iostream>
|
||||
#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>
|
||||
|
||||
// Sends a WebSocket message and prints the response
|
||||
int main(int argc, char** argv)
|
||||
@@ -45,7 +48,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;
|
||||
|
||||
// These objects perform our I/O
|
||||
tcp::resolver resolver{ioc};
|
||||
@@ -55,16 +58,16 @@ int main(int argc, char** argv)
|
||||
auto const results = resolver.resolve(host, port);
|
||||
|
||||
// Make the connection on the IP address we get from a lookup
|
||||
boost::asio::connect(ws.next_layer(), results.begin(), results.end());
|
||||
net::connect(ws.next_layer(), results.begin(), results.end());
|
||||
|
||||
// Perform the websocket handshake
|
||||
ws.handshake(host, "/");
|
||||
|
||||
// Send the message
|
||||
ws.write(boost::asio::buffer(std::string(text)));
|
||||
ws.write(net::buffer(std::string(text)));
|
||||
|
||||
// This buffer will hold the incoming message
|
||||
boost::beast::multi_buffer buffer;
|
||||
beast::multi_buffer buffer;
|
||||
|
||||
// Read a message into our buffer
|
||||
ws.read(buffer);
|
||||
@@ -75,7 +78,7 @@ int main(int argc, char** argv)
|
||||
// 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;
|
||||
}
|
||||
catch(std::exception const& e)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user