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-11-30 14:58:38 -08:00
parent a5739c3ea0
commit f995fd41a3
185 changed files with 2486 additions and 2392 deletions

View File

@@ -1,3 +1,9 @@
Version 195:
* net is a namespace alias for boost::asio
--------------------------------------------------------------------------------
Version 194: Version 194:
* http::async_read returns the right byte count on error * http::async_read returns the right byte count on error

View File

@@ -38,21 +38,23 @@
#include <thread> #include <thread>
#include <vector> #include <vector>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.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> namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp>
namespace http = boost::beast::http; // from <boost/beast/http.hpp> using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
namespace websocket = boost::beast::websocket; // from <boost/beast/websocket.hpp>
// Return a reasonable mime type based on the extension of a file. // Return a reasonable mime type based on the extension of a file.
boost::beast::string_view beast::string_view
mime_type(boost::beast::string_view path) mime_type(beast::string_view path)
{ {
using boost::beast::iequals; using beast::iequals;
auto const ext = [&path] auto const ext = [&path]
{ {
auto const pos = path.rfind("."); auto const pos = path.rfind(".");
if(pos == boost::beast::string_view::npos) if(pos == beast::string_view::npos)
return boost::beast::string_view{}; return beast::string_view{};
return path.substr(pos); return path.substr(pos);
}(); }();
if(iequals(ext, ".htm")) return "text/html"; if(iequals(ext, ".htm")) return "text/html";
@@ -83,8 +85,8 @@ mime_type(boost::beast::string_view path)
// The returned path is normalized for the platform. // The returned path is normalized for the platform.
std::string std::string
path_cat( path_cat(
boost::beast::string_view base, beast::string_view base,
boost::beast::string_view path) beast::string_view path)
{ {
if(base.empty()) if(base.empty())
return path.to_string(); return path.to_string();
@@ -115,13 +117,13 @@ template<
class Send> class Send>
void void
handle_request( handle_request(
boost::beast::string_view doc_root, beast::string_view doc_root,
http::request<Body, http::basic_fields<Allocator>>&& req, http::request<Body, http::basic_fields<Allocator>>&& req,
Send&& send) Send&& send)
{ {
// Returns a bad request response // Returns a bad request response
auto const bad_request = auto const bad_request =
[&req](boost::beast::string_view why) [&req](beast::string_view why)
{ {
http::response<http::string_body> res{http::status::bad_request, req.version()}; http::response<http::string_body> res{http::status::bad_request, req.version()};
res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
@@ -134,7 +136,7 @@ handle_request(
// Returns a not found response // Returns a not found response
auto const not_found = auto const not_found =
[&req](boost::beast::string_view target) [&req](beast::string_view target)
{ {
http::response<http::string_body> res{http::status::not_found, req.version()}; http::response<http::string_body> res{http::status::not_found, req.version()};
res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
@@ -147,7 +149,7 @@ handle_request(
// Returns a server error response // Returns a server error response
auto const server_error = auto const server_error =
[&req](boost::beast::string_view what) [&req](beast::string_view what)
{ {
http::response<http::string_body> res{http::status::internal_server_error, req.version()}; http::response<http::string_body> res{http::status::internal_server_error, req.version()};
res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
@@ -166,7 +168,7 @@ handle_request(
// Request path must be absolute and not contain "..". // Request path must be absolute and not contain "..".
if( req.target().empty() || if( req.target().empty() ||
req.target()[0] != '/' || req.target()[0] != '/' ||
req.target().find("..") != boost::beast::string_view::npos) req.target().find("..") != beast::string_view::npos)
return send(bad_request("Illegal request-target")); return send(bad_request("Illegal request-target"));
// Build the path to the requested file // Build the path to the requested file
@@ -175,12 +177,12 @@ handle_request(
path.append("index.html"); path.append("index.html");
// Attempt to open the file // Attempt to open the file
boost::beast::error_code ec; beast::error_code ec;
http::file_body::value_type body; http::file_body::value_type body;
body.open(path.c_str(), boost::beast::file_mode::scan, ec); body.open(path.c_str(), beast::file_mode::scan, ec);
// Handle the case where the file doesn't exist // Handle the case where the file doesn't exist
if(ec == boost::system::errc::no_such_file_or_directory) if(ec == beast::errc::no_such_file_or_directory)
return send(not_found(req.target())); return send(not_found(req.target()));
// Handle an unknown error // Handle an unknown error
@@ -217,7 +219,7 @@ handle_request(
// Report a failure // Report a failure
void void
fail(boost::system::error_code ec, char const* what) fail(beast::error_code ec, char const* what)
{ {
std::cerr << what << ": " << ec.message() << "\n"; std::cerr << what << ": " << ec.message() << "\n";
} }
@@ -238,18 +240,18 @@ class websocket_session
return static_cast<Derived&>(*this); return static_cast<Derived&>(*this);
} }
boost::beast::multi_buffer buffer_; beast::multi_buffer buffer_;
char ping_state_ = 0; char ping_state_ = 0;
protected: protected:
boost::asio::strand< net::strand<
boost::asio::io_context::executor_type> strand_; net::io_context::executor_type> strand_;
boost::asio::steady_timer timer_; net::steady_timer timer_;
public: public:
// Construct the session // Construct the session
explicit explicit
websocket_session(boost::asio::io_context& ioc) websocket_session(net::io_context& ioc)
: strand_(ioc.get_executor()) : strand_(ioc.get_executor())
, timer_(ioc, , timer_(ioc,
(std::chrono::steady_clock::time_point::max)()) (std::chrono::steady_clock::time_point::max)())
@@ -276,7 +278,7 @@ public:
// Accept the websocket handshake // Accept the websocket handshake
derived().ws().async_accept( derived().ws().async_accept(
req, req,
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&websocket_session::on_accept, &websocket_session::on_accept,
@@ -285,10 +287,10 @@ public:
} }
void void
on_accept(boost::system::error_code ec) on_accept(beast::error_code ec)
{ {
// Happens when the timer closes the socket // Happens when the timer closes the socket
if(ec == boost::asio::error::operation_aborted) if(ec == net::error::operation_aborted)
return; return;
if(ec) if(ec)
@@ -300,9 +302,9 @@ public:
// Called when the timer expires. // Called when the timer expires.
void void
on_timer(boost::system::error_code ec) on_timer(beast::error_code ec)
{ {
if(ec && ec != boost::asio::error::operation_aborted) if(ec && ec != net::error::operation_aborted)
return fail(ec, "timer"); return fail(ec, "timer");
// See if the timer really expired since the deadline may have moved. // See if the timer really expired since the deadline may have moved.
@@ -320,7 +322,7 @@ public:
// Now send the ping // Now send the ping
derived().ws().async_ping({}, derived().ws().async_ping({},
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&websocket_session::on_ping, &websocket_session::on_ping,
@@ -340,7 +342,7 @@ public:
// Wait on the timer // Wait on the timer
timer_.async_wait( timer_.async_wait(
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&websocket_session::on_timer, &websocket_session::on_timer,
@@ -361,10 +363,10 @@ public:
// Called after a ping is sent. // Called after a ping is sent.
void void
on_ping(boost::system::error_code ec) on_ping(beast::error_code ec)
{ {
// Happens when the timer closes the socket // Happens when the timer closes the socket
if(ec == boost::asio::error::operation_aborted) if(ec == net::error::operation_aborted)
return; return;
if(ec) if(ec)
@@ -387,7 +389,7 @@ public:
void void
on_control_callback( on_control_callback(
websocket::frame_type kind, websocket::frame_type kind,
boost::beast::string_view payload) beast::string_view payload)
{ {
boost::ignore_unused(kind, payload); boost::ignore_unused(kind, payload);
@@ -401,7 +403,7 @@ public:
// Read a message into our buffer // Read a message into our buffer
derived().ws().async_read( derived().ws().async_read(
buffer_, buffer_,
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&websocket_session::on_read, &websocket_session::on_read,
@@ -412,13 +414,13 @@ public:
void void
on_read( on_read(
boost::system::error_code ec, beast::error_code ec,
std::size_t bytes_transferred) std::size_t bytes_transferred)
{ {
boost::ignore_unused(bytes_transferred); boost::ignore_unused(bytes_transferred);
// Happens when the timer closes the socket // Happens when the timer closes the socket
if(ec == boost::asio::error::operation_aborted) if(ec == net::error::operation_aborted)
return; return;
// This indicates that the websocket_session was closed // This indicates that the websocket_session was closed
@@ -435,7 +437,7 @@ public:
derived().ws().text(derived().ws().got_text()); derived().ws().text(derived().ws().got_text());
derived().ws().async_write( derived().ws().async_write(
buffer_.data(), buffer_.data(),
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&websocket_session::on_write, &websocket_session::on_write,
@@ -446,13 +448,13 @@ public:
void void
on_write( on_write(
boost::system::error_code ec, beast::error_code ec,
std::size_t bytes_transferred) std::size_t bytes_transferred)
{ {
boost::ignore_unused(bytes_transferred); boost::ignore_unused(bytes_transferred);
// Happens when the timer closes the socket // Happens when the timer closes the socket
if(ec == boost::asio::error::operation_aborted) if(ec == net::error::operation_aborted)
return; return;
if(ec) if(ec)
@@ -518,7 +520,7 @@ public:
// Close the WebSocket Connection // Close the WebSocket Connection
ws_.async_close( ws_.async_close(
websocket::close_code::normal, websocket::close_code::normal,
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&plain_websocket_session::on_close, &plain_websocket_session::on_close,
@@ -527,10 +529,10 @@ public:
} }
void void
on_close(boost::system::error_code ec) on_close(beast::error_code ec)
{ {
// Happens when close times out // Happens when close times out
if(ec == boost::asio::error::operation_aborted) if(ec == net::error::operation_aborted)
return; return;
if(ec) if(ec)
@@ -545,13 +547,13 @@ class ssl_websocket_session
: public websocket_session<ssl_websocket_session> : public websocket_session<ssl_websocket_session>
, public std::enable_shared_from_this<ssl_websocket_session> , public std::enable_shared_from_this<ssl_websocket_session>
{ {
websocket::stream<boost::beast::ssl_stream<tcp::socket>> ws_; websocket::stream<beast::ssl_stream<tcp::socket>> ws_;
bool eof_ = false; bool eof_ = false;
public: public:
// Create the http_session // Create the http_session
explicit explicit
ssl_websocket_session(boost::beast::ssl_stream<tcp::socket> stream) ssl_websocket_session(beast::ssl_stream<tcp::socket> stream)
: websocket_session<ssl_websocket_session>( : websocket_session<ssl_websocket_session>(
stream.get_executor().context()) stream.get_executor().context())
, ws_(std::move(stream)) , ws_(std::move(stream))
@@ -559,7 +561,7 @@ public:
} }
// Called by the base class // Called by the base class
websocket::stream<boost::beast::ssl_stream<tcp::socket>>& websocket::stream<beast::ssl_stream<tcp::socket>>&
ws() ws()
{ {
return ws_; return ws_;
@@ -588,7 +590,7 @@ public:
// Perform the SSL shutdown // Perform the SSL shutdown
ws_.next_layer().async_shutdown( ws_.next_layer().async_shutdown(
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&ssl_websocket_session::on_shutdown, &ssl_websocket_session::on_shutdown,
@@ -597,10 +599,10 @@ public:
} }
void void
on_shutdown(boost::system::error_code ec) on_shutdown(beast::error_code ec)
{ {
// Happens when the shutdown times out // Happens when the shutdown times out
if(ec == boost::asio::error::operation_aborted) if(ec == net::error::operation_aborted)
return; return;
if(ec) if(ec)
@@ -637,7 +639,7 @@ make_websocket_session(
template<class Body, class Allocator> template<class Body, class Allocator>
void void
make_websocket_session( make_websocket_session(
boost::beast::ssl_stream<tcp::socket> stream, beast::ssl_stream<tcp::socket> stream,
http::request<Body, http::basic_fields<Allocator>> req) http::request<Body, http::basic_fields<Allocator>> req)
{ {
std::make_shared<ssl_websocket_session>( std::make_shared<ssl_websocket_session>(
@@ -733,7 +735,7 @@ class http_session
http::async_write( http::async_write(
self_.derived().stream(), self_.derived().stream(),
msg_, msg_,
boost::asio::bind_executor( net::bind_executor(
self_.strand_, self_.strand_,
std::bind( std::bind(
&http_session::on_write, &http_session::on_write,
@@ -758,16 +760,16 @@ class http_session
queue queue_; queue queue_;
protected: protected:
boost::asio::steady_timer timer_; net::steady_timer timer_;
boost::asio::strand< net::strand<
boost::asio::io_context::executor_type> strand_; net::io_context::executor_type> strand_;
boost::beast::flat_buffer buffer_; beast::flat_buffer buffer_;
public: public:
// Construct the session // Construct the session
http_session( http_session(
boost::asio::io_context& ioc, net::io_context& ioc,
boost::beast::flat_buffer buffer, beast::flat_buffer buffer,
std::shared_ptr<std::string const> const& doc_root) std::shared_ptr<std::string const> const& doc_root)
: doc_root_(doc_root) : doc_root_(doc_root)
, queue_(*this) , queue_(*this)
@@ -793,7 +795,7 @@ public:
derived().stream(), derived().stream(),
buffer_, buffer_,
req_, req_,
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&http_session::on_read, &http_session::on_read,
@@ -803,9 +805,9 @@ public:
// Called when the timer expires. // Called when the timer expires.
void void
on_timer(boost::system::error_code ec) on_timer(beast::error_code ec)
{ {
if(ec && ec != boost::asio::error::operation_aborted) if(ec && ec != net::error::operation_aborted)
return fail(ec, "timer"); return fail(ec, "timer");
// Check if this has been upgraded to Websocket // Check if this has been upgraded to Websocket
@@ -818,7 +820,7 @@ public:
// Wait on the timer // Wait on the timer
timer_.async_wait( timer_.async_wait(
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&http_session::on_timer, &http_session::on_timer,
@@ -827,10 +829,10 @@ public:
} }
void void
on_read(boost::system::error_code ec) on_read(beast::error_code ec)
{ {
// Happens when the timer closes the socket // Happens when the timer closes the socket
if(ec == boost::asio::error::operation_aborted) if(ec == net::error::operation_aborted)
return; return;
// This means they closed the connection // This means they closed the connection
@@ -862,10 +864,10 @@ public:
} }
void void
on_write(boost::system::error_code ec, bool close) on_write(beast::error_code ec, bool close)
{ {
// Happens when the timer closes the socket // Happens when the timer closes the socket
if(ec == boost::asio::error::operation_aborted) if(ec == net::error::operation_aborted)
return; return;
if(ec) if(ec)
@@ -893,14 +895,14 @@ class plain_http_session
, public std::enable_shared_from_this<plain_http_session> , public std::enable_shared_from_this<plain_http_session>
{ {
tcp::socket socket_; tcp::socket socket_;
boost::asio::strand< net::strand<
boost::asio::io_context::executor_type> strand_; net::io_context::executor_type> strand_;
public: public:
// Create the http_session // Create the http_session
plain_http_session( plain_http_session(
tcp::socket socket, tcp::socket socket,
boost::beast::flat_buffer buffer, beast::flat_buffer buffer,
std::shared_ptr<std::string const> const& doc_root) std::shared_ptr<std::string const> const& doc_root)
: http_session<plain_http_session>( : http_session<plain_http_session>(
socket.get_executor().context(), socket.get_executor().context(),
@@ -931,8 +933,8 @@ public:
{ {
// Make sure we run on the strand // Make sure we run on the strand
if(! strand_.running_in_this_thread()) if(! strand_.running_in_this_thread())
return boost::asio::post( return net::post(
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&plain_http_session::run, &plain_http_session::run,
@@ -949,7 +951,7 @@ public:
do_eof() do_eof()
{ {
// Send a TCP shutdown // Send a TCP shutdown
boost::system::error_code ec; beast::error_code ec;
socket_.shutdown(tcp::socket::shutdown_send, ec); socket_.shutdown(tcp::socket::shutdown_send, ec);
// At this point the connection is closed gracefully // At this point the connection is closed gracefully
@@ -959,8 +961,8 @@ public:
do_timeout() do_timeout()
{ {
// Closing the socket cancels all outstanding operations. They // Closing the socket cancels all outstanding operations. They
// will complete with boost::asio::error::operation_aborted // will complete with net::error::operation_aborted
boost::system::error_code ec; beast::error_code ec;
socket_.shutdown(tcp::socket::shutdown_both, ec); socket_.shutdown(tcp::socket::shutdown_both, ec);
socket_.close(ec); socket_.close(ec);
} }
@@ -971,9 +973,9 @@ class ssl_http_session
: public http_session<ssl_http_session> : public http_session<ssl_http_session>
, public std::enable_shared_from_this<ssl_http_session> , public std::enable_shared_from_this<ssl_http_session>
{ {
boost::beast::ssl_stream<tcp::socket> stream_; beast::ssl_stream<tcp::socket> stream_;
boost::asio::strand< net::strand<
boost::asio::io_context::executor_type> strand_; net::io_context::executor_type> strand_;
bool eof_ = false; bool eof_ = false;
public: public:
@@ -981,7 +983,7 @@ public:
ssl_http_session( ssl_http_session(
tcp::socket socket, tcp::socket socket,
ssl::context& ctx, ssl::context& ctx,
boost::beast::flat_buffer buffer, beast::flat_buffer buffer,
std::shared_ptr<std::string const> const& doc_root) std::shared_ptr<std::string const> const& doc_root)
: http_session<ssl_http_session>( : http_session<ssl_http_session>(
socket.get_executor().context(), socket.get_executor().context(),
@@ -993,14 +995,14 @@ public:
} }
// Called by the base class // Called by the base class
boost::beast::ssl_stream<tcp::socket>& beast::ssl_stream<tcp::socket>&
stream() stream()
{ {
return stream_; return stream_;
} }
// Called by the base class // Called by the base class
boost::beast::ssl_stream<tcp::socket> beast::ssl_stream<tcp::socket>
release_stream() release_stream()
{ {
return std::move(stream_); return std::move(stream_);
@@ -1012,8 +1014,8 @@ public:
{ {
// Make sure we run on the strand // Make sure we run on the strand
if(! strand_.running_in_this_thread()) if(! strand_.running_in_this_thread())
return boost::asio::post( return net::post(
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&ssl_http_session::run, &ssl_http_session::run,
@@ -1031,7 +1033,7 @@ public:
stream_.async_handshake( stream_.async_handshake(
ssl::stream_base::server, ssl::stream_base::server,
buffer_.data(), buffer_.data(),
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&ssl_http_session::on_handshake, &ssl_http_session::on_handshake,
@@ -1041,11 +1043,11 @@ public:
} }
void void
on_handshake( on_handshake(
boost::system::error_code ec, beast::error_code ec,
std::size_t bytes_used) std::size_t bytes_used)
{ {
// Happens when the handshake times out // Happens when the handshake times out
if(ec == boost::asio::error::operation_aborted) if(ec == net::error::operation_aborted)
return; return;
if(ec) if(ec)
@@ -1067,7 +1069,7 @@ public:
// Perform the SSL shutdown // Perform the SSL shutdown
stream_.async_shutdown( stream_.async_shutdown(
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&ssl_http_session::on_shutdown, &ssl_http_session::on_shutdown,
@@ -1076,10 +1078,10 @@ public:
} }
void void
on_shutdown(boost::system::error_code ec) on_shutdown(beast::error_code ec)
{ {
// Happens when the shutdown times out // Happens when the shutdown times out
if(ec == boost::asio::error::operation_aborted) if(ec == net::error::operation_aborted)
return; return;
if(ec) if(ec)
@@ -1110,10 +1112,10 @@ class detect_session : public std::enable_shared_from_this<detect_session>
{ {
tcp::socket socket_; tcp::socket socket_;
ssl::context& ctx_; ssl::context& ctx_;
boost::asio::strand< net::strand<
boost::asio::io_context::executor_type> strand_; net::io_context::executor_type> strand_;
std::shared_ptr<std::string const> doc_root_; std::shared_ptr<std::string const> doc_root_;
boost::beast::flat_buffer buffer_; beast::flat_buffer buffer_;
public: public:
explicit explicit
@@ -1135,7 +1137,7 @@ public:
async_detect_ssl( async_detect_ssl(
socket_, socket_,
buffer_, buffer_,
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&detect_session::on_detect, &detect_session::on_detect,
@@ -1146,7 +1148,7 @@ public:
} }
void void
on_detect(boost::system::error_code ec, boost::tribool result) on_detect(beast::error_code ec, boost::tribool result)
{ {
if(ec) if(ec)
return fail(ec, "detect"); return fail(ec, "detect");
@@ -1180,7 +1182,7 @@ class listener : public std::enable_shared_from_this<listener>
public: public:
listener( listener(
boost::asio::io_context& ioc, net::io_context& ioc,
ssl::context& ctx, ssl::context& ctx,
tcp::endpoint endpoint, tcp::endpoint endpoint,
std::shared_ptr<std::string const> const& doc_root) std::shared_ptr<std::string const> const& doc_root)
@@ -1189,7 +1191,7 @@ public:
, socket_(ioc) , socket_(ioc)
, doc_root_(doc_root) , doc_root_(doc_root)
{ {
boost::system::error_code ec; beast::error_code ec;
// Open the acceptor // Open the acceptor
acceptor_.open(endpoint.protocol(), ec); acceptor_.open(endpoint.protocol(), ec);
@@ -1200,7 +1202,7 @@ public:
} }
// Allow address reuse // Allow address reuse
acceptor_.set_option(boost::asio::socket_base::reuse_address(true), ec); acceptor_.set_option(net::socket_base::reuse_address(true), ec);
if(ec) if(ec)
{ {
fail(ec, "set_option"); fail(ec, "set_option");
@@ -1217,7 +1219,7 @@ public:
// Start listening for connections // Start listening for connections
acceptor_.listen( acceptor_.listen(
boost::asio::socket_base::max_listen_connections, ec); net::socket_base::max_listen_connections, ec);
if(ec) if(ec)
{ {
fail(ec, "listen"); fail(ec, "listen");
@@ -1246,7 +1248,7 @@ public:
} }
void void
on_accept(boost::system::error_code ec) on_accept(beast::error_code ec)
{ {
if(ec) if(ec)
{ {
@@ -1279,13 +1281,13 @@ int main(int argc, char* argv[])
" advanced-server-flex 0.0.0.0 8080 . 1\n"; " advanced-server-flex 0.0.0.0 8080 . 1\n";
return EXIT_FAILURE; return EXIT_FAILURE;
} }
auto const address = boost::asio::ip::make_address(argv[1]); auto const address = net::ip::make_address(argv[1]);
auto const port = static_cast<unsigned short>(std::atoi(argv[2])); auto const port = static_cast<unsigned short>(std::atoi(argv[2]));
auto const doc_root = std::make_shared<std::string>(argv[3]); auto const doc_root = std::make_shared<std::string>(argv[3]);
auto const threads = std::max<int>(1, std::atoi(argv[4])); auto const threads = std::max<int>(1, std::atoi(argv[4]));
// The io_context is required for all I/O // The io_context is required for all I/O
boost::asio::io_context ioc{threads}; net::io_context ioc{threads};
// The SSL context is required, and holds certificates // The SSL context is required, and holds certificates
ssl::context ctx{ssl::context::sslv23}; ssl::context ctx{ssl::context::sslv23};
@@ -1301,9 +1303,9 @@ int main(int argc, char* argv[])
doc_root)->run(); doc_root)->run();
// Capture SIGINT and SIGTERM to perform a clean shutdown // Capture SIGINT and SIGTERM to perform a clean shutdown
boost::asio::signal_set signals(ioc, SIGINT, SIGTERM); net::signal_set signals(ioc, SIGINT, SIGTERM);
signals.async_wait( signals.async_wait(
[&](boost::system::error_code const&, int) [&](beast::error_code const&, int)
{ {
// Stop the `io_context`. This will cause `run()` // Stop the `io_context`. This will cause `run()`
// to return immediately, eventually destroying the // to return immediately, eventually destroying the

View File

@@ -33,20 +33,22 @@
#include <thread> #include <thread>
#include <vector> #include <vector>
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> using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
namespace http = boost::beast::http; // from <boost/beast/http.hpp>
namespace websocket = boost::beast::websocket; // from <boost/beast/websocket.hpp>
// Return a reasonable mime type based on the extension of a file. // Return a reasonable mime type based on the extension of a file.
boost::beast::string_view beast::string_view
mime_type(boost::beast::string_view path) mime_type(beast::string_view path)
{ {
using boost::beast::iequals; using beast::iequals;
auto const ext = [&path] auto const ext = [&path]
{ {
auto const pos = path.rfind("."); auto const pos = path.rfind(".");
if(pos == boost::beast::string_view::npos) if(pos == beast::string_view::npos)
return boost::beast::string_view{}; return beast::string_view{};
return path.substr(pos); return path.substr(pos);
}(); }();
if(iequals(ext, ".htm")) return "text/html"; if(iequals(ext, ".htm")) return "text/html";
@@ -77,8 +79,8 @@ mime_type(boost::beast::string_view path)
// The returned path is normalized for the platform. // The returned path is normalized for the platform.
std::string std::string
path_cat( path_cat(
boost::beast::string_view base, beast::string_view base,
boost::beast::string_view path) beast::string_view path)
{ {
if(base.empty()) if(base.empty())
return path.to_string(); return path.to_string();
@@ -109,13 +111,13 @@ template<
class Send> class Send>
void void
handle_request( handle_request(
boost::beast::string_view doc_root, beast::string_view doc_root,
http::request<Body, http::basic_fields<Allocator>>&& req, http::request<Body, http::basic_fields<Allocator>>&& req,
Send&& send) Send&& send)
{ {
// Returns a bad request response // Returns a bad request response
auto const bad_request = auto const bad_request =
[&req](boost::beast::string_view why) [&req](beast::string_view why)
{ {
http::response<http::string_body> res{http::status::bad_request, req.version()}; http::response<http::string_body> res{http::status::bad_request, req.version()};
res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
@@ -128,7 +130,7 @@ handle_request(
// Returns a not found response // Returns a not found response
auto const not_found = auto const not_found =
[&req](boost::beast::string_view target) [&req](beast::string_view target)
{ {
http::response<http::string_body> res{http::status::not_found, req.version()}; http::response<http::string_body> res{http::status::not_found, req.version()};
res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
@@ -141,7 +143,7 @@ handle_request(
// Returns a server error response // Returns a server error response
auto const server_error = auto const server_error =
[&req](boost::beast::string_view what) [&req](beast::string_view what)
{ {
http::response<http::string_body> res{http::status::internal_server_error, req.version()}; http::response<http::string_body> res{http::status::internal_server_error, req.version()};
res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
@@ -160,7 +162,7 @@ handle_request(
// Request path must be absolute and not contain "..". // Request path must be absolute and not contain "..".
if( req.target().empty() || if( req.target().empty() ||
req.target()[0] != '/' || req.target()[0] != '/' ||
req.target().find("..") != boost::beast::string_view::npos) req.target().find("..") != beast::string_view::npos)
return send(bad_request("Illegal request-target")); return send(bad_request("Illegal request-target"));
// Build the path to the requested file // Build the path to the requested file
@@ -169,12 +171,12 @@ handle_request(
path.append("index.html"); path.append("index.html");
// Attempt to open the file // Attempt to open the file
boost::beast::error_code ec; beast::error_code ec;
http::file_body::value_type body; http::file_body::value_type body;
body.open(path.c_str(), boost::beast::file_mode::scan, ec); body.open(path.c_str(), beast::file_mode::scan, ec);
// Handle the case where the file doesn't exist // Handle the case where the file doesn't exist
if(ec == boost::system::errc::no_such_file_or_directory) if(ec == beast::errc::no_such_file_or_directory)
return send(not_found(req.target())); return send(not_found(req.target()));
// Handle an unknown error // Handle an unknown error
@@ -211,7 +213,7 @@ handle_request(
// Report a failure // Report a failure
void void
fail(boost::system::error_code ec, char const* what) fail(beast::error_code ec, char const* what)
{ {
std::cerr << what << ": " << ec.message() << "\n"; std::cerr << what << ": " << ec.message() << "\n";
} }
@@ -220,10 +222,10 @@ fail(boost::system::error_code ec, char const* what)
class websocket_session : public std::enable_shared_from_this<websocket_session> class websocket_session : public std::enable_shared_from_this<websocket_session>
{ {
websocket::stream<tcp::socket> ws_; websocket::stream<tcp::socket> ws_;
boost::asio::strand< net::strand<
boost::asio::io_context::executor_type> strand_; net::io_context::executor_type> strand_;
boost::asio::steady_timer timer_; net::steady_timer timer_;
boost::beast::multi_buffer buffer_; beast::multi_buffer buffer_;
char ping_state_ = 0; char ping_state_ = 0;
public: public:
@@ -261,7 +263,7 @@ public:
// Accept the websocket handshake // Accept the websocket handshake
ws_.async_accept( ws_.async_accept(
req, req,
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&websocket_session::on_accept, &websocket_session::on_accept,
@@ -270,10 +272,10 @@ public:
} }
void void
on_accept(boost::system::error_code ec) on_accept(beast::error_code ec)
{ {
// Happens when the timer closes the socket // Happens when the timer closes the socket
if(ec == boost::asio::error::operation_aborted) if(ec == net::error::operation_aborted)
return; return;
if(ec) if(ec)
@@ -285,9 +287,9 @@ public:
// Called when the timer expires. // Called when the timer expires.
void void
on_timer(boost::system::error_code ec) on_timer(beast::error_code ec)
{ {
if(ec && ec != boost::asio::error::operation_aborted) if(ec && ec != net::error::operation_aborted)
return fail(ec, "timer"); return fail(ec, "timer");
// See if the timer really expired since the deadline may have moved. // See if the timer really expired since the deadline may have moved.
@@ -305,7 +307,7 @@ public:
// Now send the ping // Now send the ping
ws_.async_ping({}, ws_.async_ping({},
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&websocket_session::on_ping, &websocket_session::on_ping,
@@ -319,7 +321,7 @@ public:
// we never got back a control frame, so close. // we never got back a control frame, so close.
// Closing the socket cancels all outstanding operations. They // Closing the socket cancels all outstanding operations. They
// will complete with boost::asio::error::operation_aborted // will complete with net::error::operation_aborted
ws_.next_layer().shutdown(tcp::socket::shutdown_both, ec); ws_.next_layer().shutdown(tcp::socket::shutdown_both, ec);
ws_.next_layer().close(ec); ws_.next_layer().close(ec);
return; return;
@@ -328,7 +330,7 @@ public:
// Wait on the timer // Wait on the timer
timer_.async_wait( timer_.async_wait(
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&websocket_session::on_timer, &websocket_session::on_timer,
@@ -349,10 +351,10 @@ public:
// Called after a ping is sent. // Called after a ping is sent.
void void
on_ping(boost::system::error_code ec) on_ping(beast::error_code ec)
{ {
// Happens when the timer closes the socket // Happens when the timer closes the socket
if(ec == boost::asio::error::operation_aborted) if(ec == net::error::operation_aborted)
return; return;
if(ec) if(ec)
@@ -375,7 +377,7 @@ public:
void void
on_control_callback( on_control_callback(
websocket::frame_type kind, websocket::frame_type kind,
boost::beast::string_view payload) beast::string_view payload)
{ {
boost::ignore_unused(kind, payload); boost::ignore_unused(kind, payload);
@@ -389,7 +391,7 @@ public:
// Read a message into our buffer // Read a message into our buffer
ws_.async_read( ws_.async_read(
buffer_, buffer_,
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&websocket_session::on_read, &websocket_session::on_read,
@@ -400,13 +402,13 @@ public:
void void
on_read( on_read(
boost::system::error_code ec, beast::error_code ec,
std::size_t bytes_transferred) std::size_t bytes_transferred)
{ {
boost::ignore_unused(bytes_transferred); boost::ignore_unused(bytes_transferred);
// Happens when the timer closes the socket // Happens when the timer closes the socket
if(ec == boost::asio::error::operation_aborted) if(ec == net::error::operation_aborted)
return; return;
// This indicates that the websocket_session was closed // This indicates that the websocket_session was closed
@@ -423,7 +425,7 @@ public:
ws_.text(ws_.got_text()); ws_.text(ws_.got_text());
ws_.async_write( ws_.async_write(
buffer_.data(), buffer_.data(),
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&websocket_session::on_write, &websocket_session::on_write,
@@ -434,13 +436,13 @@ public:
void void
on_write( on_write(
boost::system::error_code ec, beast::error_code ec,
std::size_t bytes_transferred) std::size_t bytes_transferred)
{ {
boost::ignore_unused(bytes_transferred); boost::ignore_unused(bytes_transferred);
// Happens when the timer closes the socket // Happens when the timer closes the socket
if(ec == boost::asio::error::operation_aborted) if(ec == net::error::operation_aborted)
return; return;
if(ec) if(ec)
@@ -530,7 +532,7 @@ class http_session : public std::enable_shared_from_this<http_session>
http::async_write( http::async_write(
self_.socket_, self_.socket_,
msg_, msg_,
boost::asio::bind_executor( net::bind_executor(
self_.strand_, self_.strand_,
std::bind( std::bind(
&http_session::on_write, &http_session::on_write,
@@ -551,10 +553,10 @@ class http_session : public std::enable_shared_from_this<http_session>
}; };
tcp::socket socket_; tcp::socket socket_;
boost::asio::strand< net::strand<
boost::asio::io_context::executor_type> strand_; net::io_context::executor_type> strand_;
boost::asio::steady_timer timer_; net::steady_timer timer_;
boost::beast::flat_buffer buffer_; beast::flat_buffer buffer_;
std::shared_ptr<std::string const> doc_root_; std::shared_ptr<std::string const> doc_root_;
http::request<http::string_body> req_; http::request<http::string_body> req_;
queue queue_; queue queue_;
@@ -580,8 +582,8 @@ public:
{ {
// Make sure we run on the strand // Make sure we run on the strand
if(! strand_.running_in_this_thread()) if(! strand_.running_in_this_thread())
return boost::asio::post( return net::post(
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&http_session::run, &http_session::run,
@@ -606,7 +608,7 @@ public:
// Read a request // Read a request
http::async_read(socket_, buffer_, req_, http::async_read(socket_, buffer_, req_,
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&http_session::on_read, &http_session::on_read,
@@ -616,9 +618,9 @@ public:
// Called when the timer expires. // Called when the timer expires.
void void
on_timer(boost::system::error_code ec) on_timer(beast::error_code ec)
{ {
if(ec && ec != boost::asio::error::operation_aborted) if(ec && ec != net::error::operation_aborted)
return fail(ec, "timer"); return fail(ec, "timer");
// Check if this has been upgraded to Websocket // Check if this has been upgraded to Websocket
@@ -629,7 +631,7 @@ public:
if(timer_.expiry() <= std::chrono::steady_clock::now()) if(timer_.expiry() <= std::chrono::steady_clock::now())
{ {
// Closing the socket cancels all outstanding operations. They // Closing the socket cancels all outstanding operations. They
// will complete with boost::asio::error::operation_aborted // will complete with net::error::operation_aborted
socket_.shutdown(tcp::socket::shutdown_both, ec); socket_.shutdown(tcp::socket::shutdown_both, ec);
socket_.close(ec); socket_.close(ec);
return; return;
@@ -637,7 +639,7 @@ public:
// Wait on the timer // Wait on the timer
timer_.async_wait( timer_.async_wait(
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&http_session::on_timer, &http_session::on_timer,
@@ -646,10 +648,10 @@ public:
} }
void void
on_read(boost::system::error_code ec) on_read(beast::error_code ec)
{ {
// Happens when the timer closes the socket // Happens when the timer closes the socket
if(ec == boost::asio::error::operation_aborted) if(ec == net::error::operation_aborted)
return; return;
// This means they closed the connection // This means they closed the connection
@@ -681,10 +683,10 @@ public:
} }
void void
on_write(boost::system::error_code ec, bool close) on_write(beast::error_code ec, bool close)
{ {
// Happens when the timer closes the socket // Happens when the timer closes the socket
if(ec == boost::asio::error::operation_aborted) if(ec == net::error::operation_aborted)
return; return;
if(ec) if(ec)
@@ -709,7 +711,7 @@ public:
do_close() do_close()
{ {
// Send a TCP shutdown // Send a TCP shutdown
boost::system::error_code ec; beast::error_code ec;
socket_.shutdown(tcp::socket::shutdown_send, ec); socket_.shutdown(tcp::socket::shutdown_send, ec);
// At this point the connection is closed gracefully // At this point the connection is closed gracefully
@@ -727,14 +729,14 @@ class listener : public std::enable_shared_from_this<listener>
public: public:
listener( listener(
boost::asio::io_context& ioc, net::io_context& ioc,
tcp::endpoint endpoint, tcp::endpoint endpoint,
std::shared_ptr<std::string const> const& doc_root) std::shared_ptr<std::string const> const& doc_root)
: acceptor_(ioc) : acceptor_(ioc)
, socket_(ioc) , socket_(ioc)
, doc_root_(doc_root) , doc_root_(doc_root)
{ {
boost::system::error_code ec; beast::error_code ec;
// Open the acceptor // Open the acceptor
acceptor_.open(endpoint.protocol(), ec); acceptor_.open(endpoint.protocol(), ec);
@@ -745,7 +747,7 @@ public:
} }
// Allow address reuse // Allow address reuse
acceptor_.set_option(boost::asio::socket_base::reuse_address(true), ec); acceptor_.set_option(net::socket_base::reuse_address(true), ec);
if(ec) if(ec)
{ {
fail(ec, "set_option"); fail(ec, "set_option");
@@ -762,7 +764,7 @@ public:
// Start listening for connections // Start listening for connections
acceptor_.listen( acceptor_.listen(
boost::asio::socket_base::max_listen_connections, ec); net::socket_base::max_listen_connections, ec);
if(ec) if(ec)
{ {
fail(ec, "listen"); fail(ec, "listen");
@@ -791,7 +793,7 @@ public:
} }
void void
on_accept(boost::system::error_code ec) on_accept(beast::error_code ec)
{ {
if(ec) if(ec)
{ {
@@ -823,13 +825,13 @@ int main(int argc, char* argv[])
" advanced-server 0.0.0.0 8080 . 1\n"; " advanced-server 0.0.0.0 8080 . 1\n";
return EXIT_FAILURE; return EXIT_FAILURE;
} }
auto const address = boost::asio::ip::make_address(argv[1]); auto const address = net::ip::make_address(argv[1]);
auto const port = static_cast<unsigned short>(std::atoi(argv[2])); auto const port = static_cast<unsigned short>(std::atoi(argv[2]));
auto const doc_root = std::make_shared<std::string>(argv[3]); auto const doc_root = std::make_shared<std::string>(argv[3]);
auto const threads = std::max<int>(1, std::atoi(argv[4])); auto const threads = std::max<int>(1, std::atoi(argv[4]));
// The io_context is required for all I/O // The io_context is required for all I/O
boost::asio::io_context ioc{threads}; net::io_context ioc{threads};
// Create and launch a listening port // Create and launch a listening port
std::make_shared<listener>( std::make_shared<listener>(
@@ -838,9 +840,9 @@ int main(int argc, char* argv[])
doc_root)->run(); doc_root)->run();
// Capture SIGINT and SIGTERM to perform a clean shutdown // Capture SIGINT and SIGTERM to perform a clean shutdown
boost::asio::signal_set signals(ioc, SIGINT, SIGTERM); net::signal_set signals(ioc, SIGINT, SIGTERM);
signals.async_wait( signals.async_wait(
[&](boost::system::error_code const&, int) [&](beast::error_code const&, int)
{ {
// Stop the `io_context`. This will cause `run()` // Stop the `io_context`. This will cause `run()`
// to return immediately, eventually destroying the // to return immediately, eventually destroying the

View File

@@ -12,8 +12,8 @@
#include <boost/beast.hpp> #include <boost/beast.hpp>
namespace beast = boost::beast; namespace beast = boost::beast; // from <boost/beast.hpp>
namespace http = boost::beast::http; // from <boost/beast/http.hpp> namespace http = beast::http; // from <boost/beast/http.hpp>
namespace websocket = boost::beast::websocket; // from <boost/beast/websocket.hpp> namespace websocket = beast::websocket; // from <boost/beast/websocket.hpp>
#endif #endif

View File

@@ -17,15 +17,15 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Return a reasonable mime type based on the extension of a file. // Return a reasonable mime type based on the extension of a file.
boost::beast::string_view beast::string_view
mime_type(boost::beast::string_view path) mime_type(beast::string_view path)
{ {
using boost::beast::iequals; using beast::iequals;
auto const ext = [&path] auto const ext = [&path]
{ {
auto const pos = path.rfind("."); auto const pos = path.rfind(".");
if(pos == boost::beast::string_view::npos) if(pos == beast::string_view::npos)
return boost::beast::string_view{}; return beast::string_view{};
return path.substr(pos); return path.substr(pos);
}(); }();
if(iequals(ext, ".htm")) return "text/html"; if(iequals(ext, ".htm")) return "text/html";
@@ -56,8 +56,8 @@ mime_type(boost::beast::string_view path)
// The returned path is normalized for the platform. // The returned path is normalized for the platform.
std::string std::string
path_cat( path_cat(
boost::beast::string_view base, beast::string_view base,
boost::beast::string_view path) beast::string_view path)
{ {
if(base.empty()) if(base.empty())
return path.to_string(); return path.to_string();
@@ -88,13 +88,13 @@ template<
class Send> class Send>
void void
handle_request( handle_request(
boost::beast::string_view doc_root, beast::string_view doc_root,
http::request<Body, http::basic_fields<Allocator>>&& req, http::request<Body, http::basic_fields<Allocator>>&& req,
Send&& send) Send&& send)
{ {
// Returns a bad request response // Returns a bad request response
auto const bad_request = auto const bad_request =
[&req](boost::beast::string_view why) [&req](beast::string_view why)
{ {
http::response<http::string_body> res{http::status::bad_request, req.version()}; http::response<http::string_body> res{http::status::bad_request, req.version()};
res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
@@ -107,7 +107,7 @@ handle_request(
// Returns a not found response // Returns a not found response
auto const not_found = auto const not_found =
[&req](boost::beast::string_view target) [&req](beast::string_view target)
{ {
http::response<http::string_body> res{http::status::not_found, req.version()}; http::response<http::string_body> res{http::status::not_found, req.version()};
res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
@@ -120,7 +120,7 @@ handle_request(
// Returns a server error response // Returns a server error response
auto const server_error = auto const server_error =
[&req](boost::beast::string_view what) [&req](beast::string_view what)
{ {
http::response<http::string_body> res{http::status::internal_server_error, req.version()}; http::response<http::string_body> res{http::status::internal_server_error, req.version()};
res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
@@ -139,7 +139,7 @@ handle_request(
// Request path must be absolute and not contain "..". // Request path must be absolute and not contain "..".
if( req.target().empty() || if( req.target().empty() ||
req.target()[0] != '/' || req.target()[0] != '/' ||
req.target().find("..") != boost::beast::string_view::npos) req.target().find("..") != beast::string_view::npos)
return send(bad_request("Illegal request-target")); return send(bad_request("Illegal request-target"));
// Build the path to the requested file // Build the path to the requested file
@@ -148,9 +148,9 @@ handle_request(
path.append("index.html"); path.append("index.html");
// Attempt to open the file // Attempt to open the file
boost::beast::error_code ec; beast::error_code ec;
http::file_body::value_type body; http::file_body::value_type body;
body.open(path.c_str(), boost::beast::file_mode::scan, ec); body.open(path.c_str(), beast::file_mode::scan, ec);
// Handle the case where the file doesn't exist // Handle the case where the file doesn't exist
if(ec == boost::system::errc::no_such_file_or_directory) if(ec == boost::system::errc::no_such_file_or_directory)
@@ -213,7 +213,7 @@ run()
// Report a failure // Report a failure
void void
http_session:: http_session::
fail(error_code ec, char const* what) fail(beast::error_code ec, char const* what)
{ {
// Don't report on canceled operations // Don't report on canceled operations
if(ec == net::error::operation_aborted) if(ec == net::error::operation_aborted)
@@ -239,7 +239,7 @@ operator()(http::message<isRequest, Body, Fields>&& msg) const
http::async_write( http::async_write(
self_.socket_, self_.socket_,
*sp, *sp,
[self, sp](error_code ec, std::size_t bytes) [self, sp](beast::error_code ec, std::size_t bytes)
{ {
self->on_write(ec, bytes, sp->need_eof()); self->on_write(ec, bytes, sp->need_eof());
}); });
@@ -247,7 +247,7 @@ operator()(http::message<isRequest, Body, Fields>&& msg) const
void void
http_session:: http_session::
on_read(error_code ec, std::size_t) on_read(beast::error_code ec, std::size_t)
{ {
// This means they closed the connection // This means they closed the connection
if(ec == http::error::end_of_stream) if(ec == http::error::end_of_stream)
@@ -291,7 +291,7 @@ on_read(error_code ec, std::size_t)
// Write the response // Write the response
http::async_write(this->socket_, *sp, http::async_write(this->socket_, *sp,
[self = shared_from_this(), sp]( [self = shared_from_this(), sp](
error_code ec, std::size_t bytes) beast::error_code ec, std::size_t bytes)
{ {
self->on_write(ec, bytes, sp->need_eof()); self->on_write(ec, bytes, sp->need_eof());
}); });
@@ -300,7 +300,7 @@ on_read(error_code ec, std::size_t)
auto self = shared_from_this(); auto self = shared_from_this();
http::async_write(this->socket_, *sp, http::async_write(this->socket_, *sp,
[self, sp]( [self, sp](
error_code ec, std::size_t bytes) beast::error_code ec, std::size_t bytes)
{ {
self->on_write(ec, bytes, sp->need_eof()); self->on_write(ec, bytes, sp->need_eof());
}); });
@@ -321,7 +321,7 @@ on_read(error_code ec, std::size_t)
void void
http_session:: http_session::
on_write(error_code ec, std::size_t, bool close) on_write(beast::error_code ec, std::size_t, bool close)
{ {
// Handle the error, if any // Handle the error, if any
if(ec) if(ec)

View File

@@ -40,10 +40,9 @@ class http_session : public std::enable_shared_from_this<http_session>
operator()(http::message<isRequest, Body, Fields>&& msg) const; operator()(http::message<isRequest, Body, Fields>&& msg) const;
}; };
void fail(error_code ec, char const* what); void fail(beast::error_code ec, char const* what);
void on_read(error_code ec, std::size_t); void on_read(beast::error_code ec, std::size_t);
void on_write( void on_write(beast::error_code ec, std::size_t, bool close);
error_code ec, std::size_t, bool close);
public: public:
http_session( http_session(

View File

@@ -20,7 +20,7 @@ listener(
, socket_(ioc) , socket_(ioc)
, state_(state) , state_(state)
{ {
error_code ec; beast::error_code ec;
// Open the acceptor // Open the acceptor
acceptor_.open(endpoint.protocol(), ec); acceptor_.open(endpoint.protocol(), ec);
@@ -72,7 +72,7 @@ run()
// Report a failure // Report a failure
void void
listener:: listener::
fail(error_code ec, char const* what) fail(beast::error_code ec, char const* what)
{ {
// Don't report on canceled operations // Don't report on canceled operations
if(ec == net::error::operation_aborted) if(ec == net::error::operation_aborted)
@@ -83,7 +83,7 @@ fail(error_code ec, char const* what)
// Handle a connection // Handle a connection
void void
listener:: listener::
on_accept(error_code ec) on_accept(beast::error_code ec)
{ {
if(ec) if(ec)
return fail(ec, "accept"); return fail(ec, "accept");

View File

@@ -10,6 +10,7 @@
#ifndef CPPCON2018_LISTENER_HPP #ifndef CPPCON2018_LISTENER_HPP
#define CPPCON2018_LISTENER_HPP #define CPPCON2018_LISTENER_HPP
#include "beast.hpp"
#include "net.hpp" #include "net.hpp"
#include <memory> #include <memory>
#include <string> #include <string>
@@ -24,8 +25,8 @@ class listener : public std::enable_shared_from_this<listener>
tcp::socket socket_; tcp::socket socket_;
std::shared_ptr<shared_state> state_; std::shared_ptr<shared_state> state_;
void fail(error_code ec, char const* what); void fail(beast::error_code ec, char const* what);
void on_accept(error_code ec); void on_accept(beast::error_code ec);
public: public:
listener( listener(

View File

@@ -12,8 +12,7 @@
#include <boost/asio.hpp> #include <boost/asio.hpp>
namespace net = boost::asio; // namespace asio namespace net = boost::asio; // from <boost/asio.hpp>
using tcp = net::ip::tcp; // from <boost/asio/ip/tcp.hpp> using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
using error_code = boost::system::error_code; // from <boost/system/error_code.hpp>
#endif #endif

View File

@@ -27,7 +27,7 @@ websocket_session::
void void
websocket_session:: websocket_session::
fail(error_code ec, char const* what) fail(beast::error_code ec, char const* what)
{ {
// Don't report these // Don't report these
if( ec == net::error::operation_aborted || if( ec == net::error::operation_aborted ||
@@ -39,7 +39,7 @@ fail(error_code ec, char const* what)
void void
websocket_session:: websocket_session::
on_accept(error_code ec) on_accept(beast::error_code ec)
{ {
// Handle the error, if any // Handle the error, if any
if(ec) if(ec)
@@ -60,7 +60,7 @@ on_accept(error_code ec)
void void
websocket_session:: websocket_session::
on_read(error_code ec, std::size_t) on_read(beast::error_code ec, std::size_t)
{ {
// Handle the error, if any // Handle the error, if any
if(ec) if(ec)
@@ -105,7 +105,7 @@ send(std::shared_ptr<std::string const> const& ss)
void void
websocket_session:: websocket_session::
on_write(error_code ec, std::size_t) on_write(beast::error_code ec, std::size_t)
{ {
// Handle the error, if any // Handle the error, if any
if(ec) if(ec)

View File

@@ -31,10 +31,10 @@ class websocket_session : public std::enable_shared_from_this<websocket_session>
std::shared_ptr<shared_state> state_; std::shared_ptr<shared_state> state_;
std::vector<std::shared_ptr<std::string const>> queue_; std::vector<std::shared_ptr<std::string const>> queue_;
void fail(error_code ec, char const* what); void fail(beast::error_code ec, char const* what);
void on_accept(error_code ec); void on_accept(beast::error_code ec);
void on_read(error_code ec, std::size_t bytes_transferred); void on_read(beast::error_code ec, std::size_t bytes_transferred);
void on_write(error_code ec, std::size_t bytes_transferred); void on_write(beast::error_code ec, std::size_t bytes_transferred);
public: public:
websocket_session( websocket_session(

View File

@@ -28,15 +28,17 @@
#include <memory> #include <memory>
#include <string> #include <string>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp> namespace beast = boost::beast; // from <boost/beast.hpp>
namespace http = beast::http; // from <boost/beast/http.hpp>
namespace net = boost::asio; // from <boost/asio.hpp>
namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp> namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp>
namespace http = boost::beast::http; // from <boost/beast/http.hpp> using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Report a failure // Report a failure
void void
fail(boost::system::error_code ec, char const* what) fail(beast::error_code ec, char const* what)
{ {
std::cerr << what << ": " << ec.message() << "\n"; std::cerr << what << ": " << ec.message() << "\n";
} }
@@ -46,14 +48,14 @@ class session : public std::enable_shared_from_this<session>
{ {
tcp::resolver resolver_; tcp::resolver resolver_;
ssl::stream<tcp::socket> stream_; ssl::stream<tcp::socket> stream_;
boost::beast::flat_buffer buffer_; // (Must persist between reads) beast::flat_buffer buffer_; // (Must persist between reads)
http::request<http::empty_body> req_; http::request<http::empty_body> req_;
http::response<http::string_body> res_; http::response<http::string_body> res_;
public: public:
// Resolver and stream require an io_context // Resolver and stream require an io_context
explicit explicit
session(boost::asio::io_context& ioc, ssl::context& ctx) session(net::io_context& ioc, ssl::context& ctx)
: resolver_(ioc) : resolver_(ioc)
, stream_(ioc, ctx) , stream_(ioc, ctx)
{ {
@@ -70,7 +72,7 @@ public:
// Set SNI Hostname (many hosts need this to handshake successfully) // Set SNI Hostname (many hosts need this to handshake successfully)
if(! SSL_set_tlsext_host_name(stream_.native_handle(), host)) if(! SSL_set_tlsext_host_name(stream_.native_handle(), host))
{ {
boost::system::error_code ec{static_cast<int>(::ERR_get_error()), boost::asio::error::get_ssl_category()}; beast::error_code ec{static_cast<int>(::ERR_get_error()), net::error::get_ssl_category()};
std::cerr << ec.message() << "\n"; std::cerr << ec.message() << "\n";
return; return;
} }
@@ -95,14 +97,14 @@ public:
void void
on_resolve( on_resolve(
boost::system::error_code ec, beast::error_code ec,
tcp::resolver::results_type results) tcp::resolver::results_type results)
{ {
if(ec) if(ec)
return fail(ec, "resolve"); return fail(ec, "resolve");
// Make the connection on the IP address we get from a lookup // Make the connection on the IP address we get from a lookup
boost::asio::async_connect( net::async_connect(
stream_.next_layer(), stream_.next_layer(),
results.begin(), results.begin(),
results.end(), results.end(),
@@ -113,7 +115,7 @@ public:
} }
void void
on_connect(boost::system::error_code ec) on_connect(beast::error_code ec)
{ {
if(ec) if(ec)
return fail(ec, "connect"); return fail(ec, "connect");
@@ -128,7 +130,7 @@ public:
} }
void void
on_handshake(boost::system::error_code ec) on_handshake(beast::error_code ec)
{ {
if(ec) if(ec)
return fail(ec, "handshake"); return fail(ec, "handshake");
@@ -144,7 +146,7 @@ public:
void void
on_write( on_write(
boost::system::error_code ec, beast::error_code ec,
std::size_t bytes_transferred) std::size_t bytes_transferred)
{ {
boost::ignore_unused(bytes_transferred); boost::ignore_unused(bytes_transferred);
@@ -163,7 +165,7 @@ public:
void void
on_read( on_read(
boost::system::error_code ec, beast::error_code ec,
std::size_t bytes_transferred) std::size_t bytes_transferred)
{ {
boost::ignore_unused(bytes_transferred); boost::ignore_unused(bytes_transferred);
@@ -183,9 +185,9 @@ public:
} }
void void
on_shutdown(boost::system::error_code ec) on_shutdown(beast::error_code ec)
{ {
if(ec == boost::asio::error::eof) if(ec == net::error::eof)
{ {
// Rationale: // Rationale:
// http://stackoverflow.com/questions/25587403/boost-asio-ssl-async-shutdown-always-finishes-with-an-error // http://stackoverflow.com/questions/25587403/boost-asio-ssl-async-shutdown-always-finishes-with-an-error
@@ -218,7 +220,7 @@ int main(int argc, char** argv)
int version = argc == 5 && !std::strcmp("1.0", argv[4]) ? 10 : 11; int version = argc == 5 && !std::strcmp("1.0", argv[4]) ? 10 : 11;
// The io_context is required for all I/O // 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 // The SSL context is required, and holds certificates
ssl::context ctx{ssl::context::sslv23_client}; ssl::context ctx{ssl::context::sslv23_client};

View File

@@ -24,14 +24,16 @@
#include <memory> #include <memory>
#include <string> #include <string>
namespace beast = boost::beast; // from <boost/beast.hpp>
namespace http = beast::http; // from <boost/beast/http.hpp>
namespace net = boost::asio; // from <boost/asio.hpp>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp> using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
namespace http = boost::beast::http; // from <boost/beast/http.hpp>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Report a failure // Report a failure
void void
fail(boost::system::error_code ec, char const* what) fail(beast::error_code ec, char const* what)
{ {
std::cerr << what << ": " << ec.message() << "\n"; std::cerr << what << ": " << ec.message() << "\n";
} }
@@ -41,14 +43,14 @@ class session : public std::enable_shared_from_this<session>
{ {
tcp::resolver resolver_; tcp::resolver resolver_;
tcp::socket socket_; tcp::socket socket_;
boost::beast::flat_buffer buffer_; // (Must persist between reads) beast::flat_buffer buffer_; // (Must persist between reads)
http::request<http::empty_body> req_; http::request<http::empty_body> req_;
http::response<http::string_body> res_; http::response<http::string_body> res_;
public: public:
// Resolver and socket require an io_context // Resolver and socket require an io_context
explicit explicit
session(boost::asio::io_context& ioc) session(net::io_context& ioc)
: resolver_(ioc) : resolver_(ioc)
, socket_(ioc) , socket_(ioc)
{ {
@@ -82,14 +84,14 @@ public:
void void
on_resolve( on_resolve(
boost::system::error_code ec, beast::error_code ec,
tcp::resolver::results_type results) tcp::resolver::results_type results)
{ {
if(ec) if(ec)
return fail(ec, "resolve"); return fail(ec, "resolve");
// Make the connection on the IP address we get from a lookup // Make the connection on the IP address we get from a lookup
boost::asio::async_connect( net::async_connect(
socket_, socket_,
results.begin(), results.begin(),
results.end(), results.end(),
@@ -100,7 +102,7 @@ public:
} }
void void
on_connect(boost::system::error_code ec) on_connect(beast::error_code ec)
{ {
if(ec) if(ec)
return fail(ec, "connect"); return fail(ec, "connect");
@@ -116,7 +118,7 @@ public:
void void
on_write( on_write(
boost::system::error_code ec, beast::error_code ec,
std::size_t bytes_transferred) std::size_t bytes_transferred)
{ {
boost::ignore_unused(bytes_transferred); boost::ignore_unused(bytes_transferred);
@@ -135,7 +137,7 @@ public:
void void
on_read( on_read(
boost::system::error_code ec, beast::error_code ec,
std::size_t bytes_transferred) std::size_t bytes_transferred)
{ {
boost::ignore_unused(bytes_transferred); boost::ignore_unused(bytes_transferred);
@@ -150,7 +152,7 @@ public:
socket_.shutdown(tcp::socket::shutdown_both, ec); socket_.shutdown(tcp::socket::shutdown_both, ec);
// not_connected happens sometimes so don't bother reporting it. // not_connected happens sometimes so don't bother reporting it.
if(ec && ec != boost::system::errc::not_connected) if(ec && ec != beast::errc::not_connected)
return fail(ec, "shutdown"); return fail(ec, "shutdown");
// If we get here then the connection is closed gracefully // If we get here then the connection is closed gracefully
@@ -177,7 +179,7 @@ int main(int argc, char** argv)
int version = argc == 5 && !std::strcmp("1.0", argv[4]) ? 10 : 11; int version = argc == 5 && !std::strcmp("1.0", argv[4]) ? 10 : 11;
// The io_context is required for all I/O // The io_context is required for all I/O
boost::asio::io_context ioc; net::io_context ioc;
// Launch the asynchronous operation // Launch the asynchronous operation
std::make_shared<session>(ioc)->run(host, port, target, version); std::make_shared<session>(ioc)->run(host, port, target, version);

View File

@@ -28,15 +28,17 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp> namespace beast = boost::beast; // from <boost/beast.hpp>
namespace http = beast::http; // from <boost/beast/http.hpp>
namespace net = boost::asio; // from <boost/asio.hpp>
namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp> namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp>
namespace http = boost::beast::http; // from <boost/beast/http.hpp> using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Report a failure // Report a failure
void void
fail(boost::system::error_code ec, char const* what) fail(beast::error_code ec, char const* what)
{ {
std::cerr << what << ": " << ec.message() << "\n"; std::cerr << what << ": " << ec.message() << "\n";
} }
@@ -48,11 +50,11 @@ do_session(
std::string const& port, std::string const& port,
std::string const& target, std::string const& target,
int version, int version,
boost::asio::io_context& ioc, net::io_context& ioc,
ssl::context& ctx, 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 // These objects perform our I/O
tcp::resolver resolver{ioc}; tcp::resolver resolver{ioc};
@@ -61,7 +63,7 @@ do_session(
// Set SNI Hostname (many hosts need this to handshake successfully) // Set SNI Hostname (many hosts need this to handshake successfully)
if(! SSL_set_tlsext_host_name(stream.native_handle(), host.c_str())) if(! SSL_set_tlsext_host_name(stream.native_handle(), host.c_str()))
{ {
ec.assign(static_cast<int>(::ERR_get_error()), boost::asio::error::get_ssl_category()); ec.assign(static_cast<int>(::ERR_get_error()), net::error::get_ssl_category());
std::cerr << ec.message() << "\n"; std::cerr << ec.message() << "\n";
return; return;
} }
@@ -72,7 +74,7 @@ do_session(
return fail(ec, "resolve"); return fail(ec, "resolve");
// Make the connection on the IP address we get from a lookup // Make the connection on the IP address we get from a lookup
boost::asio::async_connect(stream.next_layer(), results.begin(), results.end(), yield[ec]); net::async_connect(stream.next_layer(), results.begin(), results.end(), yield[ec]);
if(ec) if(ec)
return fail(ec, "connect"); return fail(ec, "connect");
@@ -92,7 +94,7 @@ do_session(
return fail(ec, "write"); return fail(ec, "write");
// This buffer is used for reading and must be persisted // This buffer is used for reading and must be persisted
boost::beast::flat_buffer b; beast::flat_buffer b;
// Declare a container to hold the response // Declare a container to hold the response
http::response<http::dynamic_body> res; http::response<http::dynamic_body> res;
@@ -107,7 +109,7 @@ do_session(
// Gracefully close the stream // Gracefully close the stream
stream.async_shutdown(yield[ec]); stream.async_shutdown(yield[ec]);
if(ec == boost::asio::error::eof) if(ec == net::error::eof)
{ {
// Rationale: // Rationale:
// http://stackoverflow.com/questions/25587403/boost-asio-ssl-async-shutdown-always-finishes-with-an-error // http://stackoverflow.com/questions/25587403/boost-asio-ssl-async-shutdown-always-finishes-with-an-error
@@ -139,7 +141,7 @@ int main(int argc, char** argv)
int version = argc == 5 && !std::strcmp("1.0", argv[4]) ? 10 : 11; int version = argc == 5 && !std::strcmp("1.0", argv[4]) ? 10 : 11;
// The io_context is required for all I/O // 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 // The SSL context is required, and holds certificates
ssl::context ctx{ssl::context::sslv23_client}; ssl::context ctx{ssl::context::sslv23_client};
@@ -151,7 +153,7 @@ int main(int argc, char** argv)
ctx.set_verify_mode(ssl::verify_peer); ctx.set_verify_mode(ssl::verify_peer);
// Launch the asynchronous operation // Launch the asynchronous operation
boost::asio::spawn(ioc, std::bind( net::spawn(ioc, std::bind(
&do_session, &do_session,
std::string(host), std::string(host),
std::string(port), std::string(port),

View File

@@ -24,14 +24,16 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
namespace beast = boost::beast; // from <boost/beast.hpp>
namespace http = beast::http; // from <boost/beast/http.hpp>
namespace net = boost::asio; // from <boost/asio.hpp>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp> using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
namespace http = boost::beast::http; // from <boost/beast/http.hpp>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Report a failure // Report a failure
void void
fail(boost::system::error_code ec, char const* what) fail(beast::error_code ec, char const* what)
{ {
std::cerr << what << ": " << ec.message() << "\n"; std::cerr << what << ": " << ec.message() << "\n";
} }
@@ -43,10 +45,10 @@ do_session(
std::string const& port, std::string const& port,
std::string const& target, std::string const& target,
int version, int version,
boost::asio::io_context& ioc, net::io_context& ioc,
boost::asio::yield_context yield) net::yield_context yield)
{ {
boost::system::error_code ec; beast::error_code ec;
// These objects perform our I/O // These objects perform our I/O
tcp::resolver resolver{ioc}; tcp::resolver resolver{ioc};
@@ -58,7 +60,7 @@ do_session(
return fail(ec, "resolve"); return fail(ec, "resolve");
// Make the connection on the IP address we get from a lookup // Make the connection on the IP address we get from a lookup
boost::asio::async_connect(socket, results.begin(), results.end(), yield[ec]); net::async_connect(socket, results.begin(), results.end(), yield[ec]);
if(ec) if(ec)
return fail(ec, "connect"); return fail(ec, "connect");
@@ -73,7 +75,7 @@ do_session(
return fail(ec, "write"); return fail(ec, "write");
// This buffer is used for reading and must be persisted // This buffer is used for reading and must be persisted
boost::beast::flat_buffer b; beast::flat_buffer b;
// Declare a container to hold the response // Declare a container to hold the response
http::response<http::dynamic_body> res; http::response<http::dynamic_body> res;
@@ -92,7 +94,7 @@ do_session(
// not_connected happens sometimes // not_connected happens sometimes
// so don't bother reporting it. // so don't bother reporting it.
// //
if(ec && ec != boost::system::errc::not_connected) if(ec && ec != beast::errc::not_connected)
return fail(ec, "shutdown"); return fail(ec, "shutdown");
// If we get here then the connection is closed gracefully // If we get here then the connection is closed gracefully
@@ -118,10 +120,10 @@ int main(int argc, char** argv)
int version = argc == 5 && !std::strcmp("1.0", argv[4]) ? 10 : 11; int version = argc == 5 && !std::strcmp("1.0", argv[4]) ? 10 : 11;
// The io_context is required for all I/O // The io_context is required for all I/O
boost::asio::io_context ioc; net::io_context ioc;
// Launch the asynchronous operation // Launch the asynchronous operation
boost::asio::spawn(ioc, std::bind( net::spawn(ioc, std::bind(
&do_session, &do_session,
std::string(host), std::string(host),
std::string(port), std::string(port),

View File

@@ -35,24 +35,26 @@
#include <vector> #include <vector>
#include <map> #include <map>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
namespace http = boost::beast::http; // from <boost/beast/http.hpp>
namespace chrono = std::chrono; // from <chrono> namespace chrono = std::chrono; // from <chrono>
namespace beast = boost::beast; // from <boost/beast.hpp>
namespace http = beast::http; // from <boost/beast/http.hpp>
namespace net = boost::asio; // from <boost/asio.hpp>
using tcp = net::ip::tcp; // from <boost/asio/ip/tcp.hpp>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// This structure aggregates statistics on all the sites // This structure aggregates statistics on all the sites
class crawl_report class crawl_report
{ {
boost::asio::io_context& ioc_; net::io_context& ioc_;
boost::asio::strand< net::strand<
boost::asio::io_context::executor_type> strand_; net::io_context::executor_type> strand_;
std::atomic<std::size_t> index_; std::atomic<std::size_t> index_;
std::vector<char const*> const& hosts_; std::vector<char const*> const& hosts_;
std::size_t count_ = 0; std::size_t count_ = 0;
public: public:
crawl_report(boost::asio::io_context& ioc) crawl_report(net::io_context& ioc)
: ioc_(ioc) : ioc_(ioc)
, strand_(ioc_.get_executor()) , strand_(ioc_.get_executor())
, index_(0) , index_(0)
@@ -66,7 +68,7 @@ public:
void void
aggregate(F const& f) aggregate(F const& f)
{ {
boost::asio::post( net::post(
strand_, strand_,
[&, f] [&, f]
{ {
@@ -150,10 +152,10 @@ class worker : public std::enable_shared_from_this<worker>
crawl_report& report_; crawl_report& report_;
tcp::resolver resolver_; tcp::resolver resolver_;
tcp::socket socket_; tcp::socket socket_;
boost::asio::steady_timer timer_; net::steady_timer timer_;
boost::asio::strand< net::strand<
boost::asio::io_context::executor_type> strand_; net::io_context::executor_type> strand_;
boost::beast::flat_buffer buffer_; // (Must persist between reads) beast::flat_buffer buffer_; // (Must persist between reads)
http::request<http::empty_body> req_; http::request<http::empty_body> req_;
http::response<http::string_body> res_; http::response<http::string_body> res_;
@@ -163,7 +165,7 @@ public:
// Resolver and socket require an io_context // Resolver and socket require an io_context
worker( worker(
crawl_report& report, crawl_report& report,
boost::asio::io_context& ioc) net::io_context& ioc)
: report_(report) : report_(report)
, resolver_(ioc) , resolver_(ioc)
, socket_(ioc) , socket_(ioc)
@@ -190,9 +192,9 @@ public:
} }
void void
on_timer(boost::system::error_code ec) on_timer(beast::error_code ec)
{ {
if(ec && ec != boost::asio::error::operation_aborted) if(ec && ec != net::error::operation_aborted)
{ {
// Should never happen // Should never happen
report_.aggregate( report_.aggregate(
@@ -213,7 +215,7 @@ public:
// Wait on the timer // Wait on the timer
timer_.async_wait( timer_.async_wait(
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&worker::on_timer, &worker::on_timer,
@@ -245,7 +247,7 @@ public:
resolver_.async_resolve( resolver_.async_resolve(
host, host,
"http", "http",
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&worker::on_resolve, &worker::on_resolve,
@@ -256,7 +258,7 @@ public:
void void
on_resolve( on_resolve(
boost::system::error_code ec, beast::error_code ec,
tcp::resolver::results_type results) tcp::resolver::results_type results)
{ {
if(ec) if(ec)
@@ -273,11 +275,11 @@ public:
timer_.expires_after(chrono::seconds(timeout)); timer_.expires_after(chrono::seconds(timeout));
// Make the connection on the IP address we get from a lookup // Make the connection on the IP address we get from a lookup
boost::asio::async_connect( net::async_connect(
socket_, socket_,
results.begin(), results.begin(),
results.end(), results.end(),
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&worker::on_connect, &worker::on_connect,
@@ -286,7 +288,7 @@ public:
} }
void void
on_connect(boost::system::error_code ec) on_connect(beast::error_code ec)
{ {
if(ec) if(ec)
{ {
@@ -305,7 +307,7 @@ public:
http::async_write( http::async_write(
socket_, socket_,
req_, req_,
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&worker::on_write, &worker::on_write,
@@ -316,7 +318,7 @@ public:
void void
on_write( on_write(
boost::system::error_code ec, beast::error_code ec,
std::size_t bytes_transferred) std::size_t bytes_transferred)
{ {
boost::ignore_unused(bytes_transferred); boost::ignore_unused(bytes_transferred);
@@ -339,7 +341,7 @@ public:
socket_, socket_,
buffer_, buffer_,
res_, res_,
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&worker::on_read, &worker::on_read,
@@ -350,7 +352,7 @@ public:
void void
on_read( on_read(
boost::system::error_code ec, beast::error_code ec,
std::size_t bytes_transferred) std::size_t bytes_transferred)
{ {
boost::ignore_unused(bytes_transferred); boost::ignore_unused(bytes_transferred);
@@ -418,10 +420,10 @@ int main(int argc, char* argv[])
auto const threads = std::max<int>(1, std::atoi(argv[1])); auto const threads = std::max<int>(1, std::atoi(argv[1]));
// The io_context is required for all I/O // The io_context is required for all I/O
boost::asio::io_context ioc{1}; net::io_context ioc{1};
// The work keeps io_context::run from returning // The work keeps io_context::run from returning
auto work = boost::asio::make_work_guard(ioc); auto work = net::make_work_guard(ioc);
// The report holds the aggregated statistics // The report holds the aggregated statistics
crawl_report report{ioc}; crawl_report report{ioc};
@@ -439,7 +441,7 @@ int main(int argc, char* argv[])
// the asio resolver simulates asynchronous operation using // the asio resolver simulates asynchronous operation using
// a dedicated worker thread per io_context, and we want to // a dedicated worker thread per io_context, and we want to
// do a lot of name resolutions in parallel. // do a lot of name resolutions in parallel.
boost::asio::io_context ioc{1}; net::io_context ioc{1};
std::make_shared<worker>(report, ioc)->run(); std::make_shared<worker>(report, ioc)->run();
ioc.run(); ioc.run();
}); });

View File

@@ -26,9 +26,11 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp> namespace beast = boost::beast; // from <boost/beast.hpp>
namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp> namespace http = beast::http; // from <boost/beast/http.hpp>
namespace http = boost::beast::http; // from <boost/beast/http.hpp> namespace net = boost::asio; // from <boost/asio.hpp>
namespace ssl = net::ssl; // from <boost/asio/ssl.hpp>
using tcp = net::ip::tcp; // from <boost/asio/ip/tcp.hpp>
// Performs an HTTP GET and prints the response // Performs an HTTP GET and prints the response
int main(int argc, char** argv) int main(int argc, char** argv)
@@ -51,7 +53,7 @@ int main(int argc, char** argv)
int version = argc == 5 && !std::strcmp("1.0", argv[4]) ? 10 : 11; int version = argc == 5 && !std::strcmp("1.0", argv[4]) ? 10 : 11;
// The io_context is required for all I/O // 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 // The SSL context is required, and holds certificates
ssl::context ctx{ssl::context::sslv23_client}; ssl::context ctx{ssl::context::sslv23_client};
@@ -69,15 +71,15 @@ int main(int argc, char** argv)
// Set SNI Hostname (many hosts need this to handshake successfully) // Set SNI Hostname (many hosts need this to handshake successfully)
if(! SSL_set_tlsext_host_name(stream.native_handle(), host)) if(! SSL_set_tlsext_host_name(stream.native_handle(), host))
{ {
boost::system::error_code ec{static_cast<int>(::ERR_get_error()), boost::asio::error::get_ssl_category()}; beast::error_code ec{static_cast<int>(::ERR_get_error()), net::error::get_ssl_category()};
throw boost::system::system_error{ec}; throw beast::system_error{ec};
} }
// Look up the domain name // Look up the domain name
auto const results = resolver.resolve(host, port); auto const results = resolver.resolve(host, port);
// Make the connection on the IP address we get from a lookup // Make the connection on the IP address we get from a lookup
boost::asio::connect(stream.next_layer(), results.begin(), results.end()); net::connect(stream.next_layer(), results.begin(), results.end());
// Perform the SSL handshake // Perform the SSL handshake
stream.handshake(ssl::stream_base::client); stream.handshake(ssl::stream_base::client);
@@ -91,7 +93,7 @@ int main(int argc, char** argv)
http::write(stream, req); http::write(stream, req);
// This buffer is used for reading and must be persisted // This buffer is used for reading and must be persisted
boost::beast::flat_buffer buffer; beast::flat_buffer buffer;
// Declare a container to hold the response // Declare a container to hold the response
http::response<http::dynamic_body> res; http::response<http::dynamic_body> res;
@@ -103,16 +105,16 @@ int main(int argc, char** argv)
std::cout << res << std::endl; std::cout << res << std::endl;
// Gracefully close the stream // Gracefully close the stream
boost::system::error_code ec; beast::error_code ec;
stream.shutdown(ec); stream.shutdown(ec);
if(ec == boost::asio::error::eof) if(ec == net::error::eof)
{ {
// Rationale: // Rationale:
// http://stackoverflow.com/questions/25587403/boost-asio-ssl-async-shutdown-always-finishes-with-an-error // http://stackoverflow.com/questions/25587403/boost-asio-ssl-async-shutdown-always-finishes-with-an-error
ec.assign(0, ec.category()); ec.assign(0, ec.category());
} }
if(ec) if(ec)
throw boost::system::system_error{ec}; throw beast::system_error{ec};
// If we get here then the connection is closed gracefully // If we get here then the connection is closed gracefully
} }

View File

@@ -24,8 +24,10 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp> namespace beast = boost::beast; // from <boost/beast.hpp>
namespace http = boost::beast::http; // from <boost/beast/http.hpp> namespace http = beast::http; // from <boost/beast/http.hpp>
namespace net = boost::asio; // from <boost/asio.hpp>
using tcp = net::ip::tcp; // from <boost/asio/ip/tcp.hpp>
// Performs an HTTP GET and prints the response // Performs an HTTP GET and prints the response
int main(int argc, char** argv) int main(int argc, char** argv)
@@ -48,7 +50,7 @@ int main(int argc, char** argv)
int version = argc == 5 && !std::strcmp("1.0", argv[4]) ? 10 : 11; int version = argc == 5 && !std::strcmp("1.0", argv[4]) ? 10 : 11;
// The io_context is required for all I/O // The io_context is required for all I/O
boost::asio::io_context ioc; net::io_context ioc;
// These objects perform our I/O // These objects perform our I/O
tcp::resolver resolver{ioc}; tcp::resolver resolver{ioc};
@@ -58,7 +60,7 @@ int main(int argc, char** argv)
auto const results = resolver.resolve(host, port); auto const results = resolver.resolve(host, port);
// Make the connection on the IP address we get from a lookup // Make the connection on the IP address we get from a lookup
boost::asio::connect(socket, results.begin(), results.end()); net::connect(socket, results.begin(), results.end());
// Set up an HTTP GET request message // Set up an HTTP GET request message
http::request<http::string_body> req{http::verb::get, target, version}; http::request<http::string_body> req{http::verb::get, target, version};
@@ -69,7 +71,7 @@ int main(int argc, char** argv)
http::write(socket, req); http::write(socket, req);
// This buffer is used for reading and must be persisted // This buffer is used for reading and must be persisted
boost::beast::flat_buffer buffer; beast::flat_buffer buffer;
// Declare a container to hold the response // Declare a container to hold the response
http::response<http::dynamic_body> res; http::response<http::dynamic_body> res;
@@ -81,14 +83,14 @@ int main(int argc, char** argv)
std::cout << res << std::endl; std::cout << res << std::endl;
// Gracefully close the socket // Gracefully close the socket
boost::system::error_code ec; beast::error_code ec;
socket.shutdown(tcp::socket::shutdown_both, ec); socket.shutdown(tcp::socket::shutdown_both, ec);
// not_connected happens sometimes // not_connected happens sometimes
// so don't bother reporting it. // so don't bother reporting it.
// //
if(ec && ec != boost::system::errc::not_connected) if(ec && ec != beast::errc::not_connected)
throw boost::system::system_error{ec}; throw beast::system_error{ec};
// If we get here then the connection is closed gracefully // If we get here then the connection is closed gracefully
} }

View File

@@ -32,20 +32,22 @@
#include <thread> #include <thread>
#include <vector> #include <vector>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp> namespace beast = boost::beast; // from <boost/beast.hpp>
namespace http = beast::http; // from <boost/beast/http.hpp>
namespace net = boost::asio; // from <boost/asio.hpp>
namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp> namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp>
namespace http = boost::beast::http; // from <boost/beast/http.hpp> using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
// Return a reasonable mime type based on the extension of a file. // Return a reasonable mime type based on the extension of a file.
boost::beast::string_view beast::string_view
mime_type(boost::beast::string_view path) mime_type(beast::string_view path)
{ {
using boost::beast::iequals; using beast::iequals;
auto const ext = [&path] auto const ext = [&path]
{ {
auto const pos = path.rfind("."); auto const pos = path.rfind(".");
if(pos == boost::beast::string_view::npos) if(pos == beast::string_view::npos)
return boost::beast::string_view{}; return beast::string_view{};
return path.substr(pos); return path.substr(pos);
}(); }();
if(iequals(ext, ".htm")) return "text/html"; if(iequals(ext, ".htm")) return "text/html";
@@ -76,8 +78,8 @@ mime_type(boost::beast::string_view path)
// The returned path is normalized for the platform. // The returned path is normalized for the platform.
std::string std::string
path_cat( path_cat(
boost::beast::string_view base, beast::string_view base,
boost::beast::string_view path) beast::string_view path)
{ {
if(base.empty()) if(base.empty())
return path.to_string(); return path.to_string();
@@ -108,13 +110,13 @@ template<
class Send> class Send>
void void
handle_request( handle_request(
boost::beast::string_view doc_root, beast::string_view doc_root,
http::request<Body, http::basic_fields<Allocator>>&& req, http::request<Body, http::basic_fields<Allocator>>&& req,
Send&& send) Send&& send)
{ {
// Returns a bad request response // Returns a bad request response
auto const bad_request = auto const bad_request =
[&req](boost::beast::string_view why) [&req](beast::string_view why)
{ {
http::response<http::string_body> res{http::status::bad_request, req.version()}; http::response<http::string_body> res{http::status::bad_request, req.version()};
res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
@@ -127,7 +129,7 @@ handle_request(
// Returns a not found response // Returns a not found response
auto const not_found = auto const not_found =
[&req](boost::beast::string_view target) [&req](beast::string_view target)
{ {
http::response<http::string_body> res{http::status::not_found, req.version()}; http::response<http::string_body> res{http::status::not_found, req.version()};
res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
@@ -140,7 +142,7 @@ handle_request(
// Returns a server error response // Returns a server error response
auto const server_error = auto const server_error =
[&req](boost::beast::string_view what) [&req](beast::string_view what)
{ {
http::response<http::string_body> res{http::status::internal_server_error, req.version()}; http::response<http::string_body> res{http::status::internal_server_error, req.version()};
res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
@@ -159,7 +161,7 @@ handle_request(
// Request path must be absolute and not contain "..". // Request path must be absolute and not contain "..".
if( req.target().empty() || if( req.target().empty() ||
req.target()[0] != '/' || req.target()[0] != '/' ||
req.target().find("..") != boost::beast::string_view::npos) req.target().find("..") != beast::string_view::npos)
return send(bad_request("Illegal request-target")); return send(bad_request("Illegal request-target"));
// Build the path to the requested file // Build the path to the requested file
@@ -168,12 +170,12 @@ handle_request(
path.append("index.html"); path.append("index.html");
// Attempt to open the file // Attempt to open the file
boost::beast::error_code ec; beast::error_code ec;
http::file_body::value_type body; http::file_body::value_type body;
body.open(path.c_str(), boost::beast::file_mode::scan, ec); body.open(path.c_str(), beast::file_mode::scan, ec);
// Handle the case where the file doesn't exist // Handle the case where the file doesn't exist
if(ec == boost::system::errc::no_such_file_or_directory) if(ec == beast::errc::no_such_file_or_directory)
return send(not_found(req.target())); return send(not_found(req.target()));
// Handle an unknown error // Handle an unknown error
@@ -210,7 +212,7 @@ handle_request(
// Report a failure // Report a failure
void void
fail(boost::system::error_code ec, char const* what) fail(beast::error_code ec, char const* what)
{ {
std::cerr << what << ": " << ec.message() << "\n"; std::cerr << what << ": " << ec.message() << "\n";
} }
@@ -248,7 +250,7 @@ class session : public std::enable_shared_from_this<session>
http::async_write( http::async_write(
self_.stream_, self_.stream_,
*sp, *sp,
boost::asio::bind_executor( net::bind_executor(
self_.strand_, self_.strand_,
std::bind( std::bind(
&session::on_write, &session::on_write,
@@ -261,9 +263,9 @@ class session : public std::enable_shared_from_this<session>
tcp::socket socket_; tcp::socket socket_;
ssl::stream<tcp::socket&> stream_; ssl::stream<tcp::socket&> stream_;
boost::asio::strand< net::strand<
boost::asio::io_context::executor_type> strand_; net::io_context::executor_type> strand_;
boost::beast::flat_buffer buffer_; beast::flat_buffer buffer_;
std::shared_ptr<std::string const> doc_root_; std::shared_ptr<std::string const> doc_root_;
http::request<http::string_body> req_; http::request<http::string_body> req_;
std::shared_ptr<void> res_; std::shared_ptr<void> res_;
@@ -291,7 +293,7 @@ public:
// Perform the SSL handshake // Perform the SSL handshake
stream_.async_handshake( stream_.async_handshake(
ssl::stream_base::server, ssl::stream_base::server,
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&session::on_handshake, &session::on_handshake,
@@ -300,7 +302,7 @@ public:
} }
void void
on_handshake(boost::system::error_code ec) on_handshake(beast::error_code ec)
{ {
if(ec) if(ec)
return fail(ec, "handshake"); return fail(ec, "handshake");
@@ -317,7 +319,7 @@ public:
// Read a request // Read a request
http::async_read(stream_, buffer_, req_, http::async_read(stream_, buffer_, req_,
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&session::on_read, &session::on_read,
@@ -328,7 +330,7 @@ public:
void void
on_read( on_read(
boost::system::error_code ec, beast::error_code ec,
std::size_t bytes_transferred) std::size_t bytes_transferred)
{ {
boost::ignore_unused(bytes_transferred); boost::ignore_unused(bytes_transferred);
@@ -346,7 +348,7 @@ public:
void void
on_write( on_write(
boost::system::error_code ec, beast::error_code ec,
std::size_t bytes_transferred, std::size_t bytes_transferred,
bool close) bool close)
{ {
@@ -374,7 +376,7 @@ public:
{ {
// Perform the SSL shutdown // Perform the SSL shutdown
stream_.async_shutdown( stream_.async_shutdown(
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&session::on_shutdown, &session::on_shutdown,
@@ -383,7 +385,7 @@ public:
} }
void void
on_shutdown(boost::system::error_code ec) on_shutdown(beast::error_code ec)
{ {
if(ec) if(ec)
return fail(ec, "shutdown"); return fail(ec, "shutdown");
@@ -404,7 +406,7 @@ class listener : public std::enable_shared_from_this<listener>
public: public:
listener( listener(
boost::asio::io_context& ioc, net::io_context& ioc,
ssl::context& ctx, ssl::context& ctx,
tcp::endpoint endpoint, tcp::endpoint endpoint,
std::shared_ptr<std::string const> const& doc_root) std::shared_ptr<std::string const> const& doc_root)
@@ -413,7 +415,7 @@ public:
, socket_(ioc) , socket_(ioc)
, doc_root_(doc_root) , doc_root_(doc_root)
{ {
boost::system::error_code ec; beast::error_code ec;
// Open the acceptor // Open the acceptor
acceptor_.open(endpoint.protocol(), ec); acceptor_.open(endpoint.protocol(), ec);
@@ -424,7 +426,7 @@ public:
} }
// Allow address reuse // Allow address reuse
acceptor_.set_option(boost::asio::socket_base::reuse_address(true), ec); acceptor_.set_option(net::socket_base::reuse_address(true), ec);
if(ec) if(ec)
{ {
fail(ec, "set_option"); fail(ec, "set_option");
@@ -441,7 +443,7 @@ public:
// Start listening for connections // Start listening for connections
acceptor_.listen( acceptor_.listen(
boost::asio::socket_base::max_listen_connections, ec); net::socket_base::max_listen_connections, ec);
if(ec) if(ec)
{ {
fail(ec, "listen"); fail(ec, "listen");
@@ -470,7 +472,7 @@ public:
} }
void void
on_accept(boost::system::error_code ec) on_accept(beast::error_code ec)
{ {
if(ec) if(ec)
{ {
@@ -503,13 +505,13 @@ int main(int argc, char* argv[])
" http-server-async-ssl 0.0.0.0 8080 . 1\n"; " http-server-async-ssl 0.0.0.0 8080 . 1\n";
return EXIT_FAILURE; return EXIT_FAILURE;
} }
auto const address = boost::asio::ip::make_address(argv[1]); auto const address = net::ip::make_address(argv[1]);
auto const port = static_cast<unsigned short>(std::atoi(argv[2])); auto const port = static_cast<unsigned short>(std::atoi(argv[2]));
auto const doc_root = std::make_shared<std::string>(argv[3]); auto const doc_root = std::make_shared<std::string>(argv[3]);
auto const threads = std::max<int>(1, std::atoi(argv[4])); auto const threads = std::max<int>(1, std::atoi(argv[4]));
// The io_context is required for all I/O // The io_context is required for all I/O
boost::asio::io_context ioc{threads}; net::io_context ioc{threads};
// The SSL context is required, and holds certificates // The SSL context is required, and holds certificates
ssl::context ctx{ssl::context::sslv23}; ssl::context ctx{ssl::context::sslv23};

View File

@@ -29,19 +29,21 @@
#include <thread> #include <thread>
#include <vector> #include <vector>
namespace beast = boost::beast; // from <boost/beast.hpp>
namespace http = beast::http; // from <boost/beast/http.hpp>
namespace net = boost::asio; // from <boost/asio.hpp>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp> using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
namespace http = boost::beast::http; // from <boost/beast/http.hpp>
// Return a reasonable mime type based on the extension of a file. // Return a reasonable mime type based on the extension of a file.
boost::beast::string_view beast::string_view
mime_type(boost::beast::string_view path) mime_type(beast::string_view path)
{ {
using boost::beast::iequals; using beast::iequals;
auto const ext = [&path] auto const ext = [&path]
{ {
auto const pos = path.rfind("."); auto const pos = path.rfind(".");
if(pos == boost::beast::string_view::npos) if(pos == beast::string_view::npos)
return boost::beast::string_view{}; return beast::string_view{};
return path.substr(pos); return path.substr(pos);
}(); }();
if(iequals(ext, ".htm")) return "text/html"; if(iequals(ext, ".htm")) return "text/html";
@@ -72,8 +74,8 @@ mime_type(boost::beast::string_view path)
// The returned path is normalized for the platform. // The returned path is normalized for the platform.
std::string std::string
path_cat( path_cat(
boost::beast::string_view base, beast::string_view base,
boost::beast::string_view path) beast::string_view path)
{ {
if(base.empty()) if(base.empty())
return path.to_string(); return path.to_string();
@@ -104,13 +106,13 @@ template<
class Send> class Send>
void void
handle_request( handle_request(
boost::beast::string_view doc_root, beast::string_view doc_root,
http::request<Body, http::basic_fields<Allocator>>&& req, http::request<Body, http::basic_fields<Allocator>>&& req,
Send&& send) Send&& send)
{ {
// Returns a bad request response // Returns a bad request response
auto const bad_request = auto const bad_request =
[&req](boost::beast::string_view why) [&req](beast::string_view why)
{ {
http::response<http::string_body> res{http::status::bad_request, req.version()}; http::response<http::string_body> res{http::status::bad_request, req.version()};
res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
@@ -123,7 +125,7 @@ handle_request(
// Returns a not found response // Returns a not found response
auto const not_found = auto const not_found =
[&req](boost::beast::string_view target) [&req](beast::string_view target)
{ {
http::response<http::string_body> res{http::status::not_found, req.version()}; http::response<http::string_body> res{http::status::not_found, req.version()};
res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
@@ -136,7 +138,7 @@ handle_request(
// Returns a server error response // Returns a server error response
auto const server_error = auto const server_error =
[&req](boost::beast::string_view what) [&req](beast::string_view what)
{ {
http::response<http::string_body> res{http::status::internal_server_error, req.version()}; http::response<http::string_body> res{http::status::internal_server_error, req.version()};
res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
@@ -155,7 +157,7 @@ handle_request(
// Request path must be absolute and not contain "..". // Request path must be absolute and not contain "..".
if( req.target().empty() || if( req.target().empty() ||
req.target()[0] != '/' || req.target()[0] != '/' ||
req.target().find("..") != boost::beast::string_view::npos) req.target().find("..") != beast::string_view::npos)
return send(bad_request("Illegal request-target")); return send(bad_request("Illegal request-target"));
// Build the path to the requested file // Build the path to the requested file
@@ -164,12 +166,12 @@ handle_request(
path.append("index.html"); path.append("index.html");
// Attempt to open the file // Attempt to open the file
boost::beast::error_code ec; beast::error_code ec;
http::file_body::value_type body; http::file_body::value_type body;
body.open(path.c_str(), boost::beast::file_mode::scan, ec); body.open(path.c_str(), beast::file_mode::scan, ec);
// Handle the case where the file doesn't exist // Handle the case where the file doesn't exist
if(ec == boost::system::errc::no_such_file_or_directory) if(ec == beast::errc::no_such_file_or_directory)
return send(not_found(req.target())); return send(not_found(req.target()));
// Handle an unknown error // Handle an unknown error
@@ -206,7 +208,7 @@ handle_request(
// Report a failure // Report a failure
void void
fail(boost::system::error_code ec, char const* what) fail(beast::error_code ec, char const* what)
{ {
std::cerr << what << ": " << ec.message() << "\n"; std::cerr << what << ": " << ec.message() << "\n";
} }
@@ -244,7 +246,7 @@ class session : public std::enable_shared_from_this<session>
http::async_write( http::async_write(
self_.socket_, self_.socket_,
*sp, *sp,
boost::asio::bind_executor( net::bind_executor(
self_.strand_, self_.strand_,
std::bind( std::bind(
&session::on_write, &session::on_write,
@@ -256,9 +258,9 @@ class session : public std::enable_shared_from_this<session>
}; };
tcp::socket socket_; tcp::socket socket_;
boost::asio::strand< net::strand<
boost::asio::io_context::executor_type> strand_; net::io_context::executor_type> strand_;
boost::beast::flat_buffer buffer_; beast::flat_buffer buffer_;
std::shared_ptr<std::string const> doc_root_; std::shared_ptr<std::string const> doc_root_;
http::request<http::string_body> req_; http::request<http::string_body> req_;
std::shared_ptr<void> res_; std::shared_ptr<void> res_;
@@ -293,7 +295,7 @@ public:
// Read a request // Read a request
http::async_read(socket_, buffer_, req_, http::async_read(socket_, buffer_, req_,
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&session::on_read, &session::on_read,
@@ -304,7 +306,7 @@ public:
void void
on_read( on_read(
boost::system::error_code ec, beast::error_code ec,
std::size_t bytes_transferred) std::size_t bytes_transferred)
{ {
boost::ignore_unused(bytes_transferred); boost::ignore_unused(bytes_transferred);
@@ -322,7 +324,7 @@ public:
void void
on_write( on_write(
boost::system::error_code ec, beast::error_code ec,
std::size_t bytes_transferred, std::size_t bytes_transferred,
bool close) bool close)
{ {
@@ -349,7 +351,7 @@ public:
do_close() do_close()
{ {
// Send a TCP shutdown // Send a TCP shutdown
boost::system::error_code ec; beast::error_code ec;
socket_.shutdown(tcp::socket::shutdown_send, ec); socket_.shutdown(tcp::socket::shutdown_send, ec);
// At this point the connection is closed gracefully // At this point the connection is closed gracefully
@@ -367,14 +369,14 @@ class listener : public std::enable_shared_from_this<listener>
public: public:
listener( listener(
boost::asio::io_context& ioc, net::io_context& ioc,
tcp::endpoint endpoint, tcp::endpoint endpoint,
std::shared_ptr<std::string const> const& doc_root) std::shared_ptr<std::string const> const& doc_root)
: acceptor_(ioc) : acceptor_(ioc)
, socket_(ioc) , socket_(ioc)
, doc_root_(doc_root) , doc_root_(doc_root)
{ {
boost::system::error_code ec; beast::error_code ec;
// Open the acceptor // Open the acceptor
acceptor_.open(endpoint.protocol(), ec); acceptor_.open(endpoint.protocol(), ec);
@@ -385,7 +387,7 @@ public:
} }
// Allow address reuse // Allow address reuse
acceptor_.set_option(boost::asio::socket_base::reuse_address(true), ec); acceptor_.set_option(net::socket_base::reuse_address(true), ec);
if(ec) if(ec)
{ {
fail(ec, "set_option"); fail(ec, "set_option");
@@ -402,7 +404,7 @@ public:
// Start listening for connections // Start listening for connections
acceptor_.listen( acceptor_.listen(
boost::asio::socket_base::max_listen_connections, ec); net::socket_base::max_listen_connections, ec);
if(ec) if(ec)
{ {
fail(ec, "listen"); fail(ec, "listen");
@@ -431,7 +433,7 @@ public:
} }
void void
on_accept(boost::system::error_code ec) on_accept(beast::error_code ec)
{ {
if(ec) if(ec)
{ {
@@ -463,13 +465,13 @@ int main(int argc, char* argv[])
" http-server-async 0.0.0.0 8080 . 1\n"; " http-server-async 0.0.0.0 8080 . 1\n";
return EXIT_FAILURE; return EXIT_FAILURE;
} }
auto const address = boost::asio::ip::make_address(argv[1]); auto const address = net::ip::make_address(argv[1]);
auto const port = static_cast<unsigned short>(std::atoi(argv[2])); auto const port = static_cast<unsigned short>(std::atoi(argv[2]));
auto const doc_root = std::make_shared<std::string>(argv[3]); auto const doc_root = std::make_shared<std::string>(argv[3]);
auto const threads = std::max<int>(1, std::atoi(argv[4])); auto const threads = std::max<int>(1, std::atoi(argv[4]));
// The io_context is required for all I/O // The io_context is required for all I/O
boost::asio::io_context ioc{threads}; net::io_context ioc{threads};
// Create and launch a listening port // Create and launch a listening port
std::make_shared<listener>( std::make_shared<listener>(

View File

@@ -30,20 +30,22 @@
#include <thread> #include <thread>
#include <vector> #include <vector>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp> namespace beast = boost::beast; // from <boost/beast.hpp>
namespace http = beast::http; // from <boost/beast/http.hpp>
namespace net = boost::asio; // from <boost/asio.hpp>
namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp> namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp>
namespace http = boost::beast::http; // from <boost/beast/http.hpp> using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
// Return a reasonable mime type based on the extension of a file. // Return a reasonable mime type based on the extension of a file.
boost::beast::string_view beast::string_view
mime_type(boost::beast::string_view path) mime_type(beast::string_view path)
{ {
using boost::beast::iequals; using beast::iequals;
auto const ext = [&path] auto const ext = [&path]
{ {
auto const pos = path.rfind("."); auto const pos = path.rfind(".");
if(pos == boost::beast::string_view::npos) if(pos == beast::string_view::npos)
return boost::beast::string_view{}; return beast::string_view{};
return path.substr(pos); return path.substr(pos);
}(); }();
if(iequals(ext, ".htm")) return "text/html"; if(iequals(ext, ".htm")) return "text/html";
@@ -74,8 +76,8 @@ mime_type(boost::beast::string_view path)
// The returned path is normalized for the platform. // The returned path is normalized for the platform.
std::string std::string
path_cat( path_cat(
boost::beast::string_view base, beast::string_view base,
boost::beast::string_view path) beast::string_view path)
{ {
if(base.empty()) if(base.empty())
return path.to_string(); return path.to_string();
@@ -106,13 +108,13 @@ template<
class Send> class Send>
void void
handle_request( handle_request(
boost::beast::string_view doc_root, beast::string_view doc_root,
http::request<Body, http::basic_fields<Allocator>>&& req, http::request<Body, http::basic_fields<Allocator>>&& req,
Send&& send) Send&& send)
{ {
// Returns a bad request response // Returns a bad request response
auto const bad_request = auto const bad_request =
[&req](boost::beast::string_view why) [&req](beast::string_view why)
{ {
http::response<http::string_body> res{http::status::bad_request, req.version()}; http::response<http::string_body> res{http::status::bad_request, req.version()};
res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
@@ -125,7 +127,7 @@ handle_request(
// Returns a not found response // Returns a not found response
auto const not_found = auto const not_found =
[&req](boost::beast::string_view target) [&req](beast::string_view target)
{ {
http::response<http::string_body> res{http::status::not_found, req.version()}; http::response<http::string_body> res{http::status::not_found, req.version()};
res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
@@ -138,7 +140,7 @@ handle_request(
// Returns a server error response // Returns a server error response
auto const server_error = auto const server_error =
[&req](boost::beast::string_view what) [&req](beast::string_view what)
{ {
http::response<http::string_body> res{http::status::internal_server_error, req.version()}; http::response<http::string_body> res{http::status::internal_server_error, req.version()};
res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
@@ -157,7 +159,7 @@ handle_request(
// Request path must be absolute and not contain "..". // Request path must be absolute and not contain "..".
if( req.target().empty() || if( req.target().empty() ||
req.target()[0] != '/' || req.target()[0] != '/' ||
req.target().find("..") != boost::beast::string_view::npos) req.target().find("..") != beast::string_view::npos)
return send(bad_request("Illegal request-target")); return send(bad_request("Illegal request-target"));
// Build the path to the requested file // Build the path to the requested file
@@ -166,12 +168,12 @@ handle_request(
path.append("index.html"); path.append("index.html");
// Attempt to open the file // Attempt to open the file
boost::beast::error_code ec; beast::error_code ec;
http::file_body::value_type body; http::file_body::value_type body;
body.open(path.c_str(), boost::beast::file_mode::scan, ec); body.open(path.c_str(), beast::file_mode::scan, ec);
// Handle the case where the file doesn't exist // Handle the case where the file doesn't exist
if(ec == boost::system::errc::no_such_file_or_directory) if(ec == beast::errc::no_such_file_or_directory)
return send(not_found(req.target())); return send(not_found(req.target()));
// Handle an unknown error // Handle an unknown error
@@ -208,7 +210,7 @@ handle_request(
// Report a failure // Report a failure
void void
fail(boost::system::error_code ec, char const* what) fail(beast::error_code ec, char const* what)
{ {
std::cerr << what << ": " << ec.message() << "\n"; std::cerr << what << ": " << ec.message() << "\n";
} }
@@ -220,15 +222,15 @@ struct send_lambda
{ {
Stream& stream_; Stream& stream_;
bool& close_; bool& close_;
boost::system::error_code& ec_; beast::error_code& ec_;
boost::asio::yield_context yield_; net::yield_context yield_;
explicit explicit
send_lambda( send_lambda(
Stream& stream, Stream& stream,
bool& close, bool& close,
boost::system::error_code& ec, beast::error_code& ec,
boost::asio::yield_context yield) net::yield_context yield)
: stream_(stream) : stream_(stream)
, close_(close) , close_(close)
, ec_(ec) , ec_(ec)
@@ -257,10 +259,10 @@ do_session(
tcp::socket& socket, tcp::socket& socket,
ssl::context& ctx, ssl::context& ctx,
std::shared_ptr<std::string const> const& doc_root, std::shared_ptr<std::string const> const& doc_root,
boost::asio::yield_context yield) net::yield_context yield)
{ {
bool close = false; bool close = false;
boost::system::error_code ec; beast::error_code ec;
// Construct the stream around the socket // Construct the stream around the socket
ssl::stream<tcp::socket&> stream{socket, ctx}; ssl::stream<tcp::socket&> stream{socket, ctx};
@@ -271,7 +273,7 @@ do_session(
return fail(ec, "handshake"); return fail(ec, "handshake");
// This buffer is required to persist across reads // This buffer is required to persist across reads
boost::beast::flat_buffer buffer; beast::flat_buffer buffer;
// This lambda is used to send messages // This lambda is used to send messages
send_lambda<ssl::stream<tcp::socket&>> lambda{stream, close, ec, yield}; send_lambda<ssl::stream<tcp::socket&>> lambda{stream, close, ec, yield};
@@ -311,13 +313,13 @@ do_session(
// Accepts incoming connections and launches the sessions // Accepts incoming connections and launches the sessions
void void
do_listen( do_listen(
boost::asio::io_context& ioc, net::io_context& ioc,
ssl::context& ctx, ssl::context& ctx,
tcp::endpoint endpoint, tcp::endpoint endpoint,
std::shared_ptr<std::string const> const& doc_root, std::shared_ptr<std::string const> const& doc_root,
boost::asio::yield_context yield) net::yield_context yield)
{ {
boost::system::error_code ec; beast::error_code ec;
// Open the acceptor // Open the acceptor
tcp::acceptor acceptor(ioc); tcp::acceptor acceptor(ioc);
@@ -326,7 +328,7 @@ do_listen(
return fail(ec, "open"); return fail(ec, "open");
// Allow address reuse // Allow address reuse
acceptor.set_option(boost::asio::socket_base::reuse_address(true), ec); acceptor.set_option(net::socket_base::reuse_address(true), ec);
if(ec) if(ec)
return fail(ec, "set_option"); return fail(ec, "set_option");
@@ -336,7 +338,7 @@ do_listen(
return fail(ec, "bind"); return fail(ec, "bind");
// Start listening for connections // Start listening for connections
acceptor.listen(boost::asio::socket_base::max_listen_connections, ec); acceptor.listen(net::socket_base::max_listen_connections, ec);
if(ec) if(ec)
return fail(ec, "listen"); return fail(ec, "listen");
@@ -347,7 +349,7 @@ do_listen(
if(ec) if(ec)
fail(ec, "accept"); fail(ec, "accept");
else else
boost::asio::spawn( net::spawn(
acceptor.get_executor().context(), acceptor.get_executor().context(),
std::bind( std::bind(
&do_session, &do_session,
@@ -369,13 +371,13 @@ int main(int argc, char* argv[])
" http-server-coro-ssl 0.0.0.0 8080 . 1\n"; " http-server-coro-ssl 0.0.0.0 8080 . 1\n";
return EXIT_FAILURE; return EXIT_FAILURE;
} }
auto const address = boost::asio::ip::make_address(argv[1]); auto const address = net::ip::make_address(argv[1]);
auto const port = static_cast<unsigned short>(std::atoi(argv[2])); auto const port = static_cast<unsigned short>(std::atoi(argv[2]));
auto const doc_root = std::make_shared<std::string>(argv[3]); auto const doc_root = std::make_shared<std::string>(argv[3]);
auto const threads = std::max<int>(1, std::atoi(argv[4])); auto const threads = std::max<int>(1, std::atoi(argv[4]));
// The io_context is required for all I/O // The io_context is required for all I/O
boost::asio::io_context ioc{threads}; net::io_context ioc{threads};
// The SSL context is required, and holds certificates // The SSL context is required, and holds certificates
ssl::context ctx{ssl::context::sslv23}; ssl::context ctx{ssl::context::sslv23};
@@ -384,7 +386,7 @@ int main(int argc, char* argv[])
load_server_certificate(ctx); load_server_certificate(ctx);
// Spawn a listening port // Spawn a listening port
boost::asio::spawn(ioc, net::spawn(ioc,
std::bind( std::bind(
&do_listen, &do_listen,
std::ref(ioc), std::ref(ioc),

View File

@@ -27,19 +27,21 @@
#include <thread> #include <thread>
#include <vector> #include <vector>
namespace beast = boost::beast; // from <boost/beast.hpp>
namespace http = beast::http; // from <boost/beast/http.hpp>
namespace net = boost::asio; // from <boost/asio.hpp>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp> using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
namespace http = boost::beast::http; // from <boost/beast/http.hpp>
// Return a reasonable mime type based on the extension of a file. // Return a reasonable mime type based on the extension of a file.
boost::beast::string_view beast::string_view
mime_type(boost::beast::string_view path) mime_type(beast::string_view path)
{ {
using boost::beast::iequals; using beast::iequals;
auto const ext = [&path] auto const ext = [&path]
{ {
auto const pos = path.rfind("."); auto const pos = path.rfind(".");
if(pos == boost::beast::string_view::npos) if(pos == beast::string_view::npos)
return boost::beast::string_view{}; return beast::string_view{};
return path.substr(pos); return path.substr(pos);
}(); }();
if(iequals(ext, ".htm")) return "text/html"; if(iequals(ext, ".htm")) return "text/html";
@@ -70,8 +72,8 @@ mime_type(boost::beast::string_view path)
// The returned path is normalized for the platform. // The returned path is normalized for the platform.
std::string std::string
path_cat( path_cat(
boost::beast::string_view base, beast::string_view base,
boost::beast::string_view path) beast::string_view path)
{ {
if(base.empty()) if(base.empty())
return path.to_string(); return path.to_string();
@@ -102,13 +104,13 @@ template<
class Send> class Send>
void void
handle_request( handle_request(
boost::beast::string_view doc_root, beast::string_view doc_root,
http::request<Body, http::basic_fields<Allocator>>&& req, http::request<Body, http::basic_fields<Allocator>>&& req,
Send&& send) Send&& send)
{ {
// Returns a bad request response // Returns a bad request response
auto const bad_request = auto const bad_request =
[&req](boost::beast::string_view why) [&req](beast::string_view why)
{ {
http::response<http::string_body> res{http::status::bad_request, req.version()}; http::response<http::string_body> res{http::status::bad_request, req.version()};
res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
@@ -121,7 +123,7 @@ handle_request(
// Returns a not found response // Returns a not found response
auto const not_found = auto const not_found =
[&req](boost::beast::string_view target) [&req](beast::string_view target)
{ {
http::response<http::string_body> res{http::status::not_found, req.version()}; http::response<http::string_body> res{http::status::not_found, req.version()};
res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
@@ -134,7 +136,7 @@ handle_request(
// Returns a server error response // Returns a server error response
auto const server_error = auto const server_error =
[&req](boost::beast::string_view what) [&req](beast::string_view what)
{ {
http::response<http::string_body> res{http::status::internal_server_error, req.version()}; http::response<http::string_body> res{http::status::internal_server_error, req.version()};
res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
@@ -153,7 +155,7 @@ handle_request(
// Request path must be absolute and not contain "..". // Request path must be absolute and not contain "..".
if( req.target().empty() || if( req.target().empty() ||
req.target()[0] != '/' || req.target()[0] != '/' ||
req.target().find("..") != boost::beast::string_view::npos) req.target().find("..") != beast::string_view::npos)
return send(bad_request("Illegal request-target")); return send(bad_request("Illegal request-target"));
// Build the path to the requested file // Build the path to the requested file
@@ -162,12 +164,12 @@ handle_request(
path.append("index.html"); path.append("index.html");
// Attempt to open the file // Attempt to open the file
boost::beast::error_code ec; beast::error_code ec;
http::file_body::value_type body; http::file_body::value_type body;
body.open(path.c_str(), boost::beast::file_mode::scan, ec); body.open(path.c_str(), beast::file_mode::scan, ec);
// Handle the case where the file doesn't exist // Handle the case where the file doesn't exist
if(ec == boost::system::errc::no_such_file_or_directory) if(ec == beast::errc::no_such_file_or_directory)
return send(not_found(req.target())); return send(not_found(req.target()));
// Handle an unknown error // Handle an unknown error
@@ -204,7 +206,7 @@ handle_request(
// Report a failure // Report a failure
void void
fail(boost::system::error_code ec, char const* what) fail(beast::error_code ec, char const* what)
{ {
std::cerr << what << ": " << ec.message() << "\n"; std::cerr << what << ": " << ec.message() << "\n";
} }
@@ -216,15 +218,15 @@ struct send_lambda
{ {
Stream& stream_; Stream& stream_;
bool& close_; bool& close_;
boost::system::error_code& ec_; beast::error_code& ec_;
boost::asio::yield_context yield_; net::yield_context yield_;
explicit explicit
send_lambda( send_lambda(
Stream& stream, Stream& stream,
bool& close, bool& close,
boost::system::error_code& ec, beast::error_code& ec,
boost::asio::yield_context yield) net::yield_context yield)
: stream_(stream) : stream_(stream)
, close_(close) , close_(close)
, ec_(ec) , ec_(ec)
@@ -252,13 +254,13 @@ void
do_session( do_session(
tcp::socket& socket, tcp::socket& socket,
std::shared_ptr<std::string const> const& doc_root, std::shared_ptr<std::string const> const& doc_root,
boost::asio::yield_context yield) net::yield_context yield)
{ {
bool close = false; bool close = false;
boost::system::error_code ec; beast::error_code ec;
// This buffer is required to persist across reads // This buffer is required to persist across reads
boost::beast::flat_buffer buffer; beast::flat_buffer buffer;
// This lambda is used to send messages // This lambda is used to send messages
send_lambda<tcp::socket> lambda{socket, close, ec, yield}; send_lambda<tcp::socket> lambda{socket, close, ec, yield};
@@ -296,12 +298,12 @@ do_session(
// Accepts incoming connections and launches the sessions // Accepts incoming connections and launches the sessions
void void
do_listen( do_listen(
boost::asio::io_context& ioc, net::io_context& ioc,
tcp::endpoint endpoint, tcp::endpoint endpoint,
std::shared_ptr<std::string const> const& doc_root, std::shared_ptr<std::string const> const& doc_root,
boost::asio::yield_context yield) net::yield_context yield)
{ {
boost::system::error_code ec; beast::error_code ec;
// Open the acceptor // Open the acceptor
tcp::acceptor acceptor(ioc); tcp::acceptor acceptor(ioc);
@@ -310,7 +312,7 @@ do_listen(
return fail(ec, "open"); return fail(ec, "open");
// Allow address reuse // Allow address reuse
acceptor.set_option(boost::asio::socket_base::reuse_address(true), ec); acceptor.set_option(net::socket_base::reuse_address(true), ec);
if(ec) if(ec)
return fail(ec, "set_option"); return fail(ec, "set_option");
@@ -320,7 +322,7 @@ do_listen(
return fail(ec, "bind"); return fail(ec, "bind");
// Start listening for connections // Start listening for connections
acceptor.listen(boost::asio::socket_base::max_listen_connections, ec); acceptor.listen(net::socket_base::max_listen_connections, ec);
if(ec) if(ec)
return fail(ec, "listen"); return fail(ec, "listen");
@@ -331,7 +333,7 @@ do_listen(
if(ec) if(ec)
fail(ec, "accept"); fail(ec, "accept");
else else
boost::asio::spawn( net::spawn(
acceptor.get_executor().context(), acceptor.get_executor().context(),
std::bind( std::bind(
&do_session, &do_session,
@@ -352,16 +354,16 @@ int main(int argc, char* argv[])
" http-server-coro 0.0.0.0 8080 . 1\n"; " http-server-coro 0.0.0.0 8080 . 1\n";
return EXIT_FAILURE; return EXIT_FAILURE;
} }
auto const address = boost::asio::ip::make_address(argv[1]); auto const address = net::ip::make_address(argv[1]);
auto const port = static_cast<unsigned short>(std::atoi(argv[2])); auto const port = static_cast<unsigned short>(std::atoi(argv[2]));
auto const doc_root = std::make_shared<std::string>(argv[3]); auto const doc_root = std::make_shared<std::string>(argv[3]);
auto const threads = std::max<int>(1, std::atoi(argv[4])); auto const threads = std::max<int>(1, std::atoi(argv[4]));
// The io_context is required for all I/O // The io_context is required for all I/O
boost::asio::io_context ioc{threads}; net::io_context ioc{threads};
// Spawn a listening port // Spawn a listening port
boost::asio::spawn(ioc, net::spawn(ioc,
std::bind( std::bind(
&do_listen, &do_listen,
std::ref(ioc), std::ref(ioc),

View File

@@ -28,20 +28,21 @@
#include <memory> #include <memory>
#include <string> #include <string>
namespace ip = boost::asio::ip; // from <boost/asio.hpp> namespace beast = boost::beast; // from <boost/beast.hpp>
using tcp = boost::asio::ip::tcp; // from <boost/asio.hpp> namespace http = beast::http; // from <boost/beast/http.hpp>
namespace http = boost::beast::http; // from <boost/beast/http.hpp> namespace net = boost::asio; // from <boost/asio.hpp>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
// Return a reasonable mime type based on the extension of a file. // Return a reasonable mime type based on the extension of a file.
boost::beast::string_view beast::string_view
mime_type(boost::beast::string_view path) mime_type(beast::string_view path)
{ {
using boost::beast::iequals; using beast::iequals;
auto const ext = [&path] auto const ext = [&path]
{ {
auto const pos = path.rfind("."); auto const pos = path.rfind(".");
if(pos == boost::beast::string_view::npos) if(pos == beast::string_view::npos)
return boost::beast::string_view{}; return beast::string_view{};
return path.substr(pos); return path.substr(pos);
}(); }();
if(iequals(ext, ".htm")) return "text/html"; if(iequals(ext, ".htm")) return "text/html";
@@ -88,7 +89,7 @@ public:
private: private:
using alloc_t = fields_alloc<char>; using alloc_t = fields_alloc<char>;
//using request_body_t = http::basic_dynamic_body<boost::beast::flat_static_buffer<1024 * 1024>>; //using request_body_t = http::basic_dynamic_body<beast::flat_static_buffer<1024 * 1024>>;
using request_body_t = http::string_body; using request_body_t = http::string_body;
// The acceptor used to listen for incoming connections. // The acceptor used to listen for incoming connections.
@@ -101,7 +102,7 @@ private:
tcp::socket socket_{acceptor_.get_executor().context()}; tcp::socket socket_{acceptor_.get_executor().context()};
// The buffer for performing reads // The buffer for performing reads
boost::beast::flat_static_buffer<8192> buffer_; beast::flat_static_buffer<8192> buffer_;
// The allocator used for the fields in the request and reply. // The allocator used for the fields in the request and reply.
alloc_t alloc_{8192}; alloc_t alloc_{8192};
@@ -110,7 +111,7 @@ private:
boost::optional<http::request_parser<request_body_t, alloc_t>> parser_; boost::optional<http::request_parser<request_body_t, alloc_t>> parser_;
// The timer putting a time limit on requests. // The timer putting a time limit on requests.
boost::asio::basic_waitable_timer<std::chrono::steady_clock> request_deadline_{ net::basic_waitable_timer<std::chrono::steady_clock> request_deadline_{
acceptor_.get_executor().context(), (std::chrono::steady_clock::time_point::max)()}; acceptor_.get_executor().context(), (std::chrono::steady_clock::time_point::max)()};
// The string-based response message. // The string-based response message.
@@ -128,13 +129,13 @@ private:
void accept() void accept()
{ {
// Clean up any previous connection. // Clean up any previous connection.
boost::beast::error_code ec; beast::error_code ec;
socket_.close(ec); socket_.close(ec);
buffer_.consume(buffer_.size()); buffer_.consume(buffer_.size());
acceptor_.async_accept( acceptor_.async_accept(
socket_, socket_,
[this](boost::beast::error_code ec) [this](beast::error_code ec)
{ {
if (ec) if (ec)
{ {
@@ -173,7 +174,7 @@ private:
socket_, socket_,
buffer_, buffer_,
*parser_, *parser_,
[this](boost::beast::error_code ec, std::size_t) [this](beast::error_code ec, std::size_t)
{ {
if (ec) if (ec)
accept(); accept();
@@ -221,7 +222,7 @@ private:
http::async_write( http::async_write(
socket_, socket_,
*string_serializer_, *string_serializer_,
[this](boost::beast::error_code ec, std::size_t) [this](beast::error_code ec, std::size_t)
{ {
socket_.shutdown(tcp::socket::shutdown_send, ec); socket_.shutdown(tcp::socket::shutdown_send, ec);
string_serializer_.reset(); string_serializer_.reset();
@@ -230,7 +231,7 @@ private:
}); });
} }
void send_file(boost::beast::string_view target) void send_file(beast::string_view target)
{ {
// Request path must be absolute and not contain "..". // Request path must be absolute and not contain "..".
if (target.empty() || target[0] != '/' || target.find("..") != std::string::npos) if (target.empty() || target[0] != '/' || target.find("..") != std::string::npos)
@@ -247,10 +248,10 @@ private:
target.size()); target.size());
http::file_body::value_type file; http::file_body::value_type file;
boost::beast::error_code ec; beast::error_code ec;
file.open( file.open(
full_path.c_str(), full_path.c_str(),
boost::beast::file_mode::read, beast::file_mode::read,
ec); ec);
if(ec) if(ec)
{ {
@@ -277,7 +278,7 @@ private:
http::async_write( http::async_write(
socket_, socket_,
*file_serializer_, *file_serializer_,
[this](boost::beast::error_code ec, std::size_t) [this](beast::error_code ec, std::size_t)
{ {
socket_.shutdown(tcp::socket::shutdown_send, ec); socket_.shutdown(tcp::socket::shutdown_send, ec);
file_serializer_.reset(); file_serializer_.reset();
@@ -292,7 +293,7 @@ private:
if (request_deadline_.expiry() <= std::chrono::steady_clock::now()) if (request_deadline_.expiry() <= std::chrono::steady_clock::now())
{ {
// Close socket to cancel any outstanding operation. // Close socket to cancel any outstanding operation.
boost::beast::error_code ec; beast::error_code ec;
socket_.close(); socket_.close();
// Sleep indefinitely until we're given a new deadline. // Sleep indefinitely until we're given a new deadline.
@@ -301,7 +302,7 @@ private:
} }
request_deadline_.async_wait( request_deadline_.async_wait(
[this](boost::beast::error_code) [this](beast::error_code)
{ {
check_deadline(); check_deadline();
}); });
@@ -323,13 +324,13 @@ int main(int argc, char* argv[])
return EXIT_FAILURE; return EXIT_FAILURE;
} }
auto const address = boost::asio::ip::make_address(argv[1]); auto const address = net::ip::make_address(argv[1]);
unsigned short port = static_cast<unsigned short>(std::atoi(argv[2])); unsigned short port = static_cast<unsigned short>(std::atoi(argv[2]));
std::string doc_root = argv[3]; std::string doc_root = argv[3];
int num_workers = std::atoi(argv[4]); int num_workers = std::atoi(argv[4]);
bool spin = (std::strcmp(argv[5], "spin") == 0); bool spin = (std::strcmp(argv[5], "spin") == 0);
boost::asio::io_context ioc{1}; net::io_context ioc{1};
tcp::acceptor acceptor{ioc, {address, port}}; tcp::acceptor acceptor{ioc, {address, port}};
std::list<http_worker> workers; std::list<http_worker> workers;

View File

@@ -32,20 +32,22 @@
#include <string> #include <string>
#include <thread> #include <thread>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp> namespace beast = boost::beast; // from <boost/beast.hpp>
namespace http = beast::http; // from <boost/beast/http.hpp>
namespace net = boost::asio; // from <boost/asio.hpp>
namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp> namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp>
namespace http = boost::beast::http; // from <boost/beast/http.hpp> using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
// Return a reasonable mime type based on the extension of a file. // Return a reasonable mime type based on the extension of a file.
boost::beast::string_view beast::string_view
mime_type(boost::beast::string_view path) mime_type(beast::string_view path)
{ {
using boost::beast::iequals; using beast::iequals;
auto const ext = [&path] auto const ext = [&path]
{ {
auto const pos = path.rfind("."); auto const pos = path.rfind(".");
if(pos == boost::beast::string_view::npos) if(pos == beast::string_view::npos)
return boost::beast::string_view{}; return beast::string_view{};
return path.substr(pos); return path.substr(pos);
}(); }();
if(iequals(ext, ".htm")) return "text/html"; if(iequals(ext, ".htm")) return "text/html";
@@ -76,8 +78,8 @@ mime_type(boost::beast::string_view path)
// The returned path is normalized for the platform. // The returned path is normalized for the platform.
std::string std::string
path_cat( path_cat(
boost::beast::string_view base, beast::string_view base,
boost::beast::string_view path) beast::string_view path)
{ {
if(base.empty()) if(base.empty())
return path.to_string(); return path.to_string();
@@ -108,13 +110,13 @@ template<
class Send> class Send>
void void
handle_request( handle_request(
boost::beast::string_view doc_root, beast::string_view doc_root,
http::request<Body, http::basic_fields<Allocator>>&& req, http::request<Body, http::basic_fields<Allocator>>&& req,
Send&& send) Send&& send)
{ {
// Returns a bad request response // Returns a bad request response
auto const bad_request = auto const bad_request =
[&req](boost::beast::string_view why) [&req](beast::string_view why)
{ {
http::response<http::string_body> res{http::status::bad_request, req.version()}; http::response<http::string_body> res{http::status::bad_request, req.version()};
res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
@@ -127,7 +129,7 @@ handle_request(
// Returns a not found response // Returns a not found response
auto const not_found = auto const not_found =
[&req](boost::beast::string_view target) [&req](beast::string_view target)
{ {
http::response<http::string_body> res{http::status::not_found, req.version()}; http::response<http::string_body> res{http::status::not_found, req.version()};
res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
@@ -140,7 +142,7 @@ handle_request(
// Returns a server error response // Returns a server error response
auto const server_error = auto const server_error =
[&req](boost::beast::string_view what) [&req](beast::string_view what)
{ {
http::response<http::string_body> res{http::status::internal_server_error, req.version()}; http::response<http::string_body> res{http::status::internal_server_error, req.version()};
res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
@@ -159,7 +161,7 @@ handle_request(
// Request path must be absolute and not contain "..". // Request path must be absolute and not contain "..".
if( req.target().empty() || if( req.target().empty() ||
req.target()[0] != '/' || req.target()[0] != '/' ||
req.target().find("..") != boost::beast::string_view::npos) req.target().find("..") != beast::string_view::npos)
return send(bad_request("Illegal request-target")); return send(bad_request("Illegal request-target"));
// Build the path to the requested file // Build the path to the requested file
@@ -168,12 +170,12 @@ handle_request(
path.append("index.html"); path.append("index.html");
// Attempt to open the file // Attempt to open the file
boost::beast::error_code ec; beast::error_code ec;
http::file_body::value_type body; http::file_body::value_type body;
body.open(path.c_str(), boost::beast::file_mode::scan, ec); body.open(path.c_str(), beast::file_mode::scan, ec);
// Handle the case where the file doesn't exist // Handle the case where the file doesn't exist
if(ec == boost::system::errc::no_such_file_or_directory) if(ec == beast::errc::no_such_file_or_directory)
return send(not_found(req.target())); return send(not_found(req.target()));
// Handle an unknown error // Handle an unknown error
@@ -210,7 +212,7 @@ handle_request(
// Report a failure // Report a failure
void void
fail(boost::system::error_code ec, char const* what) fail(beast::error_code ec, char const* what)
{ {
std::cerr << what << ": " << ec.message() << "\n"; std::cerr << what << ": " << ec.message() << "\n";
} }
@@ -259,7 +261,7 @@ class session
http::async_write( http::async_write(
self_.derived().stream(), self_.derived().stream(),
*sp, *sp,
boost::asio::bind_executor( net::bind_executor(
self_.strand_, self_.strand_,
std::bind( std::bind(
&session::on_write, &session::on_write,
@@ -276,16 +278,16 @@ class session
send_lambda lambda_; send_lambda lambda_;
protected: protected:
boost::asio::strand< net::strand<
boost::asio::io_context::executor_type> strand_; net::io_context::executor_type> strand_;
boost::beast::flat_buffer buffer_; beast::flat_buffer buffer_;
public: public:
// Take ownership of the buffer // Take ownership of the buffer
explicit explicit
session( session(
boost::asio::io_context& ioc, net::io_context& ioc,
boost::beast::flat_buffer buffer, beast::flat_buffer buffer,
std::shared_ptr<std::string const> const& doc_root) std::shared_ptr<std::string const> const& doc_root)
: doc_root_(doc_root) : doc_root_(doc_root)
, lambda_(*this) , lambda_(*this)
@@ -302,7 +304,7 @@ public:
derived().stream(), derived().stream(),
buffer_, buffer_,
req_, req_,
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&session::on_read, &session::on_read,
@@ -313,7 +315,7 @@ public:
void void
on_read( on_read(
boost::system::error_code ec, beast::error_code ec,
std::size_t bytes_transferred) std::size_t bytes_transferred)
{ {
boost::ignore_unused(bytes_transferred); boost::ignore_unused(bytes_transferred);
@@ -331,7 +333,7 @@ public:
void void
on_write( on_write(
boost::system::error_code ec, beast::error_code ec,
std::size_t bytes_transferred, std::size_t bytes_transferred,
bool close) bool close)
{ {
@@ -361,14 +363,14 @@ class plain_session
, public std::enable_shared_from_this<plain_session> , public std::enable_shared_from_this<plain_session>
{ {
tcp::socket socket_; tcp::socket socket_;
boost::asio::strand< net::strand<
boost::asio::io_context::executor_type> strand_; net::io_context::executor_type> strand_;
public: public:
// Create the session // Create the session
plain_session( plain_session(
tcp::socket socket, tcp::socket socket,
boost::beast::flat_buffer buffer, beast::flat_buffer buffer,
std::shared_ptr<std::string const> const& doc_root) std::shared_ptr<std::string const> const& doc_root)
: session<plain_session>( : session<plain_session>(
socket.get_executor().context(), socket.get_executor().context(),
@@ -397,7 +399,7 @@ public:
do_eof() do_eof()
{ {
// Send a TCP shutdown // Send a TCP shutdown
boost::system::error_code ec; beast::error_code ec;
socket_.shutdown(tcp::socket::shutdown_send, ec); socket_.shutdown(tcp::socket::shutdown_send, ec);
// At this point the connection is closed gracefully // At this point the connection is closed gracefully
@@ -411,15 +413,15 @@ class ssl_session
{ {
tcp::socket socket_; tcp::socket socket_;
ssl::stream<tcp::socket&> stream_; ssl::stream<tcp::socket&> stream_;
boost::asio::strand< net::strand<
boost::asio::io_context::executor_type> strand_; net::io_context::executor_type> strand_;
public: public:
// Create the session // Create the session
ssl_session( ssl_session(
tcp::socket socket, tcp::socket socket,
ssl::context& ctx, ssl::context& ctx,
boost::beast::flat_buffer buffer, beast::flat_buffer buffer,
std::shared_ptr<std::string const> const& doc_root) std::shared_ptr<std::string const> const& doc_root)
: session<ssl_session>( : session<ssl_session>(
socket.get_executor().context(), socket.get_executor().context(),
@@ -447,7 +449,7 @@ public:
stream_.async_handshake( stream_.async_handshake(
ssl::stream_base::server, ssl::stream_base::server,
buffer_.data(), buffer_.data(),
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&ssl_session::on_handshake, &ssl_session::on_handshake,
@@ -457,7 +459,7 @@ public:
} }
void void
on_handshake( on_handshake(
boost::system::error_code ec, beast::error_code ec,
std::size_t bytes_used) std::size_t bytes_used)
{ {
if(ec) if(ec)
@@ -474,7 +476,7 @@ public:
{ {
// Perform the SSL shutdown // Perform the SSL shutdown
stream_.async_shutdown( stream_.async_shutdown(
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&ssl_session::on_shutdown, &ssl_session::on_shutdown,
@@ -483,7 +485,7 @@ public:
} }
void void
on_shutdown(boost::system::error_code ec) on_shutdown(beast::error_code ec)
{ {
if(ec) if(ec)
return fail(ec, "shutdown"); return fail(ec, "shutdown");
@@ -499,10 +501,10 @@ class detect_session : public std::enable_shared_from_this<detect_session>
{ {
tcp::socket socket_; tcp::socket socket_;
ssl::context& ctx_; ssl::context& ctx_;
boost::asio::strand< net::strand<
boost::asio::io_context::executor_type> strand_; net::io_context::executor_type> strand_;
std::shared_ptr<std::string const> doc_root_; std::shared_ptr<std::string const> doc_root_;
boost::beast::flat_buffer buffer_; beast::flat_buffer buffer_;
public: public:
explicit explicit
@@ -524,7 +526,7 @@ public:
async_detect_ssl( async_detect_ssl(
socket_, socket_,
buffer_, buffer_,
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&detect_session::on_detect, &detect_session::on_detect,
@@ -535,7 +537,7 @@ public:
} }
void void
on_detect(boost::system::error_code ec, boost::tribool result) on_detect(beast::error_code ec, boost::tribool result)
{ {
if(ec) if(ec)
return fail(ec, "detect"); return fail(ec, "detect");
@@ -563,15 +565,15 @@ public:
class listener : public std::enable_shared_from_this<listener> class listener : public std::enable_shared_from_this<listener>
{ {
ssl::context& ctx_; ssl::context& ctx_;
boost::asio::strand< net::strand<
boost::asio::io_context::executor_type> strand_; net::io_context::executor_type> strand_;
tcp::acceptor acceptor_; tcp::acceptor acceptor_;
tcp::socket socket_; tcp::socket socket_;
std::shared_ptr<std::string const> doc_root_; std::shared_ptr<std::string const> doc_root_;
public: public:
listener( listener(
boost::asio::io_context& ioc, net::io_context& ioc,
ssl::context& ctx, ssl::context& ctx,
tcp::endpoint endpoint, tcp::endpoint endpoint,
std::shared_ptr<std::string const> const& doc_root) std::shared_ptr<std::string const> const& doc_root)
@@ -581,7 +583,7 @@ public:
, socket_(ioc) , socket_(ioc)
, doc_root_(doc_root) , doc_root_(doc_root)
{ {
boost::system::error_code ec; beast::error_code ec;
// Open the acceptor // Open the acceptor
acceptor_.open(endpoint.protocol(), ec); acceptor_.open(endpoint.protocol(), ec);
@@ -592,7 +594,7 @@ public:
} }
// Allow address reuse // Allow address reuse
acceptor_.set_option(boost::asio::socket_base::reuse_address(true), ec); acceptor_.set_option(net::socket_base::reuse_address(true), ec);
if(ec) if(ec)
{ {
fail(ec, "set_option"); fail(ec, "set_option");
@@ -609,7 +611,7 @@ public:
// Start listening for connections // Start listening for connections
acceptor_.listen( acceptor_.listen(
boost::asio::socket_base::max_listen_connections, ec); net::socket_base::max_listen_connections, ec);
if(ec) if(ec)
{ {
fail(ec, "listen"); fail(ec, "listen");
@@ -638,7 +640,7 @@ public:
} }
void void
on_accept(boost::system::error_code ec) on_accept(beast::error_code ec)
{ {
if(ec) if(ec)
{ {
@@ -671,13 +673,13 @@ int main(int argc, char* argv[])
" http-server-flex 0.0.0.0 8080 .\n"; " http-server-flex 0.0.0.0 8080 .\n";
return EXIT_FAILURE; return EXIT_FAILURE;
} }
auto const address = boost::asio::ip::make_address(argv[1]); auto const address = net::ip::make_address(argv[1]);
auto const port = static_cast<unsigned short>(std::atoi(argv[2])); auto const port = static_cast<unsigned short>(std::atoi(argv[2]));
auto const doc_root = std::make_shared<std::string>(argv[3]); auto const doc_root = std::make_shared<std::string>(argv[3]);
auto const threads = std::max<int>(1, std::atoi(argv[4])); auto const threads = std::max<int>(1, std::atoi(argv[4]));
// The io_context is required for all I/O // The io_context is required for all I/O
boost::asio::io_context ioc{threads}; net::io_context ioc{threads};
// The SSL context is required, and holds certificates // The SSL context is required, and holds certificates
ssl::context ctx{ssl::context::sslv23}; ssl::context ctx{ssl::context::sslv23};

View File

@@ -24,9 +24,10 @@
#include <memory> #include <memory>
#include <string> #include <string>
namespace ip = boost::asio::ip; // from <boost/asio.hpp> namespace beast = boost::beast; // from <boost/beast.hpp>
using tcp = boost::asio::ip::tcp; // from <boost/asio.hpp> namespace http = beast::http; // from <boost/beast/http.hpp>
namespace http = boost::beast::http; // from <boost/beast/http.hpp> namespace net = boost::asio; // from <boost/asio.hpp>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
namespace my_program_state namespace my_program_state
{ {
@@ -65,7 +66,7 @@ private:
tcp::socket socket_; tcp::socket socket_;
// The buffer for performing reads. // The buffer for performing reads.
boost::beast::flat_buffer buffer_{8192}; beast::flat_buffer buffer_{8192};
// The request message. // The request message.
http::request<http::dynamic_body> request_; http::request<http::dynamic_body> request_;
@@ -74,7 +75,7 @@ private:
http::response<http::dynamic_body> response_; http::response<http::dynamic_body> response_;
// The timer for putting a deadline on connection processing. // The timer for putting a deadline on connection processing.
boost::asio::basic_waitable_timer<std::chrono::steady_clock> deadline_{ net::basic_waitable_timer<std::chrono::steady_clock> deadline_{
socket_.get_executor().context(), std::chrono::seconds(60)}; socket_.get_executor().context(), std::chrono::seconds(60)};
// Asynchronously receive a complete request message. // Asynchronously receive a complete request message.
@@ -87,7 +88,7 @@ private:
socket_, socket_,
buffer_, buffer_,
request_, request_,
[self](boost::beast::error_code ec, [self](beast::error_code ec,
std::size_t bytes_transferred) std::size_t bytes_transferred)
{ {
boost::ignore_unused(bytes_transferred); boost::ignore_unused(bytes_transferred);
@@ -116,7 +117,7 @@ private:
// we do not recognize the request method. // we do not recognize the request method.
response_.result(http::status::bad_request); response_.result(http::status::bad_request);
response_.set(http::field::content_type, "text/plain"); response_.set(http::field::content_type, "text/plain");
boost::beast::ostream(response_.body()) beast::ostream(response_.body())
<< "Invalid request-method '" << "Invalid request-method '"
<< request_.method_string().to_string() << request_.method_string().to_string()
<< "'"; << "'";
@@ -133,7 +134,7 @@ private:
if(request_.target() == "/count") if(request_.target() == "/count")
{ {
response_.set(http::field::content_type, "text/html"); response_.set(http::field::content_type, "text/html");
boost::beast::ostream(response_.body()) beast::ostream(response_.body())
<< "<html>\n" << "<html>\n"
<< "<head><title>Request count</title></head>\n" << "<head><title>Request count</title></head>\n"
<< "<body>\n" << "<body>\n"
@@ -147,7 +148,7 @@ private:
else if(request_.target() == "/time") else if(request_.target() == "/time")
{ {
response_.set(http::field::content_type, "text/html"); response_.set(http::field::content_type, "text/html");
boost::beast::ostream(response_.body()) beast::ostream(response_.body())
<< "<html>\n" << "<html>\n"
<< "<head><title>Current time</title></head>\n" << "<head><title>Current time</title></head>\n"
<< "<body>\n" << "<body>\n"
@@ -162,7 +163,7 @@ private:
{ {
response_.result(http::status::not_found); response_.result(http::status::not_found);
response_.set(http::field::content_type, "text/plain"); response_.set(http::field::content_type, "text/plain");
boost::beast::ostream(response_.body()) << "File not found\r\n"; beast::ostream(response_.body()) << "File not found\r\n";
} }
} }
@@ -177,7 +178,7 @@ private:
http::async_write( http::async_write(
socket_, socket_,
response_, response_,
[self](boost::beast::error_code ec, std::size_t) [self](beast::error_code ec, std::size_t)
{ {
self->socket_.shutdown(tcp::socket::shutdown_send, ec); self->socket_.shutdown(tcp::socket::shutdown_send, ec);
self->deadline_.cancel(); self->deadline_.cancel();
@@ -191,7 +192,7 @@ private:
auto self = shared_from_this(); auto self = shared_from_this();
deadline_.async_wait( deadline_.async_wait(
[self](boost::beast::error_code ec) [self](beast::error_code ec)
{ {
if(!ec) if(!ec)
{ {
@@ -207,7 +208,7 @@ void
http_server(tcp::acceptor& acceptor, tcp::socket& socket) http_server(tcp::acceptor& acceptor, tcp::socket& socket)
{ {
acceptor.async_accept(socket, acceptor.async_accept(socket,
[&](boost::beast::error_code ec) [&](beast::error_code ec)
{ {
if(!ec) if(!ec)
std::make_shared<http_connection>(std::move(socket))->start(); std::make_shared<http_connection>(std::move(socket))->start();
@@ -231,10 +232,10 @@ main(int argc, char* argv[])
return EXIT_FAILURE; return EXIT_FAILURE;
} }
auto const address = boost::asio::ip::make_address(argv[1]); auto const address = net::ip::make_address(argv[1]);
unsigned short port = static_cast<unsigned short>(std::atoi(argv[2])); unsigned short port = static_cast<unsigned short>(std::atoi(argv[2]));
boost::asio::io_context ioc{1}; net::io_context ioc{1};
tcp::acceptor acceptor{ioc, {address, port}}; tcp::acceptor acceptor{ioc, {address, port}};
tcp::socket socket{ioc}; tcp::socket socket{ioc};

View File

@@ -33,20 +33,22 @@
#include <thread> #include <thread>
#include <vector> #include <vector>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp> namespace beast = boost::beast; // from <boost/beast.hpp>
namespace http = beast::http; // from <boost/beast/http.hpp>
namespace net = boost::asio; // from <boost/asio.hpp>
namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp> namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp>
namespace http = boost::beast::http; // from <boost/beast/http.hpp> using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
// Return a reasonable mime type based on the extension of a file. // Return a reasonable mime type based on the extension of a file.
boost::beast::string_view beast::string_view
mime_type(boost::beast::string_view path) mime_type(beast::string_view path)
{ {
using boost::beast::iequals; using beast::iequals;
auto const ext = [&path] auto const ext = [&path]
{ {
auto const pos = path.rfind("."); auto const pos = path.rfind(".");
if(pos == boost::beast::string_view::npos) if(pos == beast::string_view::npos)
return boost::beast::string_view{}; return beast::string_view{};
return path.substr(pos); return path.substr(pos);
}(); }();
if(iequals(ext, ".htm")) return "text/html"; if(iequals(ext, ".htm")) return "text/html";
@@ -77,8 +79,8 @@ mime_type(boost::beast::string_view path)
// The returned path is normalized for the platform. // The returned path is normalized for the platform.
std::string std::string
path_cat( path_cat(
boost::beast::string_view base, beast::string_view base,
boost::beast::string_view path) beast::string_view path)
{ {
if(base.empty()) if(base.empty())
return path.to_string(); return path.to_string();
@@ -109,13 +111,13 @@ template<
class Send> class Send>
void void
handle_request( handle_request(
boost::beast::string_view doc_root, beast::string_view doc_root,
http::request<Body, http::basic_fields<Allocator>>&& req, http::request<Body, http::basic_fields<Allocator>>&& req,
Send&& send) Send&& send)
{ {
// Returns a bad request response // Returns a bad request response
auto const bad_request = auto const bad_request =
[&req](boost::beast::string_view why) [&req](beast::string_view why)
{ {
http::response<http::string_body> res{http::status::bad_request, req.version()}; http::response<http::string_body> res{http::status::bad_request, req.version()};
res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
@@ -128,7 +130,7 @@ handle_request(
// Returns a not found response // Returns a not found response
auto const not_found = auto const not_found =
[&req](boost::beast::string_view target) [&req](beast::string_view target)
{ {
http::response<http::string_body> res{http::status::not_found, req.version()}; http::response<http::string_body> res{http::status::not_found, req.version()};
res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
@@ -141,7 +143,7 @@ handle_request(
// Returns a server error response // Returns a server error response
auto const server_error = auto const server_error =
[&req](boost::beast::string_view what) [&req](beast::string_view what)
{ {
http::response<http::string_body> res{http::status::internal_server_error, req.version()}; http::response<http::string_body> res{http::status::internal_server_error, req.version()};
res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
@@ -160,7 +162,7 @@ handle_request(
// Request path must be absolute and not contain "..". // Request path must be absolute and not contain "..".
if( req.target().empty() || if( req.target().empty() ||
req.target()[0] != '/' || req.target()[0] != '/' ||
req.target().find("..") != boost::beast::string_view::npos) req.target().find("..") != beast::string_view::npos)
return send(bad_request("Illegal request-target")); return send(bad_request("Illegal request-target"));
// Build the path to the requested file // Build the path to the requested file
@@ -169,12 +171,12 @@ handle_request(
path.append("index.html"); path.append("index.html");
// Attempt to open the file // Attempt to open the file
boost::beast::error_code ec; beast::error_code ec;
http::file_body::value_type body; http::file_body::value_type body;
body.open(path.c_str(), boost::beast::file_mode::scan, ec); body.open(path.c_str(), beast::file_mode::scan, ec);
// Handle the case where the file doesn't exist // Handle the case where the file doesn't exist
if(ec == boost::system::errc::no_such_file_or_directory) if(ec == beast::errc::no_such_file_or_directory)
return send(not_found(req.target())); return send(not_found(req.target()));
// Handle an unknown error // Handle an unknown error
@@ -211,14 +213,14 @@ handle_request(
// Report a failure // Report a failure
void void
fail(boost::system::error_code ec, char const* what) fail(beast::error_code ec, char const* what)
{ {
std::cerr << what << ": " << ec.message() << "\n"; std::cerr << what << ": " << ec.message() << "\n";
} }
// Handles an HTTP server connection // Handles an HTTP server connection
class session class session
: public boost::asio::coroutine : public net::coroutine
, public std::enable_shared_from_this<session> , public std::enable_shared_from_this<session>
{ {
// This is the C++11 equivalent of a generic lambda. // This is the C++11 equivalent of a generic lambda.
@@ -251,7 +253,7 @@ class session
http::async_write( http::async_write(
self_.stream_, self_.stream_,
*sp, *sp,
boost::asio::bind_executor( net::bind_executor(
self_.strand_, self_.strand_,
std::bind( std::bind(
&session::loop, &session::loop,
@@ -264,9 +266,9 @@ class session
tcp::socket socket_; tcp::socket socket_;
ssl::stream<tcp::socket&> stream_; ssl::stream<tcp::socket&> stream_;
boost::asio::strand< net::strand<
boost::asio::io_context::executor_type> strand_; net::io_context::executor_type> strand_;
boost::beast::flat_buffer buffer_; beast::flat_buffer buffer_;
std::shared_ptr<std::string const> doc_root_; std::shared_ptr<std::string const> doc_root_;
http::request<http::string_body> req_; http::request<http::string_body> req_;
std::shared_ptr<void> res_; std::shared_ptr<void> res_;
@@ -297,7 +299,7 @@ public:
#include <boost/asio/yield.hpp> #include <boost/asio/yield.hpp>
void void
loop( loop(
boost::system::error_code ec, beast::error_code ec,
std::size_t bytes_transferred, std::size_t bytes_transferred,
bool close) bool close)
{ {
@@ -307,7 +309,7 @@ public:
// Perform the SSL handshake // Perform the SSL handshake
yield stream_.async_handshake( yield stream_.async_handshake(
ssl::stream_base::server, ssl::stream_base::server,
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&session::loop, &session::loop,
@@ -326,7 +328,7 @@ public:
// Read a request // Read a request
yield http::async_read(stream_, buffer_, req_, yield http::async_read(stream_, buffer_, req_,
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&session::loop, &session::loop,
@@ -359,7 +361,7 @@ public:
// Perform the SSL shutdown // Perform the SSL shutdown
yield stream_.async_shutdown( yield stream_.async_shutdown(
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&session::loop, &session::loop,
@@ -380,7 +382,7 @@ public:
// Accepts incoming connections and launches the sessions // Accepts incoming connections and launches the sessions
class listener class listener
: public boost::asio::coroutine : public net::coroutine
, public std::enable_shared_from_this<listener> , public std::enable_shared_from_this<listener>
{ {
ssl::context& ctx_; ssl::context& ctx_;
@@ -390,7 +392,7 @@ class listener
public: public:
listener( listener(
boost::asio::io_context& ioc, net::io_context& ioc,
ssl::context& ctx, ssl::context& ctx,
tcp::endpoint endpoint, tcp::endpoint endpoint,
std::shared_ptr<std::string const> const& doc_root) std::shared_ptr<std::string const> const& doc_root)
@@ -399,7 +401,7 @@ public:
, socket_(ioc) , socket_(ioc)
, doc_root_(doc_root) , doc_root_(doc_root)
{ {
boost::system::error_code ec; beast::error_code ec;
// Open the acceptor // Open the acceptor
acceptor_.open(endpoint.protocol(), ec); acceptor_.open(endpoint.protocol(), ec);
@@ -410,7 +412,7 @@ public:
} }
// Allow address reuse // Allow address reuse
acceptor_.set_option(boost::asio::socket_base::reuse_address(true), ec); acceptor_.set_option(net::socket_base::reuse_address(true), ec);
if(ec) if(ec)
{ {
fail(ec, "set_option"); fail(ec, "set_option");
@@ -427,7 +429,7 @@ public:
// Start listening for connections // Start listening for connections
acceptor_.listen( acceptor_.listen(
boost::asio::socket_base::max_listen_connections, ec); net::socket_base::max_listen_connections, ec);
if(ec) if(ec)
{ {
fail(ec, "listen"); fail(ec, "listen");
@@ -446,7 +448,7 @@ public:
#include <boost/asio/yield.hpp> #include <boost/asio/yield.hpp>
void void
loop(boost::system::error_code ec = {}) loop(beast::error_code ec = {})
{ {
reenter(*this) reenter(*this)
{ {
@@ -489,13 +491,13 @@ int main(int argc, char* argv[])
" http-server-stackless-ssl 0.0.0.0 8080 . 1\n"; " http-server-stackless-ssl 0.0.0.0 8080 . 1\n";
return EXIT_FAILURE; return EXIT_FAILURE;
} }
auto const address = boost::asio::ip::make_address(argv[1]); auto const address = net::ip::make_address(argv[1]);
auto const port = static_cast<unsigned short>(std::atoi(argv[2])); auto const port = static_cast<unsigned short>(std::atoi(argv[2]));
auto const doc_root = std::make_shared<std::string>(argv[3]); auto const doc_root = std::make_shared<std::string>(argv[3]);
auto const threads = std::max<int>(1, std::atoi(argv[4])); auto const threads = std::max<int>(1, std::atoi(argv[4]));
// The io_context is required for all I/O // The io_context is required for all I/O
boost::asio::io_context ioc{threads}; net::io_context ioc{threads};
// The SSL context is required, and holds certificates // The SSL context is required, and holds certificates
ssl::context ctx{ssl::context::sslv23}; ssl::context ctx{ssl::context::sslv23};

View File

@@ -30,19 +30,21 @@
#include <thread> #include <thread>
#include <vector> #include <vector>
namespace beast = boost::beast; // from <boost/beast.hpp>
namespace http = beast::http; // from <boost/beast/http.hpp>
namespace net = boost::asio; // from <boost/asio.hpp>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp> using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
namespace http = boost::beast::http; // from <boost/beast/http.hpp>
// Return a reasonable mime type based on the extension of a file. // Return a reasonable mime type based on the extension of a file.
boost::beast::string_view beast::string_view
mime_type(boost::beast::string_view path) mime_type(beast::string_view path)
{ {
using boost::beast::iequals; using beast::iequals;
auto const ext = [&path] auto const ext = [&path]
{ {
auto const pos = path.rfind("."); auto const pos = path.rfind(".");
if(pos == boost::beast::string_view::npos) if(pos == beast::string_view::npos)
return boost::beast::string_view{}; return beast::string_view{};
return path.substr(pos); return path.substr(pos);
}(); }();
if(iequals(ext, ".htm")) return "text/html"; if(iequals(ext, ".htm")) return "text/html";
@@ -73,8 +75,8 @@ mime_type(boost::beast::string_view path)
// The returned path is normalized for the platform. // The returned path is normalized for the platform.
std::string std::string
path_cat( path_cat(
boost::beast::string_view base, beast::string_view base,
boost::beast::string_view path) beast::string_view path)
{ {
if(base.empty()) if(base.empty())
return path.to_string(); return path.to_string();
@@ -105,13 +107,13 @@ template<
class Send> class Send>
void void
handle_request( handle_request(
boost::beast::string_view doc_root, beast::string_view doc_root,
http::request<Body, http::basic_fields<Allocator>>&& req, http::request<Body, http::basic_fields<Allocator>>&& req,
Send&& send) Send&& send)
{ {
// Returns a bad request response // Returns a bad request response
auto const bad_request = auto const bad_request =
[&req](boost::beast::string_view why) [&req](beast::string_view why)
{ {
http::response<http::string_body> res{http::status::bad_request, req.version()}; http::response<http::string_body> res{http::status::bad_request, req.version()};
res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
@@ -124,7 +126,7 @@ handle_request(
// Returns a not found response // Returns a not found response
auto const not_found = auto const not_found =
[&req](boost::beast::string_view target) [&req](beast::string_view target)
{ {
http::response<http::string_body> res{http::status::not_found, req.version()}; http::response<http::string_body> res{http::status::not_found, req.version()};
res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
@@ -137,7 +139,7 @@ handle_request(
// Returns a server error response // Returns a server error response
auto const server_error = auto const server_error =
[&req](boost::beast::string_view what) [&req](beast::string_view what)
{ {
http::response<http::string_body> res{http::status::internal_server_error, req.version()}; http::response<http::string_body> res{http::status::internal_server_error, req.version()};
res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
@@ -156,7 +158,7 @@ handle_request(
// Request path must be absolute and not contain "..". // Request path must be absolute and not contain "..".
if( req.target().empty() || if( req.target().empty() ||
req.target()[0] != '/' || req.target()[0] != '/' ||
req.target().find("..") != boost::beast::string_view::npos) req.target().find("..") != beast::string_view::npos)
return send(bad_request("Illegal request-target")); return send(bad_request("Illegal request-target"));
// Build the path to the requested file // Build the path to the requested file
@@ -165,12 +167,12 @@ handle_request(
path.append("index.html"); path.append("index.html");
// Attempt to open the file // Attempt to open the file
boost::beast::error_code ec; beast::error_code ec;
http::file_body::value_type body; http::file_body::value_type body;
body.open(path.c_str(), boost::beast::file_mode::scan, ec); body.open(path.c_str(), beast::file_mode::scan, ec);
// Handle the case where the file doesn't exist // Handle the case where the file doesn't exist
if(ec == boost::system::errc::no_such_file_or_directory) if(ec == beast::errc::no_such_file_or_directory)
return send(not_found(req.target())); return send(not_found(req.target()));
// Handle an unknown error // Handle an unknown error
@@ -207,14 +209,14 @@ handle_request(
// Report a failure // Report a failure
void void
fail(boost::system::error_code ec, char const* what) fail(beast::error_code ec, char const* what)
{ {
std::cerr << what << ": " << ec.message() << "\n"; std::cerr << what << ": " << ec.message() << "\n";
} }
// Handles an HTTP server connection // Handles an HTTP server connection
class session class session
: public boost::asio::coroutine : public net::coroutine
, public std::enable_shared_from_this<session> , public std::enable_shared_from_this<session>
{ {
// This is the C++11 equivalent of a generic lambda. // This is the C++11 equivalent of a generic lambda.
@@ -248,7 +250,7 @@ class session
http::async_write( http::async_write(
self_.socket_, self_.socket_,
*sp, *sp,
boost::asio::bind_executor( net::bind_executor(
self_.strand_, self_.strand_,
std::bind( std::bind(
&session::loop, &session::loop,
@@ -260,9 +262,9 @@ class session
}; };
tcp::socket socket_; tcp::socket socket_;
boost::asio::strand< net::strand<
boost::asio::io_context::executor_type> strand_; net::io_context::executor_type> strand_;
boost::beast::flat_buffer buffer_; beast::flat_buffer buffer_;
std::shared_ptr<std::string const> doc_root_; std::shared_ptr<std::string const> doc_root_;
http::request<http::string_body> req_; http::request<http::string_body> req_;
std::shared_ptr<void> res_; std::shared_ptr<void> res_;
@@ -291,7 +293,7 @@ public:
#include <boost/asio/yield.hpp> #include <boost/asio/yield.hpp>
void void
loop( loop(
boost::system::error_code ec, beast::error_code ec,
std::size_t bytes_transferred, std::size_t bytes_transferred,
bool close) bool close)
{ {
@@ -306,7 +308,7 @@ public:
// Read a request // Read a request
yield http::async_read(socket_, buffer_, req_, yield http::async_read(socket_, buffer_, req_,
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&session::loop, &session::loop,
@@ -350,7 +352,7 @@ public:
// Accepts incoming connections and launches the sessions // Accepts incoming connections and launches the sessions
class listener class listener
: public boost::asio::coroutine : public net::coroutine
, public std::enable_shared_from_this<listener> , public std::enable_shared_from_this<listener>
{ {
tcp::acceptor acceptor_; tcp::acceptor acceptor_;
@@ -359,14 +361,14 @@ class listener
public: public:
listener( listener(
boost::asio::io_context& ioc, net::io_context& ioc,
tcp::endpoint endpoint, tcp::endpoint endpoint,
std::shared_ptr<std::string const> const& doc_root) std::shared_ptr<std::string const> const& doc_root)
: acceptor_(ioc) : acceptor_(ioc)
, socket_(ioc) , socket_(ioc)
, doc_root_(doc_root) , doc_root_(doc_root)
{ {
boost::system::error_code ec; beast::error_code ec;
// Open the acceptor // Open the acceptor
acceptor_.open(endpoint.protocol(), ec); acceptor_.open(endpoint.protocol(), ec);
@@ -377,7 +379,7 @@ public:
} }
// Allow address reuse // Allow address reuse
acceptor_.set_option(boost::asio::socket_base::reuse_address(true), ec); acceptor_.set_option(net::socket_base::reuse_address(true), ec);
if(ec) if(ec)
{ {
fail(ec, "set_option"); fail(ec, "set_option");
@@ -393,7 +395,7 @@ public:
} }
// Start listening for connections // Start listening for connections
acceptor_.listen(boost::asio::socket_base::max_listen_connections, ec); acceptor_.listen(net::socket_base::max_listen_connections, ec);
if(ec) if(ec)
{ {
fail(ec, "listen"); fail(ec, "listen");
@@ -412,7 +414,7 @@ public:
#include <boost/asio/yield.hpp> #include <boost/asio/yield.hpp>
void void
loop(boost::system::error_code ec = {}) loop(beast::error_code ec = {})
{ {
reenter(*this) reenter(*this)
{ {
@@ -454,13 +456,13 @@ int main(int argc, char* argv[])
" http-server-stackless 0.0.0.0 8080 . 1\n"; " http-server-stackless 0.0.0.0 8080 . 1\n";
return EXIT_FAILURE; return EXIT_FAILURE;
} }
auto const address = boost::asio::ip::make_address(argv[1]); auto const address = net::ip::make_address(argv[1]);
auto const port = static_cast<unsigned short>(std::atoi(argv[2])); auto const port = static_cast<unsigned short>(std::atoi(argv[2]));
auto const doc_root = std::make_shared<std::string>(argv[3]); auto const doc_root = std::make_shared<std::string>(argv[3]);
auto const threads = std::max<int>(1, std::atoi(argv[4])); auto const threads = std::max<int>(1, std::atoi(argv[4]));
// The io_context is required for all I/O // The io_context is required for all I/O
boost::asio::io_context ioc{threads}; net::io_context ioc{threads};
// Create and launch a listening port // Create and launch a listening port
std::make_shared<listener>( std::make_shared<listener>(

View File

@@ -27,20 +27,22 @@
#include <string> #include <string>
#include <thread> #include <thread>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp> namespace beast = boost::beast; // from <boost/beast.hpp>
namespace http = beast::http; // from <boost/beast/http.hpp>
namespace net = boost::asio; // from <boost/asio.hpp>
namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp> namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp>
namespace http = boost::beast::http; // from <boost/beast/http.hpp> using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
// Return a reasonable mime type based on the extension of a file. // Return a reasonable mime type based on the extension of a file.
boost::beast::string_view beast::string_view
mime_type(boost::beast::string_view path) mime_type(beast::string_view path)
{ {
using boost::beast::iequals; using beast::iequals;
auto const ext = [&path] auto const ext = [&path]
{ {
auto const pos = path.rfind("."); auto const pos = path.rfind(".");
if(pos == boost::beast::string_view::npos) if(pos == beast::string_view::npos)
return boost::beast::string_view{}; return beast::string_view{};
return path.substr(pos); return path.substr(pos);
}(); }();
if(iequals(ext, ".htm")) return "text/html"; if(iequals(ext, ".htm")) return "text/html";
@@ -71,8 +73,8 @@ mime_type(boost::beast::string_view path)
// The returned path is normalized for the platform. // The returned path is normalized for the platform.
std::string std::string
path_cat( path_cat(
boost::beast::string_view base, beast::string_view base,
boost::beast::string_view path) beast::string_view path)
{ {
if(base.empty()) if(base.empty())
return path.to_string(); return path.to_string();
@@ -103,13 +105,13 @@ template<
class Send> class Send>
void void
handle_request( handle_request(
boost::beast::string_view doc_root, beast::string_view doc_root,
http::request<Body, http::basic_fields<Allocator>>&& req, http::request<Body, http::basic_fields<Allocator>>&& req,
Send&& send) Send&& send)
{ {
// Returns a bad request response // Returns a bad request response
auto const bad_request = auto const bad_request =
[&req](boost::beast::string_view why) [&req](beast::string_view why)
{ {
http::response<http::string_body> res{http::status::bad_request, req.version()}; http::response<http::string_body> res{http::status::bad_request, req.version()};
res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
@@ -122,7 +124,7 @@ handle_request(
// Returns a not found response // Returns a not found response
auto const not_found = auto const not_found =
[&req](boost::beast::string_view target) [&req](beast::string_view target)
{ {
http::response<http::string_body> res{http::status::not_found, req.version()}; http::response<http::string_body> res{http::status::not_found, req.version()};
res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
@@ -135,7 +137,7 @@ handle_request(
// Returns a server error response // Returns a server error response
auto const server_error = auto const server_error =
[&req](boost::beast::string_view what) [&req](beast::string_view what)
{ {
http::response<http::string_body> res{http::status::internal_server_error, req.version()}; http::response<http::string_body> res{http::status::internal_server_error, req.version()};
res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
@@ -154,7 +156,7 @@ handle_request(
// Request path must be absolute and not contain "..". // Request path must be absolute and not contain "..".
if( req.target().empty() || if( req.target().empty() ||
req.target()[0] != '/' || req.target()[0] != '/' ||
req.target().find("..") != boost::beast::string_view::npos) req.target().find("..") != beast::string_view::npos)
return send(bad_request("Illegal request-target")); return send(bad_request("Illegal request-target"));
// Build the path to the requested file // Build the path to the requested file
@@ -163,12 +165,12 @@ handle_request(
path.append("index.html"); path.append("index.html");
// Attempt to open the file // Attempt to open the file
boost::beast::error_code ec; beast::error_code ec;
http::file_body::value_type body; http::file_body::value_type body;
body.open(path.c_str(), boost::beast::file_mode::scan, ec); body.open(path.c_str(), beast::file_mode::scan, ec);
// Handle the case where the file doesn't exist // Handle the case where the file doesn't exist
if(ec == boost::system::errc::no_such_file_or_directory) if(ec == beast::errc::no_such_file_or_directory)
return send(not_found(req.target())); return send(not_found(req.target()));
// Handle an unknown error // Handle an unknown error
@@ -205,7 +207,7 @@ handle_request(
// Report a failure // Report a failure
void void
fail(boost::system::error_code ec, char const* what) fail(beast::error_code ec, char const* what)
{ {
std::cerr << what << ": " << ec.message() << "\n"; std::cerr << what << ": " << ec.message() << "\n";
} }
@@ -217,13 +219,13 @@ struct send_lambda
{ {
Stream& stream_; Stream& stream_;
bool& close_; bool& close_;
boost::system::error_code& ec_; beast::error_code& ec_;
explicit explicit
send_lambda( send_lambda(
Stream& stream, Stream& stream,
bool& close, bool& close,
boost::system::error_code& ec) beast::error_code& ec)
: stream_(stream) : stream_(stream)
, close_(close) , close_(close)
, ec_(ec) , ec_(ec)
@@ -253,7 +255,7 @@ do_session(
std::shared_ptr<std::string const> const& doc_root) std::shared_ptr<std::string const> const& doc_root)
{ {
bool close = false; bool close = false;
boost::system::error_code ec; beast::error_code ec;
// Construct the stream around the socket // Construct the stream around the socket
ssl::stream<tcp::socket&> stream{socket, ctx}; ssl::stream<tcp::socket&> stream{socket, ctx};
@@ -264,7 +266,7 @@ do_session(
return fail(ec, "handshake"); return fail(ec, "handshake");
// This buffer is required to persist across reads // This buffer is required to persist across reads
boost::beast::flat_buffer buffer; beast::flat_buffer buffer;
// This lambda is used to send messages // This lambda is used to send messages
send_lambda<ssl::stream<tcp::socket&>> lambda{stream, close, ec}; send_lambda<ssl::stream<tcp::socket&>> lambda{stream, close, ec};
@@ -314,12 +316,12 @@ int main(int argc, char* argv[])
" http-server-sync-ssl 0.0.0.0 8080 .\n"; " http-server-sync-ssl 0.0.0.0 8080 .\n";
return EXIT_FAILURE; return EXIT_FAILURE;
} }
auto const address = boost::asio::ip::make_address(argv[1]); auto const address = net::ip::make_address(argv[1]);
auto const port = static_cast<unsigned short>(std::atoi(argv[2])); auto const port = static_cast<unsigned short>(std::atoi(argv[2]));
auto const doc_root = std::make_shared<std::string>(argv[3]); auto const doc_root = std::make_shared<std::string>(argv[3]);
// The io_context is required for all I/O // The io_context is required for all I/O
boost::asio::io_context ioc{1}; net::io_context ioc{1};
// The SSL context is required, and holds certificates // The SSL context is required, and holds certificates
ssl::context ctx{ssl::context::sslv23}; ssl::context ctx{ssl::context::sslv23};

View File

@@ -24,21 +24,23 @@
#include <string> #include <string>
#include <thread> #include <thread>
namespace beast = boost::beast; // from <boost/beast.hpp>
namespace http = beast::http; // from <boost/beast/http.hpp>
namespace net = boost::asio; // from <boost/asio.hpp>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp> using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
namespace http = boost::beast::http; // from <boost/beast/http.hpp>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Return a reasonable mime type based on the extension of a file. // Return a reasonable mime type based on the extension of a file.
boost::beast::string_view beast::string_view
mime_type(boost::beast::string_view path) mime_type(beast::string_view path)
{ {
using boost::beast::iequals; using beast::iequals;
auto const ext = [&path] auto const ext = [&path]
{ {
auto const pos = path.rfind("."); auto const pos = path.rfind(".");
if(pos == boost::beast::string_view::npos) if(pos == beast::string_view::npos)
return boost::beast::string_view{}; return beast::string_view{};
return path.substr(pos); return path.substr(pos);
}(); }();
if(iequals(ext, ".htm")) return "text/html"; if(iequals(ext, ".htm")) return "text/html";
@@ -69,8 +71,8 @@ mime_type(boost::beast::string_view path)
// The returned path is normalized for the platform. // The returned path is normalized for the platform.
std::string std::string
path_cat( path_cat(
boost::beast::string_view base, beast::string_view base,
boost::beast::string_view path) beast::string_view path)
{ {
if(base.empty()) if(base.empty())
return path.to_string(); return path.to_string();
@@ -101,13 +103,13 @@ template<
class Send> class Send>
void void
handle_request( handle_request(
boost::beast::string_view doc_root, beast::string_view doc_root,
http::request<Body, http::basic_fields<Allocator>>&& req, http::request<Body, http::basic_fields<Allocator>>&& req,
Send&& send) Send&& send)
{ {
// Returns a bad request response // Returns a bad request response
auto const bad_request = auto const bad_request =
[&req](boost::beast::string_view why) [&req](beast::string_view why)
{ {
http::response<http::string_body> res{http::status::bad_request, req.version()}; http::response<http::string_body> res{http::status::bad_request, req.version()};
res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
@@ -120,7 +122,7 @@ handle_request(
// Returns a not found response // Returns a not found response
auto const not_found = auto const not_found =
[&req](boost::beast::string_view target) [&req](beast::string_view target)
{ {
http::response<http::string_body> res{http::status::not_found, req.version()}; http::response<http::string_body> res{http::status::not_found, req.version()};
res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
@@ -133,7 +135,7 @@ handle_request(
// Returns a server error response // Returns a server error response
auto const server_error = auto const server_error =
[&req](boost::beast::string_view what) [&req](beast::string_view what)
{ {
http::response<http::string_body> res{http::status::internal_server_error, req.version()}; http::response<http::string_body> res{http::status::internal_server_error, req.version()};
res.set(http::field::server, BOOST_BEAST_VERSION_STRING); res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
@@ -152,7 +154,7 @@ handle_request(
// Request path must be absolute and not contain "..". // Request path must be absolute and not contain "..".
if( req.target().empty() || if( req.target().empty() ||
req.target()[0] != '/' || req.target()[0] != '/' ||
req.target().find("..") != boost::beast::string_view::npos) req.target().find("..") != beast::string_view::npos)
return send(bad_request("Illegal request-target")); return send(bad_request("Illegal request-target"));
// Build the path to the requested file // Build the path to the requested file
@@ -161,12 +163,12 @@ handle_request(
path.append("index.html"); path.append("index.html");
// Attempt to open the file // Attempt to open the file
boost::beast::error_code ec; beast::error_code ec;
http::file_body::value_type body; http::file_body::value_type body;
body.open(path.c_str(), boost::beast::file_mode::scan, ec); body.open(path.c_str(), beast::file_mode::scan, ec);
// Handle the case where the file doesn't exist // Handle the case where the file doesn't exist
if(ec == boost::system::errc::no_such_file_or_directory) if(ec == beast::errc::no_such_file_or_directory)
return send(not_found(req.target())); return send(not_found(req.target()));
// Handle an unknown error // Handle an unknown error
@@ -203,7 +205,7 @@ handle_request(
// Report a failure // Report a failure
void void
fail(boost::system::error_code ec, char const* what) fail(beast::error_code ec, char const* what)
{ {
std::cerr << what << ": " << ec.message() << "\n"; std::cerr << what << ": " << ec.message() << "\n";
} }
@@ -215,13 +217,13 @@ struct send_lambda
{ {
Stream& stream_; Stream& stream_;
bool& close_; bool& close_;
boost::system::error_code& ec_; beast::error_code& ec_;
explicit explicit
send_lambda( send_lambda(
Stream& stream, Stream& stream,
bool& close, bool& close,
boost::system::error_code& ec) beast::error_code& ec)
: stream_(stream) : stream_(stream)
, close_(close) , close_(close)
, ec_(ec) , ec_(ec)
@@ -250,10 +252,10 @@ do_session(
std::shared_ptr<std::string const> const& doc_root) std::shared_ptr<std::string const> const& doc_root)
{ {
bool close = false; bool close = false;
boost::system::error_code ec; beast::error_code ec;
// This buffer is required to persist across reads // This buffer is required to persist across reads
boost::beast::flat_buffer buffer; beast::flat_buffer buffer;
// This lambda is used to send messages // This lambda is used to send messages
send_lambda<tcp::socket> lambda{socket, close, ec}; send_lambda<tcp::socket> lambda{socket, close, ec};
@@ -301,12 +303,12 @@ int main(int argc, char* argv[])
" http-server-sync 0.0.0.0 8080 .\n"; " http-server-sync 0.0.0.0 8080 .\n";
return EXIT_FAILURE; return EXIT_FAILURE;
} }
auto const address = boost::asio::ip::make_address(argv[1]); auto const address = net::ip::make_address(argv[1]);
auto const port = static_cast<unsigned short>(std::atoi(argv[2])); auto const port = static_cast<unsigned short>(std::atoi(argv[2]));
auto const doc_root = std::make_shared<std::string>(argv[3]); auto const doc_root = std::make_shared<std::string>(argv[3]);
// The io_context is required for all I/O // The io_context is required for all I/O
boost::asio::io_context ioc{1}; net::io_context ioc{1};
// The acceptor receives incoming connections // The acceptor receives incoming connections
tcp::acceptor acceptor{ioc, {address, port}}; tcp::acceptor acceptor{ioc, {address, port}};

View File

@@ -27,15 +27,18 @@
#include <memory> #include <memory>
#include <string> #include <string>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp> namespace beast = boost::beast; // from <boost/beast.hpp>
namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp> namespace http = beast::http; // from <boost/beast/http.hpp>
namespace websocket = boost::beast::websocket; // from <boost/beast/websocket.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 // Report a failure
void void
fail(boost::system::error_code ec, char const* what) fail(beast::error_code ec, char const* what)
{ {
std::cerr << what << ": " << ec.message() << "\n"; std::cerr << what << ": " << ec.message() << "\n";
} }
@@ -45,14 +48,14 @@ class session : public std::enable_shared_from_this<session>
{ {
tcp::resolver resolver_; tcp::resolver resolver_;
websocket::stream<ssl::stream<tcp::socket>> ws_; websocket::stream<ssl::stream<tcp::socket>> ws_;
boost::beast::multi_buffer buffer_; beast::multi_buffer buffer_;
std::string host_; std::string host_;
std::string text_; std::string text_;
public: public:
// Resolver and socket require an io_context // Resolver and socket require an io_context
explicit explicit
session(boost::asio::io_context& ioc, ssl::context& ctx) session(net::io_context& ioc, ssl::context& ctx)
: resolver_(ioc) : resolver_(ioc)
, ws_(ioc, ctx) , ws_(ioc, ctx)
{ {
@@ -82,14 +85,14 @@ public:
void void
on_resolve( on_resolve(
boost::system::error_code ec, beast::error_code ec,
tcp::resolver::results_type results) tcp::resolver::results_type results)
{ {
if(ec) if(ec)
return fail(ec, "resolve"); return fail(ec, "resolve");
// Make the connection on the IP address we get from a lookup // Make the connection on the IP address we get from a lookup
boost::asio::async_connect( net::async_connect(
ws_.next_layer().next_layer(), ws_.next_layer().next_layer(),
results.begin(), results.begin(),
results.end(), results.end(),
@@ -100,7 +103,7 @@ public:
} }
void void
on_connect(boost::system::error_code ec) on_connect(beast::error_code ec)
{ {
if(ec) if(ec)
return fail(ec, "connect"); return fail(ec, "connect");
@@ -115,7 +118,7 @@ public:
} }
void void
on_ssl_handshake(boost::system::error_code ec) on_ssl_handshake(beast::error_code ec)
{ {
if(ec) if(ec)
return fail(ec, "ssl_handshake"); return fail(ec, "ssl_handshake");
@@ -129,14 +132,14 @@ public:
} }
void void
on_handshake(boost::system::error_code ec) on_handshake(beast::error_code ec)
{ {
if(ec) if(ec)
return fail(ec, "handshake"); return fail(ec, "handshake");
// Send the message // Send the message
ws_.async_write( ws_.async_write(
boost::asio::buffer(text_), net::buffer(text_),
std::bind( std::bind(
&session::on_write, &session::on_write,
shared_from_this(), shared_from_this(),
@@ -146,7 +149,7 @@ public:
void void
on_write( on_write(
boost::system::error_code ec, beast::error_code ec,
std::size_t bytes_transferred) std::size_t bytes_transferred)
{ {
boost::ignore_unused(bytes_transferred); boost::ignore_unused(bytes_transferred);
@@ -166,7 +169,7 @@ public:
void void
on_read( on_read(
boost::system::error_code ec, beast::error_code ec,
std::size_t bytes_transferred) std::size_t bytes_transferred)
{ {
boost::ignore_unused(bytes_transferred); boost::ignore_unused(bytes_transferred);
@@ -183,7 +186,7 @@ public:
} }
void void
on_close(boost::system::error_code ec) on_close(beast::error_code ec)
{ {
if(ec) if(ec)
return fail(ec, "close"); return fail(ec, "close");
@@ -191,7 +194,7 @@ public:
// If we get here then the connection is closed gracefully // If we get here then the connection is closed gracefully
// The buffers() function helps print a ConstBufferSequence // 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]; auto const text = argv[3];
// The io_context is required for all I/O // 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 // The SSL context is required, and holds certificates
ssl::context ctx{ssl::context::sslv23_client}; ssl::context ctx{ssl::context::sslv23_client};

View File

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

View File

@@ -27,15 +27,18 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp> namespace beast = boost::beast; // from <boost/beast.hpp>
namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp> namespace http = beast::http; // from <boost/beast/http.hpp>
namespace websocket = boost::beast::websocket; // from <boost/beast/websocket.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 // Report a failure
void void
fail(boost::system::error_code ec, char const* what) fail(beast::error_code ec, char const* what)
{ {
std::cerr << what << ": " << ec.message() << "\n"; std::cerr << what << ": " << ec.message() << "\n";
} }
@@ -46,11 +49,11 @@ do_session(
std::string const& host, std::string const& host,
std::string const& port, std::string const& port,
std::string const& text, std::string const& text,
boost::asio::io_context& ioc, net::io_context& ioc,
ssl::context& ctx, 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 // These objects perform our I/O
tcp::resolver resolver{ioc}; tcp::resolver resolver{ioc};
@@ -62,7 +65,7 @@ do_session(
return fail(ec, "resolve"); return fail(ec, "resolve");
// Make the connection on the IP address we get from a lookup // 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) if(ec)
return fail(ec, "connect"); return fail(ec, "connect");
@@ -77,12 +80,12 @@ do_session(
return fail(ec, "handshake"); return fail(ec, "handshake");
// Send the message // 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) if(ec)
return fail(ec, "write"); return fail(ec, "write");
// This buffer will hold the incoming message // This buffer will hold the incoming message
boost::beast::multi_buffer b; beast::multi_buffer b;
// Read a message into our buffer // Read a message into our buffer
ws.async_read(b, yield[ec]); ws.async_read(b, yield[ec]);
@@ -97,7 +100,7 @@ do_session(
// If we get here then the connection is closed gracefully // If we get here then the connection is closed gracefully
// The buffers() function helps print a ConstBufferSequence // 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]; auto const text = argv[3];
// The io_context is required for all I/O // 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 // The SSL context is required, and holds certificates
ssl::context ctx{ssl::context::sslv23_client}; ssl::context ctx{ssl::context::sslv23_client};
@@ -127,7 +130,7 @@ int main(int argc, char** argv)
load_root_certificates(ctx); load_root_certificates(ctx);
// Launch the asynchronous operation // Launch the asynchronous operation
boost::asio::spawn(ioc, std::bind( net::spawn(ioc, std::bind(
&do_session, &do_session,
std::string(host), std::string(host),
std::string(port), std::string(port),

View File

@@ -23,14 +23,17 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp> namespace beast = boost::beast; // from <boost/beast.hpp>
namespace websocket = boost::beast::websocket; // from <boost/beast/websocket.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 // Report a failure
void void
fail(boost::system::error_code ec, char const* what) fail(beast::error_code ec, char const* what)
{ {
std::cerr << what << ": " << ec.message() << "\n"; std::cerr << what << ": " << ec.message() << "\n";
} }
@@ -41,10 +44,10 @@ do_session(
std::string const& host, std::string const& host,
std::string const& port, std::string const& port,
std::string const& text, std::string const& text,
boost::asio::io_context& ioc, net::io_context& ioc,
boost::asio::yield_context yield) net::yield_context yield)
{ {
boost::system::error_code ec; beast::error_code ec;
// These objects perform our I/O // These objects perform our I/O
tcp::resolver resolver{ioc}; tcp::resolver resolver{ioc};
@@ -56,7 +59,7 @@ do_session(
return fail(ec, "resolve"); return fail(ec, "resolve");
// Make the connection on the IP address we get from a lookup // 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) if(ec)
return fail(ec, "connect"); return fail(ec, "connect");
@@ -66,12 +69,12 @@ do_session(
return fail(ec, "handshake"); return fail(ec, "handshake");
// Send the message // 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) if(ec)
return fail(ec, "write"); return fail(ec, "write");
// This buffer will hold the incoming message // This buffer will hold the incoming message
boost::beast::multi_buffer b; beast::multi_buffer b;
// Read a message into our buffer // Read a message into our buffer
ws.async_read(b, yield[ec]); ws.async_read(b, yield[ec]);
@@ -86,7 +89,7 @@ do_session(
// If we get here then the connection is closed gracefully // If we get here then the connection is closed gracefully
// The buffers() function helps print a ConstBufferSequence // 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]; auto const text = argv[3];
// The io_context is required for all I/O // The io_context is required for all I/O
boost::asio::io_context ioc; net::io_context ioc;
// Launch the asynchronous operation // Launch the asynchronous operation
boost::asio::spawn(ioc, std::bind( net::spawn(ioc, std::bind(
&do_session, &do_session,
std::string(host), std::string(host),
std::string(port), std::string(port),

View File

@@ -25,9 +25,12 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp> namespace beast = boost::beast; // from <boost/beast.hpp>
namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp> namespace http = beast::http; // from <boost/beast/http.hpp>
namespace websocket = boost::beast::websocket; // from <boost/beast/websocket.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 // Sends a WebSocket message and prints the response
int main(int argc, char** argv) int main(int argc, char** argv)
@@ -48,7 +51,7 @@ int main(int argc, char** argv)
auto const text = argv[3]; auto const text = argv[3];
// The io_context is required for all I/O // 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 // The SSL context is required, and holds certificates
ssl::context ctx{ssl::context::sslv23_client}; ssl::context ctx{ssl::context::sslv23_client};
@@ -64,7 +67,7 @@ int main(int argc, char** argv)
auto const results = resolver.resolve(host, port); auto const results = resolver.resolve(host, port);
// Make the connection on the IP address we get from a lookup // 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 // Perform the SSL handshake
ws.next_layer().handshake(ssl::stream_base::client); ws.next_layer().handshake(ssl::stream_base::client);
@@ -73,10 +76,10 @@ int main(int argc, char** argv)
ws.handshake(host, "/"); ws.handshake(host, "/");
// Send the message // 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 // This buffer will hold the incoming message
boost::beast::multi_buffer b; beast::multi_buffer b;
// Read a message into our buffer // Read a message into our buffer
ws.read(b); ws.read(b);
@@ -87,7 +90,7 @@ int main(int argc, char** argv)
// If we get here then the connection is closed gracefully // If we get here then the connection is closed gracefully
// The buffers() function helps print a ConstBufferSequence // 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) catch(std::exception const& e)
{ {

View File

@@ -23,8 +23,11 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp> namespace beast = boost::beast; // from <boost/beast.hpp>
namespace websocket = boost::beast::websocket; // from <boost/beast/websocket.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 // Sends a WebSocket message and prints the response
int main(int argc, char** argv) int main(int argc, char** argv)
@@ -45,7 +48,7 @@ int main(int argc, char** argv)
auto const text = argv[3]; auto const text = argv[3];
// The io_context is required for all I/O // The io_context is required for all I/O
boost::asio::io_context ioc; net::io_context ioc;
// These objects perform our I/O // These objects perform our I/O
tcp::resolver resolver{ioc}; tcp::resolver resolver{ioc};
@@ -55,16 +58,16 @@ int main(int argc, char** argv)
auto const results = resolver.resolve(host, port); auto const results = resolver.resolve(host, port);
// Make the connection on the IP address we get from a lookup // 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 // Perform the websocket handshake
ws.handshake(host, "/"); ws.handshake(host, "/");
// Send the message // 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 // This buffer will hold the incoming message
boost::beast::multi_buffer buffer; beast::multi_buffer buffer;
// Read a message into our buffer // Read a message into our buffer
ws.read(buffer); ws.read(buffer);
@@ -75,7 +78,7 @@ int main(int argc, char** argv)
// If we get here then the connection is closed gracefully // If we get here then the connection is closed gracefully
// The buffers() function helps print a ConstBufferSequence // 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) catch(std::exception const& e)
{ {

View File

@@ -31,15 +31,18 @@
#include <thread> #include <thread>
#include <vector> #include <vector>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp> namespace beast = boost::beast; // from <boost/beast.hpp>
namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp> namespace http = beast::http; // from <boost/beast/http.hpp>
namespace websocket = boost::beast::websocket; // from <boost/beast/websocket.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 // Report a failure
void void
fail(boost::system::error_code ec, char const* what) fail(beast::error_code ec, char const* what)
{ {
std::cerr << what << ": " << ec.message() << "\n"; std::cerr << what << ": " << ec.message() << "\n";
} }
@@ -49,9 +52,9 @@ class session : public std::enable_shared_from_this<session>
{ {
tcp::socket socket_; tcp::socket socket_;
websocket::stream<ssl::stream<tcp::socket&>> ws_; websocket::stream<ssl::stream<tcp::socket&>> ws_;
boost::asio::strand< net::strand<
boost::asio::io_context::executor_type> strand_; net::io_context::executor_type> strand_;
boost::beast::multi_buffer buffer_; beast::multi_buffer buffer_;
public: public:
// Take ownership of the socket // Take ownership of the socket
@@ -69,7 +72,7 @@ public:
// Perform the SSL handshake // Perform the SSL handshake
ws_.next_layer().async_handshake( ws_.next_layer().async_handshake(
ssl::stream_base::server, ssl::stream_base::server,
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&session::on_handshake, &session::on_handshake,
@@ -78,14 +81,14 @@ public:
} }
void void
on_handshake(boost::system::error_code ec) on_handshake(beast::error_code ec)
{ {
if(ec) if(ec)
return fail(ec, "handshake"); return fail(ec, "handshake");
// Accept the websocket handshake // Accept the websocket handshake
ws_.async_accept( ws_.async_accept(
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&session::on_accept, &session::on_accept,
@@ -94,7 +97,7 @@ public:
} }
void void
on_accept(boost::system::error_code ec) on_accept(beast::error_code ec)
{ {
if(ec) if(ec)
return fail(ec, "accept"); return fail(ec, "accept");
@@ -109,7 +112,7 @@ public:
// Read a message into our buffer // Read a message into our buffer
ws_.async_read( ws_.async_read(
buffer_, buffer_,
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&session::on_read, &session::on_read,
@@ -120,7 +123,7 @@ public:
void void
on_read( on_read(
boost::system::error_code ec, beast::error_code ec,
std::size_t bytes_transferred) std::size_t bytes_transferred)
{ {
boost::ignore_unused(bytes_transferred); boost::ignore_unused(bytes_transferred);
@@ -136,7 +139,7 @@ public:
ws_.text(ws_.got_text()); ws_.text(ws_.got_text());
ws_.async_write( ws_.async_write(
buffer_.data(), buffer_.data(),
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&session::on_write, &session::on_write,
@@ -147,7 +150,7 @@ public:
void void
on_write( on_write(
boost::system::error_code ec, beast::error_code ec,
std::size_t bytes_transferred) std::size_t bytes_transferred)
{ {
boost::ignore_unused(bytes_transferred); boost::ignore_unused(bytes_transferred);
@@ -174,14 +177,14 @@ class listener : public std::enable_shared_from_this<listener>
public: public:
listener( listener(
boost::asio::io_context& ioc, net::io_context& ioc,
ssl::context& ctx, ssl::context& ctx,
tcp::endpoint endpoint) tcp::endpoint endpoint)
: ctx_(ctx) : ctx_(ctx)
, acceptor_(ioc) , acceptor_(ioc)
, socket_(ioc) , socket_(ioc)
{ {
boost::system::error_code ec; beast::error_code ec;
// Open the acceptor // Open the acceptor
acceptor_.open(endpoint.protocol(), ec); acceptor_.open(endpoint.protocol(), ec);
@@ -192,7 +195,7 @@ public:
} }
// Allow address reuse // Allow address reuse
acceptor_.set_option(boost::asio::socket_base::reuse_address(true), ec); acceptor_.set_option(net::socket_base::reuse_address(true), ec);
if(ec) if(ec)
{ {
fail(ec, "set_option"); fail(ec, "set_option");
@@ -209,7 +212,7 @@ public:
// Start listening for connections // Start listening for connections
acceptor_.listen( acceptor_.listen(
boost::asio::socket_base::max_listen_connections, ec); net::socket_base::max_listen_connections, ec);
if(ec) if(ec)
{ {
fail(ec, "listen"); fail(ec, "listen");
@@ -238,7 +241,7 @@ public:
} }
void void
on_accept(boost::system::error_code ec) on_accept(beast::error_code ec)
{ {
if(ec) if(ec)
{ {
@@ -268,12 +271,12 @@ int main(int argc, char* argv[])
" websocket-server-async-ssl 0.0.0.0 8080 1\n"; " websocket-server-async-ssl 0.0.0.0 8080 1\n";
return EXIT_FAILURE; return EXIT_FAILURE;
} }
auto const address = boost::asio::ip::make_address(argv[1]); auto const address = net::ip::make_address(argv[1]);
auto const port = static_cast<unsigned short>(std::atoi(argv[2])); auto const port = static_cast<unsigned short>(std::atoi(argv[2]));
auto const threads = std::max<int>(1, std::atoi(argv[3])); auto const threads = std::max<int>(1, std::atoi(argv[3]));
// The io_context is required for all I/O // The io_context is required for all I/O
boost::asio::io_context ioc{threads}; net::io_context ioc{threads};
// The SSL context is required, and holds certificates // The SSL context is required, and holds certificates
ssl::context ctx{ssl::context::sslv23}; ssl::context ctx{ssl::context::sslv23};

View File

@@ -27,14 +27,17 @@
#include <thread> #include <thread>
#include <vector> #include <vector>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp> namespace beast = boost::beast; // from <boost/beast.hpp>
namespace websocket = boost::beast::websocket; // from <boost/beast/websocket.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 // Report a failure
void void
fail(boost::system::error_code ec, char const* what) fail(beast::error_code ec, char const* what)
{ {
std::cerr << what << ": " << ec.message() << "\n"; std::cerr << what << ": " << ec.message() << "\n";
} }
@@ -43,9 +46,9 @@ fail(boost::system::error_code ec, char const* what)
class session : public std::enable_shared_from_this<session> class session : public std::enable_shared_from_this<session>
{ {
websocket::stream<tcp::socket> ws_; websocket::stream<tcp::socket> ws_;
boost::asio::strand< net::strand<
boost::asio::io_context::executor_type> strand_; net::io_context::executor_type> strand_;
boost::beast::multi_buffer buffer_; beast::multi_buffer buffer_;
public: public:
// Take ownership of the socket // Take ownership of the socket
@@ -62,7 +65,7 @@ public:
{ {
// Accept the websocket handshake // Accept the websocket handshake
ws_.async_accept( ws_.async_accept(
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&session::on_accept, &session::on_accept,
@@ -71,7 +74,7 @@ public:
} }
void void
on_accept(boost::system::error_code ec) on_accept(beast::error_code ec)
{ {
if(ec) if(ec)
return fail(ec, "accept"); return fail(ec, "accept");
@@ -86,7 +89,7 @@ public:
// Read a message into our buffer // Read a message into our buffer
ws_.async_read( ws_.async_read(
buffer_, buffer_,
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&session::on_read, &session::on_read,
@@ -97,7 +100,7 @@ public:
void void
on_read( on_read(
boost::system::error_code ec, beast::error_code ec,
std::size_t bytes_transferred) std::size_t bytes_transferred)
{ {
boost::ignore_unused(bytes_transferred); boost::ignore_unused(bytes_transferred);
@@ -113,7 +116,7 @@ public:
ws_.text(ws_.got_text()); ws_.text(ws_.got_text());
ws_.async_write( ws_.async_write(
buffer_.data(), buffer_.data(),
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&session::on_write, &session::on_write,
@@ -124,7 +127,7 @@ public:
void void
on_write( on_write(
boost::system::error_code ec, beast::error_code ec,
std::size_t bytes_transferred) std::size_t bytes_transferred)
{ {
boost::ignore_unused(bytes_transferred); boost::ignore_unused(bytes_transferred);
@@ -150,12 +153,12 @@ class listener : public std::enable_shared_from_this<listener>
public: public:
listener( listener(
boost::asio::io_context& ioc, net::io_context& ioc,
tcp::endpoint endpoint) tcp::endpoint endpoint)
: acceptor_(ioc) : acceptor_(ioc)
, socket_(ioc) , socket_(ioc)
{ {
boost::system::error_code ec; beast::error_code ec;
// Open the acceptor // Open the acceptor
acceptor_.open(endpoint.protocol(), ec); acceptor_.open(endpoint.protocol(), ec);
@@ -166,7 +169,7 @@ public:
} }
// Allow address reuse // Allow address reuse
acceptor_.set_option(boost::asio::socket_base::reuse_address(true), ec); acceptor_.set_option(net::socket_base::reuse_address(true), ec);
if(ec) if(ec)
{ {
fail(ec, "set_option"); fail(ec, "set_option");
@@ -183,7 +186,7 @@ public:
// Start listening for connections // Start listening for connections
acceptor_.listen( acceptor_.listen(
boost::asio::socket_base::max_listen_connections, ec); net::socket_base::max_listen_connections, ec);
if(ec) if(ec)
{ {
fail(ec, "listen"); fail(ec, "listen");
@@ -212,7 +215,7 @@ public:
} }
void void
on_accept(boost::system::error_code ec) on_accept(beast::error_code ec)
{ {
if(ec) if(ec)
{ {
@@ -242,12 +245,12 @@ int main(int argc, char* argv[])
" websocket-server-async 0.0.0.0 8080 1\n"; " websocket-server-async 0.0.0.0 8080 1\n";
return EXIT_FAILURE; return EXIT_FAILURE;
} }
auto const address = boost::asio::ip::make_address(argv[1]); auto const address = net::ip::make_address(argv[1]);
auto const port = static_cast<unsigned short>(std::atoi(argv[2])); auto const port = static_cast<unsigned short>(std::atoi(argv[2]));
auto const threads = std::max<int>(1, std::atoi(argv[3])); auto const threads = std::max<int>(1, std::atoi(argv[3]));
// The io_context is required for all I/O // The io_context is required for all I/O
boost::asio::io_context ioc{threads}; net::io_context ioc{threads};
// Create and launch a listening port // Create and launch a listening port
std::make_shared<listener>(ioc, tcp::endpoint{address, port})->run(); std::make_shared<listener>(ioc, tcp::endpoint{address, port})->run();

View File

@@ -30,15 +30,18 @@
#include <thread> #include <thread>
#include <vector> #include <vector>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp> namespace beast = boost::beast; // from <boost/beast.hpp>
namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp> namespace http = beast::http; // from <boost/beast/http.hpp>
namespace websocket = boost::beast::websocket; // from <boost/beast/websocket.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 // Report a failure
void void
fail(boost::system::error_code ec, char const* what) fail(beast::error_code ec, char const* what)
{ {
std::cerr << what << ": " << ec.message() << "\n"; std::cerr << what << ": " << ec.message() << "\n";
} }
@@ -48,9 +51,9 @@ void
do_session( do_session(
tcp::socket& socket, tcp::socket& socket,
ssl::context& ctx, ssl::context& ctx,
boost::asio::yield_context yield) net::yield_context yield)
{ {
boost::system::error_code ec; beast::error_code ec;
// Construct the stream by moving in the socket // Construct the stream by moving in the socket
websocket::stream<ssl::stream<tcp::socket&>> ws{socket, ctx}; websocket::stream<ssl::stream<tcp::socket&>> ws{socket, ctx};
@@ -68,7 +71,7 @@ do_session(
for(;;) for(;;)
{ {
// This buffer will hold the incoming message // This buffer will hold the incoming message
boost::beast::multi_buffer buffer; beast::multi_buffer buffer;
// Read a message // Read a message
ws.async_read(buffer, yield[ec]); ws.async_read(buffer, yield[ec]);
@@ -93,12 +96,12 @@ do_session(
// Accepts incoming connections and launches the sessions // Accepts incoming connections and launches the sessions
void void
do_listen( do_listen(
boost::asio::io_context& ioc, net::io_context& ioc,
ssl::context& ctx, ssl::context& ctx,
tcp::endpoint endpoint, tcp::endpoint endpoint,
boost::asio::yield_context yield) net::yield_context yield)
{ {
boost::system::error_code ec; beast::error_code ec;
// Open the acceptor // Open the acceptor
tcp::acceptor acceptor(ioc); tcp::acceptor acceptor(ioc);
@@ -107,7 +110,7 @@ do_listen(
return fail(ec, "open"); return fail(ec, "open");
// Allow address reuse // Allow address reuse
acceptor.set_option(boost::asio::socket_base::reuse_address(true), ec); acceptor.set_option(net::socket_base::reuse_address(true), ec);
if(ec) if(ec)
return fail(ec, "set_option"); return fail(ec, "set_option");
@@ -117,7 +120,7 @@ do_listen(
return fail(ec, "bind"); return fail(ec, "bind");
// Start listening for connections // Start listening for connections
acceptor.listen(boost::asio::socket_base::max_listen_connections, ec); acceptor.listen(net::socket_base::max_listen_connections, ec);
if(ec) if(ec)
return fail(ec, "listen"); return fail(ec, "listen");
@@ -128,7 +131,7 @@ do_listen(
if(ec) if(ec)
fail(ec, "accept"); fail(ec, "accept");
else else
boost::asio::spawn( net::spawn(
acceptor.get_executor().context(), acceptor.get_executor().context(),
std::bind( std::bind(
&do_session, &do_session,
@@ -149,12 +152,12 @@ int main(int argc, char* argv[])
" websocket-server-coro-ssl 0.0.0.0 8080 1\n"; " websocket-server-coro-ssl 0.0.0.0 8080 1\n";
return EXIT_FAILURE; return EXIT_FAILURE;
} }
auto const address = boost::asio::ip::make_address(argv[1]); auto const address = net::ip::make_address(argv[1]);
auto const port = static_cast<unsigned short>(std::atoi(argv[2])); auto const port = static_cast<unsigned short>(std::atoi(argv[2]));
auto const threads = std::max<int>(1, std::atoi(argv[3])); auto const threads = std::max<int>(1, std::atoi(argv[3]));
// The io_context is required for all I/O // The io_context is required for all I/O
boost::asio::io_context ioc{threads}; net::io_context ioc{threads};
// The SSL context is required, and holds certificates // The SSL context is required, and holds certificates
ssl::context ctx{ssl::context::sslv23}; ssl::context ctx{ssl::context::sslv23};
@@ -163,7 +166,7 @@ int main(int argc, char* argv[])
load_server_certificate(ctx); load_server_certificate(ctx);
// Spawn a listening port // Spawn a listening port
boost::asio::spawn(ioc, net::spawn(ioc,
std::bind( std::bind(
&do_listen, &do_listen,
std::ref(ioc), std::ref(ioc),

View File

@@ -26,23 +26,26 @@
#include <thread> #include <thread>
#include <vector> #include <vector>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp> namespace beast = boost::beast; // from <boost/beast.hpp>
namespace websocket = boost::beast::websocket; // from <boost/beast/websocket.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 // Report a failure
void void
fail(boost::system::error_code ec, char const* what) fail(beast::error_code ec, char const* what)
{ {
std::cerr << what << ": " << ec.message() << "\n"; std::cerr << what << ": " << ec.message() << "\n";
} }
// Echoes back all received WebSocket messages // Echoes back all received WebSocket messages
void void
do_session(tcp::socket& socket, boost::asio::yield_context yield) do_session(tcp::socket& socket, net::yield_context yield)
{ {
boost::system::error_code ec; beast::error_code ec;
// Construct the stream by moving in the socket // Construct the stream by moving in the socket
websocket::stream<tcp::socket> ws{std::move(socket)}; websocket::stream<tcp::socket> ws{std::move(socket)};
@@ -55,7 +58,7 @@ do_session(tcp::socket& socket, boost::asio::yield_context yield)
for(;;) for(;;)
{ {
// This buffer will hold the incoming message // This buffer will hold the incoming message
boost::beast::multi_buffer buffer; beast::multi_buffer buffer;
// Read a message // Read a message
ws.async_read(buffer, yield[ec]); ws.async_read(buffer, yield[ec]);
@@ -80,11 +83,11 @@ do_session(tcp::socket& socket, boost::asio::yield_context yield)
// Accepts incoming connections and launches the sessions // Accepts incoming connections and launches the sessions
void void
do_listen( do_listen(
boost::asio::io_context& ioc, net::io_context& ioc,
tcp::endpoint endpoint, tcp::endpoint endpoint,
boost::asio::yield_context yield) net::yield_context yield)
{ {
boost::system::error_code ec; beast::error_code ec;
// Open the acceptor // Open the acceptor
tcp::acceptor acceptor(ioc); tcp::acceptor acceptor(ioc);
@@ -93,7 +96,7 @@ do_listen(
return fail(ec, "open"); return fail(ec, "open");
// Allow address reuse // Allow address reuse
acceptor.set_option(boost::asio::socket_base::reuse_address(true), ec); acceptor.set_option(net::socket_base::reuse_address(true), ec);
if(ec) if(ec)
return fail(ec, "set_option"); return fail(ec, "set_option");
@@ -103,7 +106,7 @@ do_listen(
return fail(ec, "bind"); return fail(ec, "bind");
// Start listening for connections // Start listening for connections
acceptor.listen(boost::asio::socket_base::max_listen_connections, ec); acceptor.listen(net::socket_base::max_listen_connections, ec);
if(ec) if(ec)
return fail(ec, "listen"); return fail(ec, "listen");
@@ -114,7 +117,7 @@ do_listen(
if(ec) if(ec)
fail(ec, "accept"); fail(ec, "accept");
else else
boost::asio::spawn( net::spawn(
acceptor.get_executor().context(), acceptor.get_executor().context(),
std::bind( std::bind(
&do_session, &do_session,
@@ -134,15 +137,15 @@ int main(int argc, char* argv[])
" websocket-server-coro 0.0.0.0 8080 1\n"; " websocket-server-coro 0.0.0.0 8080 1\n";
return EXIT_FAILURE; return EXIT_FAILURE;
} }
auto const address = boost::asio::ip::make_address(argv[1]); auto const address = net::ip::make_address(argv[1]);
auto const port = static_cast<unsigned short>(std::atoi(argv[2])); auto const port = static_cast<unsigned short>(std::atoi(argv[2]));
auto const threads = std::max<int>(1, std::atoi(argv[3])); auto const threads = std::max<int>(1, std::atoi(argv[3]));
// The io_context is required for all I/O // The io_context is required for all I/O
boost::asio::io_context ioc{threads}; net::io_context ioc{threads};
// Spawn a listening port // Spawn a listening port
boost::asio::spawn(ioc, net::spawn(ioc,
std::bind( std::bind(
&do_listen, &do_listen,
std::ref(ioc), std::ref(ioc),

View File

@@ -43,15 +43,17 @@
#include <thread> #include <thread>
#include <vector> #include <vector>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp> namespace beast = boost::beast; // from <boost/beast.hpp>
namespace http = boost::beast::http; // from <boost/beast/http.hpp> namespace http = beast::http; // from <boost/beast/http.hpp>
namespace websocket = boost::beast::websocket; // from <boost/beast/websocket.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 // Report a failure
void void
fail(boost::system::error_code ec, char const* what) fail(beast::error_code ec, char const* what)
{ {
std::cerr << (std::string(what) + ": " + ec.message() + "\n"); std::cerr << (std::string(what) + ": " + ec.message() + "\n");
} }
@@ -81,7 +83,7 @@ setup_stream(websocket::stream<NextLayer>& ws)
void void
do_sync_session(tcp::socket& socket) do_sync_session(tcp::socket& socket)
{ {
boost::system::error_code ec; beast::error_code ec;
websocket::stream<tcp::socket> ws{std::move(socket)}; websocket::stream<tcp::socket> ws{std::move(socket)};
setup_stream(ws); setup_stream(ws);
@@ -98,7 +100,7 @@ do_sync_session(tcp::socket& socket)
for(;;) for(;;)
{ {
boost::beast::multi_buffer buffer; beast::multi_buffer buffer;
ws.read(buffer, ec); ws.read(buffer, ec);
if(ec == websocket::error::closed) if(ec == websocket::error::closed)
@@ -114,10 +116,10 @@ do_sync_session(tcp::socket& socket)
void void
do_sync_listen( do_sync_listen(
boost::asio::io_context& ioc, net::io_context& ioc,
tcp::endpoint endpoint) tcp::endpoint endpoint)
{ {
boost::system::error_code ec; beast::error_code ec;
tcp::acceptor acceptor{ioc, endpoint}; tcp::acceptor acceptor{ioc, endpoint};
for(;;) for(;;)
{ {
@@ -139,9 +141,9 @@ do_sync_listen(
class async_session : public std::enable_shared_from_this<async_session> class async_session : public std::enable_shared_from_this<async_session>
{ {
websocket::stream<tcp::socket> ws_; websocket::stream<tcp::socket> ws_;
boost::asio::strand< net::strand<
boost::asio::io_context::executor_type> strand_; net::io_context::executor_type> strand_;
boost::beast::multi_buffer buffer_; beast::multi_buffer buffer_;
public: public:
// Take ownership of the socket // Take ownership of the socket
@@ -164,7 +166,7 @@ public:
res.set(http::field::server, res.set(http::field::server,
"Boost.Beast/" + std::to_string(BOOST_BEAST_VERSION) + "-Async"); "Boost.Beast/" + std::to_string(BOOST_BEAST_VERSION) + "-Async");
}, },
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&async_session::on_accept, &async_session::on_accept,
@@ -173,7 +175,7 @@ public:
} }
void void
on_accept(boost::system::error_code ec) on_accept(beast::error_code ec)
{ {
if(ec) if(ec)
return fail(ec, "accept"); return fail(ec, "accept");
@@ -188,7 +190,7 @@ public:
// Read a message into our buffer // Read a message into our buffer
ws_.async_read( ws_.async_read(
buffer_, buffer_,
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&async_session::on_read, &async_session::on_read,
@@ -199,7 +201,7 @@ public:
void void
on_read( on_read(
boost::system::error_code ec, beast::error_code ec,
std::size_t bytes_transferred) std::size_t bytes_transferred)
{ {
boost::ignore_unused(bytes_transferred); boost::ignore_unused(bytes_transferred);
@@ -215,7 +217,7 @@ public:
ws_.text(ws_.got_text()); ws_.text(ws_.got_text());
ws_.async_write( ws_.async_write(
buffer_.data(), buffer_.data(),
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&async_session::on_write, &async_session::on_write,
@@ -226,7 +228,7 @@ public:
void void
on_write( on_write(
boost::system::error_code ec, beast::error_code ec,
std::size_t bytes_transferred) std::size_t bytes_transferred)
{ {
boost::ignore_unused(bytes_transferred); boost::ignore_unused(bytes_transferred);
@@ -245,20 +247,20 @@ public:
// Accepts incoming connections and launches the sessions // Accepts incoming connections and launches the sessions
class async_listener : public std::enable_shared_from_this<async_listener> class async_listener : public std::enable_shared_from_this<async_listener>
{ {
boost::asio::strand< net::strand<
boost::asio::io_context::executor_type> strand_; net::io_context::executor_type> strand_;
tcp::acceptor acceptor_; tcp::acceptor acceptor_;
tcp::socket socket_; tcp::socket socket_;
public: public:
async_listener( async_listener(
boost::asio::io_context& ioc, net::io_context& ioc,
tcp::endpoint endpoint) tcp::endpoint endpoint)
: strand_(ioc.get_executor()) : strand_(ioc.get_executor())
, acceptor_(ioc) , acceptor_(ioc)
, socket_(ioc) , socket_(ioc)
{ {
boost::system::error_code ec; beast::error_code ec;
// Open the acceptor // Open the acceptor
acceptor_.open(endpoint.protocol(), ec); acceptor_.open(endpoint.protocol(), ec);
@@ -269,7 +271,7 @@ public:
} }
// Allow address reuse // Allow address reuse
acceptor_.set_option(boost::asio::socket_base::reuse_address(true), ec); acceptor_.set_option(net::socket_base::reuse_address(true), ec);
if(ec) if(ec)
{ {
fail(ec, "set_option"); fail(ec, "set_option");
@@ -286,7 +288,7 @@ public:
// Start listening for connections // Start listening for connections
acceptor_.listen( acceptor_.listen(
boost::asio::socket_base::max_listen_connections, ec); net::socket_base::max_listen_connections, ec);
if(ec) if(ec)
{ {
fail(ec, "listen"); fail(ec, "listen");
@@ -308,7 +310,7 @@ public:
{ {
acceptor_.async_accept( acceptor_.async_accept(
socket_, socket_,
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&async_listener::on_accept, &async_listener::on_accept,
@@ -317,7 +319,7 @@ public:
} }
void void
on_accept(boost::system::error_code ec) on_accept(beast::error_code ec)
{ {
if(ec) if(ec)
{ {
@@ -337,9 +339,9 @@ public:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void void
do_coro_session(tcp::socket& socket, boost::asio::yield_context yield) do_coro_session(tcp::socket& socket, net::yield_context yield)
{ {
boost::system::error_code ec; beast::error_code ec;
websocket::stream<tcp::socket> ws{std::move(socket)}; websocket::stream<tcp::socket> ws{std::move(socket)};
setup_stream(ws); setup_stream(ws);
@@ -356,7 +358,7 @@ do_coro_session(tcp::socket& socket, boost::asio::yield_context yield)
for(;;) for(;;)
{ {
boost::beast::multi_buffer buffer; beast::multi_buffer buffer;
ws.async_read(buffer, yield[ec]); ws.async_read(buffer, yield[ec]);
if(ec == websocket::error::closed) if(ec == websocket::error::closed)
@@ -373,18 +375,18 @@ do_coro_session(tcp::socket& socket, boost::asio::yield_context yield)
void void
do_coro_listen( do_coro_listen(
boost::asio::io_context& ioc, net::io_context& ioc,
tcp::endpoint endpoint, tcp::endpoint endpoint,
boost::asio::yield_context yield) net::yield_context yield)
{ {
boost::system::error_code ec; beast::error_code ec;
tcp::acceptor acceptor(ioc); tcp::acceptor acceptor(ioc);
acceptor.open(endpoint.protocol(), ec); acceptor.open(endpoint.protocol(), ec);
if(ec) if(ec)
return fail(ec, "open"); return fail(ec, "open");
acceptor.set_option(boost::asio::socket_base::reuse_address(true), ec); acceptor.set_option(net::socket_base::reuse_address(true), ec);
if(ec) if(ec)
return fail(ec, "set_option"); return fail(ec, "set_option");
@@ -392,7 +394,7 @@ do_coro_listen(
if(ec) if(ec)
return fail(ec, "bind"); return fail(ec, "bind");
acceptor.listen(boost::asio::socket_base::max_listen_connections, ec); acceptor.listen(net::socket_base::max_listen_connections, ec);
if(ec) if(ec)
return fail(ec, "listen"); return fail(ec, "listen");
@@ -407,7 +409,7 @@ do_coro_listen(
continue; continue;
} }
boost::asio::spawn( net::spawn(
acceptor.get_executor().context(), acceptor.get_executor().context(),
std::bind( std::bind(
&do_coro_session, &do_coro_session,
@@ -433,12 +435,12 @@ int main(int argc, char* argv[])
" starting-port+2 for coroutine.\n"; " starting-port+2 for coroutine.\n";
return EXIT_FAILURE; return EXIT_FAILURE;
} }
auto const address = boost::asio::ip::make_address(argv[1]); auto const address = net::ip::make_address(argv[1]);
auto const port = static_cast<unsigned short>(std::atoi(argv[2])); auto const port = static_cast<unsigned short>(std::atoi(argv[2]));
auto const threads = std::max<int>(1, std::atoi(argv[3])); auto const threads = std::max<int>(1, std::atoi(argv[3]));
// The io_context is required for all I/O // The io_context is required for all I/O
boost::asio::io_context ioc{threads}; net::io_context ioc{threads};
// Create sync port // Create sync port
std::thread(std::bind( std::thread(std::bind(
@@ -457,7 +459,7 @@ int main(int argc, char* argv[])
static_cast<unsigned short>(port + 1u)})->run(); static_cast<unsigned short>(port + 1u)})->run();
// Create coro port // Create coro port
boost::asio::spawn(ioc, net::spawn(ioc,
std::bind( std::bind(
&do_coro_listen, &do_coro_listen,
std::ref(ioc), std::ref(ioc),

View File

@@ -32,29 +32,32 @@
#include <thread> #include <thread>
#include <vector> #include <vector>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp> namespace beast = boost::beast; // from <boost/beast.hpp>
namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp> namespace http = beast::http; // from <boost/beast/http.hpp>
namespace websocket = boost::beast::websocket; // from <boost/beast/websocket.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 // Report a failure
void void
fail(boost::system::error_code ec, char const* what) fail(beast::error_code ec, char const* what)
{ {
std::cerr << what << ": " << ec.message() << "\n"; std::cerr << what << ": " << ec.message() << "\n";
} }
// Echoes back all received WebSocket messages // Echoes back all received WebSocket messages
class session class session
: public boost::asio::coroutine : public net::coroutine
, public std::enable_shared_from_this<session> , public std::enable_shared_from_this<session>
{ {
tcp::socket socket_; tcp::socket socket_;
websocket::stream<ssl::stream<tcp::socket&>> ws_; websocket::stream<ssl::stream<tcp::socket&>> ws_;
boost::asio::strand< net::strand<
boost::asio::io_context::executor_type> strand_; net::io_context::executor_type> strand_;
boost::beast::multi_buffer buffer_; beast::multi_buffer buffer_;
public: public:
// Take ownership of the socket // Take ownership of the socket
@@ -75,7 +78,7 @@ public:
#include <boost/asio/yield.hpp> #include <boost/asio/yield.hpp>
void void
loop( loop(
boost::system::error_code ec, beast::error_code ec,
std::size_t bytes_transferred) std::size_t bytes_transferred)
{ {
boost::ignore_unused(bytes_transferred); boost::ignore_unused(bytes_transferred);
@@ -85,7 +88,7 @@ public:
// Perform the SSL handshake // Perform the SSL handshake
yield ws_.next_layer().async_handshake( yield ws_.next_layer().async_handshake(
ssl::stream_base::server, ssl::stream_base::server,
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&session::loop, &session::loop,
@@ -97,7 +100,7 @@ public:
// Accept the websocket handshake // Accept the websocket handshake
yield ws_.async_accept( yield ws_.async_accept(
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&session::loop, &session::loop,
@@ -112,7 +115,7 @@ public:
// Read a message into our buffer // Read a message into our buffer
yield ws_.async_read( yield ws_.async_read(
buffer_, buffer_,
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&session::loop, &session::loop,
@@ -131,7 +134,7 @@ public:
ws_.text(ws_.got_text()); ws_.text(ws_.got_text());
yield ws_.async_write( yield ws_.async_write(
buffer_.data(), buffer_.data(),
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&session::loop, &session::loop,
@@ -153,7 +156,7 @@ public:
// Accepts incoming connections and launches the sessions // Accepts incoming connections and launches the sessions
class listener class listener
: public boost::asio::coroutine : public net::coroutine
, public std::enable_shared_from_this<listener> , public std::enable_shared_from_this<listener>
{ {
ssl::context& ctx_; ssl::context& ctx_;
@@ -162,14 +165,14 @@ class listener
public: public:
listener( listener(
boost::asio::io_context& ioc, net::io_context& ioc,
ssl::context& ctx, ssl::context& ctx,
tcp::endpoint endpoint) tcp::endpoint endpoint)
: ctx_(ctx) : ctx_(ctx)
, acceptor_(ioc) , acceptor_(ioc)
, socket_(ioc) , socket_(ioc)
{ {
boost::system::error_code ec; beast::error_code ec;
// Open the acceptor // Open the acceptor
acceptor_.open(endpoint.protocol(), ec); acceptor_.open(endpoint.protocol(), ec);
@@ -180,7 +183,7 @@ public:
} }
// Allow address reuse // Allow address reuse
acceptor_.set_option(boost::asio::socket_base::reuse_address(true), ec); acceptor_.set_option(net::socket_base::reuse_address(true), ec);
if(ec) if(ec)
{ {
fail(ec, "set_option"); fail(ec, "set_option");
@@ -197,7 +200,7 @@ public:
// Start listening for connections // Start listening for connections
acceptor_.listen( acceptor_.listen(
boost::asio::socket_base::max_listen_connections, ec); net::socket_base::max_listen_connections, ec);
if(ec) if(ec)
{ {
fail(ec, "listen"); fail(ec, "listen");
@@ -216,7 +219,7 @@ public:
#include <boost/asio/yield.hpp> #include <boost/asio/yield.hpp>
void void
loop(boost::system::error_code ec = {}) loop(beast::error_code ec = {})
{ {
reenter(*this) reenter(*this)
{ {
@@ -256,12 +259,12 @@ int main(int argc, char* argv[])
" websocket-server-async-ssl 0.0.0.0 8080 1\n"; " websocket-server-async-ssl 0.0.0.0 8080 1\n";
return EXIT_FAILURE; return EXIT_FAILURE;
} }
auto const address = boost::asio::ip::make_address(argv[1]); auto const address = net::ip::make_address(argv[1]);
auto const port = static_cast<unsigned short>(std::atoi(argv[2])); auto const port = static_cast<unsigned short>(std::atoi(argv[2]));
auto const threads = std::max<int>(1, std::atoi(argv[3])); auto const threads = std::max<int>(1, std::atoi(argv[3]));
// The io_context is required for all I/O // The io_context is required for all I/O
boost::asio::io_context ioc{threads}; net::io_context ioc{threads};
// The SSL context is required, and holds certificates // The SSL context is required, and holds certificates
ssl::context ctx{ssl::context::sslv23}; ssl::context ctx{ssl::context::sslv23};

View File

@@ -28,27 +28,30 @@
#include <thread> #include <thread>
#include <vector> #include <vector>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp> namespace beast = boost::beast; // from <boost/beast.hpp>
namespace websocket = boost::beast::websocket; // from <boost/beast/websocket.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 // Report a failure
void void
fail(boost::system::error_code ec, char const* what) fail(beast::error_code ec, char const* what)
{ {
std::cerr << what << ": " << ec.message() << "\n"; std::cerr << what << ": " << ec.message() << "\n";
} }
// Echoes back all received WebSocket messages // Echoes back all received WebSocket messages
class session class session
: public boost::asio::coroutine : public net::coroutine
, public std::enable_shared_from_this<session> , public std::enable_shared_from_this<session>
{ {
websocket::stream<tcp::socket> ws_; websocket::stream<tcp::socket> ws_;
boost::asio::strand< net::strand<
boost::asio::io_context::executor_type> strand_; net::io_context::executor_type> strand_;
boost::beast::multi_buffer buffer_; beast::multi_buffer buffer_;
public: public:
// Take ownership of the socket // Take ownership of the socket
@@ -69,7 +72,7 @@ public:
#include <boost/asio/yield.hpp> #include <boost/asio/yield.hpp>
void void
loop( loop(
boost::system::error_code ec, beast::error_code ec,
std::size_t bytes_transferred) std::size_t bytes_transferred)
{ {
boost::ignore_unused(bytes_transferred); boost::ignore_unused(bytes_transferred);
@@ -77,7 +80,7 @@ public:
{ {
// Accept the websocket handshake // Accept the websocket handshake
yield ws_.async_accept( yield ws_.async_accept(
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&session::loop, &session::loop,
@@ -92,7 +95,7 @@ public:
// Read a message into our buffer // Read a message into our buffer
yield ws_.async_read( yield ws_.async_read(
buffer_, buffer_,
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&session::loop, &session::loop,
@@ -111,7 +114,7 @@ public:
ws_.text(ws_.got_text()); ws_.text(ws_.got_text());
yield ws_.async_write( yield ws_.async_write(
buffer_.data(), buffer_.data(),
boost::asio::bind_executor( net::bind_executor(
strand_, strand_,
std::bind( std::bind(
&session::loop, &session::loop,
@@ -133,7 +136,7 @@ public:
// Accepts incoming connections and launches the sessions // Accepts incoming connections and launches the sessions
class listener class listener
: public boost::asio::coroutine : public net::coroutine
, public std::enable_shared_from_this<listener> , public std::enable_shared_from_this<listener>
{ {
tcp::acceptor acceptor_; tcp::acceptor acceptor_;
@@ -141,12 +144,12 @@ class listener
public: public:
listener( listener(
boost::asio::io_context& ioc, net::io_context& ioc,
tcp::endpoint endpoint) tcp::endpoint endpoint)
: acceptor_(ioc) : acceptor_(ioc)
, socket_(ioc) , socket_(ioc)
{ {
boost::system::error_code ec; beast::error_code ec;
// Open the acceptor // Open the acceptor
acceptor_.open(endpoint.protocol(), ec); acceptor_.open(endpoint.protocol(), ec);
@@ -157,7 +160,7 @@ public:
} }
// Allow address reuse // Allow address reuse
acceptor_.set_option(boost::asio::socket_base::reuse_address(true), ec); acceptor_.set_option(net::socket_base::reuse_address(true), ec);
if(ec) if(ec)
{ {
fail(ec, "set_option"); fail(ec, "set_option");
@@ -174,7 +177,7 @@ public:
// Start listening for connections // Start listening for connections
acceptor_.listen( acceptor_.listen(
boost::asio::socket_base::max_listen_connections, ec); net::socket_base::max_listen_connections, ec);
if(ec) if(ec)
{ {
fail(ec, "listen"); fail(ec, "listen");
@@ -193,7 +196,7 @@ public:
#include <boost/asio/yield.hpp> #include <boost/asio/yield.hpp>
void void
loop(boost::system::error_code ec = {}) loop(beast::error_code ec = {})
{ {
reenter(*this) reenter(*this)
{ {
@@ -233,12 +236,12 @@ int main(int argc, char* argv[])
" websocket-server-stackless 0.0.0.0 8080 1\n"; " websocket-server-stackless 0.0.0.0 8080 1\n";
return EXIT_FAILURE; return EXIT_FAILURE;
} }
auto const address = boost::asio::ip::make_address(argv[1]); auto const address = net::ip::make_address(argv[1]);
auto const port = static_cast<unsigned short>(std::atoi(argv[2])); auto const port = static_cast<unsigned short>(std::atoi(argv[2]));
auto const threads = std::max<int>(1, std::atoi(argv[3])); auto const threads = std::max<int>(1, std::atoi(argv[3]));
// The io_context is required for all I/O // The io_context is required for all I/O
boost::asio::io_context ioc{threads}; net::io_context ioc{threads};
// Create and launch a listening port // Create and launch a listening port
std::make_shared<listener>(ioc, tcp::endpoint{address, port})->run(); std::make_shared<listener>(ioc, tcp::endpoint{address, port})->run();

View File

@@ -26,9 +26,12 @@
#include <string> #include <string>
#include <thread> #include <thread>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp> namespace beast = boost::beast; // from <boost/beast.hpp>
namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp> namespace http = beast::http; // from <boost/beast/http.hpp>
namespace websocket = boost::beast::websocket; // from <boost/beast/websocket.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>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -50,7 +53,7 @@ do_session(tcp::socket& socket, ssl::context& ctx)
for(;;) for(;;)
{ {
// This buffer will hold the incoming message // This buffer will hold the incoming message
boost::beast::multi_buffer buffer; beast::multi_buffer buffer;
// Read a message // Read a message
ws.read(buffer); ws.read(buffer);
@@ -60,7 +63,7 @@ do_session(tcp::socket& socket, ssl::context& ctx)
ws.write(buffer.data()); ws.write(buffer.data());
} }
} }
catch(boost::system::system_error const& se) catch(beast::system_error const& se)
{ {
// This indicates that the session was closed // This indicates that the session was closed
if(se.code() != websocket::error::closed) if(se.code() != websocket::error::closed)
@@ -87,11 +90,11 @@ int main(int argc, char* argv[])
" websocket-server-sync-ssl 0.0.0.0 8080\n"; " websocket-server-sync-ssl 0.0.0.0 8080\n";
return EXIT_FAILURE; return EXIT_FAILURE;
} }
auto const address = boost::asio::ip::make_address(argv[1]); auto const address = net::ip::make_address(argv[1]);
auto const port = static_cast<unsigned short>(std::atoi(argv[2])); auto const port = static_cast<unsigned short>(std::atoi(argv[2]));
// The io_context is required for all I/O // The io_context is required for all I/O
boost::asio::io_context ioc{1}; net::io_context ioc{1};
// The SSL context is required, and holds certificates // The SSL context is required, and holds certificates
ssl::context ctx{ssl::context::sslv23}; ssl::context ctx{ssl::context::sslv23};

View File

@@ -22,8 +22,11 @@
#include <string> #include <string>
#include <thread> #include <thread>
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp> namespace beast = boost::beast; // from <boost/beast.hpp>
namespace websocket = boost::beast::websocket; // from <boost/beast/websocket.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>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -42,7 +45,7 @@ do_session(tcp::socket& socket)
for(;;) for(;;)
{ {
// This buffer will hold the incoming message // This buffer will hold the incoming message
boost::beast::multi_buffer buffer; beast::multi_buffer buffer;
// Read a message // Read a message
ws.read(buffer); ws.read(buffer);
@@ -52,7 +55,7 @@ do_session(tcp::socket& socket)
ws.write(buffer.data()); ws.write(buffer.data());
} }
} }
catch(boost::system::system_error const& se) catch(beast::system_error const& se)
{ {
// This indicates that the session was closed // This indicates that the session was closed
if(se.code() != websocket::error::closed) if(se.code() != websocket::error::closed)
@@ -79,11 +82,11 @@ int main(int argc, char* argv[])
" websocket-server-sync 0.0.0.0 8080\n"; " websocket-server-sync 0.0.0.0 8080\n";
return EXIT_FAILURE; return EXIT_FAILURE;
} }
auto const address = boost::asio::ip::make_address(argv[1]); auto const address = net::ip::make_address(argv[1]);
auto const port = static_cast<unsigned short>(std::atoi(argv[2])); auto const port = static_cast<unsigned short>(std::atoi(argv[2]));
// The io_context is required for all I/O // The io_context is required for all I/O
boost::asio::io_context ioc{1}; net::io_context ioc{1};
// The acceptor receives incoming connections // The acceptor receives incoming connections
tcp::acceptor acceptor{ioc, {address, port}}; tcp::acceptor acceptor{ioc, {address, port}};

View File

@@ -32,11 +32,11 @@ public:
coalesce(BufferSequence const& buffers, std::size_t limit) coalesce(BufferSequence const& buffers, std::size_t limit)
{ {
std::pair<std::size_t, bool> result{0, false}; std::pair<std::size_t, bool> result{0, false};
auto first = boost::asio::buffer_sequence_begin(buffers); auto first = net::buffer_sequence_begin(buffers);
auto last = boost::asio::buffer_sequence_end(buffers); auto last = net::buffer_sequence_end(buffers);
if(first != last) if(first != last)
{ {
result.first = boost::asio::buffer_size(*first); result.first = net::buffer_size(*first);
if(result.first < limit) if(result.first < limit)
{ {
auto it = first; auto it = first;
@@ -44,7 +44,7 @@ public:
while(++it != last) while(++it != last)
{ {
auto const n = auto const n =
boost::asio::buffer_size(*it); net::buffer_size(*it);
if(result.first + n > limit) if(result.first + n > limit)
break; break;
result.first += n; result.first += n;

View File

@@ -15,7 +15,7 @@ namespace beast {
namespace detail { namespace detail {
timeout_service:: timeout_service::
timeout_service(boost::asio::io_context& ctx) timeout_service(net::io_context& ctx)
: service_base(ctx) : service_base(ctx)
, thunks_(1) // element [0] reserved for "null" , thunks_(1) // element [0] reserved for "null"
, timer_(ctx) , timer_(ctx)
@@ -272,7 +272,7 @@ void
timeout_service:: timeout_service::
on_timer(error_code ec) on_timer(error_code ec)
{ {
if(ec == boost::asio::error::operation_aborted) if(ec == net::error::operation_aborted)
{ {
BOOST_ASSERT(fresh_->empty()); BOOST_ASSERT(fresh_->empty());
BOOST_ASSERT(stale_->empty()); BOOST_ASSERT(stale_->empty());

View File

@@ -17,23 +17,23 @@ namespace beast {
namespace detail { namespace detail {
template<class T> template<class T>
class service_id : public boost::asio::execution_context::id class service_id : public net::execution_context::id
{ {
}; };
template<class T> template<class T>
class service_base class service_base
: public boost::asio::execution_context::service : public net::execution_context::service
{ {
protected: protected:
boost::asio::execution_context& ctx_; net::execution_context& ctx_;
public: public:
static service_id<T> id; static service_id<T> id;
explicit explicit
service_base(boost::asio::execution_context& ctx) service_base(net::execution_context& ctx)
: boost::asio::execution_context::service(ctx) : net::execution_context::service(ctx)
, ctx_(ctx) , ctx_(ctx)
{ {
} }

View File

@@ -45,7 +45,7 @@ class timeout_service
void void
operator()() operator()()
{ {
boost::asio::post(ex, net::post(ex,
beast::bind_front_handler( beast::bind_front_handler(
std::move(*this), 0)); std::move(*this), 0));
} }
@@ -64,7 +64,7 @@ public:
// VFALCO Should be execution_context // VFALCO Should be execution_context
BOOST_BEAST_DECL BOOST_BEAST_DECL
explicit explicit
timeout_service(boost::asio::io_context& ctx); timeout_service(net::io_context& ctx);
BOOST_BEAST_DECL BOOST_BEAST_DECL
timeout_handle timeout_handle
@@ -119,7 +119,7 @@ private:
thunk::list_type* stale_ = &list_[1]; thunk::list_type* stale_ = &list_[1];
std::deque<thunk> thunks_; std::deque<thunk> thunks_;
std::size_t free_thunk_ = 0; std::size_t free_thunk_ = 0;
boost::asio::steady_timer timer_; net::steady_timer timer_;
std::chrono::seconds interval_{30ul}; std::chrono::seconds interval_{30ul};
long pending_ = 0; long pending_ = 0;
}; };

View File

@@ -26,7 +26,7 @@ namespace beast {
This wrapper flattens writes for buffer sequences having length This wrapper flattens writes for buffer sequences having length
greater than 1 and total size below a predefined amount, using greater than 1 and total size below a predefined amount, using
a dynamic memory allocation. It is primarily designed to overcome a dynamic memory allocation. It is primarily designed to overcome
a performance limitation of the current version of `boost::asio::ssl::stream`, a performance limitation of the current version of `net::ssl::stream`,
which does not use OpenSSL's scatter/gather interface for its which does not use OpenSSL's scatter/gather interface for its
low-level read some and write some operations. low-level read some and write some operations.
@@ -49,11 +49,11 @@ namespace beast {
operate on synchronous or asynchronous read or write streams, operate on synchronous or asynchronous read or write streams,
examples include: examples include:
@li `boost::asio::read`, `boost::asio::async_read` @li `net::read`, `net::async_read`
@li `boost::asio::write`, `boost::asio::async_write` @li `net::write`, `net::async_write`
@li `boost::asio::read_until`, `boost::asio::async_read_until` @li `net::read_until`, `net::async_read_until`
The stream may also be used as a template parameter in other The stream may also be used as a template parameter in other
stream wrappers, such as for websocket: stream wrappers, such as for websocket:
@@ -66,7 +66,7 @@ namespace beast {
operations, the type must support the @b SyncStream concept. For operations, the type must support the @b SyncStream concept. For
asynchronous operations, the type must support the @b AsyncStream asynchronous operations, the type must support the @b AsyncStream
concept. This type will usually be some variation of concept. This type will usually be some variation of
`boost::asio::ssl::stream`. `net::ssl::stream`.
@par Concepts @par Concepts
@b AsyncStream @b AsyncStream
@@ -209,7 +209,7 @@ public:
@throws boost::system::system_error Thrown on failure. @throws boost::system::system_error Thrown on failure.
@note The `read_some` operation may not read all of the requested number of @note The `read_some` operation may not read all of the requested number of
bytes. Consider using the function `boost::asio::read` if you need to ensure bytes. Consider using the function `net::read` if you need to ensure
that the requested amount of data is read before the blocking operation that the requested amount of data is read before the blocking operation
completes. completes.
*/ */
@@ -230,7 +230,7 @@ public:
@returns The number of bytes read. @returns The number of bytes read.
@note The `read_some` operation may not read all of the requested number of @note The `read_some` operation may not read all of the requested number of
bytes. Consider using the function `boost::asio::read` if you need to ensure bytes. Consider using the function `net::read` if you need to ensure
that the requested amount of data is read before the blocking operation that the requested amount of data is read before the blocking operation
completes. completes.
*/ */
@@ -259,7 +259,7 @@ public:
); @endcode ); @endcode
@note The `read_some` operation may not read all of the requested number of @note The `read_some` operation may not read all of the requested number of
bytes. Consider using the function `boost::asio::async_read` if you need bytes. Consider using the function `net::async_read` if you need
to ensure that the requested amount of data is read before the asynchronous to ensure that the requested amount of data is read before the asynchronous
operation completes. operation completes.
*/ */
@@ -285,7 +285,7 @@ public:
@throws boost::system::system_error Thrown on failure. @throws boost::system::system_error Thrown on failure.
@note The `write_some` operation may not transmit all of the data to the @note The `write_some` operation may not transmit all of the data to the
peer. Consider using the function `boost::asio::write` if you need to peer. Consider using the function `net::write` if you need to
ensure that all data is written before the blocking operation completes. ensure that all data is written before the blocking operation completes.
*/ */
template<class ConstBufferSequence> template<class ConstBufferSequence>
@@ -305,7 +305,7 @@ public:
@returns The number of bytes written. @returns The number of bytes written.
@note The `write_some` operation may not transmit all of the data to the @note The `write_some` operation may not transmit all of the data to the
peer. Consider using the function `boost::asio::write` if you need to peer. Consider using the function `net::write` if you need to
ensure that all data is written before the blocking operation completes. ensure that all data is written before the blocking operation completes.
*/ */
template<class ConstBufferSequence> template<class ConstBufferSequence>
@@ -333,7 +333,7 @@ public:
); @endcode ); @endcode
@note The `async_write_some` operation may not transmit all of the data to @note The `async_write_some` operation may not transmit all of the data to
the peer. Consider using the function `boost::asio::async_write` if you need the peer. Consider using the function `net::async_write` if you need
to ensure that all data is written before the asynchronous operation completes. to ensure that all data is written before the asynchronous operation completes.
*/ */
template< template<

View File

@@ -25,14 +25,14 @@ namespace beast {
template<class NextLayer> template<class NextLayer>
template<class ConstBufferSequence, class Handler> template<class ConstBufferSequence, class Handler>
class flat_stream<NextLayer>::write_op class flat_stream<NextLayer>::write_op
: public boost::asio::coroutine : public net::coroutine
{ {
using alloc_type = typename using alloc_type = typename
#if defined(BOOST_NO_CXX11_ALLOCATOR) #if defined(BOOST_NO_CXX11_ALLOCATOR)
boost::asio::associated_allocator_t<Handler>::template net::associated_allocator_t<Handler>::template
rebind<char>::other; rebind<char>::other;
#else #else
std::allocator_traits<boost::asio::associated_allocator_t<Handler>> std::allocator_traits<net::associated_allocator_t<Handler>>
::template rebind_alloc<char>; ::template rebind_alloc<char>;
#endif #endif
@@ -68,27 +68,27 @@ public:
: s_(s) : s_(s)
, b_(b) , b_(b)
, p_(nullptr, deleter{ , p_(nullptr, deleter{
(boost::asio::get_associated_allocator)(h)}) (net::get_associated_allocator)(h)})
, h_(std::forward<DeducedHandler>(h)) , h_(std::forward<DeducedHandler>(h))
{ {
} }
using allocator_type = using allocator_type =
boost::asio::associated_allocator_t<Handler>; net::associated_allocator_t<Handler>;
allocator_type allocator_type
get_allocator() const noexcept get_allocator() const noexcept
{ {
return (boost::asio::get_associated_allocator)(h_); return (net::get_associated_allocator)(h_);
} }
using executor_type = boost::asio::associated_executor_t< using executor_type = net::associated_executor_t<
Handler, decltype(std::declval<NextLayer&>().get_executor())>; Handler, decltype(std::declval<NextLayer&>().get_executor())>;
executor_type executor_type
get_executor() const noexcept get_executor() const noexcept
{ {
return (boost::asio::get_associated_executor)( return (net::get_associated_executor)(
h_, s_.get_executor()); h_, s_.get_executor());
} }
@@ -100,7 +100,7 @@ public:
friend friend
bool asio_handler_is_continuation(write_op* op) bool asio_handler_is_continuation(write_op* op)
{ {
using boost::asio::asio_handler_is_continuation; using net::asio_handler_is_continuation;
return asio_handler_is_continuation( return asio_handler_is_continuation(
std::addressof(op->h_)); std::addressof(op->h_));
} }
@@ -109,7 +109,7 @@ public:
friend friend
void asio_handler_invoke(Function&& f, write_op* op) void asio_handler_invoke(Function&& f, write_op* op)
{ {
using boost::asio::asio_handler_invoke; using net::asio_handler_invoke;
asio_handler_invoke(f, std::addressof(op->h_)); asio_handler_invoke(f, std::addressof(op->h_));
} }
}; };
@@ -133,12 +133,12 @@ operator()(
p_.get_deleter().size = result.first; p_.get_deleter().size = result.first;
p_.reset(p_.get_deleter().alloc.allocate( p_.reset(p_.get_deleter().alloc.allocate(
p_.get_deleter().size)); p_.get_deleter().size));
boost::asio::buffer_copy( net::buffer_copy(
boost::asio::buffer( net::buffer(
p_.get(), p_.get_deleter().size), p_.get(), p_.get_deleter().size),
b_, result.first); b_, result.first);
s_.stream_.async_write_some( s_.stream_.async_write_some(
boost::asio::buffer( net::buffer(
p_.get(), p_.get_deleter().size), p_.get(), p_.get_deleter().size),
std::move(*this)); std::move(*this));
} }
@@ -172,7 +172,7 @@ read_some(MutableBufferSequence const& buffers)
{ {
static_assert(boost::beast::is_sync_read_stream<next_layer_type>::value, static_assert(boost::beast::is_sync_read_stream<next_layer_type>::value,
"SyncReadStream requirements not met"); "SyncReadStream requirements not met");
static_assert(boost::asio::is_mutable_buffer_sequence< static_assert(net::is_mutable_buffer_sequence<
MutableBufferSequence>::value, MutableBufferSequence>::value,
"MutableBufferSequence requirements not met"); "MutableBufferSequence requirements not met");
error_code ec; error_code ec;
@@ -204,7 +204,7 @@ async_read_some(
{ {
static_assert(boost::beast::is_async_read_stream<next_layer_type>::value, static_assert(boost::beast::is_async_read_stream<next_layer_type>::value,
"AsyncReadStream requirements not met"); "AsyncReadStream requirements not met");
static_assert(boost::asio::is_mutable_buffer_sequence< static_assert(net::is_mutable_buffer_sequence<
MutableBufferSequence >::value, MutableBufferSequence >::value,
"MutableBufferSequence requirements not met"); "MutableBufferSequence requirements not met");
return stream_.async_read_some( return stream_.async_read_some(
@@ -219,15 +219,15 @@ write_some(ConstBufferSequence const& buffers)
{ {
static_assert(boost::beast::is_sync_write_stream<next_layer_type>::value, static_assert(boost::beast::is_sync_write_stream<next_layer_type>::value,
"SyncWriteStream requirements not met"); "SyncWriteStream requirements not met");
static_assert(boost::asio::is_const_buffer_sequence< static_assert(net::is_const_buffer_sequence<
ConstBufferSequence>::value, ConstBufferSequence>::value,
"ConstBufferSequence requirements not met"); "ConstBufferSequence requirements not met");
auto const result = coalesce(buffers, coalesce_limit); auto const result = coalesce(buffers, coalesce_limit);
if(result.second) if(result.second)
{ {
std::unique_ptr<char[]> p{new char[result.first]}; std::unique_ptr<char[]> p{new char[result.first]};
auto const b = boost::asio::buffer(p.get(), result.first); auto const b = net::buffer(p.get(), result.first);
boost::asio::buffer_copy(b, buffers); net::buffer_copy(b, buffers);
return stream_.write_some(b); return stream_.write_some(b);
} }
return stream_.write_some( return stream_.write_some(
@@ -242,15 +242,15 @@ write_some(ConstBufferSequence const& buffers, error_code& ec)
{ {
static_assert(boost::beast::is_sync_write_stream<next_layer_type>::value, static_assert(boost::beast::is_sync_write_stream<next_layer_type>::value,
"SyncWriteStream requirements not met"); "SyncWriteStream requirements not met");
static_assert(boost::asio::is_const_buffer_sequence< static_assert(net::is_const_buffer_sequence<
ConstBufferSequence>::value, ConstBufferSequence>::value,
"ConstBufferSequence requirements not met"); "ConstBufferSequence requirements not met");
auto const result = coalesce(buffers, coalesce_limit); auto const result = coalesce(buffers, coalesce_limit);
if(result.second) if(result.second)
{ {
std::unique_ptr<char[]> p{new char[result.first]}; std::unique_ptr<char[]> p{new char[result.first]};
auto const b = boost::asio::buffer(p.get(), result.first); auto const b = net::buffer(p.get(), result.first);
boost::asio::buffer_copy(b, buffers); net::buffer_copy(b, buffers);
return stream_.write_some(b, ec); return stream_.write_some(b, ec);
} }
return stream_.write_some( return stream_.write_some(
@@ -270,7 +270,7 @@ async_write_some(
{ {
static_assert(boost::beast::is_async_write_stream<next_layer_type>::value, static_assert(boost::beast::is_async_write_stream<next_layer_type>::value,
"AsyncWriteStream requirements not met"); "AsyncWriteStream requirements not met");
static_assert(boost::asio::is_const_buffer_sequence< static_assert(net::is_const_buffer_sequence<
ConstBufferSequence>::value, ConstBufferSequence>::value,
"ConstBufferSequence requirements not met"); "ConstBufferSequence requirements not met");
BOOST_BEAST_HANDLER_INIT( BOOST_BEAST_HANDLER_INIT(

View File

@@ -18,9 +18,9 @@ namespace boost {
namespace beast { namespace beast {
timeout_handle:: timeout_handle::
timeout_handle(boost::asio::io_context& ioc) timeout_handle(net::io_context& ioc)
: timeout_handle( : timeout_handle(
boost::asio::use_service< net::use_service<
detail::timeout_service>( detail::timeout_service>(
ioc).make_handle()) ioc).make_handle())
{ {
@@ -50,10 +50,10 @@ set_callback(
void void
set_timeout_service_options( set_timeout_service_options(
boost::asio::io_context& ioc, net::io_context& ioc,
std::chrono::seconds interval) std::chrono::seconds interval)
{ {
boost::asio::use_service< net::use_service<
detail::timeout_service>( detail::timeout_service>(
ioc).set_option(interval); ioc).set_option(interval);
} }

View File

@@ -61,30 +61,30 @@ public:
} }
using allocator_type = using allocator_type =
boost::asio::associated_allocator_t<Handler>; net::associated_allocator_t<Handler>;
allocator_type allocator_type
get_allocator() const noexcept get_allocator() const noexcept
{ {
return boost::asio::get_associated_allocator(h_); return net::get_associated_allocator(h_);
} }
using executor_type = using executor_type =
boost::asio::associated_executor_t<Handler, net::associated_executor_t<Handler,
decltype(std::declval<basic_timeout_socket< decltype(std::declval<basic_timeout_socket<
Protocol, Executor>&>().get_executor())>; Protocol, Executor>&>().get_executor())>;
executor_type executor_type
get_executor() const noexcept get_executor() const noexcept
{ {
return boost::asio::get_associated_executor( return net::get_associated_executor(
h_, s_.get_executor()); h_, s_.get_executor());
} }
friend friend
bool asio_handler_is_continuation(async_op* op) bool asio_handler_is_continuation(async_op* op)
{ {
using boost::asio::asio_handler_is_continuation; using net::asio_handler_is_continuation;
return asio_handler_is_continuation( return asio_handler_is_continuation(
std::addressof(op->h_)); std::addressof(op->h_));
} }
@@ -93,7 +93,7 @@ public:
friend friend
void asio_handler_invoke(Function&& f, async_op* op) void asio_handler_invoke(Function&& f, async_op* op)
{ {
using boost::asio::asio_handler_invoke; using net::asio_handler_invoke;
asio_handler_invoke(f, std::addressof(op->h_)); asio_handler_invoke(f, std::addressof(op->h_));
} }
@@ -115,8 +115,8 @@ private:
Handler h_; Handler h_;
basic_timeout_socket& s_; basic_timeout_socket& s_;
timeout_work_guard work_; timeout_work_guard work_;
boost::asio::executor_work_guard<Executor> wg0_; net::executor_work_guard<Executor> wg0_;
boost::asio::executor_work_guard<executor_type> wg1_; net::executor_work_guard<executor_type> wg1_;
detail::saved_handler& saved_; detail::saved_handler& saved_;
}; };
@@ -177,7 +177,7 @@ async_read_some(
MutableBufferSequence const& buffers, MutableBufferSequence const& buffers,
ReadHandler&& handler) ReadHandler&& handler)
{ {
static_assert(boost::asio::is_mutable_buffer_sequence< static_assert(net::is_mutable_buffer_sequence<
MutableBufferSequence>::value, MutableBufferSequence>::value,
"MutableBufferSequence requirements not met"); "MutableBufferSequence requirements not met");
BOOST_BEAST_HANDLER_INIT( BOOST_BEAST_HANDLER_INIT(
@@ -198,7 +198,7 @@ async_write_some(
ConstBufferSequence const& buffers, ConstBufferSequence const& buffers,
WriteHandler&& handler) WriteHandler&& handler)
{ {
static_assert(boost::asio::is_const_buffer_sequence< static_assert(net::is_const_buffer_sequence<
ConstBufferSequence>::value, ConstBufferSequence>::value,
"ConstBufferSequence requirements not met"); "ConstBufferSequence requirements not met");
BOOST_BEAST_HANDLER_INIT( BOOST_BEAST_HANDLER_INIT(
@@ -235,36 +235,36 @@ public:
, wg0_(s_.get_executor()) , wg0_(s_.get_executor())
, wg1_(get_executor()) , wg1_(get_executor())
{ {
boost::asio::async_connect( net::async_connect(
s_.next_layer(), eps, cond, s_.next_layer(), eps, cond,
std::move(*this)); std::move(*this));
} }
using allocator_type = using allocator_type =
boost::asio::associated_allocator_t<Handler>; net::associated_allocator_t<Handler>;
allocator_type allocator_type
get_allocator() const noexcept get_allocator() const noexcept
{ {
return boost::asio::get_associated_allocator(h_); return net::get_associated_allocator(h_);
} }
using executor_type = using executor_type =
boost::asio::associated_executor_t<Handler, net::associated_executor_t<Handler,
decltype(std::declval<basic_timeout_socket< decltype(std::declval<basic_timeout_socket<
Protocol, Executor>&>().get_executor())>; Protocol, Executor>&>().get_executor())>;
executor_type executor_type
get_executor() const noexcept get_executor() const noexcept
{ {
return boost::asio::get_associated_executor( return net::get_associated_executor(
h_, s_.get_executor()); h_, s_.get_executor());
} }
friend friend
bool asio_handler_is_continuation(connect_op* op) bool asio_handler_is_continuation(connect_op* op)
{ {
using boost::asio::asio_handler_is_continuation; using net::asio_handler_is_continuation;
return asio_handler_is_continuation( return asio_handler_is_continuation(
std::addressof(op->h_)); std::addressof(op->h_));
} }
@@ -273,7 +273,7 @@ public:
friend friend
void asio_handler_invoke(Function&& f, connect_op* op) void asio_handler_invoke(Function&& f, connect_op* op)
{ {
using boost::asio::asio_handler_invoke; using net::asio_handler_invoke;
asio_handler_invoke(f, std::addressof(op->h_)); asio_handler_invoke(f, std::addressof(op->h_));
} }
@@ -296,8 +296,8 @@ private:
Handler h_; Handler h_;
timeout_work_guard work_; timeout_work_guard work_;
basic_timeout_socket<Protocol, Executor>& s_; basic_timeout_socket<Protocol, Executor>& s_;
boost::asio::executor_work_guard<Executor> wg0_; net::executor_work_guard<Executor> wg0_;
boost::asio::executor_work_guard<executor_type> wg1_; net::executor_work_guard<executor_type> wg1_;
}; };
struct any_endpoint struct any_endpoint

View File

@@ -37,14 +37,14 @@ namespace beast {
strand. strand.
@par Example @par Example
To use this template with a `boost::asio::ip::tcp::socket`, you would write: To use this template with a `net::ip::tcp::socket`, you would write:
@code @code
boost::asio::io_context ioc; net::io_context ioc;
boost::asio::ssl::context ctx{boost::asio::ssl::context::sslv23}; net::ssl::context ctx{net::ssl::context::sslv23};
boost::beast::ssl_stream<boost::asio:ip::tcp::socket> sock{ioc, ctx}; boost::beast::ssl_stream<net:ip::tcp::socket> sock{ioc, ctx};
@endcode @endcode
In addition to providing an interface identical to `boost::asio::ssl::stream`, In addition to providing an interface identical to `net::ssl::stream`,
the wrapper has the following additional properties: the wrapper has the following additional properties:
@li Satisfies @b MoveConstructible @li Satisfies @b MoveConstructible
@@ -54,7 +54,7 @@ namespace beast {
@li Constructible from a moved socket. @li Constructible from a moved socket.
@li Uses @ref flat_stream internally, as a performance work-around for a @li Uses @ref flat_stream internally, as a performance work-around for a
limitation of `boost::asio::ssl::stream` when writing buffer sequences limitation of `net::ssl::stream` when writing buffer sequences
having length greater than one. having length greater than one.
@par Concepts: @par Concepts:
@@ -66,9 +66,9 @@ namespace beast {
*/ */
template<class NextLayer> template<class NextLayer>
class ssl_stream class ssl_stream
: public boost::asio::ssl::stream_base : public net::ssl::stream_base
{ {
using ssl_stream_type = boost::asio::ssl::stream<NextLayer>; using ssl_stream_type = net::ssl::stream<NextLayer>;
using stream_type = boost::beast::flat_stream<ssl_stream_type>; using stream_type = boost::beast::flat_stream<ssl_stream_type>;
std::unique_ptr<stream_type> p_; std::unique_ptr<stream_type> p_;
@@ -102,7 +102,7 @@ public:
template<class Arg> template<class Arg>
ssl_stream( ssl_stream(
Arg&& arg, Arg&& arg,
boost::asio::ssl::context& ctx) net::ssl::context& ctx)
: p_(new stream_type{ : p_(new stream_type{
std::forward<Arg>(arg), ctx}) std::forward<Arg>(arg), ctx})
{ {
@@ -132,7 +132,7 @@ public:
suitable for passing to functions such as @c SSL_get_verify_result and suitable for passing to functions such as @c SSL_get_verify_result and
@c SSL_get_peer_certificate: @c SSL_get_peer_certificate:
@code @code
boost::beast::ssl_stream<boost::asio:ip::tcp::socket> ss{ioc, ctx}; boost::beast::ssl_stream<net::ip::tcp::socket> ss{ioc, ctx};
// ... establish connection and perform handshake ... // ... establish connection and perform handshake ...
@@ -225,7 +225,7 @@ public:
@note Calls @c SSL_set_verify. @note Calls @c SSL_set_verify.
*/ */
void void
set_verify_mode(boost::asio::ssl::verify_mode v) set_verify_mode(net::ssl::verify_mode v)
{ {
p_->next_layer().set_verify_mode(v); p_->next_layer().set_verify_mode(v);
} }
@@ -243,7 +243,7 @@ public:
@note Calls @c SSL_set_verify. @note Calls @c SSL_set_verify.
*/ */
void void
set_verify_mode(boost::asio::ssl::verify_mode v, set_verify_mode(net::ssl::verify_mode v,
boost::system::error_code& ec) boost::system::error_code& ec)
{ {
p_->next_layer().set_verify_mode(v, ec); p_->next_layer().set_verify_mode(v, ec);
@@ -320,7 +320,7 @@ public:
The function signature of the handler must be: The function signature of the handler must be:
@code bool verify_callback( @code bool verify_callback(
bool preverified, // True if the certificate passed pre-verification. bool preverified, // True if the certificate passed pre-verification.
boost::asio::verify_context& ctx // The peer certificate and other context. net::verify_context& ctx // The peer certificate and other context.
); @endcode ); @endcode
The return value of the callback is true if the certificate has passed The return value of the callback is true if the certificate has passed
verification, false otherwise. verification, false otherwise.
@@ -527,7 +527,7 @@ public:
@throws boost::system::system_error Thrown on failure. @throws boost::system::system_error Thrown on failure.
@note The `write_some` operation may not transmit all of the data to the @note The `write_some` operation may not transmit all of the data to the
peer. Consider using the `boost::asio::write` function if you need to peer. Consider using the `net::write` function if you need to
ensure that all data is written before the blocking operation completes. ensure that all data is written before the blocking operation completes.
*/ */
template<class ConstBufferSequence> template<class ConstBufferSequence>
@@ -550,7 +550,7 @@ public:
@returns The number of bytes written. Returns 0 if an error occurred. @returns The number of bytes written. Returns 0 if an error occurred.
@note The `write_some` operation may not transmit all of the data to the @note The `write_some` operation may not transmit all of the data to the
peer. Consider using the `boost::asio::write` function if you need to peer. Consider using the `net::write` function if you need to
ensure that all data is written before the blocking operation completes. ensure that all data is written before the blocking operation completes.
*/ */
template<class ConstBufferSequence> template<class ConstBufferSequence>
@@ -580,7 +580,7 @@ public:
); @endcode ); @endcode
@note The `async_write_some` operation may not transmit all of the data to @note The `async_write_some` operation may not transmit all of the data to
the peer. Consider using the `boost::asio::async_write` function if you the peer. Consider using the `net::async_write` function if you
need to ensure that all data is written before the asynchronous operation need to ensure that all data is written before the asynchronous operation
completes. completes.
*/ */
@@ -607,7 +607,7 @@ public:
@throws boost::system::system_error Thrown on failure. @throws boost::system::system_error Thrown on failure.
@note The `read_some` operation may not read all of the requested number of @note The `read_some` operation may not read all of the requested number of
bytes. Consider using the `boost::asio::read` function if you need to ensure bytes. Consider using the `net::read` function if you need to ensure
that the requested amount of data is read before the blocking operation that the requested amount of data is read before the blocking operation
completes. completes.
*/ */
@@ -631,7 +631,7 @@ public:
@returns The number of bytes read. Returns 0 if an error occurred. @returns The number of bytes read. Returns 0 if an error occurred.
@note The `read_some` operation may not read all of the requested number of @note The `read_some` operation may not read all of the requested number of
bytes. Consider using the `boost::asio::read` function if you need to ensure bytes. Consider using the `net::read` function if you need to ensure
that the requested amount of data is read before the blocking operation that the requested amount of data is read before the blocking operation
completes. completes.
*/ */
@@ -662,7 +662,7 @@ public:
); @endcode ); @endcode
@note The `async_read_some` operation may not read all of the requested @note The `async_read_some` operation may not read all of the requested
number of bytes. Consider using the `boost::asio::async_read` function number of bytes. Consider using the `net::async_read` function
if you need to ensure that the requested amount of data is read before if you need to ensure that the requested amount of data is read before
the asynchronous operation completes. the asynchronous operation completes.
*/ */

View File

@@ -67,7 +67,7 @@ public:
// VFALCO should be execution_context // VFALCO should be execution_context
BOOST_BEAST_DECL BOOST_BEAST_DECL
explicit explicit
timeout_handle(boost::asio::io_context& ioc); timeout_handle(net::io_context& ioc);
BOOST_BEAST_DECL BOOST_BEAST_DECL
void void
@@ -126,7 +126,7 @@ public:
BOOST_BEAST_DECL BOOST_BEAST_DECL
void void
set_timeout_service_options( set_timeout_service_options(
boost::asio::io_context& ctx, // VFALCO should be execution_context net::io_context& ctx, // VFALCO should be execution_context
std::chrono::seconds interval); std::chrono::seconds interval);
} // beast } // beast

View File

@@ -46,7 +46,7 @@ class connect_op;
*/ */
template< template<
class Protocol, class Protocol,
class Executor = boost::asio::executor class Executor = net::executor
> >
class basic_timeout_socket class basic_timeout_socket
{ {
@@ -57,14 +57,14 @@ class basic_timeout_socket
timeout_handle rd_timer_; timeout_handle rd_timer_;
timeout_handle wr_timer_; timeout_handle wr_timer_;
timeout_handle cn_timer_; timeout_handle cn_timer_;
boost::asio::basic_stream_socket<Protocol> sock_; net::basic_stream_socket<Protocol> sock_;
detail::saved_handler rd_op_; detail::saved_handler rd_op_;
detail::saved_handler wr_op_; detail::saved_handler wr_op_;
detail::saved_handler cn_op_; detail::saved_handler cn_op_;
public: public:
/// The type of the next layer. /// The type of the next layer.
using next_layer_type = boost::asio::basic_stream_socket<Protocol>; using next_layer_type = net::basic_stream_socket<Protocol>;
/// The type of the lowest layer. /// The type of the lowest layer.
using lowest_layer_type = get_lowest_layer<next_layer_type>; using lowest_layer_type = get_lowest_layer<next_layer_type>;
@@ -93,7 +93,7 @@ public:
, class = typename std::enable_if< , class = typename std::enable_if<
std::is_convertible< std::is_convertible<
ExecutionContext&, ExecutionContext&,
boost::asio::execution_context&>::value && net::execution_context&>::value &&
std::is_constructible< std::is_constructible<
executor_type, executor_type,
typename ExecutionContext::executor_type>::value typename ExecutionContext::executor_type>::value
@@ -196,7 +196,7 @@ public:
Regardless of whether the asynchronous operation completes immediately or Regardless of whether the asynchronous operation completes immediately or
not, the handler will not be invoked from within this function. Invocation not, the handler will not be invoked from within this function. Invocation
of the handler will be performed in a manner equivalent to using of the handler will be performed in a manner equivalent to using
boost::asio::io_context::post(). net::io_context::post().
*/ */
template<class MutableBufferSequence, class ReadHandler> template<class MutableBufferSequence, class ReadHandler>
BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler, BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
@@ -225,7 +225,7 @@ public:
Regardless of whether the asynchronous operation completes immediately or Regardless of whether the asynchronous operation completes immediately or
not, the handler will not be invoked from within this function. Invocation not, the handler will not be invoked from within this function. Invocation
of the handler will be performed in a manner equivalent to using of the handler will be performed in a manner equivalent to using
boost::asio::io_context::post(). net::io_context::post().
*/ */
template<class ConstBufferSequence, class WriteHandler> template<class ConstBufferSequence, class WriteHandler>
BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler, BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
@@ -239,8 +239,8 @@ public:
/// A TCP/IP socket wrapper which has a built-in asynchronous timeout /// A TCP/IP socket wrapper which has a built-in asynchronous timeout
using timeout_socket = basic_timeout_socket< using timeout_socket = basic_timeout_socket<
boost::asio::ip::tcp, net::ip::tcp,
boost::asio::io_context::executor_type>; net::io_context::executor_type>;
/** /**
@defgroup async_connect boost::beast::async_connect @defgroup async_connect boost::beast::async_connect
@@ -267,7 +267,7 @@ using timeout_socket = basic_timeout_socket<
@code @code
void handler( void handler(
// Result of operation. if the sequence is empty, set to // Result of operation. if the sequence is empty, set to
// boost::asio::error::not_found. Otherwise, contains the // net::error::not_found. Otherwise, contains the
// error from the last connection attempt. // error from the last connection attempt.
error_code const& error, error_code const& error,
@@ -280,13 +280,13 @@ using timeout_socket = basic_timeout_socket<
Regardless of whether the asynchronous operation completes immediately or Regardless of whether the asynchronous operation completes immediately or
not, the handler will not be invoked from within this function. Invocation not, the handler will not be invoked from within this function. Invocation
of the handler will be performed in a manner equivalent to using of the handler will be performed in a manner equivalent to using
`boost::asio::io_context::post()`. `net::io_context::post()`.
@par Example @par Example
@code @code
boost::asio::tcp::resolver r(ioc); net::tcp::resolver r(ioc);
boost::asio::tcp::resolver::query q("host", "service"); net::tcp::resolver::query q("host", "service");
timeout_socket s(ioc.get_executor()); timeout_socket s(ioc.get_executor());
// ... // ...
@@ -321,7 +321,7 @@ template<
class RangeConnectHandler class RangeConnectHandler
#if ! BOOST_BEAST_DOXYGEN #if ! BOOST_BEAST_DOXYGEN
,class = typename std::enable_if< ,class = typename std::enable_if<
boost::asio::is_endpoint_sequence< net::is_endpoint_sequence<
EndpointSequence>::value>::type EndpointSequence>::value>::type
#endif #endif
> >
@@ -365,7 +365,7 @@ async_connect(
@code @code
void handler( void handler(
// Result of operation. if the sequence is empty, set to // Result of operation. if the sequence is empty, set to
// boost::asio::error::not_found. Otherwise, contains the // net::error::not_found. Otherwise, contains the
// error from the last connection attempt. // error from the last connection attempt.
error_code const& error, error_code const& error,
@@ -378,7 +378,7 @@ async_connect(
Regardless of whether the asynchronous operation completes immediately or Regardless of whether the asynchronous operation completes immediately or
not, the handler will not be invoked from within this function. Invocation not, the handler will not be invoked from within this function. Invocation
of the handler will be performed in a manner equivalent to using of the handler will be performed in a manner equivalent to using
`boost::asio::io_context::post()`. `net::io_context::post()`.
@par Example @par Example
@@ -390,7 +390,7 @@ async_connect(
{ {
bool operator()( bool operator()(
boost::system::error_code const& ec, boost::system::error_code const& ec,
boost::asio::ip::tcp::endpoint const& next) net::ip::tcp::endpoint const& next)
{ {
if (ec) std::cout << "Error: " << ec.message() << std::endl; if (ec) std::cout << "Error: " << ec.message() << std::endl;
std::cout << "Trying: " << next << std::endl; std::cout << "Trying: " << next << std::endl;
@@ -403,8 +403,8 @@ async_connect(
function as follows: function as follows:
@code @code
boost::asio::tcp::resolver r(ioc); net::tcp::resolver r(ioc);
boost::asio::tcp::resolver::query q("host", "service"); net::tcp::resolver::query q("host", "service");
timeout_socket s(ioc.get_executor()); timeout_socket s(ioc.get_executor());
// ... // ...
@@ -440,7 +440,7 @@ template<
class RangeConnectHandler class RangeConnectHandler
#if ! BOOST_BEAST_DOXYGEN #if ! BOOST_BEAST_DOXYGEN
,class = typename std::enable_if< ,class = typename std::enable_if<
boost::asio::is_endpoint_sequence< net::is_endpoint_sequence<
EndpointSequence>::value>::type EndpointSequence>::value>::type
#endif #endif
> >
@@ -472,7 +472,7 @@ async_connect(
@code @code
void handler( void handler(
// Result of operation. if the sequence is empty, set to // Result of operation. if the sequence is empty, set to
// boost::asio::error::not_found. Otherwise, contains the // net::error::not_found. Otherwise, contains the
// error from the last connection attempt. // error from the last connection attempt.
error_code const& error, error_code const& error,
@@ -485,7 +485,7 @@ async_connect(
Regardless of whether the asynchronous operation completes immediately or Regardless of whether the asynchronous operation completes immediately or
not, the handler will not be invoked from within this function. Invocation not, the handler will not be invoked from within this function. Invocation
of the handler will be performed in a manner equivalent to using of the handler will be performed in a manner equivalent to using
`boost::asio::io_context::post()`. `net::io_context::post()`.
@par Example @par Example
@@ -511,7 +511,7 @@ template<
class IteratorConnectHandler class IteratorConnectHandler
#if ! BOOST_BEAST_DOXYGEN #if ! BOOST_BEAST_DOXYGEN
,class = typename std::enable_if< ,class = typename std::enable_if<
! boost::asio::is_endpoint_sequence< ! net::is_endpoint_sequence<
Iterator>::value>::type Iterator>::value>::type
#endif #endif
> >
@@ -551,7 +551,7 @@ async_connect(
@code @code
void handler( void handler(
// Result of operation. if the sequence is empty, set to // Result of operation. if the sequence is empty, set to
// boost::asio::error::not_found. Otherwise, contains the // net::error::not_found. Otherwise, contains the
// error from the last connection attempt. // error from the last connection attempt.
error_code const& error, error_code const& error,
@@ -564,7 +564,7 @@ async_connect(
Regardless of whether the asynchronous operation completes immediately or Regardless of whether the asynchronous operation completes immediately or
not, the handler will not be invoked from within this function. Invocation not, the handler will not be invoked from within this function. Invocation
of the handler will be performed in a manner equivalent to using of the handler will be performed in a manner equivalent to using
`boost::asio::io_context::post()`. `net::io_context::post()`.
@par Example @par Example
@@ -576,7 +576,7 @@ async_connect(
{ {
bool operator()( bool operator()(
boost::system::error_code const& ec, boost::system::error_code const& ec,
boost::asio::ip::tcp::endpoint const& next) net::ip::tcp::endpoint const& next)
{ {
if (ec) std::cout << "Error: " << ec.message() << std::endl; if (ec) std::cout << "Error: " << ec.message() << std::endl;
std::cout << "Trying: " << next << std::endl; std::cout << "Trying: " << next << std::endl;
@@ -610,7 +610,7 @@ template<
class IteratorConnectHandler class IteratorConnectHandler
#if ! BOOST_BEAST_DOXYGEN #if ! BOOST_BEAST_DOXYGEN
,class = typename std::enable_if< ,class = typename std::enable_if<
! boost::asio::is_endpoint_sequence< ! net::is_endpoint_sequence<
Iterator>::value>::type Iterator>::value>::type
#endif #endif
> >

View File

@@ -76,7 +76,7 @@ class icy_stream
char buf_[8]; char buf_[8];
static static
boost::asio::const_buffer net::const_buffer
version() version()
{ {
return {"HTTP/1.1", 8}; return {"HTTP/1.1", 8};
@@ -199,7 +199,7 @@ public:
@throws boost::system::system_error Thrown on failure. @throws boost::system::system_error Thrown on failure.
@note The `read_some` operation may not read all of the requested number of @note The `read_some` operation may not read all of the requested number of
bytes. Consider using the function `boost::asio::read` if you need to ensure bytes. Consider using the function `net::read` if you need to ensure
that the requested amount of data is read before the blocking operation that the requested amount of data is read before the blocking operation
completes. completes.
*/ */
@@ -220,7 +220,7 @@ public:
@returns The number of bytes read. @returns The number of bytes read.
@note The `read_some` operation may not read all of the requested number of @note The `read_some` operation may not read all of the requested number of
bytes. Consider using the function `boost::asio::read` if you need to ensure bytes. Consider using the function `net::read` if you need to ensure
that the requested amount of data is read before the blocking operation that the requested amount of data is read before the blocking operation
completes. completes.
*/ */
@@ -249,7 +249,7 @@ public:
); @endcode ); @endcode
@note The `read_some` operation may not read all of the requested number of @note The `read_some` operation may not read all of the requested number of
bytes. Consider using the function `boost::asio::async_read` if you need bytes. Consider using the function `net::async_read` if you need
to ensure that the requested amount of data is read before the asynchronous to ensure that the requested amount of data is read before the asynchronous
operation completes. operation completes.
*/ */
@@ -275,7 +275,7 @@ public:
@throws boost::system::system_error Thrown on failure. @throws boost::system::system_error Thrown on failure.
@note The `write_some` operation may not transmit all of the data to the @note The `write_some` operation may not transmit all of the data to the
peer. Consider using the function `boost::asio::write` if you need to peer. Consider using the function `net::write` if you need to
ensure that all data is written before the blocking operation completes. ensure that all data is written before the blocking operation completes.
*/ */
template<class ConstBufferSequence> template<class ConstBufferSequence>
@@ -295,7 +295,7 @@ public:
@returns The number of bytes written. @returns The number of bytes written.
@note The `write_some` operation may not transmit all of the data to the @note The `write_some` operation may not transmit all of the data to the
peer. Consider using the function `boost::asio::write` if you need to peer. Consider using the function `net::write` if you need to
ensure that all data is written before the blocking operation completes. ensure that all data is written before the blocking operation completes.
*/ */
template<class ConstBufferSequence> template<class ConstBufferSequence>
@@ -323,7 +323,7 @@ public:
); @endcode ); @endcode
@note The `async_write_some` operation may not transmit all of the data to @note The `async_write_some` operation may not transmit all of the data to
the peer. Consider using the function `boost::asio::async_write` if you need the peer. Consider using the function `net::async_write` if you need
to ensure that all data is written before the asynchronous operation completes. to ensure that all data is written before the asynchronous operation completes.
*/ */
template< template<

View File

@@ -103,7 +103,7 @@ public:
template<class DynamicBuffer> template<class DynamicBuffer>
typename std::enable_if< typename std::enable_if<
boost::asio::is_dynamic_buffer<DynamicBuffer>::value, net::is_dynamic_buffer<DynamicBuffer>::value,
dynamic_buffer_ref<DynamicBuffer>>::type dynamic_buffer_ref<DynamicBuffer>>::type
ref(DynamicBuffer& b) ref(DynamicBuffer& b)
{ {
@@ -114,16 +114,16 @@ template<class MutableBuffers, class ConstBuffers>
void void
buffer_shift(MutableBuffers const& out, ConstBuffers const& in) buffer_shift(MutableBuffers const& out, ConstBuffers const& in)
{ {
using boost::asio::buffer_size; using net::buffer_size;
auto in_pos = boost::asio::buffer_sequence_end(in); auto in_pos = net::buffer_sequence_end(in);
auto out_pos = boost::asio::buffer_sequence_end(out); auto out_pos = net::buffer_sequence_end(out);
auto const in_begin = boost::asio::buffer_sequence_begin(in); auto const in_begin = net::buffer_sequence_begin(in);
auto const out_begin = boost::asio::buffer_sequence_begin(out); auto const out_begin = net::buffer_sequence_begin(out);
BOOST_ASSERT(buffer_size(in) == buffer_size(out)); BOOST_ASSERT(buffer_size(in) == buffer_size(out));
if(in_pos == in_begin || out_pos == out_begin) if(in_pos == in_begin || out_pos == out_begin)
return; return;
boost::asio::const_buffer cb{*--in_pos}; net::const_buffer cb{*--in_pos};
boost::asio::mutable_buffer mb{*--out_pos}; net::mutable_buffer mb{*--out_pos};
for(;;) for(;;)
{ {
if(mb.size() >= cb.size()) if(mb.size() >= cb.size())
@@ -133,7 +133,7 @@ buffer_shift(MutableBuffers const& out, ConstBuffers const& in)
mb.data()) + mb.size() - cb.size(), mb.data()) + mb.size() - cb.size(),
cb.data(), cb.data(),
cb.size()); cb.size());
mb = boost::asio::mutable_buffer{ mb = net::mutable_buffer{
mb.data(), mb.size() - cb.size()}; mb.data(), mb.size() - cb.size()};
if(in_pos == in_begin) if(in_pos == in_begin)
break; break;
@@ -146,7 +146,7 @@ buffer_shift(MutableBuffers const& out, ConstBuffers const& in)
static_cast<char const*>( static_cast<char const*>(
cb.data()) + cb.size() - mb.size(), cb.data()) + cb.size() - mb.size(),
mb.size()); mb.size());
cb = boost::asio::const_buffer{ cb = net::const_buffer{
cb.data(), cb.size() - mb.size()}; cb.data(), cb.size() - mb.size()};
if(out_pos == out_begin) if(out_pos == out_begin)
break; break;
@@ -194,14 +194,14 @@ public:
template<class NextLayer> template<class NextLayer>
template<class MutableBufferSequence, class Handler> template<class MutableBufferSequence, class Handler>
class icy_stream<NextLayer>::read_op class icy_stream<NextLayer>::read_op
: public boost::asio::coroutine : public net::coroutine
{ {
using alloc_type = typename using alloc_type = typename
#if defined(BOOST_NO_CXX11_ALLOCATOR) #if defined(BOOST_NO_CXX11_ALLOCATOR)
boost::asio::associated_allocator_t<Handler>::template net::associated_allocator_t<Handler>::template
rebind<char>::other; rebind<char>::other;
#else #else
std::allocator_traits<boost::asio::associated_allocator_t<Handler>> std::allocator_traits<net::associated_allocator_t<Handler>>
::template rebind_alloc<char>; ::template rebind_alloc<char>;
#endif #endif
@@ -237,21 +237,21 @@ public:
} }
using allocator_type = using allocator_type =
boost::asio::associated_allocator_t<Handler>; net::associated_allocator_t<Handler>;
allocator_type allocator_type
get_allocator() const noexcept get_allocator() const noexcept
{ {
return (boost::asio::get_associated_allocator)(d_.handler()); return (net::get_associated_allocator)(d_.handler());
} }
using executor_type = boost::asio::associated_executor_t< using executor_type = net::associated_executor_t<
Handler, decltype(std::declval<NextLayer&>().get_executor())>; Handler, decltype(std::declval<NextLayer&>().get_executor())>;
executor_type executor_type
get_executor() const noexcept get_executor() const noexcept
{ {
return (boost::asio::get_associated_executor)( return (net::get_associated_executor)(
d_.handler(), d_->s.get_executor()); d_.handler(), d_->s.get_executor());
} }
@@ -264,7 +264,7 @@ public:
friend friend
void asio_handler_invoke(Function&& f, read_op* op) void asio_handler_invoke(Function&& f, read_op* op)
{ {
using boost::asio::asio_handler_invoke; using net::asio_handler_invoke;
asio_handler_invoke(f, std::addressof(op->d_.handler())); asio_handler_invoke(f, std::addressof(op->d_.handler()));
} }
}; };
@@ -278,9 +278,9 @@ operator()(
error_code ec, error_code ec,
std::size_t bytes_transferred) std::size_t bytes_transferred)
{ {
using boost::asio::buffer_copy; using net::buffer_copy;
using boost::asio::buffer_size; using net::buffer_size;
using iterator = boost::asio::buffers_iterator< using iterator = net::buffers_iterator<
typename detail::dynamic_buffer_ref< typename detail::dynamic_buffer_ref<
buffers_adapter<MutableBufferSequence>>::const_buffers_type>; buffers_adapter<MutableBufferSequence>>::const_buffers_type>;
auto& d = *d_; auto& d = *d_;
@@ -289,7 +289,7 @@ operator()(
if(d.b.max_size() == 0) if(d.b.max_size() == 0)
{ {
BOOST_ASIO_CORO_YIELD BOOST_ASIO_CORO_YIELD
boost::asio::post(d.s.get_executor(), net::post(d.s.get_executor(),
beast::bind_handler(std::move(*this), ec, 0)); beast::bind_handler(std::move(*this), ec, 0));
goto upcall; goto upcall;
} }
@@ -300,7 +300,7 @@ operator()(
auto const n = buffer_copy( auto const n = buffer_copy(
d.b.prepare(std::min<std::size_t>( d.b.prepare(std::min<std::size_t>(
d.s.copy_, d.b.max_size())), d.s.copy_, d.b.max_size())),
boost::asio::buffer(d.s.buf_)); net::buffer(d.s.buf_));
d.b.commit(n); d.b.commit(n);
d.s.copy_ = static_cast<unsigned char>( d.s.copy_ = static_cast<unsigned char>(
d.s.copy_ - n); d.s.copy_ - n);
@@ -326,9 +326,9 @@ operator()(
if(d.b.max_size() < 8) if(d.b.max_size() < 8)
{ {
BOOST_ASIO_CORO_YIELD BOOST_ASIO_CORO_YIELD
boost::asio::async_read( net::async_read(
d.s.next_layer(), d.s.next_layer(),
boost::asio::buffer(d.s.buf_, 3), net::buffer(d.s.buf_, 3),
std::move(*this)); std::move(*this));
if(ec) if(ec)
goto upcall; goto upcall;
@@ -341,7 +341,7 @@ operator()(
{ {
buffer_copy( buffer_copy(
d.b.value(), d.b.value(),
boost::asio::buffer(d.s.buf_, n)); net::buffer(d.s.buf_, n));
if(d.b.max_size() < 3) if(d.b.max_size() < 3)
{ {
d.s.copy_ = static_cast<unsigned char>( d.s.copy_ = static_cast<unsigned char>(
@@ -358,7 +358,7 @@ operator()(
} }
d.s.copy_ = static_cast<unsigned char>( d.s.copy_ = static_cast<unsigned char>(
buffer_copy( buffer_copy(
boost::asio::buffer(d.s.buf_), net::buffer(d.s.buf_),
icy_stream::version() + d.b.max_size())); icy_stream::version() + d.b.max_size()));
bytes_transferred = buffer_copy( bytes_transferred = buffer_copy(
d.b.value(), d.b.value(),
@@ -367,7 +367,7 @@ operator()(
} }
BOOST_ASIO_CORO_YIELD BOOST_ASIO_CORO_YIELD
boost::asio::async_read_until( net::async_read_until(
d.s.next_layer(), d.s.next_layer(),
detail::ref(d.b), detail::ref(d.b),
detail::match_icy<iterator>(d.match), detail::match_icy<iterator>(d.match),
@@ -384,8 +384,8 @@ operator()(
d.s.copy_ = static_cast<unsigned char>( d.s.copy_ = static_cast<unsigned char>(
n + 5 - d.b.max_size()); n + 5 - d.b.max_size());
std::copy( std::copy(
boost::asio::buffers_begin(d.b.value()) + n - d.s.copy_, net::buffers_begin(d.b.value()) + n - d.s.copy_,
boost::asio::buffers_begin(d.b.value()) + n, net::buffers_begin(d.b.value()) + n,
d.s.buf_); d.s.buf_);
n = d.b.max_size() - 5; n = d.b.max_size() - 5;
} }
@@ -425,7 +425,7 @@ read_some(MutableBufferSequence const& buffers)
{ {
static_assert(boost::beast::is_sync_read_stream<next_layer_type>::value, static_assert(boost::beast::is_sync_read_stream<next_layer_type>::value,
"SyncReadStream requirements not met"); "SyncReadStream requirements not met");
static_assert(boost::asio::is_mutable_buffer_sequence< static_assert(net::is_mutable_buffer_sequence<
MutableBufferSequence>::value, MutableBufferSequence>::value,
"MutableBufferSequence requirements not met"); "MutableBufferSequence requirements not met");
error_code ec; error_code ec;
@@ -443,12 +443,12 @@ read_some(MutableBufferSequence const& buffers, error_code& ec)
{ {
static_assert(boost::beast::is_sync_read_stream<next_layer_type>::value, static_assert(boost::beast::is_sync_read_stream<next_layer_type>::value,
"SyncReadStream requirements not met"); "SyncReadStream requirements not met");
static_assert(boost::asio::is_mutable_buffer_sequence< static_assert(net::is_mutable_buffer_sequence<
MutableBufferSequence>::value, MutableBufferSequence>::value,
"MutableBufferSequence requirements not met"); "MutableBufferSequence requirements not met");
using boost::asio::buffer_copy; using net::buffer_copy;
using boost::asio::buffer_size; using net::buffer_size;
using iterator = boost::asio::buffers_iterator< using iterator = net::buffers_iterator<
typename detail::dynamic_buffer_ref< typename detail::dynamic_buffer_ref<
buffers_adapter<MutableBufferSequence>>::const_buffers_type>; buffers_adapter<MutableBufferSequence>>::const_buffers_type>;
buffers_adapter<MutableBufferSequence> b(buffers); buffers_adapter<MutableBufferSequence> b(buffers);
@@ -464,7 +464,7 @@ read_some(MutableBufferSequence const& buffers, error_code& ec)
auto const n = buffer_copy( auto const n = buffer_copy(
b.prepare(std::min<std::size_t>( b.prepare(std::min<std::size_t>(
copy_, b.max_size())), copy_, b.max_size())),
boost::asio::buffer(buf_)); net::buffer(buf_));
b.commit(n); b.commit(n);
copy_ = static_cast<unsigned char>( copy_ = static_cast<unsigned char>(
copy_ - n); copy_ - n);
@@ -483,9 +483,9 @@ read_some(MutableBufferSequence const& buffers, error_code& ec)
detect_ = false; detect_ = false;
if(b.max_size() < 8) if(b.max_size() < 8)
{ {
auto n = boost::asio::read( auto n = net::read(
stream_, stream_,
boost::asio::buffer(buf_, 3), net::buffer(buf_, 3),
ec); ec);
if(ec) if(ec)
return 0; return 0;
@@ -497,7 +497,7 @@ read_some(MutableBufferSequence const& buffers, error_code& ec)
{ {
buffer_copy( buffer_copy(
buffers, buffers,
boost::asio::buffer(buf_, n)); net::buffer(buf_, n));
if(b.max_size() < 3) if(b.max_size() < 3)
{ {
copy_ = static_cast<unsigned char>( copy_ = static_cast<unsigned char>(
@@ -512,7 +512,7 @@ read_some(MutableBufferSequence const& buffers, error_code& ec)
} }
copy_ = static_cast<unsigned char>( copy_ = static_cast<unsigned char>(
buffer_copy( buffer_copy(
boost::asio::buffer(buf_), net::buffer(buf_),
version() + b.max_size())); version() + b.max_size()));
return buffer_copy( return buffer_copy(
buffers, buffers,
@@ -520,7 +520,7 @@ read_some(MutableBufferSequence const& buffers, error_code& ec)
} }
bool match = false; bool match = false;
auto n = boost::asio::read_until( auto n = net::read_until(
stream_, stream_,
detail::ref(b), detail::ref(b),
detail::match_icy<iterator>(match), detail::match_icy<iterator>(match),
@@ -535,8 +535,8 @@ read_some(MutableBufferSequence const& buffers, error_code& ec)
copy_ = static_cast<unsigned char>( copy_ = static_cast<unsigned char>(
n + 5 - b.max_size()); n + 5 - b.max_size());
std::copy( std::copy(
boost::asio::buffers_begin(buffers) + n - copy_, net::buffers_begin(buffers) + n - copy_,
boost::asio::buffers_begin(buffers) + n, net::buffers_begin(buffers) + n,
buf_); buf_);
n = b.max_size() - 5; n = b.max_size() - 5;
} }
@@ -565,7 +565,7 @@ async_read_some(
{ {
static_assert(boost::beast::is_async_read_stream<next_layer_type>::value, static_assert(boost::beast::is_async_read_stream<next_layer_type>::value,
"AsyncReadStream requirements not met"); "AsyncReadStream requirements not met");
static_assert(boost::asio::is_mutable_buffer_sequence< static_assert(net::is_mutable_buffer_sequence<
MutableBufferSequence >::value, MutableBufferSequence >::value,
"MutableBufferSequence requirements not met"); "MutableBufferSequence requirements not met");
BOOST_BEAST_HANDLER_INIT( BOOST_BEAST_HANDLER_INIT(
@@ -587,7 +587,7 @@ write_some(MutableBufferSequence const& buffers)
{ {
static_assert(boost::beast::is_sync_write_stream<next_layer_type>::value, static_assert(boost::beast::is_sync_write_stream<next_layer_type>::value,
"SyncWriteStream requirements not met"); "SyncWriteStream requirements not met");
static_assert(boost::asio::is_const_buffer_sequence< static_assert(net::is_const_buffer_sequence<
MutableBufferSequence>::value, MutableBufferSequence>::value,
"MutableBufferSequence requirements not met"); "MutableBufferSequence requirements not met");
return stream_.write_some(buffers); return stream_.write_some(buffers);
@@ -601,7 +601,7 @@ write_some(MutableBufferSequence const& buffers, error_code& ec)
{ {
static_assert(boost::beast::is_sync_write_stream<next_layer_type>::value, static_assert(boost::beast::is_sync_write_stream<next_layer_type>::value,
"SyncWriteStream requirements not met"); "SyncWriteStream requirements not met");
static_assert(boost::asio::is_const_buffer_sequence< static_assert(net::is_const_buffer_sequence<
MutableBufferSequence>::value, MutableBufferSequence>::value,
"MutableBufferSequence requirements not met"); "MutableBufferSequence requirements not met");
return stream_.write_some(buffers, ec); return stream_.write_some(buffers, ec);
@@ -620,7 +620,7 @@ async_write_some(
{ {
static_assert(boost::beast::is_async_write_stream<next_layer_type>::value, static_assert(boost::beast::is_async_write_stream<next_layer_type>::value,
"AsyncWriteStream requirements not met"); "AsyncWriteStream requirements not met");
static_assert(boost::asio::is_const_buffer_sequence< static_assert(net::is_const_buffer_sequence<
MutableBufferSequence>::value, MutableBufferSequence>::value,
"MutableBufferSequence requirements not met"); "MutableBufferSequence requirements not met");
return stream_.async_write_some(buffers, std::forward<WriteHandler>(handler)); return stream_.async_write_some(buffers, std::forward<WriteHandler>(handler));

View File

@@ -62,7 +62,7 @@ operator=(stream&& other)
inline inline
stream:: stream::
stream(boost::asio::io_context& ioc) stream(net::io_context& ioc)
: in_(std::make_shared<state>(ioc, nullptr)) : in_(std::make_shared<state>(ioc, nullptr))
{ {
} }
@@ -70,7 +70,7 @@ stream(boost::asio::io_context& ioc)
inline inline
stream:: stream::
stream( stream(
boost::asio::io_context& ioc, net::io_context& ioc,
fail_count& fc) fail_count& fc)
: in_(std::make_shared<state>(ioc, &fc)) : in_(std::make_shared<state>(ioc, &fc))
{ {
@@ -79,12 +79,12 @@ stream(
inline inline
stream:: stream::
stream( stream(
boost::asio::io_context& ioc, net::io_context& ioc,
string_view s) string_view s)
: in_(std::make_shared<state>(ioc, nullptr)) : in_(std::make_shared<state>(ioc, nullptr))
{ {
using boost::asio::buffer; using net::buffer;
using boost::asio::buffer_copy; using net::buffer_copy;
in_->b.commit(buffer_copy( in_->b.commit(buffer_copy(
in_->b.prepare(s.size()), in_->b.prepare(s.size()),
buffer(s.data(), s.size()))); buffer(s.data(), s.size())));
@@ -93,13 +93,13 @@ stream(
inline inline
stream:: stream::
stream( stream(
boost::asio::io_context& ioc, net::io_context& ioc,
fail_count& fc, fail_count& fc,
string_view s) string_view s)
: in_(std::make_shared<state>(ioc, &fc)) : in_(std::make_shared<state>(ioc, &fc))
{ {
using boost::asio::buffer; using net::buffer;
using boost::asio::buffer_copy; using net::buffer_copy;
in_->b.commit(buffer_copy( in_->b.commit(buffer_copy(
in_->b.prepare(s.size()), in_->b.prepare(s.size()),
buffer(s.data(), s.size()))); buffer(s.data(), s.size())));
@@ -121,7 +121,7 @@ stream::
str() const str() const
{ {
auto const bs = in_->b.data(); auto const bs = in_->b.data();
if(boost::asio::buffer_size(bs) == 0) if(net::buffer_size(bs) == 0)
return {}; return {};
auto const b = buffers_front(bs); auto const b = buffers_front(bs);
return {static_cast<char const*>(b.data()), b.size()}; return {static_cast<char const*>(b.data()), b.size()};
@@ -132,8 +132,8 @@ void
stream:: stream::
append(string_view s) append(string_view s)
{ {
using boost::asio::buffer; using net::buffer;
using boost::asio::buffer_copy; using net::buffer_copy;
std::lock_guard<std::mutex> lock{in_->m}; std::lock_guard<std::mutex> lock{in_->m};
in_->b.commit(buffer_copy( in_->b.commit(buffer_copy(
in_->b.prepare(s.size()), in_->b.prepare(s.size()),
@@ -184,7 +184,7 @@ std::size_t
stream:: stream::
read_some(MutableBufferSequence const& buffers) read_some(MutableBufferSequence const& buffers)
{ {
static_assert(boost::asio::is_mutable_buffer_sequence< static_assert(net::is_mutable_buffer_sequence<
MutableBufferSequence>::value, MutableBufferSequence>::value,
"MutableBufferSequence requirements not met"); "MutableBufferSequence requirements not met");
error_code ec; error_code ec;
@@ -200,11 +200,11 @@ stream::
read_some(MutableBufferSequence const& buffers, read_some(MutableBufferSequence const& buffers,
error_code& ec) error_code& ec)
{ {
static_assert(boost::asio::is_mutable_buffer_sequence< static_assert(net::is_mutable_buffer_sequence<
MutableBufferSequence>::value, MutableBufferSequence>::value,
"MutableBufferSequence requirements not met"); "MutableBufferSequence requirements not met");
using boost::asio::buffer_copy; using net::buffer_copy;
using boost::asio::buffer_size; using net::buffer_size;
if(in_->fc && in_->fc->fail(ec)) if(in_->fc && in_->fc->fail(ec))
return 0; return 0;
if(buffer_size(buffers) == 0) if(buffer_size(buffers) == 0)
@@ -234,9 +234,9 @@ read_some(MutableBufferSequence const& buffers,
BOOST_ASSERT(in_->code != status::ok); BOOST_ASSERT(in_->code != status::ok);
bytes_transferred = 0; bytes_transferred = 0;
if(in_->code == status::eof) if(in_->code == status::eof)
ec = boost::asio::error::eof; ec = net::error::eof;
else if(in_->code == status::reset) else if(in_->code == status::reset)
ec = boost::asio::error::connection_reset; ec = net::error::connection_reset;
} }
++in_->nread; ++in_->nread;
return bytes_transferred; return bytes_transferred;
@@ -250,18 +250,18 @@ async_read_some(
MutableBufferSequence const& buffers, MutableBufferSequence const& buffers,
ReadHandler&& handler) ReadHandler&& handler)
{ {
static_assert(boost::asio::is_mutable_buffer_sequence< static_assert(net::is_mutable_buffer_sequence<
MutableBufferSequence>::value, MutableBufferSequence>::value,
"MutableBufferSequence requirements not met"); "MutableBufferSequence requirements not met");
using boost::asio::buffer_copy; using net::buffer_copy;
using boost::asio::buffer_size; using net::buffer_size;
BOOST_BEAST_HANDLER_INIT( BOOST_BEAST_HANDLER_INIT(
ReadHandler, void(error_code, std::size_t)); ReadHandler, void(error_code, std::size_t));
error_code ec; error_code ec;
if(in_->fc && in_->fc->fail(ec)) if(in_->fc && in_->fc->fail(ec))
{ {
boost::asio::post( net::post(
in_->ioc.get_executor(), in_->ioc.get_executor(),
beast::bind_front_handler( beast::bind_front_handler(
std::move(init.completion_handler), std::move(init.completion_handler),
@@ -280,7 +280,7 @@ async_read_some(
in_->b.consume(bytes_transferred); in_->b.consume(bytes_transferred);
lock.unlock(); lock.unlock();
++in_->nread; ++in_->nread;
boost::asio::post( net::post(
in_->ioc.get_executor(), in_->ioc.get_executor(),
beast::bind_front_handler( beast::bind_front_handler(
std::move(init.completion_handler), std::move(init.completion_handler),
@@ -292,10 +292,10 @@ async_read_some(
lock.unlock(); lock.unlock();
++in_->nread; ++in_->nread;
if(in_->code == status::eof) if(in_->code == status::eof)
ec = boost::asio::error::eof; ec = net::error::eof;
else if(in_->code == status::reset) else if(in_->code == status::reset)
ec = boost::asio::error::connection_reset; ec = net::error::connection_reset;
boost::asio::post( net::post(
in_->ioc.get_executor(), in_->ioc.get_executor(),
beast::bind_front_handler( beast::bind_front_handler(
std::move(init.completion_handler), std::move(init.completion_handler),
@@ -318,7 +318,7 @@ std::size_t
stream:: stream::
write_some(ConstBufferSequence const& buffers) write_some(ConstBufferSequence const& buffers)
{ {
static_assert(boost::asio::is_const_buffer_sequence< static_assert(net::is_const_buffer_sequence<
ConstBufferSequence>::value, ConstBufferSequence>::value,
"ConstBufferSequence requirements not met"); "ConstBufferSequence requirements not met");
error_code ec; error_code ec;
@@ -335,15 +335,15 @@ stream::
write_some( write_some(
ConstBufferSequence const& buffers, error_code& ec) ConstBufferSequence const& buffers, error_code& ec)
{ {
static_assert(boost::asio::is_const_buffer_sequence< static_assert(net::is_const_buffer_sequence<
ConstBufferSequence>::value, ConstBufferSequence>::value,
"ConstBufferSequence requirements not met"); "ConstBufferSequence requirements not met");
using boost::asio::buffer_copy; using net::buffer_copy;
using boost::asio::buffer_size; using net::buffer_size;
auto out = out_.lock(); auto out = out_.lock();
if(! out) if(! out)
{ {
ec = boost::asio::error::connection_reset; ec = net::error::connection_reset;
return 0; return 0;
} }
BOOST_ASSERT(out->code == status::ok); BOOST_ASSERT(out->code == status::ok);
@@ -369,21 +369,21 @@ stream::
async_write_some(ConstBufferSequence const& buffers, async_write_some(ConstBufferSequence const& buffers,
WriteHandler&& handler) WriteHandler&& handler)
{ {
static_assert(boost::asio::is_const_buffer_sequence< static_assert(net::is_const_buffer_sequence<
ConstBufferSequence>::value, ConstBufferSequence>::value,
"ConstBufferSequence requirements not met"); "ConstBufferSequence requirements not met");
using boost::asio::buffer_copy; using net::buffer_copy;
using boost::asio::buffer_size; using net::buffer_size;
BOOST_BEAST_HANDLER_INIT( BOOST_BEAST_HANDLER_INIT(
WriteHandler, void(error_code, std::size_t)); WriteHandler, void(error_code, std::size_t));
auto out = out_.lock(); auto out = out_.lock();
if(! out) if(! out)
{ {
boost::asio::post( net::post(
in_->ioc.get_executor(), in_->ioc.get_executor(),
beast::bind_front_handler( beast::bind_front_handler(
std::move(init.completion_handler), std::move(init.completion_handler),
boost::asio::error::connection_reset, net::error::connection_reset,
0)); 0));
} }
else else
@@ -392,7 +392,7 @@ async_write_some(ConstBufferSequence const& buffers,
error_code ec; error_code ec;
if(in_->fc && in_->fc->fail(ec)) if(in_->fc && in_->fc->fail(ec))
{ {
boost::asio::post( net::post(
in_->ioc.get_executor(), in_->ioc.get_executor(),
beast::bind_front_handler( beast::bind_front_handler(
std::move(init.completion_handler), std::move(init.completion_handler),
@@ -410,7 +410,7 @@ async_write_some(ConstBufferSequence const& buffers,
out->on_write(); out->on_write();
lock.unlock(); lock.unlock();
++in_->nwrite; ++in_->nwrite;
boost::asio::post( net::post(
in_->ioc.get_executor(), in_->ioc.get_executor(),
beast::bind_front_handler( beast::bind_front_handler(
std::move(init.completion_handler), std::move(init.completion_handler),
@@ -437,7 +437,7 @@ boost::system::error_code& ec)
if( s.in_->fc && if( s.in_->fc &&
s.in_->fc->fail(ec)) s.in_->fc->fail(ec))
ec = boost::asio::error::eof; ec = net::error::eof;
else else
ec.assign(0, ec.category()); ec.assign(0, ec.category());
} }
@@ -453,17 +453,17 @@ TeardownHandler&& handler)
error_code ec; error_code ec;
if( s.in_->fc && if( s.in_->fc &&
s.in_->fc->fail(ec)) s.in_->fc->fail(ec))
return boost::asio::post( return net::post(
s.get_executor(), s.get_executor(),
beast::bind_front_handler(std::move(handler), ec)); beast::bind_front_handler(std::move(handler), ec));
s.close(); s.close();
if( s.in_->fc && if( s.in_->fc &&
s.in_->fc->fail(ec)) s.in_->fc->fail(ec))
ec = boost::asio::error::eof; ec = net::error::eof;
else else
ec.assign(0, ec.category()); ec.assign(0, ec.category());
boost::asio::post( net::post(
s.get_executor(), s.get_executor(),
beast::bind_front_handler(std::move(handler), ec)); beast::bind_front_handler(std::move(handler), ec));
} }
@@ -478,8 +478,8 @@ class stream::read_op : public stream::read_op_base
state& s_; state& s_;
Buffers b_; Buffers b_;
Handler h_; Handler h_;
boost::asio::executor_work_guard< net::executor_work_guard<
boost::asio::io_context::executor_type> work_; net::io_context::executor_type> work_;
public: public:
lambda(lambda&&) = default; lambda(lambda&&) = default;
@@ -497,7 +497,7 @@ class stream::read_op : public stream::read_op_base
void void
post() post()
{ {
boost::asio::post( net::post(
s_.ioc.get_executor(), s_.ioc.get_executor(),
std::move(*this)); std::move(*this));
work_.reset(); work_.reset();
@@ -506,8 +506,8 @@ class stream::read_op : public stream::read_op_base
void void
operator()() operator()()
{ {
using boost::asio::buffer_copy; using net::buffer_copy;
using boost::asio::buffer_size; using net::buffer_size;
std::unique_lock<std::mutex> lock{s_.m}; std::unique_lock<std::mutex> lock{s_.m};
BOOST_ASSERT(! s_.op); BOOST_ASSERT(! s_.op);
if(s_.b.size() > 0) if(s_.b.size() > 0)
@@ -519,7 +519,7 @@ class stream::read_op : public stream::read_op_base
Handler h{std::move(h_)}; Handler h{std::move(h_)};
lock.unlock(); lock.unlock();
++s.nread; ++s.nread;
boost::asio::post( net::post(
s.ioc.get_executor(), s.ioc.get_executor(),
beast::bind_front_handler( beast::bind_front_handler(
std::move(h), std::move(h),
@@ -535,10 +535,10 @@ class stream::read_op : public stream::read_op_base
++s.nread; ++s.nread;
error_code ec; error_code ec;
if(s.code == status::eof) if(s.code == status::eof)
ec = boost::asio::error::eof; ec = net::error::eof;
else if(s.code == status::reset) else if(s.code == status::reset)
ec = boost::asio::error::connection_reset; ec = net::error::connection_reset;
boost::asio::post( net::post(
s.ioc.get_executor(), s.ioc.get_executor(),
beast::bind_front_handler(std::move(h), ec, 0)); beast::bind_front_handler(std::move(h), ec, 0));
} }

View File

@@ -49,11 +49,11 @@ namespace test {
These streams may be used anywhere an algorithm accepts a These streams may be used anywhere an algorithm accepts a
reference to a synchronous or asynchronous read or write reference to a synchronous or asynchronous read or write
stream. It is possible to use a test stream in a call to stream. It is possible to use a test stream in a call to
`boost::asio::read_until`, or in a call to `net::read_until`, or in a call to
@ref boost::beast::http::async_write for example. @ref boost::beast::http::async_write for example.
As with Boost.Asio I/O objects, a @ref stream constructs As with Boost.Asio I/O objects, a @ref stream constructs
with a reference to the `boost::asio::io_context` to use for with a reference to the `net::io_context` to use for
handling asynchronous I/O. For asynchronous operations, the handling asynchronous I/O. For asynchronous operations, the
stream follows the same rules as a traditional asio socket stream follows the same rules as a traditional asio socket
with respect to how completion handlers for asynchronous with respect to how completion handlers for asynchronous
@@ -120,7 +120,7 @@ class stream
flat_buffer b; flat_buffer b;
std::condition_variable cv; std::condition_variable cv;
std::unique_ptr<read_op_base> op; std::unique_ptr<read_op_base> op;
boost::asio::io_context& ioc; net::io_context& ioc;
status code = status::ok; status code = status::ok;
fail_count* fc = nullptr; fail_count* fc = nullptr;
std::size_t nread = 0; std::size_t nread = 0;
@@ -137,7 +137,7 @@ class stream
explicit explicit
state( state(
boost::asio::io_context& ioc_, net::io_context& ioc_,
fail_count* fc_) fail_count* fc_)
: ioc(ioc_) : ioc(ioc_)
, fc(fc_) , fc(fc_)
@@ -175,7 +175,7 @@ public:
handler. handler.
If a connection is established while the stream is destroyed, If a connection is established while the stream is destroyed,
the peer will see the error `boost::asio::error::connection_reset` the peer will see the error `net::error::connection_reset`
when performing any reads or writes. when performing any reads or writes.
*/ */
~stream(); ~stream();
@@ -203,7 +203,7 @@ public:
dispatch handlers for any asynchronous operations. dispatch handlers for any asynchronous operations.
*/ */
explicit explicit
stream(boost::asio::io_context& ioc); stream(net::io_context& ioc);
/** Construct a stream /** Construct a stream
@@ -218,7 +218,7 @@ public:
a simulated failure error will be raised. a simulated failure error will be raised.
*/ */
stream( stream(
boost::asio::io_context& ioc, net::io_context& ioc,
fail_count& fc); fail_count& fc);
/** Construct a stream /** Construct a stream
@@ -232,7 +232,7 @@ public:
including the null terminator. including the null terminator.
*/ */
stream( stream(
boost::asio::io_context& ioc, net::io_context& ioc,
string_view s); string_view s);
/** Construct a stream /** Construct a stream
@@ -251,7 +251,7 @@ public:
including the null terminator. including the null terminator.
*/ */
stream( stream(
boost::asio::io_context& ioc, net::io_context& ioc,
fail_count& fc, fail_count& fc,
string_view s); string_view s);
@@ -261,10 +261,10 @@ public:
/// The type of the executor associated with the object. /// The type of the executor associated with the object.
using executor_type = using executor_type =
boost::asio::io_context::executor_type; net::io_context::executor_type;
/// Return the executor associated with the object. /// Return the executor associated with the object.
boost::asio::io_context::executor_type net::io_context::executor_type
get_executor() noexcept get_executor() noexcept
{ {
return in_->ioc.get_executor(); return in_->ioc.get_executor();
@@ -374,7 +374,7 @@ public:
@throws boost::system::system_error Thrown on failure. @throws boost::system::system_error Thrown on failure.
@note The `read_some` operation may not read all of the requested number of @note The `read_some` operation may not read all of the requested number of
bytes. Consider using the function `boost::asio::read` if you need to ensure bytes. Consider using the function `net::read` if you need to ensure
that the requested amount of data is read before the blocking operation that the requested amount of data is read before the blocking operation
completes. completes.
*/ */
@@ -395,7 +395,7 @@ public:
@returns The number of bytes read. @returns The number of bytes read.
@note The `read_some` operation may not read all of the requested number of @note The `read_some` operation may not read all of the requested number of
bytes. Consider using the function `boost::asio::read` if you need to ensure bytes. Consider using the function `net::read` if you need to ensure
that the requested amount of data is read before the blocking operation that the requested amount of data is read before the blocking operation
completes. completes.
*/ */
@@ -423,7 +423,7 @@ public:
); @endcode ); @endcode
@note The `read_some` operation may not read all of the requested number of @note The `read_some` operation may not read all of the requested number of
bytes. Consider using the function `boost::asio::async_read` if you need bytes. Consider using the function `net::async_read` if you need
to ensure that the requested amount of data is read before the asynchronous to ensure that the requested amount of data is read before the asynchronous
operation completes. operation completes.
*/ */
@@ -446,7 +446,7 @@ public:
@throws boost::system::system_error Thrown on failure. @throws boost::system::system_error Thrown on failure.
@note The `write_some` operation may not transmit all of the data to the @note The `write_some` operation may not transmit all of the data to the
peer. Consider using the function `boost::asio::write` if you need to peer. Consider using the function `net::write` if you need to
ensure that all data is written before the blocking operation completes. ensure that all data is written before the blocking operation completes.
*/ */
template<class ConstBufferSequence> template<class ConstBufferSequence>
@@ -466,7 +466,7 @@ public:
@returns The number of bytes written. @returns The number of bytes written.
@note The `write_some` operation may not transmit all of the data to the @note The `write_some` operation may not transmit all of the data to the
peer. Consider using the function `boost::asio::write` if you need to peer. Consider using the function `net::write` if you need to
ensure that all data is written before the blocking operation completes. ensure that all data is written before the blocking operation completes.
*/ */
template<class ConstBufferSequence> template<class ConstBufferSequence>
@@ -493,7 +493,7 @@ public:
); @endcode ); @endcode
@note The `async_write_some` operation may not transmit all of the data to @note The `async_write_some` operation may not transmit all of the data to
the peer. Consider using the function `boost::asio::async_write` if you need the peer. Consider using the function `net::async_write` if you need
to ensure that all data is written before the asynchronous operation completes. to ensure that all data is written before the asynchronous operation completes.
*/ */
template<class ConstBufferSequence, class WriteHandler> template<class ConstBufferSequence, class WriteHandler>

View File

@@ -38,10 +38,10 @@ namespace beast {
void void
signal_aborted(AsyncReadStream& stream, ReadHandler&& handler) signal_aborted(AsyncReadStream& stream, ReadHandler&& handler)
{ {
boost::asio::post( net::post(
stream.get_executor(), stream.get_executor(),
bind_handler(std::forward<ReadHandler>(handler), bind_handler(std::forward<ReadHandler>(handler),
boost::asio::error::operation_aborted, 0)); net::error::operation_aborted, 0));
} }
@endcode @endcode
@@ -90,10 +90,10 @@ bind_handler(Handler&& handler, Args&&... args)
void void
signal_aborted(AsyncReadStream& stream, ReadHandler&& handler) signal_aborted(AsyncReadStream& stream, ReadHandler&& handler)
{ {
boost::asio::post( net::post(
stream.get_executor(), stream.get_executor(),
bind_front_handler(std::forward<ReadHandler>(handler), bind_front_handler(std::forward<ReadHandler>(handler),
boost::asio::error::operation_aborted, 0)); net::error::operation_aborted, 0));
} }
@endcode @endcode

View File

@@ -31,17 +31,17 @@ namespace beast {
is part of the object. is part of the object.
The use-case for this class is different than that of the The use-case for this class is different than that of the
`boost::asio::buffered_readstream`. It is designed to facilitate `net::buffered_readstream`. It is designed to facilitate
the use of `boost::asio::read_until`, and to allow buffers the use of `net::read_until`, and to allow buffers
acquired during detection of handshakes to be made transparently acquired during detection of handshakes to be made transparently
available to callers. A hypothetical implementation of the available to callers. A hypothetical implementation of the
buffered version of `boost::asio::ssl::stream::async_handshake` buffered version of `net::ssl::stream::async_handshake`
could make use of this wrapper. could make use of this wrapper.
Uses: Uses:
@li Transparently leave untouched input acquired in calls @li Transparently leave untouched input acquired in calls
to `boost::asio::read_until` behind for subsequent callers. to `net::read_until` behind for subsequent callers.
@li "Preload" a stream with handshake input data acquired @li "Preload" a stream with handshake input data acquired
from other sources. from other sources.
@@ -62,7 +62,7 @@ namespace beast {
// part up to the end of the delimiter. // part up to the end of the delimiter.
// //
std::size_t bytes_transferred = std::size_t bytes_transferred =
boost::asio::read_until( net::read_until(
stream.next_layer(), stream.buffer(), "\r\n\r\n"); stream.next_layer(), stream.buffer(), "\r\n\r\n");
// Use buffers_prefix() to limit the input // Use buffers_prefix() to limit the input
@@ -92,7 +92,7 @@ template<class Stream, class DynamicBuffer>
class buffered_read_stream class buffered_read_stream
{ {
static_assert( static_assert(
boost::asio::is_dynamic_buffer<DynamicBuffer>::value, net::is_dynamic_buffer<DynamicBuffer>::value,
"DynamicBuffer requirements not met"); "DynamicBuffer requirements not met");
template<class Buffers, class Handler> template<class Buffers, class Handler>
@@ -283,7 +283,7 @@ public:
Regardless of whether the asynchronous operation completes Regardless of whether the asynchronous operation completes
immediately or not, the handler will not be invoked from within immediately or not, the handler will not be invoked from within
this function. Invocation of the handler will be performed in a this function. Invocation of the handler will be performed in a
manner equivalent to using `boost::asio::io_context::post`. manner equivalent to using `net::io_context::post`.
*/ */
template<class MutableBufferSequence, class ReadHandler> template<class MutableBufferSequence, class ReadHandler>
BOOST_ASIO_INITFN_RESULT_TYPE( BOOST_ASIO_INITFN_RESULT_TYPE(
@@ -355,7 +355,7 @@ public:
Regardless of whether the asynchronous operation completes Regardless of whether the asynchronous operation completes
immediately or not, the handler will not be invoked from within immediately or not, the handler will not be invoked from within
this function. Invocation of the handler will be performed in a this function. Invocation of the handler will be performed in a
manner equivalent to using `boost::asio::io_context::post`. manner equivalent to using `net::io_context::post`.
*/ */
template<class ConstBufferSequence, class WriteHandler> template<class ConstBufferSequence, class WriteHandler>
BOOST_ASIO_INITFN_RESULT_TYPE( BOOST_ASIO_INITFN_RESULT_TYPE(

View File

@@ -36,7 +36,7 @@ namespace beast {
template<class MutableBufferSequence> template<class MutableBufferSequence>
class buffers_adapter class buffers_adapter
{ {
static_assert(boost::asio::is_mutable_buffer_sequence<MutableBufferSequence>::value, static_assert(net::is_mutable_buffer_sequence<MutableBufferSequence>::value,
"MutableBufferSequence requirements not met"); "MutableBufferSequence requirements not met");
using iter_type = typename using iter_type = typename

View File

@@ -30,8 +30,8 @@ public:
/** The type of buffer returned when dereferencing an iterator. /** The type of buffer returned when dereferencing an iterator.
If every buffer sequence in the view is a @b MutableBufferSequence, If every buffer sequence in the view is a @b MutableBufferSequence,
then `value_type` will be `boost::asio::mutable_buffer`. then `value_type` will be `net::mutable_buffer`.
Otherwise, `value_type` will be `boost::asio::const_buffer`. Otherwise, `value_type` will be `net::const_buffer`.
*/ */
#if BOOST_BEAST_DOXYGEN #if BOOST_BEAST_DOXYGEN
using value_type = __implementation_defined__; using value_type = __implementation_defined__;

View File

@@ -60,9 +60,9 @@ public:
using value_type = typename std::conditional< using value_type = typename std::conditional<
std::is_convertible<typename std::is_convertible<typename
std::iterator_traits<iter_type>::value_type, std::iterator_traits<iter_type>::value_type,
boost::asio::mutable_buffer>::value, net::mutable_buffer>::value,
boost::asio::mutable_buffer, net::mutable_buffer,
boost::asio::const_buffer>::type; net::const_buffer>::type;
#if BOOST_BEAST_DOXYGEN #if BOOST_BEAST_DOXYGEN
/// A bidirectional iterator type that may be used to read elements. /// A bidirectional iterator type that may be used to read elements.
@@ -139,9 +139,9 @@ public:
bytes of the original buffer. bytes of the original buffer.
*/ */
inline inline
boost::asio::const_buffer net::const_buffer
buffers_prefix(std::size_t size, buffers_prefix(std::size_t size,
boost::asio::const_buffer buffer) net::const_buffer buffer)
{ {
return {buffer.data(), return {buffer.data(),
(std::min)(size, buffer.size())}; (std::min)(size, buffer.size())};
@@ -162,9 +162,9 @@ buffers_prefix(std::size_t size,
of the original buffer. of the original buffer.
*/ */
inline inline
boost::asio::mutable_buffer net::mutable_buffer
buffers_prefix(std::size_t size, buffers_prefix(std::size_t size,
boost::asio::mutable_buffer buffer) net::mutable_buffer buffer)
{ {
return {buffer.data(), return {buffer.data(),
(std::min)(size, buffer.size())}; (std::min)(size, buffer.size())};
@@ -193,16 +193,16 @@ buffers_prefix_view<BufferSequence>
inline inline
typename std::enable_if< typename std::enable_if<
! std::is_same<BufferSequence, ! std::is_same<BufferSequence,
boost::asio::const_buffer>::value && net::const_buffer>::value &&
! std::is_same<BufferSequence, ! std::is_same<BufferSequence,
boost::asio::mutable_buffer>::value, net::mutable_buffer>::value,
buffers_prefix_view<BufferSequence>>::type buffers_prefix_view<BufferSequence>>::type
#endif #endif
buffers_prefix(std::size_t size, BufferSequence const& buffers) buffers_prefix(std::size_t size, BufferSequence const& buffers)
{ {
static_assert( static_assert(
boost::asio::is_const_buffer_sequence<BufferSequence>::value || net::is_const_buffer_sequence<BufferSequence>::value ||
boost::asio::is_mutable_buffer_sequence<BufferSequence>::value, net::is_mutable_buffer_sequence<BufferSequence>::value,
"BufferSequence requirements not met"); "BufferSequence requirements not met");
return buffers_prefix_view<BufferSequence>(size, buffers); return buffers_prefix_view<BufferSequence>(size, buffers);
} }
@@ -219,14 +219,14 @@ buffers_prefix(std::size_t size, BufferSequence const& buffers)
*/ */
template<class BufferSequence> template<class BufferSequence>
typename std::conditional< typename std::conditional<
boost::asio::is_mutable_buffer_sequence<BufferSequence>::value, net::is_mutable_buffer_sequence<BufferSequence>::value,
boost::asio::mutable_buffer, net::mutable_buffer,
boost::asio::const_buffer>::type net::const_buffer>::type
buffers_front(BufferSequence const& buffers) buffers_front(BufferSequence const& buffers)
{ {
auto const first = auto const first =
boost::asio::buffer_sequence_begin(buffers); net::buffer_sequence_begin(buffers);
if(first == boost::asio::buffer_sequence_end(buffers)) if(first == net::buffer_sequence_end(buffers))
return {}; return {};
return *first; return *first;
} }

View File

@@ -64,7 +64,7 @@ detail::buffers_range_adaptor<ConstBufferSequence>
buffers_range(ConstBufferSequence const& buffers) buffers_range(ConstBufferSequence const& buffers)
{ {
static_assert( static_assert(
boost::asio::is_const_buffer_sequence<ConstBufferSequence>::value, net::is_const_buffer_sequence<ConstBufferSequence>::value,
"ConstBufferSequence requirements not met"); "ConstBufferSequence requirements not met");
return detail::buffers_range_adaptor<ConstBufferSequence>(buffers); return detail::buffers_range_adaptor<ConstBufferSequence>(buffers);
} }
@@ -78,7 +78,7 @@ detail::buffers_range_adaptor<ConstBufferSequence const&>
buffers_range(std::reference_wrapper<ConstBufferSequence> buffers) buffers_range(std::reference_wrapper<ConstBufferSequence> buffers)
{ {
static_assert( static_assert(
boost::asio::is_const_buffer_sequence<ConstBufferSequence>::value, net::is_const_buffer_sequence<ConstBufferSequence>::value,
"ConstBufferSequence requirements not met"); "ConstBufferSequence requirements not met");
return detail::buffers_range_adaptor<ConstBufferSequence const&>(buffers.get()); return detail::buffers_range_adaptor<ConstBufferSequence const&>(buffers.get());
} }

View File

@@ -45,7 +45,7 @@ namespace beast {
void send(SyncWriteStream& stream, ConstBufferSequence const& buffers) void send(SyncWriteStream& stream, ConstBufferSequence const& buffers)
{ {
buffers_suffix<ConstBufferSequence> bs{buffers}; buffers_suffix<ConstBufferSequence> bs{buffers};
while(boost::asio::buffer_size(bs) > 0) while(net::buffer_size(bs) > 0)
bs.consume(stream.write_some(bs)); bs.consume(stream.write_some(bs));
} }
@endcode @endcode
@@ -67,7 +67,7 @@ class buffers_suffix
buffers_suffix(Deduced&& other, std::size_t dist) buffers_suffix(Deduced&& other, std::size_t dist)
: bs_(std::forward<Deduced>(other).bs_) : bs_(std::forward<Deduced>(other).bs_)
, begin_(std::next( , begin_(std::next(
boost::asio::buffer_sequence_begin(bs_), net::buffer_sequence_begin(bs_),
dist)) dist))
, skip_(other.skip_) , skip_(other.skip_)
{ {
@@ -77,9 +77,9 @@ public:
/** The type for each element in the list of buffers. /** The type for each element in the list of buffers.
If the buffers in the underlying sequence are convertible to If the buffers in the underlying sequence are convertible to
`boost::asio::mutable_buffer`, then this type will be `net::mutable_buffer`, then this type will be
`boost::asio::mutable_buffer`, else this type will be `net::mutable_buffer`, else this type will be
`boost::asio::const_buffer`. `net::const_buffer`.
*/ */
#if BOOST_BEAST_DOXYGEN #if BOOST_BEAST_DOXYGEN
using value_type = __implementation_defined__; using value_type = __implementation_defined__;
@@ -87,9 +87,9 @@ public:
using value_type = typename std::conditional< using value_type = typename std::conditional<
std::is_convertible<typename std::is_convertible<typename
std::iterator_traits<iter_type>::value_type, std::iterator_traits<iter_type>::value_type,
boost::asio::mutable_buffer>::value, net::mutable_buffer>::value,
boost::asio::mutable_buffer, net::mutable_buffer,
boost::asio::const_buffer>::type; net::const_buffer>::type;
#endif #endif
#if BOOST_BEAST_DOXYGEN #if BOOST_BEAST_DOXYGEN

View File

@@ -45,10 +45,10 @@ std::string
buffers_to_string(ConstBufferSequence const& buffers) buffers_to_string(ConstBufferSequence const& buffers)
{ {
static_assert( static_assert(
boost::asio::is_const_buffer_sequence<ConstBufferSequence>::value, net::is_const_buffer_sequence<ConstBufferSequence>::value,
"ConstBufferSequence requirements not met"); "ConstBufferSequence requirements not met");
std::string result; std::string result;
result.reserve(boost::asio::buffer_size(buffers)); result.reserve(net::buffer_size(buffers));
for(auto const buffer : buffers_range(std::ref(buffers))) for(auto const buffer : buffers_range(std::ref(buffers)))
result.append(static_cast<char const*>( result.append(static_cast<char const*>(
buffer.data()), buffer.size()); buffer.data()), buffer.size());

View File

@@ -40,7 +40,7 @@ class bind_wrapper
// Can't friend partial specializations, // Can't friend partial specializations,
// so we just friend the whole thing. // so we just friend the whole thing.
template<class T, class Executor> template<class T, class Executor>
friend struct boost::asio::associated_executor; friend struct net::associated_executor;
template<class Arg, class Vals> template<class Arg, class Vals>
static static
@@ -123,7 +123,7 @@ public:
using result_type = void; using result_type = void;
using allocator_type = using allocator_type =
boost::asio::associated_allocator_t<Handler>; net::associated_allocator_t<Handler>;
bind_wrapper(bind_wrapper&&) = default; bind_wrapper(bind_wrapper&&) = default;
bind_wrapper(bind_wrapper const&) = default; bind_wrapper(bind_wrapper const&) = default;
@@ -140,14 +140,14 @@ public:
allocator_type allocator_type
get_allocator() const noexcept get_allocator() const noexcept
{ {
return (boost::asio::get_associated_allocator)(h_); return (net::get_associated_allocator)(h_);
} }
friend friend
bool bool
asio_handler_is_continuation(bind_wrapper* w) asio_handler_is_continuation(bind_wrapper* w)
{ {
using boost::asio::asio_handler_is_continuation; using net::asio_handler_is_continuation;
return asio_handler_is_continuation(std::addressof(w->h_)); return asio_handler_is_continuation(std::addressof(w->h_));
} }
@@ -155,7 +155,7 @@ public:
friend friend
void asio_handler_invoke(Function&& f, bind_wrapper* w) void asio_handler_invoke(Function&& f, bind_wrapper* w)
{ {
using boost::asio::asio_handler_invoke; using net::asio_handler_invoke;
asio_handler_invoke(f, std::addressof(w->h_)); asio_handler_invoke(f, std::addressof(w->h_));
} }
@@ -194,13 +194,13 @@ class bind_front_wrapper<Handler>
// Can't friend partial specializations, // Can't friend partial specializations,
// so we just friend the whole thing. // so we just friend the whole thing.
template<class T, class Executor> template<class T, class Executor>
friend struct boost::asio::associated_executor; friend struct net::associated_executor;
public: public:
using result_type = void; using result_type = void;
using allocator_type = using allocator_type =
boost::asio::associated_allocator_t<Handler>; net::associated_allocator_t<Handler>;
bind_front_wrapper(bind_front_wrapper&&) = default; bind_front_wrapper(bind_front_wrapper&&) = default;
bind_front_wrapper(bind_front_wrapper const&) = default; bind_front_wrapper(bind_front_wrapper const&) = default;
@@ -215,14 +215,14 @@ public:
allocator_type allocator_type
get_allocator() const noexcept get_allocator() const noexcept
{ {
return boost::asio::get_associated_allocator(h_); return net::get_associated_allocator(h_);
} }
friend friend
bool bool
asio_handler_is_continuation(bind_front_wrapper* w) asio_handler_is_continuation(bind_front_wrapper* w)
{ {
using boost::asio::asio_handler_is_continuation; using net::asio_handler_is_continuation;
return asio_handler_is_continuation(std::addressof(w->h_)); return asio_handler_is_continuation(std::addressof(w->h_));
} }
@@ -230,7 +230,7 @@ public:
friend friend
void asio_handler_invoke(Function&& f, bind_front_wrapper* w) void asio_handler_invoke(Function&& f, bind_front_wrapper* w)
{ {
using boost::asio::asio_handler_invoke; using net::asio_handler_invoke;
asio_handler_invoke(f, std::addressof(w->h_)); asio_handler_invoke(f, std::addressof(w->h_));
} }
@@ -251,13 +251,13 @@ class bind_front_wrapper<Handler, Arg>
// Can't friend partial specializations, // Can't friend partial specializations,
// so we just friend the whole thing. // so we just friend the whole thing.
template<class T, class Executor> template<class T, class Executor>
friend struct boost::asio::associated_executor; friend struct net::associated_executor;
public: public:
using result_type = void; using result_type = void;
using allocator_type = using allocator_type =
boost::asio::associated_allocator_t<Handler>; net::associated_allocator_t<Handler>;
bind_front_wrapper(bind_front_wrapper&&) = default; bind_front_wrapper(bind_front_wrapper&&) = default;
bind_front_wrapper(bind_front_wrapper const&) = default; bind_front_wrapper(bind_front_wrapper const&) = default;
@@ -273,14 +273,14 @@ public:
allocator_type allocator_type
get_allocator() const noexcept get_allocator() const noexcept
{ {
return boost::asio::get_associated_allocator(h_); return net::get_associated_allocator(h_);
} }
friend friend
bool bool
asio_handler_is_continuation(bind_front_wrapper* w) asio_handler_is_continuation(bind_front_wrapper* w)
{ {
using boost::asio::asio_handler_is_continuation; using net::asio_handler_is_continuation;
return asio_handler_is_continuation(std::addressof(w->h_)); return asio_handler_is_continuation(std::addressof(w->h_));
} }
@@ -288,7 +288,7 @@ public:
friend friend
void asio_handler_invoke(Function&& f, bind_front_wrapper* w) void asio_handler_invoke(Function&& f, bind_front_wrapper* w)
{ {
using boost::asio::asio_handler_invoke; using net::asio_handler_invoke;
asio_handler_invoke(f, std::addressof(w->h_)); asio_handler_invoke(f, std::addressof(w->h_));
} }
@@ -311,13 +311,13 @@ class bind_front_wrapper<Handler, Arg1, Arg2>
// Can't friend partial specializations, // Can't friend partial specializations,
// so we just friend the whole thing. // so we just friend the whole thing.
template<class T, class Executor> template<class T, class Executor>
friend struct boost::asio::associated_executor; friend struct net::associated_executor;
public: public:
using result_type = void; using result_type = void;
using allocator_type = using allocator_type =
boost::asio::associated_allocator_t<Handler>; net::associated_allocator_t<Handler>;
bind_front_wrapper(bind_front_wrapper&&) = default; bind_front_wrapper(bind_front_wrapper&&) = default;
bind_front_wrapper(bind_front_wrapper const&) = default; bind_front_wrapper(bind_front_wrapper const&) = default;
@@ -334,14 +334,14 @@ public:
allocator_type allocator_type
get_allocator() const noexcept get_allocator() const noexcept
{ {
return boost::asio::get_associated_allocator(h_); return net::get_associated_allocator(h_);
} }
friend friend
bool bool
asio_handler_is_continuation(bind_front_wrapper* w) asio_handler_is_continuation(bind_front_wrapper* w)
{ {
using boost::asio::asio_handler_is_continuation; using net::asio_handler_is_continuation;
return asio_handler_is_continuation(std::addressof(w->h_)); return asio_handler_is_continuation(std::addressof(w->h_));
} }
@@ -349,7 +349,7 @@ public:
friend friend
void asio_handler_invoke(Function&& f, bind_front_wrapper* w) void asio_handler_invoke(Function&& f, bind_front_wrapper* w)
{ {
using boost::asio::asio_handler_invoke; using net::asio_handler_invoke;
asio_handler_invoke(f, std::addressof(w->h_)); asio_handler_invoke(f, std::addressof(w->h_));
} }
@@ -379,7 +379,7 @@ class bind_front_wrapper<Handler, Arg1, Arg2, Arg3, Args...>
// Can't friend partial specializations, // Can't friend partial specializations,
// so we just friend the whole thing. // so we just friend the whole thing.
template<class T, class Executor> template<class T, class Executor>
friend struct boost::asio::associated_executor; friend struct net::associated_executor;
template<std::size_t... I, class... Ts> template<std::size_t... I, class... Ts>
void void
@@ -395,7 +395,7 @@ public:
using result_type = void; using result_type = void;
using allocator_type = using allocator_type =
boost::asio::associated_allocator_t<Handler>; net::associated_allocator_t<Handler>;
bind_front_wrapper(bind_front_wrapper&&) = default; bind_front_wrapper(bind_front_wrapper&&) = default;
bind_front_wrapper(bind_front_wrapper const&) = default; bind_front_wrapper(bind_front_wrapper const&) = default;
@@ -416,14 +416,14 @@ public:
allocator_type allocator_type
get_allocator() const noexcept get_allocator() const noexcept
{ {
return boost::asio::get_associated_allocator(h_); return net::get_associated_allocator(h_);
} }
friend friend
bool bool
asio_handler_is_continuation(bind_front_wrapper* w) asio_handler_is_continuation(bind_front_wrapper* w)
{ {
using boost::asio::asio_handler_is_continuation; using net::asio_handler_is_continuation;
return asio_handler_is_continuation(std::addressof(w->h_)); return asio_handler_is_continuation(std::addressof(w->h_));
} }
@@ -431,7 +431,7 @@ public:
friend friend
void asio_handler_invoke(Function&& f, bind_front_wrapper* w) void asio_handler_invoke(Function&& f, bind_front_wrapper* w)
{ {
using boost::asio::asio_handler_invoke; using net::asio_handler_invoke;
asio_handler_invoke(f, std::addressof(w->h_)); asio_handler_invoke(f, std::addressof(w->h_));
} }
@@ -461,7 +461,7 @@ public:
using result_type = void; using result_type = void;
using allocator_type = using allocator_type =
boost::asio::associated_allocator_t<Handler>; net::associated_allocator_t<Handler>;
bind_front_wrapper(bind_front_wrapper&&) = default; bind_front_wrapper(bind_front_wrapper&&) = default;
bind_front_wrapper(bind_front_wrapper const&) = default; bind_front_wrapper(bind_front_wrapper const&) = default;
@@ -478,14 +478,14 @@ public:
allocator_type allocator_type
get_allocator() const noexcept get_allocator() const noexcept
{ {
return boost::asio::get_associated_allocator(h_); return net::get_associated_allocator(h_);
} }
friend friend
bool bool
asio_handler_is_continuation(bind_front_wrapper* w) asio_handler_is_continuation(bind_front_wrapper* w)
{ {
using boost::asio::asio_handler_is_continuation; using net::asio_handler_is_continuation;
return asio_handler_is_continuation(std::addressof(w->h_)); return asio_handler_is_continuation(std::addressof(w->h_));
} }
@@ -493,7 +493,7 @@ public:
friend friend
void asio_handler_invoke(Function&& f, bind_front_wrapper* w) void asio_handler_invoke(Function&& f, bind_front_wrapper* w)
{ {
using boost::asio::asio_handler_invoke; using net::asio_handler_invoke;
asio_handler_invoke(f, std::addressof(w->h_)); asio_handler_invoke(f, std::addressof(w->h_));
} }

View File

@@ -33,9 +33,9 @@ public:
typename std::iterator_traits< typename std::iterator_traits<
typename detail::buffer_sequence_iterator< typename detail::buffer_sequence_iterator<
BufferSequence>::type>::value_type, BufferSequence>::type>::value_type,
boost::asio::mutable_buffer>::value, net::mutable_buffer>::value,
boost::asio::mutable_buffer, net::mutable_buffer,
boost::asio::const_buffer>::type; net::const_buffer>::type;
#endif #endif
class const_iterator class const_iterator
@@ -124,13 +124,13 @@ public:
const_iterator const_iterator
begin() const noexcept begin() const noexcept
{ {
return boost::asio::buffer_sequence_begin(b_); return net::buffer_sequence_begin(b_);
} }
const_iterator const_iterator
end() const noexcept end() const noexcept
{ {
return boost::asio::buffer_sequence_end(b_); return net::buffer_sequence_end(b_);
} }
}; };

View File

@@ -42,13 +42,13 @@ public:
const_iterator const_iterator
begin() const begin() const
{ {
return boost::asio::buffer_sequence_begin(*buffers_); return net::buffer_sequence_begin(*buffers_);
} }
const_iterator const_iterator
end() const end() const
{ {
return boost::asio::buffer_sequence_end(*buffers_); return net::buffer_sequence_end(*buffers_);
} }
}; };

View File

@@ -262,21 +262,21 @@ struct BufferSequence
const_iterator end() const noexcept; const_iterator end() const noexcept;
}; };
using ConstBufferSequence = using ConstBufferSequence =
BufferSequence<boost::asio::const_buffer>; BufferSequence<net::const_buffer>;
using MutableBufferSequence = using MutableBufferSequence =
BufferSequence<boost::asio::mutable_buffer>; BufferSequence<net::mutable_buffer>;
template<class B1, class... Bn> template<class B1, class... Bn>
struct is_all_const_buffer_sequence struct is_all_const_buffer_sequence
: std::integral_constant<bool, : std::integral_constant<bool,
boost::asio::is_const_buffer_sequence<B1>::value && net::is_const_buffer_sequence<B1>::value &&
is_all_const_buffer_sequence<Bn...>::value> is_all_const_buffer_sequence<Bn...>::value>
{ {
}; };
template<class B> template<class B>
struct is_all_const_buffer_sequence<B> struct is_all_const_buffer_sequence<B>
: boost::asio::is_const_buffer_sequence<B> : net::is_const_buffer_sequence<B>
{ {
}; };
@@ -288,22 +288,22 @@ template<class B>
struct buffer_sequence_iterator struct buffer_sequence_iterator
{ {
using type = decltype( using type = decltype(
boost::asio::buffer_sequence_begin( net::buffer_sequence_begin(
std::declval<B const&>())); std::declval<B const&>()));
}; };
template<> template<>
struct buffer_sequence_iterator< struct buffer_sequence_iterator<
boost::asio::const_buffer> net::const_buffer>
{ {
using type = boost::asio::const_buffer const*; using type = net::const_buffer const*;
}; };
template<> template<>
struct buffer_sequence_iterator< struct buffer_sequence_iterator<
boost::asio::mutable_buffer> net::mutable_buffer>
{ {
using type = boost::asio::mutable_buffer const*; using type = net::mutable_buffer const*;
}; };
// //
@@ -320,16 +320,16 @@ struct buffer_sequence_value_type
template<> template<>
struct buffer_sequence_value_type< struct buffer_sequence_value_type<
boost::asio::const_buffer const*> net::const_buffer const*>
{ {
using type = boost::asio::const_buffer; using type = net::const_buffer;
}; };
template<> template<>
struct buffer_sequence_value_type< struct buffer_sequence_value_type<
boost::asio::mutable_buffer const*> net::mutable_buffer const*>
{ {
using type = boost::asio::mutable_buffer; using type = net::mutable_buffer;
}; };
// //
@@ -341,9 +341,9 @@ struct common_buffers_type
mp11::mp_and< mp11::mp_and<
boost::is_convertible< boost::is_convertible<
typename buffer_sequence_value_type<Bn>::type, typename buffer_sequence_value_type<Bn>::type,
boost::asio::mutable_buffer>...>::value, net::mutable_buffer>...>::value,
boost::asio::mutable_buffer, net::mutable_buffer,
boost::asio::const_buffer>::type; net::const_buffer>::type;
}; };
// Types that meet the requirements, // Types that meet the requirements,
@@ -366,7 +366,7 @@ using WriteHandler = StreamHandler;
static_assert(boost::beast::is_completion_handler< \ static_assert(boost::beast::is_completion_handler< \
BOOST_ASIO_HANDLER_TYPE(type, sig), sig>::value, \ BOOST_ASIO_HANDLER_TYPE(type, sig), sig>::value, \
"CompletionHandler signature requirements not met"); \ "CompletionHandler signature requirements not met"); \
boost::asio::async_completion<type, sig> init{handler} net::async_completion<type, sig> init{handler}
} // detail } // detail
} // beast } // beast

View File

@@ -281,13 +281,13 @@ public:
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
/// The ConstBufferSequence used to represent the readable bytes. /// The ConstBufferSequence used to represent the readable bytes.
using const_buffers_type = boost::asio::const_buffer; using const_buffers_type = net::const_buffer;
/// The MutableBufferSequence used to represent the readable bytes. /// The MutableBufferSequence used to represent the readable bytes.
using mutable_data_type = boost::asio::mutable_buffer; using mutable_data_type = net::mutable_buffer;
/// The MutableBufferSequence used to represent the writable bytes. /// The MutableBufferSequence used to represent the writable bytes.
using mutable_buffers_type = boost::asio::mutable_buffer; using mutable_buffers_type = net::mutable_buffer;
/// Returns the number of readable bytes. /// Returns the number of readable bytes.
std::size_t std::size_t

View File

@@ -92,13 +92,13 @@ public:
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
/// The ConstBufferSequence used to represent the readable bytes. /// The ConstBufferSequence used to represent the readable bytes.
using const_buffers_type = boost::asio::const_buffer; using const_buffers_type = net::const_buffer;
/// The MutableBufferSequence used to represent the readable bytes. /// The MutableBufferSequence used to represent the readable bytes.
using mutable_data_type = boost::asio::mutable_buffer; using mutable_data_type = net::mutable_buffer;
/// The MutableBufferSequence used to represent the writable bytes. /// The MutableBufferSequence used to represent the writable bytes.
using mutable_buffers_type = boost::asio::mutable_buffer; using mutable_buffers_type = net::mutable_buffer;
/// Returns the number of readable bytes. /// Returns the number of readable bytes.
std::size_t std::size_t

View File

@@ -33,7 +33,7 @@ class buffered_read_stream<
Stream, DynamicBuffer>::read_some_op Stream, DynamicBuffer>::read_some_op
{ {
buffered_read_stream& s_; buffered_read_stream& s_;
boost::asio::executor_work_guard<decltype( net::executor_work_guard<decltype(
std::declval<Stream&>().get_executor())> wg_; std::declval<Stream&>().get_executor())> wg_;
MutableBufferSequence b_; MutableBufferSequence b_;
Handler h_; Handler h_;
@@ -55,22 +55,22 @@ public:
} }
using allocator_type = using allocator_type =
boost::asio::associated_allocator_t<Handler>; net::associated_allocator_t<Handler>;
allocator_type allocator_type
get_allocator() const noexcept get_allocator() const noexcept
{ {
return (boost::asio::get_associated_allocator)(h_); return (net::get_associated_allocator)(h_);
} }
using executor_type = using executor_type =
boost::asio::associated_executor_t<Handler, decltype( net::associated_executor_t<Handler, decltype(
std::declval<buffered_read_stream&>().get_executor())>; std::declval<buffered_read_stream&>().get_executor())>;
executor_type executor_type
get_executor() const noexcept get_executor() const noexcept
{ {
return (boost::asio::get_associated_executor)( return (net::get_associated_executor)(
h_, s_.get_executor()); h_, s_.get_executor());
} }
@@ -81,7 +81,7 @@ public:
friend friend
bool asio_handler_is_continuation(read_some_op* op) bool asio_handler_is_continuation(read_some_op* op)
{ {
using boost::asio::asio_handler_is_continuation; using net::asio_handler_is_continuation;
return asio_handler_is_continuation( return asio_handler_is_continuation(
std::addressof(op->h_)); std::addressof(op->h_));
} }
@@ -90,7 +90,7 @@ public:
friend friend
void asio_handler_invoke(Function&& f, read_some_op* op) void asio_handler_invoke(Function&& f, read_some_op* op)
{ {
using boost::asio::asio_handler_invoke; using net::asio_handler_invoke;
asio_handler_invoke(f, std::addressof(op->h_)); asio_handler_invoke(f, std::addressof(op->h_));
} }
}; };
@@ -124,7 +124,7 @@ read_some_op<MutableBufferSequence, Handler>::operator()(
} }
step_ = 3; step_ = 3;
return boost::asio::post( return net::post(
s_.get_executor(), s_.get_executor(),
beast::bind_front_handler(std::move(*this), ec, 0)); beast::bind_front_handler(std::move(*this), ec, 0));
@@ -138,7 +138,7 @@ read_some_op<MutableBufferSequence, Handler>::operator()(
case 3: case 3:
bytes_transferred = bytes_transferred =
boost::asio::buffer_copy(b_, s_.buffer_.data()); net::buffer_copy(b_, s_.buffer_.data());
s_.buffer_.consume(bytes_transferred); s_.buffer_.consume(bytes_transferred);
break; break;
} }
@@ -166,7 +166,7 @@ async_write_some(
{ {
static_assert(is_async_write_stream<next_layer_type>::value, static_assert(is_async_write_stream<next_layer_type>::value,
"AsyncWriteStream requirements not met"); "AsyncWriteStream requirements not met");
static_assert(boost::asio::is_const_buffer_sequence< static_assert(net::is_const_buffer_sequence<
ConstBufferSequence>::value, ConstBufferSequence>::value,
"ConstBufferSequence requirements not met"); "ConstBufferSequence requirements not met");
static_assert(is_completion_handler<WriteHandler, static_assert(is_completion_handler<WriteHandler,
@@ -185,7 +185,7 @@ read_some(
{ {
static_assert(is_sync_read_stream<next_layer_type>::value, static_assert(is_sync_read_stream<next_layer_type>::value,
"SyncReadStream requirements not met"); "SyncReadStream requirements not met");
static_assert(boost::asio::is_mutable_buffer_sequence< static_assert(net::is_mutable_buffer_sequence<
MutableBufferSequence>::value, MutableBufferSequence>::value,
"MutableBufferSequence requirements not met"); "MutableBufferSequence requirements not met");
error_code ec; error_code ec;
@@ -204,11 +204,11 @@ read_some(MutableBufferSequence const& buffers,
{ {
static_assert(is_sync_read_stream<next_layer_type>::value, static_assert(is_sync_read_stream<next_layer_type>::value,
"SyncReadStream requirements not met"); "SyncReadStream requirements not met");
static_assert(boost::asio::is_mutable_buffer_sequence< static_assert(net::is_mutable_buffer_sequence<
MutableBufferSequence>::value, MutableBufferSequence>::value,
"MutableBufferSequence requirements not met"); "MutableBufferSequence requirements not met");
using boost::asio::buffer_size; using net::buffer_size;
using boost::asio::buffer_copy; using net::buffer_copy;
if(buffer_.size() == 0) if(buffer_.size() == 0)
{ {
if(capacity_ == 0) if(capacity_ == 0)
@@ -240,7 +240,7 @@ async_read_some(
{ {
static_assert(is_async_read_stream<next_layer_type>::value, static_assert(is_async_read_stream<next_layer_type>::value,
"AsyncReadStream requirements not met"); "AsyncReadStream requirements not met");
static_assert(boost::asio::is_mutable_buffer_sequence< static_assert(net::is_mutable_buffer_sequence<
MutableBufferSequence>::value, MutableBufferSequence>::value,
"MutableBufferSequence requirements not met"); "MutableBufferSequence requirements not met");
if(buffer_.size() == 0 && capacity_ == 0) if(buffer_.size() == 0 && capacity_ == 0)

View File

@@ -29,7 +29,7 @@ class buffers_adapter<MutableBufferSequence>::
buffers_adapter const* b_; buffers_adapter const* b_;
public: public:
using value_type = boost::asio::const_buffer; using value_type = net::const_buffer;
class const_iterator; class const_iterator;
@@ -62,7 +62,7 @@ class buffers_adapter<MutableBufferSequence>::
buffers_adapter const* b_ = nullptr; buffers_adapter const* b_ = nullptr;
public: public:
using value_type = boost::asio::const_buffer; using value_type = net::const_buffer;
using pointer = value_type const*; using pointer = value_type const*;
using reference = value_type; using reference = value_type;
using difference_type = std::ptrdiff_t; using difference_type = std::ptrdiff_t;
@@ -105,7 +105,7 @@ public:
{ {
value_type const b = *it_; value_type const b = *it_;
return value_type{b.data(), return value_type{b.data(),
(b_->out_ == boost::asio::buffer_sequence_end(b_->bs_) || (b_->out_ == net::buffer_sequence_end(b_->bs_) ||
it_ != b_->out_) ? b.size() : b_->out_pos_} + it_ != b_->out_) ? b.size() : b_->out_pos_} +
(it_ == b_->begin_ ? b_->in_pos_ : 0); (it_ == b_->begin_ ? b_->in_pos_ : 0);
} }
@@ -181,7 +181,7 @@ mutable_buffers_type
buffers_adapter const* b_; buffers_adapter const* b_;
public: public:
using value_type = boost::asio::mutable_buffer; using value_type = net::mutable_buffer;
class const_iterator; class const_iterator;
@@ -215,7 +215,7 @@ mutable_buffers_type::const_iterator
buffers_adapter const* b_ = nullptr; buffers_adapter const* b_ = nullptr;
public: public:
using value_type = boost::asio::mutable_buffer; using value_type = net::mutable_buffer;
using pointer = value_type const*; using pointer = value_type const*;
using reference = value_type; using reference = value_type;
using difference_type = std::ptrdiff_t; using difference_type = std::ptrdiff_t;
@@ -344,9 +344,9 @@ template<class MutableBufferSequence>
buffers_adapter<MutableBufferSequence>:: buffers_adapter<MutableBufferSequence>::
buffers_adapter(buffers_adapter&& other) buffers_adapter(buffers_adapter&& other)
: buffers_adapter(std::move(other), : buffers_adapter(std::move(other),
std::distance<iter_type>(boost::asio::buffer_sequence_begin(other.bs_), other.begin_), std::distance<iter_type>(net::buffer_sequence_begin(other.bs_), other.begin_),
std::distance<iter_type>(boost::asio::buffer_sequence_begin(other.bs_), other.out_), std::distance<iter_type>(net::buffer_sequence_begin(other.bs_), other.out_),
std::distance<iter_type>(boost::asio::buffer_sequence_begin(other.bs_), other.end_)) std::distance<iter_type>(net::buffer_sequence_begin(other.bs_), other.end_))
{ {
} }
@@ -354,9 +354,9 @@ template<class MutableBufferSequence>
buffers_adapter<MutableBufferSequence>:: buffers_adapter<MutableBufferSequence>::
buffers_adapter(buffers_adapter const& other) buffers_adapter(buffers_adapter const& other)
: buffers_adapter(other, : buffers_adapter(other,
std::distance<iter_type>(boost::asio::buffer_sequence_begin(other.bs_), other.begin_), std::distance<iter_type>(net::buffer_sequence_begin(other.bs_), other.begin_),
std::distance<iter_type>(boost::asio::buffer_sequence_begin(other.bs_), other.out_), std::distance<iter_type>(net::buffer_sequence_begin(other.bs_), other.out_),
std::distance<iter_type>(boost::asio::buffer_sequence_begin(other.bs_), other.end_)) std::distance<iter_type>(net::buffer_sequence_begin(other.bs_), other.end_))
{ {
} }
@@ -367,18 +367,18 @@ operator=(buffers_adapter&& other) ->
buffers_adapter& buffers_adapter&
{ {
auto const nbegin = std::distance<iter_type>( auto const nbegin = std::distance<iter_type>(
boost::asio::buffer_sequence_begin(other.bs_), net::buffer_sequence_begin(other.bs_),
other.begin_); other.begin_);
auto const nout = std::distance<iter_type>( auto const nout = std::distance<iter_type>(
boost::asio::buffer_sequence_begin(other.bs_), net::buffer_sequence_begin(other.bs_),
other.out_); other.out_);
auto const nend = std::distance<iter_type>( auto const nend = std::distance<iter_type>(
boost::asio::buffer_sequence_begin(other.bs_), net::buffer_sequence_begin(other.bs_),
other.end_); other.end_);
bs_ = std::move(other.bs_); bs_ = std::move(other.bs_);
begin_ = std::next(boost::asio::buffer_sequence_begin(bs_), nbegin); begin_ = std::next(net::buffer_sequence_begin(bs_), nbegin);
out_ = std::next(boost::asio::buffer_sequence_begin(bs_), nout); out_ = std::next(net::buffer_sequence_begin(bs_), nout);
end_ = std::next(boost::asio::buffer_sequence_begin(bs_), nend); end_ = std::next(net::buffer_sequence_begin(bs_), nend);
max_size_ = other.max_size_; max_size_ = other.max_size_;
in_pos_ = other.in_pos_; in_pos_ = other.in_pos_;
in_size_ = other.in_size_; in_size_ = other.in_size_;
@@ -394,18 +394,18 @@ operator=(buffers_adapter const& other) ->
buffers_adapter& buffers_adapter&
{ {
auto const nbegin = std::distance<iter_type>( auto const nbegin = std::distance<iter_type>(
boost::asio::buffer_sequence_begin(other.bs_), net::buffer_sequence_begin(other.bs_),
other.begin_); other.begin_);
auto const nout = std::distance<iter_type>( auto const nout = std::distance<iter_type>(
boost::asio::buffer_sequence_begin(other.bs_), net::buffer_sequence_begin(other.bs_),
other.out_); other.out_);
auto const nend = std::distance<iter_type>( auto const nend = std::distance<iter_type>(
boost::asio::buffer_sequence_begin(other.bs_), net::buffer_sequence_begin(other.bs_),
other.end_); other.end_);
bs_ = other.bs_; bs_ = other.bs_;
begin_ = std::next(boost::asio::buffer_sequence_begin(bs_), nbegin); begin_ = std::next(net::buffer_sequence_begin(bs_), nbegin);
out_ = std::next(boost::asio::buffer_sequence_begin(bs_), nout); out_ = std::next(net::buffer_sequence_begin(bs_), nout);
end_ = std::next(boost::asio::buffer_sequence_begin(bs_), nend); end_ = std::next(net::buffer_sequence_begin(bs_), nend);
max_size_ = other.max_size_; max_size_ = other.max_size_;
in_pos_ = other.in_pos_; in_pos_ = other.in_pos_;
in_size_ = other.in_size_; in_size_ = other.in_size_;
@@ -418,10 +418,10 @@ template<class MutableBufferSequence>
buffers_adapter<MutableBufferSequence>:: buffers_adapter<MutableBufferSequence>::
buffers_adapter(MutableBufferSequence const& bs) buffers_adapter(MutableBufferSequence const& bs)
: bs_(bs) : bs_(bs)
, begin_(boost::asio::buffer_sequence_begin(bs_)) , begin_(net::buffer_sequence_begin(bs_))
, out_ (boost::asio::buffer_sequence_begin(bs_)) , out_ (net::buffer_sequence_begin(bs_))
, end_ (boost::asio::buffer_sequence_begin(bs_)) , end_ (net::buffer_sequence_begin(bs_))
, max_size_(boost::asio::buffer_size(bs_)) , max_size_(net::buffer_size(bs_))
{ {
} }
@@ -430,10 +430,10 @@ template<class... Args>
buffers_adapter<MutableBufferSequence>:: buffers_adapter<MutableBufferSequence>::
buffers_adapter(boost::in_place_init_t, Args&&... args) buffers_adapter(boost::in_place_init_t, Args&&... args)
: bs_{std::forward<Args>(args)...} : bs_{std::forward<Args>(args)...}
, begin_(boost::asio::buffer_sequence_begin(bs_)) , begin_(net::buffer_sequence_begin(bs_))
, out_ (boost::asio::buffer_sequence_begin(bs_)) , out_ (net::buffer_sequence_begin(bs_))
, end_ (boost::asio::buffer_sequence_begin(bs_)) , end_ (net::buffer_sequence_begin(bs_))
, max_size_(boost::asio::buffer_size(bs_)) , max_size_(net::buffer_size(bs_))
{ {
} }
@@ -443,16 +443,16 @@ buffers_adapter<MutableBufferSequence>::
prepare(std::size_t n) -> prepare(std::size_t n) ->
mutable_buffers_type mutable_buffers_type
{ {
using boost::asio::buffer_size; using net::buffer_size;
end_ = out_; end_ = out_;
if(end_ != boost::asio::buffer_sequence_end(bs_)) if(end_ != net::buffer_sequence_end(bs_))
{ {
auto size = buffer_size(*end_) - out_pos_; auto size = buffer_size(*end_) - out_pos_;
if(n > size) if(n > size)
{ {
n -= size; n -= size;
while(++end_ != while(++end_ !=
boost::asio::buffer_sequence_end(bs_)) net::buffer_sequence_end(bs_))
{ {
size = buffer_size(*end_); size = buffer_size(*end_);
if(n < size) if(n < size)
@@ -484,7 +484,7 @@ void
buffers_adapter<MutableBufferSequence>:: buffers_adapter<MutableBufferSequence>::
commit(std::size_t n) commit(std::size_t n)
{ {
using boost::asio::buffer_size; using net::buffer_size;
if(out_ == end_) if(out_ == end_)
return; return;
auto const last = std::prev(end_); auto const last = std::prev(end_);
@@ -530,7 +530,7 @@ void
buffers_adapter<MutableBufferSequence>:: buffers_adapter<MutableBufferSequence>::
consume(std::size_t n) consume(std::size_t n)
{ {
using boost::asio::buffer_size; using net::buffer_size;
while(begin_ != out_) while(begin_ != out_)
{ {
auto const avail = auto const avail =

View File

@@ -32,7 +32,7 @@ struct buffers_cat_view_iterator_base
{ {
char unused = 0; // make g++8 happy char unused = 0; // make g++8 happy
boost::asio::mutable_buffer net::mutable_buffer
operator*() const operator*() const
{ {
BOOST_THROW_EXCEPTION(std::logic_error{ BOOST_THROW_EXCEPTION(std::logic_error{
@@ -119,11 +119,11 @@ private:
void void
next(C<I> const&) next(C<I> const&)
{ {
if(boost::asio::buffer_size( if(net::buffer_size(
detail::get<I>(*bn_)) != 0) detail::get<I>(*bn_)) != 0)
{ {
it_.template emplace<I+1>( it_.template emplace<I+1>(
boost::asio::buffer_sequence_begin( net::buffer_sequence_begin(
detail::get<I>(*bn_))); detail::get<I>(*bn_)));
return; return;
} }
@@ -142,11 +142,11 @@ private:
void void
prev(C<I> const&) prev(C<I> const&)
{ {
if(boost::asio::buffer_size( if(net::buffer_size(
detail::get<I>(*bn_)) != 0) detail::get<I>(*bn_)) != 0)
{ {
it_.template emplace<I+1>( it_.template emplace<I+1>(
boost::asio::buffer_sequence_end( net::buffer_sequence_end(
detail::get<I>(*bn_))); detail::get<I>(*bn_)));
return; return;
} }
@@ -158,7 +158,7 @@ private:
{ {
auto constexpr I = 0; auto constexpr I = 0;
it_.template emplace<I+1>( it_.template emplace<I+1>(
boost::asio::buffer_sequence_end( net::buffer_sequence_end(
detail::get<I>(*bn_))); detail::get<I>(*bn_)));
} }
@@ -205,7 +205,7 @@ private:
operator()(mp11::mp_size_t<I>) operator()(mp11::mp_size_t<I>)
{ {
auto& it = self.it_.template get<I>(); auto& it = self.it_.template get<I>();
if (++it == boost::asio::buffer_sequence_end( if (++it == net::buffer_sequence_end(
detail::get<I - 1>(*self.bn_))) detail::get<I - 1>(*self.bn_)))
self.next(C<I>()); self.next(C<I>());
} }
@@ -227,7 +227,7 @@ private:
if(it_.index() == I+1) if(it_.index() == I+1)
{ {
if(it_.template get<I+1>() != if(it_.template get<I+1>() !=
boost::asio::buffer_sequence_begin( net::buffer_sequence_begin(
detail::get<I>(*bn_))) detail::get<I>(*bn_)))
{ {
--it_.template get<I+1>(); --it_.template get<I+1>();
@@ -243,7 +243,7 @@ private:
{ {
auto constexpr I = 0; auto constexpr I = 0;
if(it_.template get<I+1>() != if(it_.template get<I+1>() !=
boost::asio::buffer_sequence_begin( net::buffer_sequence_begin(
detail::get<I>(*bn_))) detail::get<I>(*bn_)))
{ {
--it_.template get<I+1>(); --it_.template get<I+1>();

View File

@@ -23,18 +23,18 @@ namespace beast {
namespace detail { namespace detail {
inline inline
boost::asio::const_buffer net::const_buffer
buffers_prefix(std::size_t size, buffers_prefix(std::size_t size,
boost::asio::const_buffer buffer) net::const_buffer buffer)
{ {
return {buffer.data(), return {buffer.data(),
(std::min)(size, buffer.size())}; (std::min)(size, buffer.size())};
} }
inline inline
boost::asio::mutable_buffer net::mutable_buffer
buffers_prefix(std::size_t size, buffers_prefix(std::size_t size,
boost::asio::mutable_buffer buffer) net::mutable_buffer buffer)
{ {
return {buffer.data(), return {buffer.data(),
(std::min)(size, buffer.size())}; (std::min)(size, buffer.size())};
@@ -55,9 +55,9 @@ public:
using value_type = typename std::conditional< using value_type = typename std::conditional<
boost::is_convertible<typename boost::is_convertible<typename
std::iterator_traits<iter_type>::value_type, std::iterator_traits<iter_type>::value_type,
boost::asio::mutable_buffer>::value, net::mutable_buffer>::value,
boost::asio::mutable_buffer, net::mutable_buffer,
boost::asio::const_buffer>::type; net::const_buffer>::type;
using pointer = value_type const*; using pointer = value_type const*;
using reference = value_type; using reference = value_type;
using difference_type = std::ptrdiff_t; using difference_type = std::ptrdiff_t;
@@ -107,7 +107,7 @@ public:
const_iterator& const_iterator&
operator++() operator++()
{ {
remain_ -= boost::asio::buffer_size(*it_++); remain_ -= net::buffer_size(*it_++);
return *this; return *this;
} }
@@ -115,14 +115,14 @@ public:
operator++(int) operator++(int)
{ {
auto temp = *this; auto temp = *this;
remain_ -= boost::asio::buffer_size(*it_++); remain_ -= net::buffer_size(*it_++);
return temp; return temp;
} }
const_iterator& const_iterator&
operator--() operator--()
{ {
remain_ += boost::asio::buffer_size(*--it_); remain_ += net::buffer_size(*--it_);
return *this; return *this;
} }
@@ -130,7 +130,7 @@ public:
operator--(int) operator--(int)
{ {
auto temp = *this; auto temp = *this;
remain_ += boost::asio::buffer_size(*--it_); remain_ += net::buffer_size(*--it_);
return temp; return temp;
} }
@@ -147,7 +147,7 @@ private:
std::false_type) std::false_type)
: b_(&b) : b_(&b)
, remain_(b_->size_) , remain_(b_->size_)
, it_(boost::asio::buffer_sequence_begin(b_->bs_)) , it_(net::buffer_sequence_begin(b_->bs_))
{ {
} }
}; };
@@ -161,12 +161,12 @@ setup(std::size_t size)
{ {
size_ = 0; size_ = 0;
remain_ = 0; remain_ = 0;
end_ = boost::asio::buffer_sequence_begin(bs_); end_ = net::buffer_sequence_begin(bs_);
auto const last = bs_.end(); auto const last = bs_.end();
while(end_ != last) while(end_ != last)
{ {
auto const len = auto const len =
boost::asio::buffer_size(*end_++); net::buffer_size(*end_++);
if(len >= size) if(len >= size)
{ {
size_ += size; size_ += size;
@@ -183,7 +183,7 @@ buffers_prefix_view<BufferSequence>::
buffers_prefix_view(buffers_prefix_view&& other) buffers_prefix_view(buffers_prefix_view&& other)
: buffers_prefix_view(std::move(other), : buffers_prefix_view(std::move(other),
std::distance<iter_type>( std::distance<iter_type>(
boost::asio::buffer_sequence_begin(other.bs_), net::buffer_sequence_begin(other.bs_),
other.end_)) other.end_))
{ {
} }
@@ -193,7 +193,7 @@ buffers_prefix_view<BufferSequence>::
buffers_prefix_view(buffers_prefix_view const& other) buffers_prefix_view(buffers_prefix_view const& other)
: buffers_prefix_view(other, : buffers_prefix_view(other,
std::distance<iter_type>( std::distance<iter_type>(
boost::asio::buffer_sequence_begin(other.bs_), net::buffer_sequence_begin(other.bs_),
other.end_)) other.end_))
{ {
} }
@@ -205,13 +205,13 @@ operator=(buffers_prefix_view&& other) ->
buffers_prefix_view& buffers_prefix_view&
{ {
auto const dist = std::distance<iter_type>( auto const dist = std::distance<iter_type>(
boost::asio::buffer_sequence_begin(other.bs_), net::buffer_sequence_begin(other.bs_),
other.end_); other.end_);
bs_ = std::move(other.bs_); bs_ = std::move(other.bs_);
size_ = other.size_; size_ = other.size_;
remain_ = other.remain_; remain_ = other.remain_;
end_ = std::next( end_ = std::next(
boost::asio::buffer_sequence_begin(bs_), net::buffer_sequence_begin(bs_),
dist); dist);
return *this; return *this;
} }
@@ -223,13 +223,13 @@ operator=(buffers_prefix_view const& other) ->
buffers_prefix_view& buffers_prefix_view&
{ {
auto const dist = std::distance<iter_type>( auto const dist = std::distance<iter_type>(
boost::asio::buffer_sequence_begin(other.bs_), net::buffer_sequence_begin(other.bs_),
other.end_); other.end_);
bs_ = other.bs_; bs_ = other.bs_;
size_ = other.size_; size_ = other.size_;
remain_ = other.remain_; remain_ = other.remain_;
end_ = std::next( end_ = std::next(
boost::asio::buffer_sequence_begin(bs_), net::buffer_sequence_begin(bs_),
dist); dist);
return *this; return *this;
} }

View File

@@ -36,9 +36,9 @@ public:
using value_type = typename std::conditional< using value_type = typename std::conditional<
boost::is_convertible<typename boost::is_convertible<typename
std::iterator_traits<iter_type>::value_type, std::iterator_traits<iter_type>::value_type,
boost::asio::mutable_buffer>::value, net::mutable_buffer>::value,
boost::asio::mutable_buffer, net::mutable_buffer,
boost::asio::const_buffer>::type; net::const_buffer>::type;
using pointer = value_type const*; using pointer = value_type const*;
using reference = value_type; using reference = value_type;
using difference_type = std::ptrdiff_t; using difference_type = std::ptrdiff_t;
@@ -58,11 +58,11 @@ public:
(b_ == nullptr) ? (b_ == nullptr) ?
( (
other.b_ == nullptr || other.b_ == nullptr ||
other.it_ == boost::asio::buffer_sequence_end(other.b_->bs_) other.it_ == net::buffer_sequence_end(other.b_->bs_)
):( ):(
(other.b_ == nullptr) ? (other.b_ == nullptr) ?
( (
it_ == boost::asio::buffer_sequence_end(b_->bs_) it_ == net::buffer_sequence_end(b_->bs_)
): ( ): (
b_ == other.b_ && b_ == other.b_ &&
it_ == other.it_ it_ == other.it_
@@ -131,7 +131,7 @@ private:
template<class Buffers> template<class Buffers>
buffers_suffix<Buffers>:: buffers_suffix<Buffers>::
buffers_suffix() buffers_suffix()
: begin_(boost::asio::buffer_sequence_begin(bs_)) : begin_(net::buffer_sequence_begin(bs_))
{ {
} }
@@ -140,7 +140,7 @@ buffers_suffix<Buffers>::
buffers_suffix(buffers_suffix&& other) buffers_suffix(buffers_suffix&& other)
: buffers_suffix(std::move(other), : buffers_suffix(std::move(other),
std::distance<iter_type>( std::distance<iter_type>(
boost::asio::buffer_sequence_begin( net::buffer_sequence_begin(
other.bs_), other.begin_)) other.bs_), other.begin_))
{ {
} }
@@ -150,7 +150,7 @@ buffers_suffix<Buffers>::
buffers_suffix(buffers_suffix const& other) buffers_suffix(buffers_suffix const& other)
: buffers_suffix(other, : buffers_suffix(other,
std::distance<iter_type>( std::distance<iter_type>(
boost::asio::buffer_sequence_begin( net::buffer_sequence_begin(
other.bs_), other.begin_)) other.bs_), other.begin_))
{ {
} }
@@ -159,11 +159,11 @@ template<class Buffers>
buffers_suffix<Buffers>:: buffers_suffix<Buffers>::
buffers_suffix(Buffers const& bs) buffers_suffix(Buffers const& bs)
: bs_(bs) : bs_(bs)
, begin_(boost::asio::buffer_sequence_begin(bs_)) , begin_(net::buffer_sequence_begin(bs_))
{ {
static_assert( static_assert(
boost::asio::is_const_buffer_sequence<Buffers>::value|| net::is_const_buffer_sequence<Buffers>::value||
boost::asio::is_mutable_buffer_sequence<Buffers>::value, net::is_mutable_buffer_sequence<Buffers>::value,
"BufferSequence requirements not met"); "BufferSequence requirements not met");
} }
@@ -172,7 +172,7 @@ template<class... Args>
buffers_suffix<Buffers>:: buffers_suffix<Buffers>::
buffers_suffix(boost::in_place_init_t, Args&&... args) buffers_suffix(boost::in_place_init_t, Args&&... args)
: bs_(std::forward<Args>(args)...) : bs_(std::forward<Args>(args)...)
, begin_(boost::asio::buffer_sequence_begin(bs_)) , begin_(net::buffer_sequence_begin(bs_))
{ {
static_assert(sizeof...(Args) > 0, static_assert(sizeof...(Args) > 0,
"Missing constructor arguments"); "Missing constructor arguments");
@@ -188,11 +188,11 @@ operator=(buffers_suffix&& other) ->
buffers_suffix& buffers_suffix&
{ {
auto const dist = std::distance<iter_type>( auto const dist = std::distance<iter_type>(
boost::asio::buffer_sequence_begin(other.bs_), net::buffer_sequence_begin(other.bs_),
other.begin_); other.begin_);
bs_ = std::move(other.bs_); bs_ = std::move(other.bs_);
begin_ = std::next( begin_ = std::next(
boost::asio::buffer_sequence_begin(bs_), net::buffer_sequence_begin(bs_),
dist); dist);
skip_ = other.skip_; skip_ = other.skip_;
return *this; return *this;
@@ -205,11 +205,11 @@ operator=(buffers_suffix const& other) ->
buffers_suffix& buffers_suffix&
{ {
auto const dist = std::distance<iter_type>( auto const dist = std::distance<iter_type>(
boost::asio::buffer_sequence_begin(other.bs_), net::buffer_sequence_begin(other.bs_),
other.begin_); other.begin_);
bs_ = other.bs_; bs_ = other.bs_;
begin_ = std::next( begin_ = std::next(
boost::asio::buffer_sequence_begin(bs_), dist); net::buffer_sequence_begin(bs_), dist);
skip_ = other.skip_; skip_ = other.skip_;
return *this; return *this;
} }
@@ -232,7 +232,7 @@ end() const ->
const_iterator const_iterator
{ {
return const_iterator{*this, return const_iterator{*this,
boost::asio::buffer_sequence_end(bs_)}; net::buffer_sequence_end(bs_)};
} }
template<class Buffers> template<class Buffers>
@@ -240,9 +240,9 @@ void
buffers_suffix<Buffers>:: buffers_suffix<Buffers>::
consume(std::size_t amount) consume(std::size_t amount)
{ {
using boost::asio::buffer_size; using net::buffer_size;
auto const end = auto const end =
boost::asio::buffer_sequence_end(bs_); net::buffer_sequence_end(bs_);
for(;amount > 0 && begin_ != end; ++begin_) for(;amount > 0 && begin_ != end; ++begin_)
{ {
auto const len = auto const len =

View File

@@ -351,7 +351,7 @@ copy_from(DynamicBuffer const& buffer)
{ {
if(buffer.size() == 0) if(buffer.size() == 0)
return; return;
commit(boost::asio::buffer_copy( commit(net::buffer_copy(
prepare(buffer.size()), buffer.data())); prepare(buffer.size()), buffer.data()));
} }

View File

@@ -90,7 +90,7 @@ flat_static_buffer<N>::
flat_static_buffer(flat_static_buffer const& other) flat_static_buffer(flat_static_buffer const& other)
: flat_static_buffer_base(buf_, N) : flat_static_buffer_base(buf_, N)
{ {
using boost::asio::buffer_copy; using net::buffer_copy;
this->commit(buffer_copy( this->commit(buffer_copy(
this->prepare(other.size()), other.data())); this->prepare(other.size()), other.data()));
} }
@@ -101,7 +101,7 @@ flat_static_buffer<N>::
operator=(flat_static_buffer const& other) -> operator=(flat_static_buffer const& other) ->
flat_static_buffer<N>& flat_static_buffer<N>&
{ {
using boost::asio::buffer_copy; using net::buffer_copy;
this->consume(this->size()); this->consume(this->size());
this->commit(buffer_copy( this->commit(buffer_copy(
this->prepare(other.size()), other.data())); this->prepare(other.size()), other.data()));

View File

@@ -23,9 +23,9 @@ handler_ptr<T, Handler>::
clear() clear()
{ {
typename beast::detail::allocator_traits< typename beast::detail::allocator_traits<
boost::asio::associated_allocator_t< net::associated_allocator_t<
Handler>>::template rebind_alloc<T> alloc( Handler>>::template rebind_alloc<T> alloc(
boost::asio::get_associated_allocator( net::get_associated_allocator(
handler())); handler()));
beast::detail::allocator_traits< beast::detail::allocator_traits<
decltype(alloc)>::destroy(alloc, t_); decltype(alloc)>::destroy(alloc, t_);
@@ -65,9 +65,9 @@ handler_ptr(DeducedHandler&& h, Args&&... args)
{ {
BOOST_STATIC_ASSERT(! std::is_array<T>::value); BOOST_STATIC_ASSERT(! std::is_array<T>::value);
typename beast::detail::allocator_traits< typename beast::detail::allocator_traits<
boost::asio::associated_allocator_t< net::associated_allocator_t<
Handler>>::template rebind_alloc<T> alloc{ Handler>>::template rebind_alloc<T> alloc{
boost::asio::get_associated_allocator(h)}; net::get_associated_allocator(h)};
using A = decltype(alloc); using A = decltype(alloc);
bool destroy = false; bool destroy = false;
auto deleter = [&alloc, &destroy](T* p) auto deleter = [&alloc, &destroy](T* p)

View File

@@ -143,8 +143,8 @@ class basic_multi_buffer<Allocator>::readable_bytes
public: public:
using value_type = typename std::conditional< using value_type = typename std::conditional<
IsMutable, IsMutable,
boost::asio::mutable_buffer, net::mutable_buffer,
boost::asio::const_buffer>::type; net::const_buffer>::type;
class const_iterator; class const_iterator;
@@ -881,7 +881,7 @@ copy_from(DynamicBuffer const& buffer)
{ {
if(buffer.size() == 0) if(buffer.size() == 0)
return; return;
using boost::asio::buffer_copy; using net::buffer_copy;
commit(buffer_copy( commit(buffer_copy(
prepare(buffer.size()), buffer.data())); prepare(buffer.size()), buffer.data()));
} }
@@ -1018,7 +1018,7 @@ basic_multi_buffer<Allocator>::
debug_check() const debug_check() const
{ {
#ifndef NDEBUG #ifndef NDEBUG
using boost::asio::buffer_size; using net::buffer_size;
BOOST_ASSERT(buffer_size(data()) == in_size_); BOOST_ASSERT(buffer_size(data()) == in_size_);
if(list_.empty()) if(list_.empty())
{ {

View File

@@ -43,7 +43,7 @@ read_size(DynamicBuffer& buffer,
std::size_t max_size, std::false_type) std::size_t max_size, std::false_type)
{ {
static_assert( static_assert(
boost::asio::is_dynamic_buffer<DynamicBuffer>::value, net::is_dynamic_buffer<DynamicBuffer>::value,
"DynamicBuffer requirements not met"); "DynamicBuffer requirements not met");
BOOST_ASSERT(max_size >= 1); BOOST_ASSERT(max_size >= 1);
auto const size = buffer.size(); auto const size = buffer.size();

View File

@@ -35,7 +35,7 @@ static_buffer_base::
data() const noexcept -> data() const noexcept ->
const_buffers_type const_buffers_type
{ {
using boost::asio::const_buffer; using net::const_buffer;
const_buffers_type result; const_buffers_type result;
if(in_off_ + in_size_ <= capacity_) if(in_off_ + in_size_ <= capacity_)
{ {
@@ -56,7 +56,7 @@ static_buffer_base::
data() noexcept -> data() noexcept ->
mutable_data_type mutable_data_type
{ {
using boost::asio::mutable_buffer; using net::mutable_buffer;
mutable_data_type result; mutable_data_type result;
if(in_off_ + in_size_ <= capacity_) if(in_off_ + in_size_ <= capacity_)
{ {
@@ -77,7 +77,7 @@ static_buffer_base::
prepare(std::size_t n) -> prepare(std::size_t n) ->
mutable_buffers_type mutable_buffers_type
{ {
using boost::asio::mutable_buffer; using net::mutable_buffer;
if(n > capacity_ - in_size_) if(n > capacity_ - in_size_)
BOOST_THROW_EXCEPTION(std::length_error{ BOOST_THROW_EXCEPTION(std::length_error{
"buffer overflow"}); "buffer overflow"});
@@ -145,7 +145,7 @@ static_buffer<N>::
static_buffer(static_buffer const& other) static_buffer(static_buffer const& other)
: static_buffer_base(buf_, N) : static_buffer_base(buf_, N)
{ {
using boost::asio::buffer_copy; using net::buffer_copy;
this->commit(buffer_copy( this->commit(buffer_copy(
this->prepare(other.size()), other.data())); this->prepare(other.size()), other.data()));
} }
@@ -156,7 +156,7 @@ static_buffer<N>::
operator=(static_buffer const& other) -> operator=(static_buffer const& other) ->
static_buffer<N>& static_buffer<N>&
{ {
using boost::asio::buffer_copy; using net::buffer_copy;
this->consume(this->size()); this->consume(this->size());
this->commit(buffer_copy( this->commit(buffer_copy(
this->prepare(other.size()), other.data())); this->prepare(other.size()), other.data()));

View File

@@ -86,8 +86,8 @@ class basic_multi_buffer
using const_iter = typename list_type::const_iterator; using const_iter = typename list_type::const_iterator;
using size_type = typename alloc_traits::size_type; using size_type = typename alloc_traits::size_type;
using const_buffer = boost::asio::const_buffer; using const_buffer = net::const_buffer;
using mutable_buffer = boost::asio::mutable_buffer; using mutable_buffer = net::mutable_buffer;
static_assert(std::is_base_of<std::bidirectional_iterator_tag, static_assert(std::is_base_of<std::bidirectional_iterator_tag,
typename std::iterator_traits<iter>::iterator_category>::value, typename std::iterator_traits<iter>::iterator_category>::value,

View File

@@ -49,7 +49,7 @@ detail::buffers_helper<ConstBufferSequence>
#endif #endif
buffers(ConstBufferSequence const& b) buffers(ConstBufferSequence const& b)
{ {
static_assert(boost::asio::is_const_buffer_sequence< static_assert(net::is_const_buffer_sequence<
ConstBufferSequence>::value, ConstBufferSequence>::value,
"ConstBufferSequence requirements not met"); "ConstBufferSequence requirements not met");
return detail::buffers_helper< return detail::buffers_helper<
@@ -91,7 +91,7 @@ detail::ostream_helper<
ostream(DynamicBuffer& buffer) ostream(DynamicBuffer& buffer)
{ {
static_assert( static_assert(
boost::asio::is_dynamic_buffer<DynamicBuffer>::value, net::is_dynamic_buffer<DynamicBuffer>::value,
"DynamicBuffer requirements not met"); "DynamicBuffer requirements not met");
return detail::ostream_helper< return detail::ostream_helper<
DynamicBuffer, char, std::char_traits<char>, DynamicBuffer, char, std::char_traits<char>,

View File

@@ -64,23 +64,23 @@ class static_buffer_base
class mutable_buffer_pair class mutable_buffer_pair
{ {
boost::asio::mutable_buffer b_[2]; net::mutable_buffer b_[2];
friend class const_buffer_pair; friend class const_buffer_pair;
public: public:
using const_iterator = using const_iterator =
boost::asio::mutable_buffer const*; net::mutable_buffer const*;
// workaround for buffers_iterator bug // workaround for buffers_iterator bug
using value_type = using value_type =
boost::asio::mutable_buffer; net::mutable_buffer;
mutable_buffer_pair() = default; mutable_buffer_pair() = default;
mutable_buffer_pair( mutable_buffer_pair(
mutable_buffer_pair const&) = default; mutable_buffer_pair const&) = default;
boost::asio::mutable_buffer& net::mutable_buffer&
operator[](int i) noexcept operator[](int i) noexcept
{ {
BOOST_ASSERT(i >= 0 && i < 2); BOOST_ASSERT(i >= 0 && i < 2);
@@ -105,15 +105,15 @@ class static_buffer_base
class const_buffer_pair class const_buffer_pair
{ {
boost::asio::const_buffer b_[2]; net::const_buffer b_[2];
public: public:
using const_iterator = using const_iterator =
boost::asio::const_buffer const*; net::const_buffer const*;
// workaround for buffers_iterator bug // workaround for buffers_iterator bug
using value_type = using value_type =
boost::asio::const_buffer; net::const_buffer;
const_buffer_pair() = default; const_buffer_pair() = default;
const_buffer_pair( const_buffer_pair(
@@ -125,7 +125,7 @@ class static_buffer_base
{ {
} }
boost::asio::const_buffer& net::const_buffer&
operator[](int i) noexcept operator[](int i) noexcept
{ {
BOOST_ASSERT(i >= 0 && i < 2); BOOST_ASSERT(i >= 0 && i < 2);

View File

@@ -76,7 +76,7 @@ using is_completion_handler = std::integral_constant<bool,
template<class T> template<class T>
void maybe_hello(T& t, std::true_type) void maybe_hello(T& t, std::true_type)
{ {
boost::asio::post( net::post(
t.get_executor(), t.get_executor(),
[] []
{ {
@@ -102,7 +102,7 @@ using is_completion_handler = std::integral_constant<bool,
@code @code
struct stream struct stream
{ {
using executor_type = boost::asio::io_context::executor_type; using executor_type = net::io_context::executor_type;
executor_type get_executor() noexcept; executor_type get_executor() noexcept;
}; };

View File

@@ -34,7 +34,7 @@ template<class DynamicBuffer>
struct basic_dynamic_body struct basic_dynamic_body
{ {
static_assert( static_assert(
boost::asio::is_dynamic_buffer<DynamicBuffer>::value, net::is_dynamic_buffer<DynamicBuffer>::value,
"DynamicBuffer requirements not met"); "DynamicBuffer requirements not met");
/** The type of container used for the body /** The type of container used for the body
@@ -88,8 +88,8 @@ struct basic_dynamic_body
put(ConstBufferSequence const& buffers, put(ConstBufferSequence const& buffers,
error_code& ec) error_code& ec)
{ {
using boost::asio::buffer_copy; using net::buffer_copy;
using boost::asio::buffer_size; using net::buffer_size;
auto const n = buffer_size(buffers); auto const n = buffer_size(buffers);
if(body_.size() > body_.max_size() - n) if(body_.size() > body_.max_size() - n)
{ {

View File

@@ -235,7 +235,7 @@ public:
// The type of buffer sequence returned by `get`. // The type of buffer sequence returned by `get`.
// //
using const_buffers_type = using const_buffers_type =
boost::asio::const_buffer; net::const_buffer;
// Constructor. // Constructor.
// //
@@ -492,11 +492,11 @@ put(ConstBufferSequence const& buffers, error_code& ec)
// Loop over all the buffers in the sequence, // Loop over all the buffers in the sequence,
// and write each one to the file. // and write each one to the file.
for(auto it = boost::asio::buffer_sequence_begin(buffers); for(auto it = net::buffer_sequence_begin(buffers);
it != boost::asio::buffer_sequence_end(buffers); ++it) it != net::buffer_sequence_end(buffers); ++it)
{ {
// Write this buffer to the file // Write this buffer to the file
boost::asio::const_buffer buffer = *it; net::const_buffer buffer = *it;
nwritten += body_.file_.write( nwritten += body_.file_.write(
buffer.data(), buffer.size(), ec); buffer.data(), buffer.size(), ec);
if(ec) if(ec)

View File

@@ -526,7 +526,7 @@ public:
#if ! BOOST_BEAST_DOXYGEN #if ! BOOST_BEAST_DOXYGEN
std::size_t std::size_t
put(boost::asio::const_buffer const& buffer, put(net::const_buffer const& buffer,
error_code& ec); error_code& ec);
#endif #endif
@@ -540,7 +540,7 @@ public:
This is typically called when a read from the This is typically called when a read from the
underlying stream object sets the error code to underlying stream object sets the error code to
`boost::asio::error::eof`. `net::error::eof`.
@note Only valid after parsing a complete header. @note Only valid after parsing a complete header.

View File

@@ -121,15 +121,15 @@ struct buffer_body
put(ConstBufferSequence const& buffers, put(ConstBufferSequence const& buffers,
error_code& ec) error_code& ec)
{ {
using boost::asio::buffer_size; using net::buffer_size;
using boost::asio::buffer_copy; using net::buffer_copy;
if(! body_.data) if(! body_.data)
{ {
ec = error::need_buffer; ec = error::need_buffer;
return 0; return 0;
} }
auto const bytes_transferred = auto const bytes_transferred =
buffer_copy(boost::asio::buffer( buffer_copy(net::buffer(
body_.data, body_.size), buffers); body_.data, body_.size), buffers);
body_.data = static_cast<char*>( body_.data = static_cast<char*>(
body_.data) + bytes_transferred; body_.data) + bytes_transferred;
@@ -163,7 +163,7 @@ struct buffer_body
public: public:
using const_buffers_type = using const_buffers_type =
boost::asio::const_buffer; net::const_buffer;
template<bool isRequest, class Fields> template<bool isRequest, class Fields>
explicit explicit

View File

@@ -32,7 +32,7 @@ namespace http {
stream algorithm as the buffer sequence: stream algorithm as the buffer sequence:
@code @code
// writes "\r\n" // writes "\r\n"
boost::asio::write(stream, chunk_crlf{}); net::write(stream, chunk_crlf{});
@endcode @endcode
@see https://tools.ietf.org/html/rfc7230#section-4.1 @see https://tools.ietf.org/html/rfc7230#section-4.1
@@ -97,7 +97,7 @@ struct chunk_crlf
stream algorithm as the buffer sequence: stream algorithm as the buffer sequence:
@code @code
// writes "400;x\r\n" // writes "400;x\r\n"
boost::asio::write(stream, chunk_header{1024, "x"}); net::write(stream, chunk_header{1024, "x"});
@endcode @endcode
@see https://tools.ietf.org/html/rfc7230#section-4.1 @see https://tools.ietf.org/html/rfc7230#section-4.1
@@ -106,7 +106,7 @@ class chunk_header
{ {
using view_type = buffers_cat_view< using view_type = buffers_cat_view<
detail::chunk_size, // chunk-size detail::chunk_size, // chunk-size
boost::asio::const_buffer, // chunk-extensions net::const_buffer, // chunk-extensions
chunk_crlf>; // CRLF chunk_crlf>; // CRLF
std::shared_ptr< std::shared_ptr<
@@ -285,7 +285,7 @@ class chunk_body
{ {
using view_type = buffers_cat_view< using view_type = buffers_cat_view<
detail::chunk_size, // chunk-size detail::chunk_size, // chunk-size
boost::asio::const_buffer, // chunk-extensions net::const_buffer, // chunk-extensions
chunk_crlf, // CRLF chunk_crlf, // CRLF
ConstBufferSequence, // chunk-body ConstBufferSequence, // chunk-body
chunk_crlf>; // CRLF chunk_crlf>; // CRLF
@@ -459,7 +459,7 @@ class chunk_last
{ {
static_assert( static_assert(
is_fields<Trailer>::value || is_fields<Trailer>::value ||
boost::asio::is_const_buffer_sequence<Trailer>::value, net::is_const_buffer_sequence<Trailer>::value,
"Trailer requirements not met"); "Trailer requirements not met");
using buffers_type = typename using buffers_type = typename

View File

@@ -26,7 +26,7 @@ namespace detail {
struct chunk_extensions struct chunk_extensions
{ {
virtual ~chunk_extensions() = default; virtual ~chunk_extensions() = default;
virtual boost::asio::const_buffer str() = 0; virtual net::const_buffer str() = 0;
}; };
template<class ChunkExtensions> template<class ChunkExtensions>
@@ -44,7 +44,7 @@ struct chunk_extensions_impl : chunk_extensions
{ {
} }
boost::asio::const_buffer net::const_buffer
str() override str() override
{ {
auto const s = ext_.str(); auto const s = ext_.str();
@@ -88,7 +88,7 @@ class chunk_size
struct sequence struct sequence
{ {
boost::asio::const_buffer b; net::const_buffer b;
char data[1 + 2 * sizeof(std::size_t)]; char data[1 + 2 * sizeof(std::size_t)];
explicit explicit
@@ -104,7 +104,7 @@ class chunk_size
std::shared_ptr<sequence> sp_; std::shared_ptr<sequence> sp_;
public: public:
using value_type = boost::asio::const_buffer; using value_type = net::const_buffer;
using const_iterator = value_type const*; using const_iterator = value_type const*;
@@ -136,7 +136,7 @@ public:
/// Returns a buffer sequence holding a CRLF for chunk encoding /// Returns a buffer sequence holding a CRLF for chunk encoding
inline inline
boost::asio::const_buffer net::const_buffer
chunk_crlf() chunk_crlf()
{ {
return {"\r\n", 2}; return {"\r\n", 2};
@@ -144,7 +144,7 @@ chunk_crlf()
/// Returns a buffer sequence holding a final chunk header /// Returns a buffer sequence holding a final chunk header
inline inline
boost::asio::const_buffer net::const_buffer
chunk_last() chunk_last()
{ {
return {"0\r\n", 3}; return {"0\r\n", 3};
@@ -163,7 +163,7 @@ struct chunk_crlf_iter_type
value_type() = default; value_type() = default;
operator operator
boost::asio::const_buffer() const net::const_buffer() const
{ {
return {s, sizeof(s)}; return {s, sizeof(s)};
} }
@@ -190,7 +190,7 @@ struct chunk_size0_iter_type
value_type() = default; value_type() = default;
operator operator
boost::asio::const_buffer() const net::const_buffer() const
{ {
return {s, sizeof(s)}; return {s, sizeof(s)};
} }

View File

@@ -100,7 +100,7 @@ struct empty_body
struct writer struct writer
{ {
using const_buffers_type = using const_buffers_type =
boost::asio::const_buffer; net::const_buffer;
template<bool isRequest, class Fields> template<bool isRequest, class Fields>
explicit explicit

View File

@@ -23,7 +23,7 @@ enum class error
/** The end of the stream was reached. /** The end of the stream was reached.
This error is returned when attempting to read HTTP data, This error is returned when attempting to read HTTP data,
and the stream returns the error `boost::asio::error::eof` and the stream returns the error `net::error::eof`
before any octets corresponding to a new HTTP message have before any octets corresponding to a new HTTP message have
been received. been received.
*/ */

View File

@@ -85,7 +85,7 @@ public:
char* char*
data() const; data() const;
boost::asio::const_buffer net::const_buffer
buffer() const; buffer() const;
protected: protected:

View File

@@ -91,13 +91,13 @@ basic_parser<isRequest, Derived>::
put(ConstBufferSequence const& buffers, put(ConstBufferSequence const& buffers,
error_code& ec) error_code& ec)
{ {
static_assert(boost::asio::is_const_buffer_sequence< static_assert(net::is_const_buffer_sequence<
ConstBufferSequence>::value, ConstBufferSequence>::value,
"ConstBufferSequence requirements not met"); "ConstBufferSequence requirements not met");
using boost::asio::buffer_copy; using net::buffer_copy;
using boost::asio::buffer_size; using net::buffer_size;
auto const p = boost::asio::buffer_sequence_begin(buffers); auto const p = net::buffer_sequence_begin(buffers);
auto const last = boost::asio::buffer_sequence_end(buffers); auto const last = net::buffer_sequence_end(buffers);
if(p == last) if(p == last)
{ {
ec.assign(0, ec.category()); ec.assign(0, ec.category());
@@ -106,7 +106,7 @@ put(ConstBufferSequence const& buffers,
if(std::next(p) == last) if(std::next(p) == last)
{ {
// single buffer // single buffer
return put(boost::asio::const_buffer(*p), ec); return put(net::const_buffer(*p), ec);
} }
auto const size = buffer_size(buffers); auto const size = buffer_size(buffers);
if(size <= max_stack_buffer) if(size <= max_stack_buffer)
@@ -118,20 +118,20 @@ put(ConstBufferSequence const& buffers,
buf_len_ = size; buf_len_ = size;
} }
// flatten // flatten
buffer_copy(boost::asio::buffer( buffer_copy(net::buffer(
buf_.get(), buf_len_), buffers); buf_.get(), buf_len_), buffers);
return put(boost::asio::const_buffer{ return put(net::const_buffer{
buf_.get(), buf_len_}, ec); buf_.get(), buf_len_}, ec);
} }
template<bool isRequest, class Derived> template<bool isRequest, class Derived>
std::size_t std::size_t
basic_parser<isRequest, Derived>:: basic_parser<isRequest, Derived>::
put(boost::asio::const_buffer const& buffer, put(net::const_buffer const& buffer,
error_code& ec) error_code& ec)
{ {
BOOST_ASSERT(state_ != state::complete); BOOST_ASSERT(state_ != state::complete);
using boost::asio::buffer_size; using net::buffer_size;
auto p = static_cast<char const*>(buffer.data()); auto p = static_cast<char const*>(buffer.data());
auto n = buffer.size(); auto n = buffer.size();
auto const p0 = p; auto const p0 = p;
@@ -304,10 +304,10 @@ put_from_stack(std::size_t size,
error_code& ec) error_code& ec)
{ {
char buf[max_stack_buffer]; char buf[max_stack_buffer];
using boost::asio::buffer; using net::buffer;
using boost::asio::buffer_copy; using net::buffer_copy;
buffer_copy(buffer(buf, sizeof(buf)), buffers); buffer_copy(buffer(buf, sizeof(buf)), buffers);
return put(boost::asio::const_buffer{ return put(net::const_buffer{
buf, size}, ec); buf, size}, ec);
} }

View File

@@ -24,7 +24,7 @@ chunk_header::
chunk_header(std::size_t size) chunk_header(std::size_t size)
: view_( : view_(
size, size,
boost::asio::const_buffer{nullptr, 0}, net::const_buffer{nullptr, 0},
chunk_crlf{}) chunk_crlf{})
{ {
BOOST_ASSERT(size > 0); BOOST_ASSERT(size > 0);
@@ -37,7 +37,7 @@ chunk_header(
string_view extensions) string_view extensions)
: view_( : view_(
size, size,
boost::asio::const_buffer{ net::const_buffer{
extensions.data(), extensions.size()}, extensions.data(), extensions.size()},
chunk_crlf{}) chunk_crlf{})
{ {
@@ -89,8 +89,8 @@ template<class ConstBufferSequence>
chunk_body<ConstBufferSequence>:: chunk_body<ConstBufferSequence>::
chunk_body(ConstBufferSequence const& buffers) chunk_body(ConstBufferSequence const& buffers)
: view_( : view_(
boost::asio::buffer_size(buffers), net::buffer_size(buffers),
boost::asio::const_buffer{nullptr, 0}, net::const_buffer{nullptr, 0},
chunk_crlf{}, chunk_crlf{},
buffers, buffers,
chunk_crlf{}) chunk_crlf{})
@@ -103,8 +103,8 @@ chunk_body(
ConstBufferSequence const& buffers, ConstBufferSequence const& buffers,
string_view extensions) string_view extensions)
: view_( : view_(
boost::asio::buffer_size(buffers), net::buffer_size(buffers),
boost::asio::const_buffer{ net::const_buffer{
extensions.data(), extensions.size()}, extensions.data(), extensions.size()},
chunk_crlf{}, chunk_crlf{},
buffers, buffers,
@@ -122,7 +122,7 @@ chunk_body(
typename std::decay<ChunkExtensions>::type>>( typename std::decay<ChunkExtensions>::type>>(
std::forward<ChunkExtensions>(extensions))) std::forward<ChunkExtensions>(extensions)))
, view_( , view_(
boost::asio::buffer_size(buffers), net::buffer_size(buffers),
exts_->str(), exts_->str(),
chunk_crlf{}, chunk_crlf{},
buffers, buffers,
@@ -141,7 +141,7 @@ chunk_body(
typename std::decay<ChunkExtensions>::type>>(allocator, typename std::decay<ChunkExtensions>::type>>(allocator,
std::forward<ChunkExtensions>(extensions))) std::forward<ChunkExtensions>(extensions)))
, view_( , view_(
boost::asio::buffer_size(buffers), net::buffer_size(buffers),
exts_->str(), exts_->str(),
chunk_crlf{}, chunk_crlf{},
buffers, buffers,

View File

@@ -44,7 +44,7 @@ public:
{ {
iter_type it_; iter_type it_;
using value_type = boost::asio::const_buffer; using value_type = net::const_buffer;
using pointer = value_type const*; using pointer = value_type const*;
using reference = value_type const; using reference = value_type const;
using difference_type = std::ptrdiff_t; using difference_type = std::ptrdiff_t;
@@ -144,9 +144,9 @@ public:
}; };
using view_type = buffers_cat_view< using view_type = buffers_cat_view<
boost::asio::const_buffer, net::const_buffer,
boost::asio::const_buffer, net::const_buffer,
boost::asio::const_buffer, net::const_buffer,
field_range, field_range,
chunk_crlf>; chunk_crlf>;
@@ -179,9 +179,9 @@ writer(basic_fields const& f)
: f_(f) : f_(f)
{ {
view_.emplace( view_.emplace(
boost::asio::const_buffer{nullptr, 0}, net::const_buffer{nullptr, 0},
boost::asio::const_buffer{nullptr, 0}, net::const_buffer{nullptr, 0},
boost::asio::const_buffer{nullptr, 0}, net::const_buffer{nullptr, 0},
field_range(f_.list_.begin(), f_.list_.end()), field_range(f_.list_.begin(), f_.list_.end()),
chunk_crlf()); chunk_crlf());
} }
@@ -219,11 +219,11 @@ writer(basic_fields const& f,
buf_[10]= '\n'; buf_[10]= '\n';
view_.emplace( view_.emplace(
boost::asio::const_buffer{sv.data(), sv.size()}, net::const_buffer{sv.data(), sv.size()},
boost::asio::const_buffer{ net::const_buffer{
f_.target_or_reason_.data(), f_.target_or_reason_.data(),
f_.target_or_reason_.size()}, f_.target_or_reason_.size()},
boost::asio::const_buffer{buf_, 11}, net::const_buffer{buf_, 11},
field_range(f_.list_.begin(), f_.list_.end()), field_range(f_.list_.begin(), f_.list_.end()),
chunk_crlf()); chunk_crlf());
} }
@@ -261,9 +261,9 @@ writer(basic_fields const& f,
sv = obsolete_reason(static_cast<status>(code)); sv = obsolete_reason(static_cast<status>(code));
view_.emplace( view_.emplace(
boost::asio::const_buffer{buf_, 13}, net::const_buffer{buf_, 13},
boost::asio::const_buffer{sv.data(), sv.size()}, net::const_buffer{sv.data(), sv.size()},
boost::asio::const_buffer{"\r\n", 2}, net::const_buffer{"\r\n", 2},
field_range(f_.list_.begin(), f_.list_.end()), field_range(f_.list_.begin(), f_.list_.end()),
chunk_crlf{}); chunk_crlf{});
} }
@@ -282,12 +282,12 @@ data() const
} }
template<class Allocator> template<class Allocator>
boost::asio::const_buffer net::const_buffer
basic_fields<Allocator>:: basic_fields<Allocator>::
value_type:: value_type::
buffer() const buffer() const
{ {
return boost::asio::const_buffer{data(), return net::const_buffer{data(),
static_cast<std::size_t>(off_) + len_ + 2}; static_cast<std::size_t>(off_) + len_ + 2};
} }

Some files were not shown because too many files have changed in this diff Show More