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:
1 parent
a5739c3ea0
commit
f995fd41a3
185 files changed
+2486
-2392
No files matched your search
@@ -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),
|
||||
|
||||
Reference in new issue
Block a user