mirror of
https://github.com/boostorg/beast.git
synced 2025-07-31 05:17:26 +02:00
net is a namespace alias for boost::asio:
The namespace alias beast::net replaces boost::asio in all code and documentation.
This commit is contained in:
@ -1,3 +1,9 @@
|
||||
Version 195:
|
||||
|
||||
* net is a namespace alias for boost::asio
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
Version 194:
|
||||
|
||||
* http::async_read returns the right byte count on error
|
||||
|
@ -38,21 +38,23 @@
|
||||
#include <thread>
|
||||
#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 http = boost::beast::http; // from <boost/beast/http.hpp>
|
||||
namespace websocket = boost::beast::websocket; // from <boost/beast/websocket.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.
|
||||
boost::beast::string_view
|
||||
mime_type(boost::beast::string_view path)
|
||||
beast::string_view
|
||||
mime_type(beast::string_view path)
|
||||
{
|
||||
using boost::beast::iequals;
|
||||
using beast::iequals;
|
||||
auto const ext = [&path]
|
||||
{
|
||||
auto const pos = path.rfind(".");
|
||||
if(pos == boost::beast::string_view::npos)
|
||||
return boost::beast::string_view{};
|
||||
if(pos == beast::string_view::npos)
|
||||
return beast::string_view{};
|
||||
return path.substr(pos);
|
||||
}();
|
||||
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.
|
||||
std::string
|
||||
path_cat(
|
||||
boost::beast::string_view base,
|
||||
boost::beast::string_view path)
|
||||
beast::string_view base,
|
||||
beast::string_view path)
|
||||
{
|
||||
if(base.empty())
|
||||
return path.to_string();
|
||||
@ -115,13 +117,13 @@ template<
|
||||
class Send>
|
||||
void
|
||||
handle_request(
|
||||
boost::beast::string_view doc_root,
|
||||
beast::string_view doc_root,
|
||||
http::request<Body, http::basic_fields<Allocator>>&& req,
|
||||
Send&& send)
|
||||
{
|
||||
// Returns a bad request response
|
||||
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()};
|
||||
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
@ -134,7 +136,7 @@ handle_request(
|
||||
|
||||
// Returns a not found response
|
||||
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()};
|
||||
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
@ -147,7 +149,7 @@ handle_request(
|
||||
|
||||
// Returns a server error response
|
||||
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()};
|
||||
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
@ -166,7 +168,7 @@ handle_request(
|
||||
// Request path must be absolute and not contain "..".
|
||||
if( req.target().empty() ||
|
||||
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"));
|
||||
|
||||
// Build the path to the requested file
|
||||
@ -175,12 +177,12 @@ handle_request(
|
||||
path.append("index.html");
|
||||
|
||||
// Attempt to open the file
|
||||
boost::beast::error_code ec;
|
||||
beast::error_code ec;
|
||||
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
|
||||
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()));
|
||||
|
||||
// Handle an unknown error
|
||||
@ -217,7 +219,7 @@ handle_request(
|
||||
|
||||
// Report a failure
|
||||
void
|
||||
fail(boost::system::error_code ec, char const* what)
|
||||
fail(beast::error_code ec, char const* what)
|
||||
{
|
||||
std::cerr << what << ": " << ec.message() << "\n";
|
||||
}
|
||||
@ -238,18 +240,18 @@ class websocket_session
|
||||
return static_cast<Derived&>(*this);
|
||||
}
|
||||
|
||||
boost::beast::multi_buffer buffer_;
|
||||
beast::multi_buffer buffer_;
|
||||
char ping_state_ = 0;
|
||||
|
||||
protected:
|
||||
boost::asio::strand<
|
||||
boost::asio::io_context::executor_type> strand_;
|
||||
boost::asio::steady_timer timer_;
|
||||
net::strand<
|
||||
net::io_context::executor_type> strand_;
|
||||
net::steady_timer timer_;
|
||||
|
||||
public:
|
||||
// Construct the session
|
||||
explicit
|
||||
websocket_session(boost::asio::io_context& ioc)
|
||||
websocket_session(net::io_context& ioc)
|
||||
: strand_(ioc.get_executor())
|
||||
, timer_(ioc,
|
||||
(std::chrono::steady_clock::time_point::max)())
|
||||
@ -276,7 +278,7 @@ public:
|
||||
// Accept the websocket handshake
|
||||
derived().ws().async_accept(
|
||||
req,
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&websocket_session::on_accept,
|
||||
@ -285,10 +287,10 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
on_accept(boost::system::error_code ec)
|
||||
on_accept(beast::error_code ec)
|
||||
{
|
||||
// Happens when the timer closes the socket
|
||||
if(ec == boost::asio::error::operation_aborted)
|
||||
if(ec == net::error::operation_aborted)
|
||||
return;
|
||||
|
||||
if(ec)
|
||||
@ -300,9 +302,9 @@ public:
|
||||
|
||||
// Called when the timer expires.
|
||||
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");
|
||||
|
||||
// See if the timer really expired since the deadline may have moved.
|
||||
@ -320,7 +322,7 @@ public:
|
||||
|
||||
// Now send the ping
|
||||
derived().ws().async_ping({},
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&websocket_session::on_ping,
|
||||
@ -340,7 +342,7 @@ public:
|
||||
|
||||
// Wait on the timer
|
||||
timer_.async_wait(
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&websocket_session::on_timer,
|
||||
@ -361,10 +363,10 @@ public:
|
||||
|
||||
// Called after a ping is sent.
|
||||
void
|
||||
on_ping(boost::system::error_code ec)
|
||||
on_ping(beast::error_code ec)
|
||||
{
|
||||
// Happens when the timer closes the socket
|
||||
if(ec == boost::asio::error::operation_aborted)
|
||||
if(ec == net::error::operation_aborted)
|
||||
return;
|
||||
|
||||
if(ec)
|
||||
@ -387,7 +389,7 @@ public:
|
||||
void
|
||||
on_control_callback(
|
||||
websocket::frame_type kind,
|
||||
boost::beast::string_view payload)
|
||||
beast::string_view payload)
|
||||
{
|
||||
boost::ignore_unused(kind, payload);
|
||||
|
||||
@ -401,7 +403,7 @@ public:
|
||||
// Read a message into our buffer
|
||||
derived().ws().async_read(
|
||||
buffer_,
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&websocket_session::on_read,
|
||||
@ -412,13 +414,13 @@ public:
|
||||
|
||||
void
|
||||
on_read(
|
||||
boost::system::error_code ec,
|
||||
beast::error_code ec,
|
||||
std::size_t bytes_transferred)
|
||||
{
|
||||
boost::ignore_unused(bytes_transferred);
|
||||
|
||||
// Happens when the timer closes the socket
|
||||
if(ec == boost::asio::error::operation_aborted)
|
||||
if(ec == net::error::operation_aborted)
|
||||
return;
|
||||
|
||||
// This indicates that the websocket_session was closed
|
||||
@ -435,7 +437,7 @@ public:
|
||||
derived().ws().text(derived().ws().got_text());
|
||||
derived().ws().async_write(
|
||||
buffer_.data(),
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&websocket_session::on_write,
|
||||
@ -446,13 +448,13 @@ public:
|
||||
|
||||
void
|
||||
on_write(
|
||||
boost::system::error_code ec,
|
||||
beast::error_code ec,
|
||||
std::size_t bytes_transferred)
|
||||
{
|
||||
boost::ignore_unused(bytes_transferred);
|
||||
|
||||
// Happens when the timer closes the socket
|
||||
if(ec == boost::asio::error::operation_aborted)
|
||||
if(ec == net::error::operation_aborted)
|
||||
return;
|
||||
|
||||
if(ec)
|
||||
@ -518,7 +520,7 @@ public:
|
||||
// Close the WebSocket Connection
|
||||
ws_.async_close(
|
||||
websocket::close_code::normal,
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&plain_websocket_session::on_close,
|
||||
@ -527,10 +529,10 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
on_close(boost::system::error_code ec)
|
||||
on_close(beast::error_code ec)
|
||||
{
|
||||
// Happens when close times out
|
||||
if(ec == boost::asio::error::operation_aborted)
|
||||
if(ec == net::error::operation_aborted)
|
||||
return;
|
||||
|
||||
if(ec)
|
||||
@ -545,13 +547,13 @@ class ssl_websocket_session
|
||||
: public websocket_session<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;
|
||||
|
||||
public:
|
||||
// Create the http_session
|
||||
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>(
|
||||
stream.get_executor().context())
|
||||
, ws_(std::move(stream))
|
||||
@ -559,7 +561,7 @@ public:
|
||||
}
|
||||
|
||||
// Called by the base class
|
||||
websocket::stream<boost::beast::ssl_stream<tcp::socket>>&
|
||||
websocket::stream<beast::ssl_stream<tcp::socket>>&
|
||||
ws()
|
||||
{
|
||||
return ws_;
|
||||
@ -588,7 +590,7 @@ public:
|
||||
|
||||
// Perform the SSL shutdown
|
||||
ws_.next_layer().async_shutdown(
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&ssl_websocket_session::on_shutdown,
|
||||
@ -597,10 +599,10 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
on_shutdown(boost::system::error_code ec)
|
||||
on_shutdown(beast::error_code ec)
|
||||
{
|
||||
// Happens when the shutdown times out
|
||||
if(ec == boost::asio::error::operation_aborted)
|
||||
if(ec == net::error::operation_aborted)
|
||||
return;
|
||||
|
||||
if(ec)
|
||||
@ -637,7 +639,7 @@ make_websocket_session(
|
||||
template<class Body, class Allocator>
|
||||
void
|
||||
make_websocket_session(
|
||||
boost::beast::ssl_stream<tcp::socket> stream,
|
||||
beast::ssl_stream<tcp::socket> stream,
|
||||
http::request<Body, http::basic_fields<Allocator>> req)
|
||||
{
|
||||
std::make_shared<ssl_websocket_session>(
|
||||
@ -733,7 +735,7 @@ class http_session
|
||||
http::async_write(
|
||||
self_.derived().stream(),
|
||||
msg_,
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
self_.strand_,
|
||||
std::bind(
|
||||
&http_session::on_write,
|
||||
@ -758,16 +760,16 @@ class http_session
|
||||
queue queue_;
|
||||
|
||||
protected:
|
||||
boost::asio::steady_timer timer_;
|
||||
boost::asio::strand<
|
||||
boost::asio::io_context::executor_type> strand_;
|
||||
boost::beast::flat_buffer buffer_;
|
||||
net::steady_timer timer_;
|
||||
net::strand<
|
||||
net::io_context::executor_type> strand_;
|
||||
beast::flat_buffer buffer_;
|
||||
|
||||
public:
|
||||
// Construct the session
|
||||
http_session(
|
||||
boost::asio::io_context& ioc,
|
||||
boost::beast::flat_buffer buffer,
|
||||
net::io_context& ioc,
|
||||
beast::flat_buffer buffer,
|
||||
std::shared_ptr<std::string const> const& doc_root)
|
||||
: doc_root_(doc_root)
|
||||
, queue_(*this)
|
||||
@ -793,7 +795,7 @@ public:
|
||||
derived().stream(),
|
||||
buffer_,
|
||||
req_,
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&http_session::on_read,
|
||||
@ -803,9 +805,9 @@ public:
|
||||
|
||||
// Called when the timer expires.
|
||||
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");
|
||||
|
||||
// Check if this has been upgraded to Websocket
|
||||
@ -818,7 +820,7 @@ public:
|
||||
|
||||
// Wait on the timer
|
||||
timer_.async_wait(
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&http_session::on_timer,
|
||||
@ -827,10 +829,10 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
on_read(boost::system::error_code ec)
|
||||
on_read(beast::error_code ec)
|
||||
{
|
||||
// Happens when the timer closes the socket
|
||||
if(ec == boost::asio::error::operation_aborted)
|
||||
if(ec == net::error::operation_aborted)
|
||||
return;
|
||||
|
||||
// This means they closed the connection
|
||||
@ -862,10 +864,10 @@ public:
|
||||
}
|
||||
|
||||
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
|
||||
if(ec == boost::asio::error::operation_aborted)
|
||||
if(ec == net::error::operation_aborted)
|
||||
return;
|
||||
|
||||
if(ec)
|
||||
@ -893,14 +895,14 @@ class plain_http_session
|
||||
, public std::enable_shared_from_this<plain_http_session>
|
||||
{
|
||||
tcp::socket socket_;
|
||||
boost::asio::strand<
|
||||
boost::asio::io_context::executor_type> strand_;
|
||||
net::strand<
|
||||
net::io_context::executor_type> strand_;
|
||||
|
||||
public:
|
||||
// Create the http_session
|
||||
plain_http_session(
|
||||
tcp::socket socket,
|
||||
boost::beast::flat_buffer buffer,
|
||||
beast::flat_buffer buffer,
|
||||
std::shared_ptr<std::string const> const& doc_root)
|
||||
: http_session<plain_http_session>(
|
||||
socket.get_executor().context(),
|
||||
@ -931,8 +933,8 @@ public:
|
||||
{
|
||||
// Make sure we run on the strand
|
||||
if(! strand_.running_in_this_thread())
|
||||
return boost::asio::post(
|
||||
boost::asio::bind_executor(
|
||||
return net::post(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&plain_http_session::run,
|
||||
@ -949,7 +951,7 @@ public:
|
||||
do_eof()
|
||||
{
|
||||
// Send a TCP shutdown
|
||||
boost::system::error_code ec;
|
||||
beast::error_code ec;
|
||||
socket_.shutdown(tcp::socket::shutdown_send, ec);
|
||||
|
||||
// At this point the connection is closed gracefully
|
||||
@ -959,8 +961,8 @@ public:
|
||||
do_timeout()
|
||||
{
|
||||
// Closing the socket cancels all outstanding operations. They
|
||||
// will complete with boost::asio::error::operation_aborted
|
||||
boost::system::error_code ec;
|
||||
// will complete with net::error::operation_aborted
|
||||
beast::error_code ec;
|
||||
socket_.shutdown(tcp::socket::shutdown_both, ec);
|
||||
socket_.close(ec);
|
||||
}
|
||||
@ -971,9 +973,9 @@ class ssl_http_session
|
||||
: public http_session<ssl_http_session>
|
||||
, public std::enable_shared_from_this<ssl_http_session>
|
||||
{
|
||||
boost::beast::ssl_stream<tcp::socket> stream_;
|
||||
boost::asio::strand<
|
||||
boost::asio::io_context::executor_type> strand_;
|
||||
beast::ssl_stream<tcp::socket> stream_;
|
||||
net::strand<
|
||||
net::io_context::executor_type> strand_;
|
||||
bool eof_ = false;
|
||||
|
||||
public:
|
||||
@ -981,7 +983,7 @@ public:
|
||||
ssl_http_session(
|
||||
tcp::socket socket,
|
||||
ssl::context& ctx,
|
||||
boost::beast::flat_buffer buffer,
|
||||
beast::flat_buffer buffer,
|
||||
std::shared_ptr<std::string const> const& doc_root)
|
||||
: http_session<ssl_http_session>(
|
||||
socket.get_executor().context(),
|
||||
@ -993,14 +995,14 @@ public:
|
||||
}
|
||||
|
||||
// Called by the base class
|
||||
boost::beast::ssl_stream<tcp::socket>&
|
||||
beast::ssl_stream<tcp::socket>&
|
||||
stream()
|
||||
{
|
||||
return stream_;
|
||||
}
|
||||
|
||||
// Called by the base class
|
||||
boost::beast::ssl_stream<tcp::socket>
|
||||
beast::ssl_stream<tcp::socket>
|
||||
release_stream()
|
||||
{
|
||||
return std::move(stream_);
|
||||
@ -1012,8 +1014,8 @@ public:
|
||||
{
|
||||
// Make sure we run on the strand
|
||||
if(! strand_.running_in_this_thread())
|
||||
return boost::asio::post(
|
||||
boost::asio::bind_executor(
|
||||
return net::post(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&ssl_http_session::run,
|
||||
@ -1031,7 +1033,7 @@ public:
|
||||
stream_.async_handshake(
|
||||
ssl::stream_base::server,
|
||||
buffer_.data(),
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&ssl_http_session::on_handshake,
|
||||
@ -1041,11 +1043,11 @@ public:
|
||||
}
|
||||
void
|
||||
on_handshake(
|
||||
boost::system::error_code ec,
|
||||
beast::error_code ec,
|
||||
std::size_t bytes_used)
|
||||
{
|
||||
// Happens when the handshake times out
|
||||
if(ec == boost::asio::error::operation_aborted)
|
||||
if(ec == net::error::operation_aborted)
|
||||
return;
|
||||
|
||||
if(ec)
|
||||
@ -1067,7 +1069,7 @@ public:
|
||||
|
||||
// Perform the SSL shutdown
|
||||
stream_.async_shutdown(
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&ssl_http_session::on_shutdown,
|
||||
@ -1076,10 +1078,10 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
on_shutdown(boost::system::error_code ec)
|
||||
on_shutdown(beast::error_code ec)
|
||||
{
|
||||
// Happens when the shutdown times out
|
||||
if(ec == boost::asio::error::operation_aborted)
|
||||
if(ec == net::error::operation_aborted)
|
||||
return;
|
||||
|
||||
if(ec)
|
||||
@ -1110,10 +1112,10 @@ class detect_session : public std::enable_shared_from_this<detect_session>
|
||||
{
|
||||
tcp::socket socket_;
|
||||
ssl::context& ctx_;
|
||||
boost::asio::strand<
|
||||
boost::asio::io_context::executor_type> strand_;
|
||||
net::strand<
|
||||
net::io_context::executor_type> strand_;
|
||||
std::shared_ptr<std::string const> doc_root_;
|
||||
boost::beast::flat_buffer buffer_;
|
||||
beast::flat_buffer buffer_;
|
||||
|
||||
public:
|
||||
explicit
|
||||
@ -1135,7 +1137,7 @@ public:
|
||||
async_detect_ssl(
|
||||
socket_,
|
||||
buffer_,
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&detect_session::on_detect,
|
||||
@ -1146,7 +1148,7 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
on_detect(boost::system::error_code ec, boost::tribool result)
|
||||
on_detect(beast::error_code ec, boost::tribool result)
|
||||
{
|
||||
if(ec)
|
||||
return fail(ec, "detect");
|
||||
@ -1180,7 +1182,7 @@ class listener : public std::enable_shared_from_this<listener>
|
||||
|
||||
public:
|
||||
listener(
|
||||
boost::asio::io_context& ioc,
|
||||
net::io_context& ioc,
|
||||
ssl::context& ctx,
|
||||
tcp::endpoint endpoint,
|
||||
std::shared_ptr<std::string const> const& doc_root)
|
||||
@ -1189,7 +1191,7 @@ public:
|
||||
, socket_(ioc)
|
||||
, doc_root_(doc_root)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
beast::error_code ec;
|
||||
|
||||
// Open the acceptor
|
||||
acceptor_.open(endpoint.protocol(), ec);
|
||||
@ -1200,7 +1202,7 @@ public:
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
fail(ec, "set_option");
|
||||
@ -1217,7 +1219,7 @@ public:
|
||||
|
||||
// Start listening for connections
|
||||
acceptor_.listen(
|
||||
boost::asio::socket_base::max_listen_connections, ec);
|
||||
net::socket_base::max_listen_connections, ec);
|
||||
if(ec)
|
||||
{
|
||||
fail(ec, "listen");
|
||||
@ -1246,7 +1248,7 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
on_accept(boost::system::error_code ec)
|
||||
on_accept(beast::error_code ec)
|
||||
{
|
||||
if(ec)
|
||||
{
|
||||
@ -1279,13 +1281,13 @@ int main(int argc, char* argv[])
|
||||
" advanced-server-flex 0.0.0.0 8080 . 1\n";
|
||||
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 doc_root = std::make_shared<std::string>(argv[3]);
|
||||
auto const threads = std::max<int>(1, std::atoi(argv[4]));
|
||||
|
||||
// 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
|
||||
ssl::context ctx{ssl::context::sslv23};
|
||||
@ -1301,9 +1303,9 @@ int main(int argc, char* argv[])
|
||||
doc_root)->run();
|
||||
|
||||
// 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(
|
||||
[&](boost::system::error_code const&, int)
|
||||
[&](beast::error_code const&, int)
|
||||
{
|
||||
// Stop the `io_context`. This will cause `run()`
|
||||
// to return immediately, eventually destroying the
|
||||
|
@ -33,20 +33,22 @@
|
||||
#include <thread>
|
||||
#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>
|
||||
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.
|
||||
boost::beast::string_view
|
||||
mime_type(boost::beast::string_view path)
|
||||
beast::string_view
|
||||
mime_type(beast::string_view path)
|
||||
{
|
||||
using boost::beast::iequals;
|
||||
using beast::iequals;
|
||||
auto const ext = [&path]
|
||||
{
|
||||
auto const pos = path.rfind(".");
|
||||
if(pos == boost::beast::string_view::npos)
|
||||
return boost::beast::string_view{};
|
||||
if(pos == beast::string_view::npos)
|
||||
return beast::string_view{};
|
||||
return path.substr(pos);
|
||||
}();
|
||||
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.
|
||||
std::string
|
||||
path_cat(
|
||||
boost::beast::string_view base,
|
||||
boost::beast::string_view path)
|
||||
beast::string_view base,
|
||||
beast::string_view path)
|
||||
{
|
||||
if(base.empty())
|
||||
return path.to_string();
|
||||
@ -109,13 +111,13 @@ template<
|
||||
class Send>
|
||||
void
|
||||
handle_request(
|
||||
boost::beast::string_view doc_root,
|
||||
beast::string_view doc_root,
|
||||
http::request<Body, http::basic_fields<Allocator>>&& req,
|
||||
Send&& send)
|
||||
{
|
||||
// Returns a bad request response
|
||||
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()};
|
||||
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
@ -128,7 +130,7 @@ handle_request(
|
||||
|
||||
// Returns a not found response
|
||||
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()};
|
||||
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
@ -141,7 +143,7 @@ handle_request(
|
||||
|
||||
// Returns a server error response
|
||||
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()};
|
||||
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
@ -160,7 +162,7 @@ handle_request(
|
||||
// Request path must be absolute and not contain "..".
|
||||
if( req.target().empty() ||
|
||||
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"));
|
||||
|
||||
// Build the path to the requested file
|
||||
@ -169,12 +171,12 @@ handle_request(
|
||||
path.append("index.html");
|
||||
|
||||
// Attempt to open the file
|
||||
boost::beast::error_code ec;
|
||||
beast::error_code ec;
|
||||
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
|
||||
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()));
|
||||
|
||||
// Handle an unknown error
|
||||
@ -211,7 +213,7 @@ handle_request(
|
||||
|
||||
// Report a failure
|
||||
void
|
||||
fail(boost::system::error_code ec, char const* what)
|
||||
fail(beast::error_code ec, char const* what)
|
||||
{
|
||||
std::cerr << what << ": " << ec.message() << "\n";
|
||||
}
|
||||
@ -220,10 +222,10 @@ fail(boost::system::error_code ec, char const* what)
|
||||
class websocket_session : public std::enable_shared_from_this<websocket_session>
|
||||
{
|
||||
websocket::stream<tcp::socket> ws_;
|
||||
boost::asio::strand<
|
||||
boost::asio::io_context::executor_type> strand_;
|
||||
boost::asio::steady_timer timer_;
|
||||
boost::beast::multi_buffer buffer_;
|
||||
net::strand<
|
||||
net::io_context::executor_type> strand_;
|
||||
net::steady_timer timer_;
|
||||
beast::multi_buffer buffer_;
|
||||
char ping_state_ = 0;
|
||||
|
||||
public:
|
||||
@ -261,7 +263,7 @@ public:
|
||||
// Accept the websocket handshake
|
||||
ws_.async_accept(
|
||||
req,
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&websocket_session::on_accept,
|
||||
@ -270,10 +272,10 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
on_accept(boost::system::error_code ec)
|
||||
on_accept(beast::error_code ec)
|
||||
{
|
||||
// Happens when the timer closes the socket
|
||||
if(ec == boost::asio::error::operation_aborted)
|
||||
if(ec == net::error::operation_aborted)
|
||||
return;
|
||||
|
||||
if(ec)
|
||||
@ -285,9 +287,9 @@ public:
|
||||
|
||||
// Called when the timer expires.
|
||||
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");
|
||||
|
||||
// See if the timer really expired since the deadline may have moved.
|
||||
@ -305,7 +307,7 @@ public:
|
||||
|
||||
// Now send the ping
|
||||
ws_.async_ping({},
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&websocket_session::on_ping,
|
||||
@ -319,7 +321,7 @@ public:
|
||||
// we never got back a control frame, so close.
|
||||
|
||||
// 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().close(ec);
|
||||
return;
|
||||
@ -328,7 +330,7 @@ public:
|
||||
|
||||
// Wait on the timer
|
||||
timer_.async_wait(
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&websocket_session::on_timer,
|
||||
@ -349,10 +351,10 @@ public:
|
||||
|
||||
// Called after a ping is sent.
|
||||
void
|
||||
on_ping(boost::system::error_code ec)
|
||||
on_ping(beast::error_code ec)
|
||||
{
|
||||
// Happens when the timer closes the socket
|
||||
if(ec == boost::asio::error::operation_aborted)
|
||||
if(ec == net::error::operation_aborted)
|
||||
return;
|
||||
|
||||
if(ec)
|
||||
@ -375,7 +377,7 @@ public:
|
||||
void
|
||||
on_control_callback(
|
||||
websocket::frame_type kind,
|
||||
boost::beast::string_view payload)
|
||||
beast::string_view payload)
|
||||
{
|
||||
boost::ignore_unused(kind, payload);
|
||||
|
||||
@ -389,7 +391,7 @@ public:
|
||||
// Read a message into our buffer
|
||||
ws_.async_read(
|
||||
buffer_,
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&websocket_session::on_read,
|
||||
@ -400,13 +402,13 @@ public:
|
||||
|
||||
void
|
||||
on_read(
|
||||
boost::system::error_code ec,
|
||||
beast::error_code ec,
|
||||
std::size_t bytes_transferred)
|
||||
{
|
||||
boost::ignore_unused(bytes_transferred);
|
||||
|
||||
// Happens when the timer closes the socket
|
||||
if(ec == boost::asio::error::operation_aborted)
|
||||
if(ec == net::error::operation_aborted)
|
||||
return;
|
||||
|
||||
// This indicates that the websocket_session was closed
|
||||
@ -423,7 +425,7 @@ public:
|
||||
ws_.text(ws_.got_text());
|
||||
ws_.async_write(
|
||||
buffer_.data(),
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&websocket_session::on_write,
|
||||
@ -434,13 +436,13 @@ public:
|
||||
|
||||
void
|
||||
on_write(
|
||||
boost::system::error_code ec,
|
||||
beast::error_code ec,
|
||||
std::size_t bytes_transferred)
|
||||
{
|
||||
boost::ignore_unused(bytes_transferred);
|
||||
|
||||
// Happens when the timer closes the socket
|
||||
if(ec == boost::asio::error::operation_aborted)
|
||||
if(ec == net::error::operation_aborted)
|
||||
return;
|
||||
|
||||
if(ec)
|
||||
@ -530,7 +532,7 @@ class http_session : public std::enable_shared_from_this<http_session>
|
||||
http::async_write(
|
||||
self_.socket_,
|
||||
msg_,
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
self_.strand_,
|
||||
std::bind(
|
||||
&http_session::on_write,
|
||||
@ -551,10 +553,10 @@ class http_session : public std::enable_shared_from_this<http_session>
|
||||
};
|
||||
|
||||
tcp::socket socket_;
|
||||
boost::asio::strand<
|
||||
boost::asio::io_context::executor_type> strand_;
|
||||
boost::asio::steady_timer timer_;
|
||||
boost::beast::flat_buffer buffer_;
|
||||
net::strand<
|
||||
net::io_context::executor_type> strand_;
|
||||
net::steady_timer timer_;
|
||||
beast::flat_buffer buffer_;
|
||||
std::shared_ptr<std::string const> doc_root_;
|
||||
http::request<http::string_body> req_;
|
||||
queue queue_;
|
||||
@ -580,8 +582,8 @@ public:
|
||||
{
|
||||
// Make sure we run on the strand
|
||||
if(! strand_.running_in_this_thread())
|
||||
return boost::asio::post(
|
||||
boost::asio::bind_executor(
|
||||
return net::post(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&http_session::run,
|
||||
@ -606,7 +608,7 @@ public:
|
||||
|
||||
// Read a request
|
||||
http::async_read(socket_, buffer_, req_,
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&http_session::on_read,
|
||||
@ -616,9 +618,9 @@ public:
|
||||
|
||||
// Called when the timer expires.
|
||||
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");
|
||||
|
||||
// Check if this has been upgraded to Websocket
|
||||
@ -629,7 +631,7 @@ public:
|
||||
if(timer_.expiry() <= std::chrono::steady_clock::now())
|
||||
{
|
||||
// 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_.close(ec);
|
||||
return;
|
||||
@ -637,7 +639,7 @@ public:
|
||||
|
||||
// Wait on the timer
|
||||
timer_.async_wait(
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&http_session::on_timer,
|
||||
@ -646,10 +648,10 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
on_read(boost::system::error_code ec)
|
||||
on_read(beast::error_code ec)
|
||||
{
|
||||
// Happens when the timer closes the socket
|
||||
if(ec == boost::asio::error::operation_aborted)
|
||||
if(ec == net::error::operation_aborted)
|
||||
return;
|
||||
|
||||
// This means they closed the connection
|
||||
@ -681,10 +683,10 @@ public:
|
||||
}
|
||||
|
||||
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
|
||||
if(ec == boost::asio::error::operation_aborted)
|
||||
if(ec == net::error::operation_aborted)
|
||||
return;
|
||||
|
||||
if(ec)
|
||||
@ -709,7 +711,7 @@ public:
|
||||
do_close()
|
||||
{
|
||||
// Send a TCP shutdown
|
||||
boost::system::error_code ec;
|
||||
beast::error_code ec;
|
||||
socket_.shutdown(tcp::socket::shutdown_send, ec);
|
||||
|
||||
// At this point the connection is closed gracefully
|
||||
@ -727,14 +729,14 @@ class listener : public std::enable_shared_from_this<listener>
|
||||
|
||||
public:
|
||||
listener(
|
||||
boost::asio::io_context& ioc,
|
||||
net::io_context& ioc,
|
||||
tcp::endpoint endpoint,
|
||||
std::shared_ptr<std::string const> const& doc_root)
|
||||
: acceptor_(ioc)
|
||||
, socket_(ioc)
|
||||
, doc_root_(doc_root)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
beast::error_code ec;
|
||||
|
||||
// Open the acceptor
|
||||
acceptor_.open(endpoint.protocol(), ec);
|
||||
@ -745,7 +747,7 @@ public:
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
fail(ec, "set_option");
|
||||
@ -762,7 +764,7 @@ public:
|
||||
|
||||
// Start listening for connections
|
||||
acceptor_.listen(
|
||||
boost::asio::socket_base::max_listen_connections, ec);
|
||||
net::socket_base::max_listen_connections, ec);
|
||||
if(ec)
|
||||
{
|
||||
fail(ec, "listen");
|
||||
@ -791,7 +793,7 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
on_accept(boost::system::error_code ec)
|
||||
on_accept(beast::error_code ec)
|
||||
{
|
||||
if(ec)
|
||||
{
|
||||
@ -823,13 +825,13 @@ int main(int argc, char* argv[])
|
||||
" advanced-server 0.0.0.0 8080 . 1\n";
|
||||
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 doc_root = std::make_shared<std::string>(argv[3]);
|
||||
auto const threads = std::max<int>(1, std::atoi(argv[4]));
|
||||
|
||||
// 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
|
||||
std::make_shared<listener>(
|
||||
@ -838,9 +840,9 @@ int main(int argc, char* argv[])
|
||||
doc_root)->run();
|
||||
|
||||
// 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(
|
||||
[&](boost::system::error_code const&, int)
|
||||
[&](beast::error_code const&, int)
|
||||
{
|
||||
// Stop the `io_context`. This will cause `run()`
|
||||
// to return immediately, eventually destroying the
|
||||
|
@ -12,8 +12,8 @@
|
||||
|
||||
#include <boost/beast.hpp>
|
||||
|
||||
namespace beast = boost::beast;
|
||||
namespace http = boost::beast::http; // from <boost/beast/http.hpp>
|
||||
namespace websocket = boost::beast::websocket; // from <boost/beast/websocket.hpp>
|
||||
namespace beast = boost::beast; // from <boost/beast.hpp>
|
||||
namespace http = beast::http; // from <boost/beast/http.hpp>
|
||||
namespace websocket = beast::websocket; // from <boost/beast/websocket.hpp>
|
||||
|
||||
#endif
|
||||
|
@ -17,15 +17,15 @@
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Return a reasonable mime type based on the extension of a file.
|
||||
boost::beast::string_view
|
||||
mime_type(boost::beast::string_view path)
|
||||
beast::string_view
|
||||
mime_type(beast::string_view path)
|
||||
{
|
||||
using boost::beast::iequals;
|
||||
using beast::iequals;
|
||||
auto const ext = [&path]
|
||||
{
|
||||
auto const pos = path.rfind(".");
|
||||
if(pos == boost::beast::string_view::npos)
|
||||
return boost::beast::string_view{};
|
||||
if(pos == beast::string_view::npos)
|
||||
return beast::string_view{};
|
||||
return path.substr(pos);
|
||||
}();
|
||||
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.
|
||||
std::string
|
||||
path_cat(
|
||||
boost::beast::string_view base,
|
||||
boost::beast::string_view path)
|
||||
beast::string_view base,
|
||||
beast::string_view path)
|
||||
{
|
||||
if(base.empty())
|
||||
return path.to_string();
|
||||
@ -88,13 +88,13 @@ template<
|
||||
class Send>
|
||||
void
|
||||
handle_request(
|
||||
boost::beast::string_view doc_root,
|
||||
beast::string_view doc_root,
|
||||
http::request<Body, http::basic_fields<Allocator>>&& req,
|
||||
Send&& send)
|
||||
{
|
||||
// Returns a bad request response
|
||||
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()};
|
||||
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
@ -107,7 +107,7 @@ handle_request(
|
||||
|
||||
// Returns a not found response
|
||||
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()};
|
||||
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
@ -120,7 +120,7 @@ handle_request(
|
||||
|
||||
// Returns a server error response
|
||||
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()};
|
||||
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
@ -139,7 +139,7 @@ handle_request(
|
||||
// Request path must be absolute and not contain "..".
|
||||
if( req.target().empty() ||
|
||||
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"));
|
||||
|
||||
// Build the path to the requested file
|
||||
@ -148,9 +148,9 @@ handle_request(
|
||||
path.append("index.html");
|
||||
|
||||
// Attempt to open the file
|
||||
boost::beast::error_code ec;
|
||||
beast::error_code ec;
|
||||
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
|
||||
if(ec == boost::system::errc::no_such_file_or_directory)
|
||||
@ -213,7 +213,7 @@ run()
|
||||
// Report a failure
|
||||
void
|
||||
http_session::
|
||||
fail(error_code ec, char const* what)
|
||||
fail(beast::error_code ec, char const* what)
|
||||
{
|
||||
// Don't report on canceled operations
|
||||
if(ec == net::error::operation_aborted)
|
||||
@ -239,7 +239,7 @@ operator()(http::message<isRequest, Body, Fields>&& msg) const
|
||||
http::async_write(
|
||||
self_.socket_,
|
||||
*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());
|
||||
});
|
||||
@ -247,7 +247,7 @@ operator()(http::message<isRequest, Body, Fields>&& msg) const
|
||||
|
||||
void
|
||||
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
|
||||
if(ec == http::error::end_of_stream)
|
||||
@ -291,7 +291,7 @@ on_read(error_code ec, std::size_t)
|
||||
// Write the response
|
||||
http::async_write(this->socket_, *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());
|
||||
});
|
||||
@ -300,7 +300,7 @@ on_read(error_code ec, std::size_t)
|
||||
auto self = shared_from_this();
|
||||
http::async_write(this->socket_, *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());
|
||||
});
|
||||
@ -321,7 +321,7 @@ on_read(error_code ec, std::size_t)
|
||||
|
||||
void
|
||||
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
|
||||
if(ec)
|
||||
|
@ -40,10 +40,9 @@ class http_session : public std::enable_shared_from_this<http_session>
|
||||
operator()(http::message<isRequest, Body, Fields>&& msg) const;
|
||||
};
|
||||
|
||||
void fail(error_code ec, char const* what);
|
||||
void on_read(error_code ec, std::size_t);
|
||||
void on_write(
|
||||
error_code ec, std::size_t, bool close);
|
||||
void fail(beast::error_code ec, char const* what);
|
||||
void on_read(beast::error_code ec, std::size_t);
|
||||
void on_write(beast::error_code ec, std::size_t, bool close);
|
||||
|
||||
public:
|
||||
http_session(
|
||||
|
@ -20,7 +20,7 @@ listener(
|
||||
, socket_(ioc)
|
||||
, state_(state)
|
||||
{
|
||||
error_code ec;
|
||||
beast::error_code ec;
|
||||
|
||||
// Open the acceptor
|
||||
acceptor_.open(endpoint.protocol(), ec);
|
||||
@ -72,7 +72,7 @@ run()
|
||||
// Report a failure
|
||||
void
|
||||
listener::
|
||||
fail(error_code ec, char const* what)
|
||||
fail(beast::error_code ec, char const* what)
|
||||
{
|
||||
// Don't report on canceled operations
|
||||
if(ec == net::error::operation_aborted)
|
||||
@ -83,7 +83,7 @@ fail(error_code ec, char const* what)
|
||||
// Handle a connection
|
||||
void
|
||||
listener::
|
||||
on_accept(error_code ec)
|
||||
on_accept(beast::error_code ec)
|
||||
{
|
||||
if(ec)
|
||||
return fail(ec, "accept");
|
||||
|
@ -10,6 +10,7 @@
|
||||
#ifndef CPPCON2018_LISTENER_HPP
|
||||
#define CPPCON2018_LISTENER_HPP
|
||||
|
||||
#include "beast.hpp"
|
||||
#include "net.hpp"
|
||||
#include <memory>
|
||||
#include <string>
|
||||
@ -24,8 +25,8 @@ class listener : public std::enable_shared_from_this<listener>
|
||||
tcp::socket socket_;
|
||||
std::shared_ptr<shared_state> state_;
|
||||
|
||||
void fail(error_code ec, char const* what);
|
||||
void on_accept(error_code ec);
|
||||
void fail(beast::error_code ec, char const* what);
|
||||
void on_accept(beast::error_code ec);
|
||||
|
||||
public:
|
||||
listener(
|
||||
|
@ -12,8 +12,7 @@
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
|
||||
namespace net = boost::asio; // namespace asio
|
||||
using tcp = net::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
using error_code = boost::system::error_code; // from <boost/system/error_code.hpp>
|
||||
namespace net = boost::asio; // from <boost/asio.hpp>
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
|
||||
#endif
|
||||
|
@ -27,7 +27,7 @@ websocket_session::
|
||||
|
||||
void
|
||||
websocket_session::
|
||||
fail(error_code ec, char const* what)
|
||||
fail(beast::error_code ec, char const* what)
|
||||
{
|
||||
// Don't report these
|
||||
if( ec == net::error::operation_aborted ||
|
||||
@ -39,7 +39,7 @@ fail(error_code ec, char const* what)
|
||||
|
||||
void
|
||||
websocket_session::
|
||||
on_accept(error_code ec)
|
||||
on_accept(beast::error_code ec)
|
||||
{
|
||||
// Handle the error, if any
|
||||
if(ec)
|
||||
@ -60,7 +60,7 @@ on_accept(error_code ec)
|
||||
|
||||
void
|
||||
websocket_session::
|
||||
on_read(error_code ec, std::size_t)
|
||||
on_read(beast::error_code ec, std::size_t)
|
||||
{
|
||||
// Handle the error, if any
|
||||
if(ec)
|
||||
@ -105,7 +105,7 @@ send(std::shared_ptr<std::string const> const& ss)
|
||||
|
||||
void
|
||||
websocket_session::
|
||||
on_write(error_code ec, std::size_t)
|
||||
on_write(beast::error_code ec, std::size_t)
|
||||
{
|
||||
// Handle the error, if any
|
||||
if(ec)
|
||||
|
@ -31,10 +31,10 @@ class websocket_session : public std::enable_shared_from_this<websocket_session>
|
||||
std::shared_ptr<shared_state> state_;
|
||||
std::vector<std::shared_ptr<std::string const>> queue_;
|
||||
|
||||
void fail(error_code ec, char const* what);
|
||||
void on_accept(error_code ec);
|
||||
void on_read(error_code ec, std::size_t bytes_transferred);
|
||||
void on_write(error_code ec, std::size_t bytes_transferred);
|
||||
void fail(beast::error_code ec, char const* what);
|
||||
void on_accept(beast::error_code ec);
|
||||
void on_read(beast::error_code ec, std::size_t bytes_transferred);
|
||||
void on_write(beast::error_code ec, std::size_t bytes_transferred);
|
||||
|
||||
public:
|
||||
websocket_session(
|
||||
|
@ -28,15 +28,17 @@
|
||||
#include <memory>
|
||||
#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 http = boost::beast::http; // from <boost/beast/http.hpp>
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Report a failure
|
||||
void
|
||||
fail(boost::system::error_code ec, char const* what)
|
||||
fail(beast::error_code ec, char const* what)
|
||||
{
|
||||
std::cerr << what << ": " << ec.message() << "\n";
|
||||
}
|
||||
@ -46,14 +48,14 @@ class session : public std::enable_shared_from_this<session>
|
||||
{
|
||||
tcp::resolver resolver_;
|
||||
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::response<http::string_body> res_;
|
||||
|
||||
public:
|
||||
// Resolver and stream require an io_context
|
||||
explicit
|
||||
session(boost::asio::io_context& ioc, ssl::context& ctx)
|
||||
session(net::io_context& ioc, ssl::context& ctx)
|
||||
: resolver_(ioc)
|
||||
, stream_(ioc, ctx)
|
||||
{
|
||||
@ -70,7 +72,7 @@ public:
|
||||
// Set SNI Hostname (many hosts need this to handshake successfully)
|
||||
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";
|
||||
return;
|
||||
}
|
||||
@ -95,14 +97,14 @@ public:
|
||||
|
||||
void
|
||||
on_resolve(
|
||||
boost::system::error_code ec,
|
||||
beast::error_code ec,
|
||||
tcp::resolver::results_type results)
|
||||
{
|
||||
if(ec)
|
||||
return fail(ec, "resolve");
|
||||
|
||||
// Make the connection on the IP address we get from a lookup
|
||||
boost::asio::async_connect(
|
||||
net::async_connect(
|
||||
stream_.next_layer(),
|
||||
results.begin(),
|
||||
results.end(),
|
||||
@ -113,7 +115,7 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
on_connect(boost::system::error_code ec)
|
||||
on_connect(beast::error_code ec)
|
||||
{
|
||||
if(ec)
|
||||
return fail(ec, "connect");
|
||||
@ -128,7 +130,7 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
on_handshake(boost::system::error_code ec)
|
||||
on_handshake(beast::error_code ec)
|
||||
{
|
||||
if(ec)
|
||||
return fail(ec, "handshake");
|
||||
@ -144,7 +146,7 @@ public:
|
||||
|
||||
void
|
||||
on_write(
|
||||
boost::system::error_code ec,
|
||||
beast::error_code ec,
|
||||
std::size_t bytes_transferred)
|
||||
{
|
||||
boost::ignore_unused(bytes_transferred);
|
||||
@ -163,7 +165,7 @@ public:
|
||||
|
||||
void
|
||||
on_read(
|
||||
boost::system::error_code ec,
|
||||
beast::error_code ec,
|
||||
std::size_t bytes_transferred)
|
||||
{
|
||||
boost::ignore_unused(bytes_transferred);
|
||||
@ -183,9 +185,9 @@ public:
|
||||
}
|
||||
|
||||
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:
|
||||
// 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;
|
||||
|
||||
// The io_context is required for all I/O
|
||||
boost::asio::io_context ioc;
|
||||
net::io_context ioc;
|
||||
|
||||
// The SSL context is required, and holds certificates
|
||||
ssl::context ctx{ssl::context::sslv23_client};
|
||||
|
@ -24,14 +24,16 @@
|
||||
#include <memory>
|
||||
#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>
|
||||
namespace http = boost::beast::http; // from <boost/beast/http.hpp>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Report a failure
|
||||
void
|
||||
fail(boost::system::error_code ec, char const* what)
|
||||
fail(beast::error_code ec, char const* what)
|
||||
{
|
||||
std::cerr << what << ": " << ec.message() << "\n";
|
||||
}
|
||||
@ -41,14 +43,14 @@ class session : public std::enable_shared_from_this<session>
|
||||
{
|
||||
tcp::resolver resolver_;
|
||||
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::response<http::string_body> res_;
|
||||
|
||||
public:
|
||||
// Resolver and socket require an io_context
|
||||
explicit
|
||||
session(boost::asio::io_context& ioc)
|
||||
session(net::io_context& ioc)
|
||||
: resolver_(ioc)
|
||||
, socket_(ioc)
|
||||
{
|
||||
@ -82,14 +84,14 @@ public:
|
||||
|
||||
void
|
||||
on_resolve(
|
||||
boost::system::error_code ec,
|
||||
beast::error_code ec,
|
||||
tcp::resolver::results_type results)
|
||||
{
|
||||
if(ec)
|
||||
return fail(ec, "resolve");
|
||||
|
||||
// Make the connection on the IP address we get from a lookup
|
||||
boost::asio::async_connect(
|
||||
net::async_connect(
|
||||
socket_,
|
||||
results.begin(),
|
||||
results.end(),
|
||||
@ -100,7 +102,7 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
on_connect(boost::system::error_code ec)
|
||||
on_connect(beast::error_code ec)
|
||||
{
|
||||
if(ec)
|
||||
return fail(ec, "connect");
|
||||
@ -116,7 +118,7 @@ public:
|
||||
|
||||
void
|
||||
on_write(
|
||||
boost::system::error_code ec,
|
||||
beast::error_code ec,
|
||||
std::size_t bytes_transferred)
|
||||
{
|
||||
boost::ignore_unused(bytes_transferred);
|
||||
@ -135,7 +137,7 @@ public:
|
||||
|
||||
void
|
||||
on_read(
|
||||
boost::system::error_code ec,
|
||||
beast::error_code ec,
|
||||
std::size_t bytes_transferred)
|
||||
{
|
||||
boost::ignore_unused(bytes_transferred);
|
||||
@ -150,7 +152,7 @@ public:
|
||||
socket_.shutdown(tcp::socket::shutdown_both, ec);
|
||||
|
||||
// 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");
|
||||
|
||||
// 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;
|
||||
|
||||
// The io_context is required for all I/O
|
||||
boost::asio::io_context ioc;
|
||||
net::io_context ioc;
|
||||
|
||||
// Launch the asynchronous operation
|
||||
std::make_shared<session>(ioc)->run(host, port, target, version);
|
||||
|
@ -28,15 +28,17 @@
|
||||
#include <iostream>
|
||||
#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 http = boost::beast::http; // from <boost/beast/http.hpp>
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Report a failure
|
||||
void
|
||||
fail(boost::system::error_code ec, char const* what)
|
||||
fail(beast::error_code ec, char const* what)
|
||||
{
|
||||
std::cerr << what << ": " << ec.message() << "\n";
|
||||
}
|
||||
@ -48,11 +50,11 @@ do_session(
|
||||
std::string const& port,
|
||||
std::string const& target,
|
||||
int version,
|
||||
boost::asio::io_context& ioc,
|
||||
net::io_context& ioc,
|
||||
ssl::context& ctx,
|
||||
boost::asio::yield_context yield)
|
||||
net::yield_context yield)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
beast::error_code ec;
|
||||
|
||||
// These objects perform our I/O
|
||||
tcp::resolver resolver{ioc};
|
||||
@ -61,7 +63,7 @@ do_session(
|
||||
// Set SNI Hostname (many hosts need this to handshake successfully)
|
||||
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";
|
||||
return;
|
||||
}
|
||||
@ -72,7 +74,7 @@ do_session(
|
||||
return fail(ec, "resolve");
|
||||
|
||||
// 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)
|
||||
return fail(ec, "connect");
|
||||
|
||||
@ -92,7 +94,7 @@ do_session(
|
||||
return fail(ec, "write");
|
||||
|
||||
// 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
|
||||
http::response<http::dynamic_body> res;
|
||||
@ -107,7 +109,7 @@ do_session(
|
||||
|
||||
// Gracefully close the stream
|
||||
stream.async_shutdown(yield[ec]);
|
||||
if(ec == boost::asio::error::eof)
|
||||
if(ec == net::error::eof)
|
||||
{
|
||||
// Rationale:
|
||||
// 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;
|
||||
|
||||
// The io_context is required for all I/O
|
||||
boost::asio::io_context ioc;
|
||||
net::io_context ioc;
|
||||
|
||||
// The SSL context is required, and holds certificates
|
||||
ssl::context ctx{ssl::context::sslv23_client};
|
||||
@ -151,7 +153,7 @@ int main(int argc, char** argv)
|
||||
ctx.set_verify_mode(ssl::verify_peer);
|
||||
|
||||
// Launch the asynchronous operation
|
||||
boost::asio::spawn(ioc, std::bind(
|
||||
net::spawn(ioc, std::bind(
|
||||
&do_session,
|
||||
std::string(host),
|
||||
std::string(port),
|
||||
|
@ -24,14 +24,16 @@
|
||||
#include <iostream>
|
||||
#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>
|
||||
namespace http = boost::beast::http; // from <boost/beast/http.hpp>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Report a failure
|
||||
void
|
||||
fail(boost::system::error_code ec, char const* what)
|
||||
fail(beast::error_code ec, char const* what)
|
||||
{
|
||||
std::cerr << what << ": " << ec.message() << "\n";
|
||||
}
|
||||
@ -43,10 +45,10 @@ do_session(
|
||||
std::string const& port,
|
||||
std::string const& target,
|
||||
int version,
|
||||
boost::asio::io_context& ioc,
|
||||
boost::asio::yield_context yield)
|
||||
net::io_context& ioc,
|
||||
net::yield_context yield)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
beast::error_code ec;
|
||||
|
||||
// These objects perform our I/O
|
||||
tcp::resolver resolver{ioc};
|
||||
@ -58,7 +60,7 @@ do_session(
|
||||
return fail(ec, "resolve");
|
||||
|
||||
// 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)
|
||||
return fail(ec, "connect");
|
||||
|
||||
@ -73,7 +75,7 @@ do_session(
|
||||
return fail(ec, "write");
|
||||
|
||||
// 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
|
||||
http::response<http::dynamic_body> res;
|
||||
@ -92,7 +94,7 @@ do_session(
|
||||
// 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");
|
||||
|
||||
// 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;
|
||||
|
||||
// The io_context is required for all I/O
|
||||
boost::asio::io_context ioc;
|
||||
net::io_context ioc;
|
||||
|
||||
// Launch the asynchronous operation
|
||||
boost::asio::spawn(ioc, std::bind(
|
||||
net::spawn(ioc, std::bind(
|
||||
&do_session,
|
||||
std::string(host),
|
||||
std::string(port),
|
||||
|
@ -35,24 +35,26 @@
|
||||
#include <vector>
|
||||
#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 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
|
||||
class crawl_report
|
||||
{
|
||||
boost::asio::io_context& ioc_;
|
||||
boost::asio::strand<
|
||||
boost::asio::io_context::executor_type> strand_;
|
||||
net::io_context& ioc_;
|
||||
net::strand<
|
||||
net::io_context::executor_type> strand_;
|
||||
std::atomic<std::size_t> index_;
|
||||
std::vector<char const*> const& hosts_;
|
||||
std::size_t count_ = 0;
|
||||
|
||||
public:
|
||||
crawl_report(boost::asio::io_context& ioc)
|
||||
crawl_report(net::io_context& ioc)
|
||||
: ioc_(ioc)
|
||||
, strand_(ioc_.get_executor())
|
||||
, index_(0)
|
||||
@ -66,7 +68,7 @@ public:
|
||||
void
|
||||
aggregate(F const& f)
|
||||
{
|
||||
boost::asio::post(
|
||||
net::post(
|
||||
strand_,
|
||||
[&, f]
|
||||
{
|
||||
@ -150,10 +152,10 @@ class worker : public std::enable_shared_from_this<worker>
|
||||
crawl_report& report_;
|
||||
tcp::resolver resolver_;
|
||||
tcp::socket socket_;
|
||||
boost::asio::steady_timer timer_;
|
||||
boost::asio::strand<
|
||||
boost::asio::io_context::executor_type> strand_;
|
||||
boost::beast::flat_buffer buffer_; // (Must persist between reads)
|
||||
net::steady_timer timer_;
|
||||
net::strand<
|
||||
net::io_context::executor_type> strand_;
|
||||
beast::flat_buffer buffer_; // (Must persist between reads)
|
||||
http::request<http::empty_body> req_;
|
||||
http::response<http::string_body> res_;
|
||||
|
||||
@ -163,7 +165,7 @@ public:
|
||||
// Resolver and socket require an io_context
|
||||
worker(
|
||||
crawl_report& report,
|
||||
boost::asio::io_context& ioc)
|
||||
net::io_context& ioc)
|
||||
: report_(report)
|
||||
, resolver_(ioc)
|
||||
, socket_(ioc)
|
||||
@ -190,9 +192,9 @@ public:
|
||||
}
|
||||
|
||||
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
|
||||
report_.aggregate(
|
||||
@ -213,7 +215,7 @@ public:
|
||||
|
||||
// Wait on the timer
|
||||
timer_.async_wait(
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&worker::on_timer,
|
||||
@ -245,7 +247,7 @@ public:
|
||||
resolver_.async_resolve(
|
||||
host,
|
||||
"http",
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&worker::on_resolve,
|
||||
@ -256,7 +258,7 @@ public:
|
||||
|
||||
void
|
||||
on_resolve(
|
||||
boost::system::error_code ec,
|
||||
beast::error_code ec,
|
||||
tcp::resolver::results_type results)
|
||||
{
|
||||
if(ec)
|
||||
@ -273,11 +275,11 @@ public:
|
||||
timer_.expires_after(chrono::seconds(timeout));
|
||||
|
||||
// Make the connection on the IP address we get from a lookup
|
||||
boost::asio::async_connect(
|
||||
net::async_connect(
|
||||
socket_,
|
||||
results.begin(),
|
||||
results.end(),
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&worker::on_connect,
|
||||
@ -286,7 +288,7 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
on_connect(boost::system::error_code ec)
|
||||
on_connect(beast::error_code ec)
|
||||
{
|
||||
if(ec)
|
||||
{
|
||||
@ -305,7 +307,7 @@ public:
|
||||
http::async_write(
|
||||
socket_,
|
||||
req_,
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&worker::on_write,
|
||||
@ -316,7 +318,7 @@ public:
|
||||
|
||||
void
|
||||
on_write(
|
||||
boost::system::error_code ec,
|
||||
beast::error_code ec,
|
||||
std::size_t bytes_transferred)
|
||||
{
|
||||
boost::ignore_unused(bytes_transferred);
|
||||
@ -339,7 +341,7 @@ public:
|
||||
socket_,
|
||||
buffer_,
|
||||
res_,
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&worker::on_read,
|
||||
@ -350,7 +352,7 @@ public:
|
||||
|
||||
void
|
||||
on_read(
|
||||
boost::system::error_code ec,
|
||||
beast::error_code ec,
|
||||
std::size_t 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]));
|
||||
|
||||
// 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
|
||||
auto work = boost::asio::make_work_guard(ioc);
|
||||
auto work = net::make_work_guard(ioc);
|
||||
|
||||
// The report holds the aggregated statistics
|
||||
crawl_report report{ioc};
|
||||
@ -439,7 +441,7 @@ int main(int argc, char* argv[])
|
||||
// the asio resolver simulates asynchronous operation using
|
||||
// a dedicated worker thread per io_context, and we want to
|
||||
// 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();
|
||||
ioc.run();
|
||||
});
|
||||
|
@ -26,9 +26,11 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp>
|
||||
namespace http = boost::beast::http; // from <boost/beast/http.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 = 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
|
||||
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;
|
||||
|
||||
// The io_context is required for all I/O
|
||||
boost::asio::io_context ioc;
|
||||
net::io_context ioc;
|
||||
|
||||
// The SSL context is required, and holds certificates
|
||||
ssl::context ctx{ssl::context::sslv23_client};
|
||||
@ -69,15 +71,15 @@ int main(int argc, char** argv)
|
||||
// Set SNI Hostname (many hosts need this to handshake successfully)
|
||||
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()};
|
||||
throw boost::system::system_error{ec};
|
||||
beast::error_code ec{static_cast<int>(::ERR_get_error()), net::error::get_ssl_category()};
|
||||
throw beast::system_error{ec};
|
||||
}
|
||||
|
||||
// Look up the domain name
|
||||
auto const results = resolver.resolve(host, port);
|
||||
|
||||
// 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
|
||||
stream.handshake(ssl::stream_base::client);
|
||||
@ -91,7 +93,7 @@ int main(int argc, char** argv)
|
||||
http::write(stream, req);
|
||||
|
||||
// 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
|
||||
http::response<http::dynamic_body> res;
|
||||
@ -103,16 +105,16 @@ int main(int argc, char** argv)
|
||||
std::cout << res << std::endl;
|
||||
|
||||
// Gracefully close the stream
|
||||
boost::system::error_code ec;
|
||||
beast::error_code ec;
|
||||
stream.shutdown(ec);
|
||||
if(ec == boost::asio::error::eof)
|
||||
if(ec == net::error::eof)
|
||||
{
|
||||
// Rationale:
|
||||
// http://stackoverflow.com/questions/25587403/boost-asio-ssl-async-shutdown-always-finishes-with-an-error
|
||||
ec.assign(0, ec.category());
|
||||
}
|
||||
if(ec)
|
||||
throw boost::system::system_error{ec};
|
||||
throw beast::system_error{ec};
|
||||
|
||||
// If we get here then the connection is closed gracefully
|
||||
}
|
||||
|
@ -24,8 +24,10 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
namespace http = boost::beast::http; // from <boost/beast/http.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>
|
||||
using tcp = net::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
|
||||
// Performs an HTTP GET and prints the response
|
||||
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;
|
||||
|
||||
// The io_context is required for all I/O
|
||||
boost::asio::io_context ioc;
|
||||
net::io_context ioc;
|
||||
|
||||
// These objects perform our I/O
|
||||
tcp::resolver resolver{ioc};
|
||||
@ -58,7 +60,7 @@ int main(int argc, char** argv)
|
||||
auto const results = resolver.resolve(host, port);
|
||||
|
||||
// Make the connection on the IP address we get from a lookup
|
||||
boost::asio::connect(socket, results.begin(), results.end());
|
||||
net::connect(socket, results.begin(), results.end());
|
||||
|
||||
// Set up an HTTP GET request message
|
||||
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);
|
||||
|
||||
// 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
|
||||
http::response<http::dynamic_body> res;
|
||||
@ -81,14 +83,14 @@ int main(int argc, char** argv)
|
||||
std::cout << res << std::endl;
|
||||
|
||||
// Gracefully close the socket
|
||||
boost::system::error_code ec;
|
||||
beast::error_code ec;
|
||||
socket.shutdown(tcp::socket::shutdown_both, ec);
|
||||
|
||||
// not_connected happens sometimes
|
||||
// so don't bother reporting it.
|
||||
//
|
||||
if(ec && ec != boost::system::errc::not_connected)
|
||||
throw boost::system::system_error{ec};
|
||||
if(ec && ec != beast::errc::not_connected)
|
||||
throw beast::system_error{ec};
|
||||
|
||||
// If we get here then the connection is closed gracefully
|
||||
}
|
||||
|
@ -32,20 +32,22 @@
|
||||
#include <thread>
|
||||
#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 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.
|
||||
boost::beast::string_view
|
||||
mime_type(boost::beast::string_view path)
|
||||
beast::string_view
|
||||
mime_type(beast::string_view path)
|
||||
{
|
||||
using boost::beast::iequals;
|
||||
using beast::iequals;
|
||||
auto const ext = [&path]
|
||||
{
|
||||
auto const pos = path.rfind(".");
|
||||
if(pos == boost::beast::string_view::npos)
|
||||
return boost::beast::string_view{};
|
||||
if(pos == beast::string_view::npos)
|
||||
return beast::string_view{};
|
||||
return path.substr(pos);
|
||||
}();
|
||||
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.
|
||||
std::string
|
||||
path_cat(
|
||||
boost::beast::string_view base,
|
||||
boost::beast::string_view path)
|
||||
beast::string_view base,
|
||||
beast::string_view path)
|
||||
{
|
||||
if(base.empty())
|
||||
return path.to_string();
|
||||
@ -108,13 +110,13 @@ template<
|
||||
class Send>
|
||||
void
|
||||
handle_request(
|
||||
boost::beast::string_view doc_root,
|
||||
beast::string_view doc_root,
|
||||
http::request<Body, http::basic_fields<Allocator>>&& req,
|
||||
Send&& send)
|
||||
{
|
||||
// Returns a bad request response
|
||||
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()};
|
||||
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
@ -127,7 +129,7 @@ handle_request(
|
||||
|
||||
// Returns a not found response
|
||||
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()};
|
||||
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
@ -140,7 +142,7 @@ handle_request(
|
||||
|
||||
// Returns a server error response
|
||||
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()};
|
||||
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
@ -159,7 +161,7 @@ handle_request(
|
||||
// Request path must be absolute and not contain "..".
|
||||
if( req.target().empty() ||
|
||||
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"));
|
||||
|
||||
// Build the path to the requested file
|
||||
@ -168,12 +170,12 @@ handle_request(
|
||||
path.append("index.html");
|
||||
|
||||
// Attempt to open the file
|
||||
boost::beast::error_code ec;
|
||||
beast::error_code ec;
|
||||
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
|
||||
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()));
|
||||
|
||||
// Handle an unknown error
|
||||
@ -210,7 +212,7 @@ handle_request(
|
||||
|
||||
// Report a failure
|
||||
void
|
||||
fail(boost::system::error_code ec, char const* what)
|
||||
fail(beast::error_code ec, char const* what)
|
||||
{
|
||||
std::cerr << what << ": " << ec.message() << "\n";
|
||||
}
|
||||
@ -248,7 +250,7 @@ class session : public std::enable_shared_from_this<session>
|
||||
http::async_write(
|
||||
self_.stream_,
|
||||
*sp,
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
self_.strand_,
|
||||
std::bind(
|
||||
&session::on_write,
|
||||
@ -261,9 +263,9 @@ class session : public std::enable_shared_from_this<session>
|
||||
|
||||
tcp::socket socket_;
|
||||
ssl::stream<tcp::socket&> stream_;
|
||||
boost::asio::strand<
|
||||
boost::asio::io_context::executor_type> strand_;
|
||||
boost::beast::flat_buffer buffer_;
|
||||
net::strand<
|
||||
net::io_context::executor_type> strand_;
|
||||
beast::flat_buffer buffer_;
|
||||
std::shared_ptr<std::string const> doc_root_;
|
||||
http::request<http::string_body> req_;
|
||||
std::shared_ptr<void> res_;
|
||||
@ -291,7 +293,7 @@ public:
|
||||
// Perform the SSL handshake
|
||||
stream_.async_handshake(
|
||||
ssl::stream_base::server,
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&session::on_handshake,
|
||||
@ -300,7 +302,7 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
on_handshake(boost::system::error_code ec)
|
||||
on_handshake(beast::error_code ec)
|
||||
{
|
||||
if(ec)
|
||||
return fail(ec, "handshake");
|
||||
@ -317,7 +319,7 @@ public:
|
||||
|
||||
// Read a request
|
||||
http::async_read(stream_, buffer_, req_,
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&session::on_read,
|
||||
@ -328,7 +330,7 @@ public:
|
||||
|
||||
void
|
||||
on_read(
|
||||
boost::system::error_code ec,
|
||||
beast::error_code ec,
|
||||
std::size_t bytes_transferred)
|
||||
{
|
||||
boost::ignore_unused(bytes_transferred);
|
||||
@ -346,7 +348,7 @@ public:
|
||||
|
||||
void
|
||||
on_write(
|
||||
boost::system::error_code ec,
|
||||
beast::error_code ec,
|
||||
std::size_t bytes_transferred,
|
||||
bool close)
|
||||
{
|
||||
@ -374,7 +376,7 @@ public:
|
||||
{
|
||||
// Perform the SSL shutdown
|
||||
stream_.async_shutdown(
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&session::on_shutdown,
|
||||
@ -383,7 +385,7 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
on_shutdown(boost::system::error_code ec)
|
||||
on_shutdown(beast::error_code ec)
|
||||
{
|
||||
if(ec)
|
||||
return fail(ec, "shutdown");
|
||||
@ -404,7 +406,7 @@ class listener : public std::enable_shared_from_this<listener>
|
||||
|
||||
public:
|
||||
listener(
|
||||
boost::asio::io_context& ioc,
|
||||
net::io_context& ioc,
|
||||
ssl::context& ctx,
|
||||
tcp::endpoint endpoint,
|
||||
std::shared_ptr<std::string const> const& doc_root)
|
||||
@ -413,7 +415,7 @@ public:
|
||||
, socket_(ioc)
|
||||
, doc_root_(doc_root)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
beast::error_code ec;
|
||||
|
||||
// Open the acceptor
|
||||
acceptor_.open(endpoint.protocol(), ec);
|
||||
@ -424,7 +426,7 @@ public:
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
fail(ec, "set_option");
|
||||
@ -441,7 +443,7 @@ public:
|
||||
|
||||
// Start listening for connections
|
||||
acceptor_.listen(
|
||||
boost::asio::socket_base::max_listen_connections, ec);
|
||||
net::socket_base::max_listen_connections, ec);
|
||||
if(ec)
|
||||
{
|
||||
fail(ec, "listen");
|
||||
@ -470,7 +472,7 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
on_accept(boost::system::error_code ec)
|
||||
on_accept(beast::error_code ec)
|
||||
{
|
||||
if(ec)
|
||||
{
|
||||
@ -503,13 +505,13 @@ int main(int argc, char* argv[])
|
||||
" http-server-async-ssl 0.0.0.0 8080 . 1\n";
|
||||
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 doc_root = std::make_shared<std::string>(argv[3]);
|
||||
auto const threads = std::max<int>(1, std::atoi(argv[4]));
|
||||
|
||||
// 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
|
||||
ssl::context ctx{ssl::context::sslv23};
|
||||
|
@ -29,19 +29,21 @@
|
||||
#include <thread>
|
||||
#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>
|
||||
namespace http = boost::beast::http; // from <boost/beast/http.hpp>
|
||||
|
||||
// Return a reasonable mime type based on the extension of a file.
|
||||
boost::beast::string_view
|
||||
mime_type(boost::beast::string_view path)
|
||||
beast::string_view
|
||||
mime_type(beast::string_view path)
|
||||
{
|
||||
using boost::beast::iequals;
|
||||
using beast::iequals;
|
||||
auto const ext = [&path]
|
||||
{
|
||||
auto const pos = path.rfind(".");
|
||||
if(pos == boost::beast::string_view::npos)
|
||||
return boost::beast::string_view{};
|
||||
if(pos == beast::string_view::npos)
|
||||
return beast::string_view{};
|
||||
return path.substr(pos);
|
||||
}();
|
||||
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.
|
||||
std::string
|
||||
path_cat(
|
||||
boost::beast::string_view base,
|
||||
boost::beast::string_view path)
|
||||
beast::string_view base,
|
||||
beast::string_view path)
|
||||
{
|
||||
if(base.empty())
|
||||
return path.to_string();
|
||||
@ -104,13 +106,13 @@ template<
|
||||
class Send>
|
||||
void
|
||||
handle_request(
|
||||
boost::beast::string_view doc_root,
|
||||
beast::string_view doc_root,
|
||||
http::request<Body, http::basic_fields<Allocator>>&& req,
|
||||
Send&& send)
|
||||
{
|
||||
// Returns a bad request response
|
||||
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()};
|
||||
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
@ -123,7 +125,7 @@ handle_request(
|
||||
|
||||
// Returns a not found response
|
||||
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()};
|
||||
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
@ -136,7 +138,7 @@ handle_request(
|
||||
|
||||
// Returns a server error response
|
||||
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()};
|
||||
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
@ -155,7 +157,7 @@ handle_request(
|
||||
// Request path must be absolute and not contain "..".
|
||||
if( req.target().empty() ||
|
||||
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"));
|
||||
|
||||
// Build the path to the requested file
|
||||
@ -164,12 +166,12 @@ handle_request(
|
||||
path.append("index.html");
|
||||
|
||||
// Attempt to open the file
|
||||
boost::beast::error_code ec;
|
||||
beast::error_code ec;
|
||||
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
|
||||
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()));
|
||||
|
||||
// Handle an unknown error
|
||||
@ -206,7 +208,7 @@ handle_request(
|
||||
|
||||
// Report a failure
|
||||
void
|
||||
fail(boost::system::error_code ec, char const* what)
|
||||
fail(beast::error_code ec, char const* what)
|
||||
{
|
||||
std::cerr << what << ": " << ec.message() << "\n";
|
||||
}
|
||||
@ -244,7 +246,7 @@ class session : public std::enable_shared_from_this<session>
|
||||
http::async_write(
|
||||
self_.socket_,
|
||||
*sp,
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
self_.strand_,
|
||||
std::bind(
|
||||
&session::on_write,
|
||||
@ -256,9 +258,9 @@ class session : public std::enable_shared_from_this<session>
|
||||
};
|
||||
|
||||
tcp::socket socket_;
|
||||
boost::asio::strand<
|
||||
boost::asio::io_context::executor_type> strand_;
|
||||
boost::beast::flat_buffer buffer_;
|
||||
net::strand<
|
||||
net::io_context::executor_type> strand_;
|
||||
beast::flat_buffer buffer_;
|
||||
std::shared_ptr<std::string const> doc_root_;
|
||||
http::request<http::string_body> req_;
|
||||
std::shared_ptr<void> res_;
|
||||
@ -293,7 +295,7 @@ public:
|
||||
|
||||
// Read a request
|
||||
http::async_read(socket_, buffer_, req_,
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&session::on_read,
|
||||
@ -304,7 +306,7 @@ public:
|
||||
|
||||
void
|
||||
on_read(
|
||||
boost::system::error_code ec,
|
||||
beast::error_code ec,
|
||||
std::size_t bytes_transferred)
|
||||
{
|
||||
boost::ignore_unused(bytes_transferred);
|
||||
@ -322,7 +324,7 @@ public:
|
||||
|
||||
void
|
||||
on_write(
|
||||
boost::system::error_code ec,
|
||||
beast::error_code ec,
|
||||
std::size_t bytes_transferred,
|
||||
bool close)
|
||||
{
|
||||
@ -349,7 +351,7 @@ public:
|
||||
do_close()
|
||||
{
|
||||
// Send a TCP shutdown
|
||||
boost::system::error_code ec;
|
||||
beast::error_code ec;
|
||||
socket_.shutdown(tcp::socket::shutdown_send, ec);
|
||||
|
||||
// At this point the connection is closed gracefully
|
||||
@ -367,14 +369,14 @@ class listener : public std::enable_shared_from_this<listener>
|
||||
|
||||
public:
|
||||
listener(
|
||||
boost::asio::io_context& ioc,
|
||||
net::io_context& ioc,
|
||||
tcp::endpoint endpoint,
|
||||
std::shared_ptr<std::string const> const& doc_root)
|
||||
: acceptor_(ioc)
|
||||
, socket_(ioc)
|
||||
, doc_root_(doc_root)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
beast::error_code ec;
|
||||
|
||||
// Open the acceptor
|
||||
acceptor_.open(endpoint.protocol(), ec);
|
||||
@ -385,7 +387,7 @@ public:
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
fail(ec, "set_option");
|
||||
@ -402,7 +404,7 @@ public:
|
||||
|
||||
// Start listening for connections
|
||||
acceptor_.listen(
|
||||
boost::asio::socket_base::max_listen_connections, ec);
|
||||
net::socket_base::max_listen_connections, ec);
|
||||
if(ec)
|
||||
{
|
||||
fail(ec, "listen");
|
||||
@ -431,7 +433,7 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
on_accept(boost::system::error_code ec)
|
||||
on_accept(beast::error_code ec)
|
||||
{
|
||||
if(ec)
|
||||
{
|
||||
@ -463,13 +465,13 @@ int main(int argc, char* argv[])
|
||||
" http-server-async 0.0.0.0 8080 . 1\n";
|
||||
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 doc_root = std::make_shared<std::string>(argv[3]);
|
||||
auto const threads = std::max<int>(1, std::atoi(argv[4]));
|
||||
|
||||
// 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
|
||||
std::make_shared<listener>(
|
||||
|
@ -30,20 +30,22 @@
|
||||
#include <thread>
|
||||
#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 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.
|
||||
boost::beast::string_view
|
||||
mime_type(boost::beast::string_view path)
|
||||
beast::string_view
|
||||
mime_type(beast::string_view path)
|
||||
{
|
||||
using boost::beast::iequals;
|
||||
using beast::iequals;
|
||||
auto const ext = [&path]
|
||||
{
|
||||
auto const pos = path.rfind(".");
|
||||
if(pos == boost::beast::string_view::npos)
|
||||
return boost::beast::string_view{};
|
||||
if(pos == beast::string_view::npos)
|
||||
return beast::string_view{};
|
||||
return path.substr(pos);
|
||||
}();
|
||||
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.
|
||||
std::string
|
||||
path_cat(
|
||||
boost::beast::string_view base,
|
||||
boost::beast::string_view path)
|
||||
beast::string_view base,
|
||||
beast::string_view path)
|
||||
{
|
||||
if(base.empty())
|
||||
return path.to_string();
|
||||
@ -106,13 +108,13 @@ template<
|
||||
class Send>
|
||||
void
|
||||
handle_request(
|
||||
boost::beast::string_view doc_root,
|
||||
beast::string_view doc_root,
|
||||
http::request<Body, http::basic_fields<Allocator>>&& req,
|
||||
Send&& send)
|
||||
{
|
||||
// Returns a bad request response
|
||||
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()};
|
||||
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
@ -125,7 +127,7 @@ handle_request(
|
||||
|
||||
// Returns a not found response
|
||||
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()};
|
||||
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
@ -138,7 +140,7 @@ handle_request(
|
||||
|
||||
// Returns a server error response
|
||||
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()};
|
||||
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
@ -157,7 +159,7 @@ handle_request(
|
||||
// Request path must be absolute and not contain "..".
|
||||
if( req.target().empty() ||
|
||||
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"));
|
||||
|
||||
// Build the path to the requested file
|
||||
@ -166,12 +168,12 @@ handle_request(
|
||||
path.append("index.html");
|
||||
|
||||
// Attempt to open the file
|
||||
boost::beast::error_code ec;
|
||||
beast::error_code ec;
|
||||
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
|
||||
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()));
|
||||
|
||||
// Handle an unknown error
|
||||
@ -208,7 +210,7 @@ handle_request(
|
||||
|
||||
// Report a failure
|
||||
void
|
||||
fail(boost::system::error_code ec, char const* what)
|
||||
fail(beast::error_code ec, char const* what)
|
||||
{
|
||||
std::cerr << what << ": " << ec.message() << "\n";
|
||||
}
|
||||
@ -220,15 +222,15 @@ struct send_lambda
|
||||
{
|
||||
Stream& stream_;
|
||||
bool& close_;
|
||||
boost::system::error_code& ec_;
|
||||
boost::asio::yield_context yield_;
|
||||
beast::error_code& ec_;
|
||||
net::yield_context yield_;
|
||||
|
||||
explicit
|
||||
send_lambda(
|
||||
Stream& stream,
|
||||
bool& close,
|
||||
boost::system::error_code& ec,
|
||||
boost::asio::yield_context yield)
|
||||
beast::error_code& ec,
|
||||
net::yield_context yield)
|
||||
: stream_(stream)
|
||||
, close_(close)
|
||||
, ec_(ec)
|
||||
@ -257,10 +259,10 @@ do_session(
|
||||
tcp::socket& socket,
|
||||
ssl::context& ctx,
|
||||
std::shared_ptr<std::string const> const& doc_root,
|
||||
boost::asio::yield_context yield)
|
||||
net::yield_context yield)
|
||||
{
|
||||
bool close = false;
|
||||
boost::system::error_code ec;
|
||||
beast::error_code ec;
|
||||
|
||||
// Construct the stream around the socket
|
||||
ssl::stream<tcp::socket&> stream{socket, ctx};
|
||||
@ -271,7 +273,7 @@ do_session(
|
||||
return fail(ec, "handshake");
|
||||
|
||||
// This buffer is required to persist across reads
|
||||
boost::beast::flat_buffer buffer;
|
||||
beast::flat_buffer buffer;
|
||||
|
||||
// This lambda is used to send messages
|
||||
send_lambda<ssl::stream<tcp::socket&>> lambda{stream, close, ec, yield};
|
||||
@ -311,13 +313,13 @@ do_session(
|
||||
// Accepts incoming connections and launches the sessions
|
||||
void
|
||||
do_listen(
|
||||
boost::asio::io_context& ioc,
|
||||
net::io_context& ioc,
|
||||
ssl::context& ctx,
|
||||
tcp::endpoint endpoint,
|
||||
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
|
||||
tcp::acceptor acceptor(ioc);
|
||||
@ -326,7 +328,7 @@ do_listen(
|
||||
return fail(ec, "open");
|
||||
|
||||
// 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)
|
||||
return fail(ec, "set_option");
|
||||
|
||||
@ -336,7 +338,7 @@ do_listen(
|
||||
return fail(ec, "bind");
|
||||
|
||||
// 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)
|
||||
return fail(ec, "listen");
|
||||
|
||||
@ -347,7 +349,7 @@ do_listen(
|
||||
if(ec)
|
||||
fail(ec, "accept");
|
||||
else
|
||||
boost::asio::spawn(
|
||||
net::spawn(
|
||||
acceptor.get_executor().context(),
|
||||
std::bind(
|
||||
&do_session,
|
||||
@ -369,13 +371,13 @@ int main(int argc, char* argv[])
|
||||
" http-server-coro-ssl 0.0.0.0 8080 . 1\n";
|
||||
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 doc_root = std::make_shared<std::string>(argv[3]);
|
||||
auto const threads = std::max<int>(1, std::atoi(argv[4]));
|
||||
|
||||
// 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
|
||||
ssl::context ctx{ssl::context::sslv23};
|
||||
@ -384,7 +386,7 @@ int main(int argc, char* argv[])
|
||||
load_server_certificate(ctx);
|
||||
|
||||
// Spawn a listening port
|
||||
boost::asio::spawn(ioc,
|
||||
net::spawn(ioc,
|
||||
std::bind(
|
||||
&do_listen,
|
||||
std::ref(ioc),
|
||||
|
@ -27,19 +27,21 @@
|
||||
#include <thread>
|
||||
#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>
|
||||
namespace http = boost::beast::http; // from <boost/beast/http.hpp>
|
||||
|
||||
// Return a reasonable mime type based on the extension of a file.
|
||||
boost::beast::string_view
|
||||
mime_type(boost::beast::string_view path)
|
||||
beast::string_view
|
||||
mime_type(beast::string_view path)
|
||||
{
|
||||
using boost::beast::iequals;
|
||||
using beast::iequals;
|
||||
auto const ext = [&path]
|
||||
{
|
||||
auto const pos = path.rfind(".");
|
||||
if(pos == boost::beast::string_view::npos)
|
||||
return boost::beast::string_view{};
|
||||
if(pos == beast::string_view::npos)
|
||||
return beast::string_view{};
|
||||
return path.substr(pos);
|
||||
}();
|
||||
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.
|
||||
std::string
|
||||
path_cat(
|
||||
boost::beast::string_view base,
|
||||
boost::beast::string_view path)
|
||||
beast::string_view base,
|
||||
beast::string_view path)
|
||||
{
|
||||
if(base.empty())
|
||||
return path.to_string();
|
||||
@ -102,13 +104,13 @@ template<
|
||||
class Send>
|
||||
void
|
||||
handle_request(
|
||||
boost::beast::string_view doc_root,
|
||||
beast::string_view doc_root,
|
||||
http::request<Body, http::basic_fields<Allocator>>&& req,
|
||||
Send&& send)
|
||||
{
|
||||
// Returns a bad request response
|
||||
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()};
|
||||
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
@ -121,7 +123,7 @@ handle_request(
|
||||
|
||||
// Returns a not found response
|
||||
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()};
|
||||
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
@ -134,7 +136,7 @@ handle_request(
|
||||
|
||||
// Returns a server error response
|
||||
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()};
|
||||
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
@ -153,7 +155,7 @@ handle_request(
|
||||
// Request path must be absolute and not contain "..".
|
||||
if( req.target().empty() ||
|
||||
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"));
|
||||
|
||||
// Build the path to the requested file
|
||||
@ -162,12 +164,12 @@ handle_request(
|
||||
path.append("index.html");
|
||||
|
||||
// Attempt to open the file
|
||||
boost::beast::error_code ec;
|
||||
beast::error_code ec;
|
||||
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
|
||||
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()));
|
||||
|
||||
// Handle an unknown error
|
||||
@ -204,7 +206,7 @@ handle_request(
|
||||
|
||||
// Report a failure
|
||||
void
|
||||
fail(boost::system::error_code ec, char const* what)
|
||||
fail(beast::error_code ec, char const* what)
|
||||
{
|
||||
std::cerr << what << ": " << ec.message() << "\n";
|
||||
}
|
||||
@ -216,15 +218,15 @@ struct send_lambda
|
||||
{
|
||||
Stream& stream_;
|
||||
bool& close_;
|
||||
boost::system::error_code& ec_;
|
||||
boost::asio::yield_context yield_;
|
||||
beast::error_code& ec_;
|
||||
net::yield_context yield_;
|
||||
|
||||
explicit
|
||||
send_lambda(
|
||||
Stream& stream,
|
||||
bool& close,
|
||||
boost::system::error_code& ec,
|
||||
boost::asio::yield_context yield)
|
||||
beast::error_code& ec,
|
||||
net::yield_context yield)
|
||||
: stream_(stream)
|
||||
, close_(close)
|
||||
, ec_(ec)
|
||||
@ -252,13 +254,13 @@ void
|
||||
do_session(
|
||||
tcp::socket& socket,
|
||||
std::shared_ptr<std::string const> const& doc_root,
|
||||
boost::asio::yield_context yield)
|
||||
net::yield_context yield)
|
||||
{
|
||||
bool close = false;
|
||||
boost::system::error_code ec;
|
||||
beast::error_code ec;
|
||||
|
||||
// This buffer is required to persist across reads
|
||||
boost::beast::flat_buffer buffer;
|
||||
beast::flat_buffer buffer;
|
||||
|
||||
// This lambda is used to send messages
|
||||
send_lambda<tcp::socket> lambda{socket, close, ec, yield};
|
||||
@ -296,12 +298,12 @@ do_session(
|
||||
// Accepts incoming connections and launches the sessions
|
||||
void
|
||||
do_listen(
|
||||
boost::asio::io_context& ioc,
|
||||
net::io_context& ioc,
|
||||
tcp::endpoint endpoint,
|
||||
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
|
||||
tcp::acceptor acceptor(ioc);
|
||||
@ -310,7 +312,7 @@ do_listen(
|
||||
return fail(ec, "open");
|
||||
|
||||
// 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)
|
||||
return fail(ec, "set_option");
|
||||
|
||||
@ -320,7 +322,7 @@ do_listen(
|
||||
return fail(ec, "bind");
|
||||
|
||||
// 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)
|
||||
return fail(ec, "listen");
|
||||
|
||||
@ -331,7 +333,7 @@ do_listen(
|
||||
if(ec)
|
||||
fail(ec, "accept");
|
||||
else
|
||||
boost::asio::spawn(
|
||||
net::spawn(
|
||||
acceptor.get_executor().context(),
|
||||
std::bind(
|
||||
&do_session,
|
||||
@ -352,16 +354,16 @@ int main(int argc, char* argv[])
|
||||
" http-server-coro 0.0.0.0 8080 . 1\n";
|
||||
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 doc_root = std::make_shared<std::string>(argv[3]);
|
||||
auto const threads = std::max<int>(1, std::atoi(argv[4]));
|
||||
|
||||
// The io_context is required for all I/O
|
||||
boost::asio::io_context ioc{threads};
|
||||
net::io_context ioc{threads};
|
||||
|
||||
// Spawn a listening port
|
||||
boost::asio::spawn(ioc,
|
||||
net::spawn(ioc,
|
||||
std::bind(
|
||||
&do_listen,
|
||||
std::ref(ioc),
|
||||
|
@ -28,20 +28,21 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace ip = boost::asio::ip; // from <boost/asio.hpp>
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio.hpp>
|
||||
namespace http = boost::beast::http; // from <boost/beast/http.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>
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
|
||||
// Return a reasonable mime type based on the extension of a file.
|
||||
boost::beast::string_view
|
||||
mime_type(boost::beast::string_view path)
|
||||
beast::string_view
|
||||
mime_type(beast::string_view path)
|
||||
{
|
||||
using boost::beast::iequals;
|
||||
using beast::iequals;
|
||||
auto const ext = [&path]
|
||||
{
|
||||
auto const pos = path.rfind(".");
|
||||
if(pos == boost::beast::string_view::npos)
|
||||
return boost::beast::string_view{};
|
||||
if(pos == beast::string_view::npos)
|
||||
return beast::string_view{};
|
||||
return path.substr(pos);
|
||||
}();
|
||||
if(iequals(ext, ".htm")) return "text/html";
|
||||
@ -88,7 +89,7 @@ public:
|
||||
|
||||
private:
|
||||
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;
|
||||
|
||||
// The acceptor used to listen for incoming connections.
|
||||
@ -101,7 +102,7 @@ private:
|
||||
tcp::socket socket_{acceptor_.get_executor().context()};
|
||||
|
||||
// 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.
|
||||
alloc_t alloc_{8192};
|
||||
@ -110,7 +111,7 @@ private:
|
||||
boost::optional<http::request_parser<request_body_t, alloc_t>> parser_;
|
||||
|
||||
// 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)()};
|
||||
|
||||
// The string-based response message.
|
||||
@ -128,13 +129,13 @@ private:
|
||||
void accept()
|
||||
{
|
||||
// Clean up any previous connection.
|
||||
boost::beast::error_code ec;
|
||||
beast::error_code ec;
|
||||
socket_.close(ec);
|
||||
buffer_.consume(buffer_.size());
|
||||
|
||||
acceptor_.async_accept(
|
||||
socket_,
|
||||
[this](boost::beast::error_code ec)
|
||||
[this](beast::error_code ec)
|
||||
{
|
||||
if (ec)
|
||||
{
|
||||
@ -173,7 +174,7 @@ private:
|
||||
socket_,
|
||||
buffer_,
|
||||
*parser_,
|
||||
[this](boost::beast::error_code ec, std::size_t)
|
||||
[this](beast::error_code ec, std::size_t)
|
||||
{
|
||||
if (ec)
|
||||
accept();
|
||||
@ -221,7 +222,7 @@ private:
|
||||
http::async_write(
|
||||
socket_,
|
||||
*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);
|
||||
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 "..".
|
||||
if (target.empty() || target[0] != '/' || target.find("..") != std::string::npos)
|
||||
@ -247,10 +248,10 @@ private:
|
||||
target.size());
|
||||
|
||||
http::file_body::value_type file;
|
||||
boost::beast::error_code ec;
|
||||
beast::error_code ec;
|
||||
file.open(
|
||||
full_path.c_str(),
|
||||
boost::beast::file_mode::read,
|
||||
beast::file_mode::read,
|
||||
ec);
|
||||
if(ec)
|
||||
{
|
||||
@ -277,7 +278,7 @@ private:
|
||||
http::async_write(
|
||||
socket_,
|
||||
*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);
|
||||
file_serializer_.reset();
|
||||
@ -292,7 +293,7 @@ private:
|
||||
if (request_deadline_.expiry() <= std::chrono::steady_clock::now())
|
||||
{
|
||||
// Close socket to cancel any outstanding operation.
|
||||
boost::beast::error_code ec;
|
||||
beast::error_code ec;
|
||||
socket_.close();
|
||||
|
||||
// Sleep indefinitely until we're given a new deadline.
|
||||
@ -301,7 +302,7 @@ private:
|
||||
}
|
||||
|
||||
request_deadline_.async_wait(
|
||||
[this](boost::beast::error_code)
|
||||
[this](beast::error_code)
|
||||
{
|
||||
check_deadline();
|
||||
});
|
||||
@ -323,13 +324,13 @@ int main(int argc, char* argv[])
|
||||
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]));
|
||||
std::string doc_root = argv[3];
|
||||
int num_workers = std::atoi(argv[4]);
|
||||
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}};
|
||||
|
||||
std::list<http_worker> workers;
|
||||
|
@ -32,20 +32,22 @@
|
||||
#include <string>
|
||||
#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 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.
|
||||
boost::beast::string_view
|
||||
mime_type(boost::beast::string_view path)
|
||||
beast::string_view
|
||||
mime_type(beast::string_view path)
|
||||
{
|
||||
using boost::beast::iequals;
|
||||
using beast::iequals;
|
||||
auto const ext = [&path]
|
||||
{
|
||||
auto const pos = path.rfind(".");
|
||||
if(pos == boost::beast::string_view::npos)
|
||||
return boost::beast::string_view{};
|
||||
if(pos == beast::string_view::npos)
|
||||
return beast::string_view{};
|
||||
return path.substr(pos);
|
||||
}();
|
||||
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.
|
||||
std::string
|
||||
path_cat(
|
||||
boost::beast::string_view base,
|
||||
boost::beast::string_view path)
|
||||
beast::string_view base,
|
||||
beast::string_view path)
|
||||
{
|
||||
if(base.empty())
|
||||
return path.to_string();
|
||||
@ -108,13 +110,13 @@ template<
|
||||
class Send>
|
||||
void
|
||||
handle_request(
|
||||
boost::beast::string_view doc_root,
|
||||
beast::string_view doc_root,
|
||||
http::request<Body, http::basic_fields<Allocator>>&& req,
|
||||
Send&& send)
|
||||
{
|
||||
// Returns a bad request response
|
||||
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()};
|
||||
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
@ -127,7 +129,7 @@ handle_request(
|
||||
|
||||
// Returns a not found response
|
||||
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()};
|
||||
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
@ -140,7 +142,7 @@ handle_request(
|
||||
|
||||
// Returns a server error response
|
||||
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()};
|
||||
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
@ -159,7 +161,7 @@ handle_request(
|
||||
// Request path must be absolute and not contain "..".
|
||||
if( req.target().empty() ||
|
||||
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"));
|
||||
|
||||
// Build the path to the requested file
|
||||
@ -168,12 +170,12 @@ handle_request(
|
||||
path.append("index.html");
|
||||
|
||||
// Attempt to open the file
|
||||
boost::beast::error_code ec;
|
||||
beast::error_code ec;
|
||||
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
|
||||
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()));
|
||||
|
||||
// Handle an unknown error
|
||||
@ -210,7 +212,7 @@ handle_request(
|
||||
|
||||
// Report a failure
|
||||
void
|
||||
fail(boost::system::error_code ec, char const* what)
|
||||
fail(beast::error_code ec, char const* what)
|
||||
{
|
||||
std::cerr << what << ": " << ec.message() << "\n";
|
||||
}
|
||||
@ -259,7 +261,7 @@ class session
|
||||
http::async_write(
|
||||
self_.derived().stream(),
|
||||
*sp,
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
self_.strand_,
|
||||
std::bind(
|
||||
&session::on_write,
|
||||
@ -276,16 +278,16 @@ class session
|
||||
send_lambda lambda_;
|
||||
|
||||
protected:
|
||||
boost::asio::strand<
|
||||
boost::asio::io_context::executor_type> strand_;
|
||||
boost::beast::flat_buffer buffer_;
|
||||
net::strand<
|
||||
net::io_context::executor_type> strand_;
|
||||
beast::flat_buffer buffer_;
|
||||
|
||||
public:
|
||||
// Take ownership of the buffer
|
||||
explicit
|
||||
session(
|
||||
boost::asio::io_context& ioc,
|
||||
boost::beast::flat_buffer buffer,
|
||||
net::io_context& ioc,
|
||||
beast::flat_buffer buffer,
|
||||
std::shared_ptr<std::string const> const& doc_root)
|
||||
: doc_root_(doc_root)
|
||||
, lambda_(*this)
|
||||
@ -302,7 +304,7 @@ public:
|
||||
derived().stream(),
|
||||
buffer_,
|
||||
req_,
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&session::on_read,
|
||||
@ -313,7 +315,7 @@ public:
|
||||
|
||||
void
|
||||
on_read(
|
||||
boost::system::error_code ec,
|
||||
beast::error_code ec,
|
||||
std::size_t bytes_transferred)
|
||||
{
|
||||
boost::ignore_unused(bytes_transferred);
|
||||
@ -331,7 +333,7 @@ public:
|
||||
|
||||
void
|
||||
on_write(
|
||||
boost::system::error_code ec,
|
||||
beast::error_code ec,
|
||||
std::size_t bytes_transferred,
|
||||
bool close)
|
||||
{
|
||||
@ -361,14 +363,14 @@ class plain_session
|
||||
, public std::enable_shared_from_this<plain_session>
|
||||
{
|
||||
tcp::socket socket_;
|
||||
boost::asio::strand<
|
||||
boost::asio::io_context::executor_type> strand_;
|
||||
net::strand<
|
||||
net::io_context::executor_type> strand_;
|
||||
|
||||
public:
|
||||
// Create the session
|
||||
plain_session(
|
||||
tcp::socket socket,
|
||||
boost::beast::flat_buffer buffer,
|
||||
beast::flat_buffer buffer,
|
||||
std::shared_ptr<std::string const> const& doc_root)
|
||||
: session<plain_session>(
|
||||
socket.get_executor().context(),
|
||||
@ -397,7 +399,7 @@ public:
|
||||
do_eof()
|
||||
{
|
||||
// Send a TCP shutdown
|
||||
boost::system::error_code ec;
|
||||
beast::error_code ec;
|
||||
socket_.shutdown(tcp::socket::shutdown_send, ec);
|
||||
|
||||
// At this point the connection is closed gracefully
|
||||
@ -411,15 +413,15 @@ class ssl_session
|
||||
{
|
||||
tcp::socket socket_;
|
||||
ssl::stream<tcp::socket&> stream_;
|
||||
boost::asio::strand<
|
||||
boost::asio::io_context::executor_type> strand_;
|
||||
net::strand<
|
||||
net::io_context::executor_type> strand_;
|
||||
|
||||
public:
|
||||
// Create the session
|
||||
ssl_session(
|
||||
tcp::socket socket,
|
||||
ssl::context& ctx,
|
||||
boost::beast::flat_buffer buffer,
|
||||
beast::flat_buffer buffer,
|
||||
std::shared_ptr<std::string const> const& doc_root)
|
||||
: session<ssl_session>(
|
||||
socket.get_executor().context(),
|
||||
@ -447,7 +449,7 @@ public:
|
||||
stream_.async_handshake(
|
||||
ssl::stream_base::server,
|
||||
buffer_.data(),
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&ssl_session::on_handshake,
|
||||
@ -457,7 +459,7 @@ public:
|
||||
}
|
||||
void
|
||||
on_handshake(
|
||||
boost::system::error_code ec,
|
||||
beast::error_code ec,
|
||||
std::size_t bytes_used)
|
||||
{
|
||||
if(ec)
|
||||
@ -474,7 +476,7 @@ public:
|
||||
{
|
||||
// Perform the SSL shutdown
|
||||
stream_.async_shutdown(
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&ssl_session::on_shutdown,
|
||||
@ -483,7 +485,7 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
on_shutdown(boost::system::error_code ec)
|
||||
on_shutdown(beast::error_code ec)
|
||||
{
|
||||
if(ec)
|
||||
return fail(ec, "shutdown");
|
||||
@ -499,10 +501,10 @@ class detect_session : public std::enable_shared_from_this<detect_session>
|
||||
{
|
||||
tcp::socket socket_;
|
||||
ssl::context& ctx_;
|
||||
boost::asio::strand<
|
||||
boost::asio::io_context::executor_type> strand_;
|
||||
net::strand<
|
||||
net::io_context::executor_type> strand_;
|
||||
std::shared_ptr<std::string const> doc_root_;
|
||||
boost::beast::flat_buffer buffer_;
|
||||
beast::flat_buffer buffer_;
|
||||
|
||||
public:
|
||||
explicit
|
||||
@ -524,7 +526,7 @@ public:
|
||||
async_detect_ssl(
|
||||
socket_,
|
||||
buffer_,
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&detect_session::on_detect,
|
||||
@ -535,7 +537,7 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
on_detect(boost::system::error_code ec, boost::tribool result)
|
||||
on_detect(beast::error_code ec, boost::tribool result)
|
||||
{
|
||||
if(ec)
|
||||
return fail(ec, "detect");
|
||||
@ -563,15 +565,15 @@ public:
|
||||
class listener : public std::enable_shared_from_this<listener>
|
||||
{
|
||||
ssl::context& ctx_;
|
||||
boost::asio::strand<
|
||||
boost::asio::io_context::executor_type> strand_;
|
||||
net::strand<
|
||||
net::io_context::executor_type> strand_;
|
||||
tcp::acceptor acceptor_;
|
||||
tcp::socket socket_;
|
||||
std::shared_ptr<std::string const> doc_root_;
|
||||
|
||||
public:
|
||||
listener(
|
||||
boost::asio::io_context& ioc,
|
||||
net::io_context& ioc,
|
||||
ssl::context& ctx,
|
||||
tcp::endpoint endpoint,
|
||||
std::shared_ptr<std::string const> const& doc_root)
|
||||
@ -581,7 +583,7 @@ public:
|
||||
, socket_(ioc)
|
||||
, doc_root_(doc_root)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
beast::error_code ec;
|
||||
|
||||
// Open the acceptor
|
||||
acceptor_.open(endpoint.protocol(), ec);
|
||||
@ -592,7 +594,7 @@ public:
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
fail(ec, "set_option");
|
||||
@ -609,7 +611,7 @@ public:
|
||||
|
||||
// Start listening for connections
|
||||
acceptor_.listen(
|
||||
boost::asio::socket_base::max_listen_connections, ec);
|
||||
net::socket_base::max_listen_connections, ec);
|
||||
if(ec)
|
||||
{
|
||||
fail(ec, "listen");
|
||||
@ -638,7 +640,7 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
on_accept(boost::system::error_code ec)
|
||||
on_accept(beast::error_code ec)
|
||||
{
|
||||
if(ec)
|
||||
{
|
||||
@ -671,13 +673,13 @@ int main(int argc, char* argv[])
|
||||
" http-server-flex 0.0.0.0 8080 .\n";
|
||||
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 doc_root = std::make_shared<std::string>(argv[3]);
|
||||
auto const threads = std::max<int>(1, std::atoi(argv[4]));
|
||||
|
||||
// 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
|
||||
ssl::context ctx{ssl::context::sslv23};
|
||||
|
@ -24,9 +24,10 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace ip = boost::asio::ip; // from <boost/asio.hpp>
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio.hpp>
|
||||
namespace http = boost::beast::http; // from <boost/beast/http.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>
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
|
||||
namespace my_program_state
|
||||
{
|
||||
@ -65,7 +66,7 @@ private:
|
||||
tcp::socket socket_;
|
||||
|
||||
// The buffer for performing reads.
|
||||
boost::beast::flat_buffer buffer_{8192};
|
||||
beast::flat_buffer buffer_{8192};
|
||||
|
||||
// The request message.
|
||||
http::request<http::dynamic_body> request_;
|
||||
@ -74,7 +75,7 @@ private:
|
||||
http::response<http::dynamic_body> response_;
|
||||
|
||||
// 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)};
|
||||
|
||||
// Asynchronously receive a complete request message.
|
||||
@ -87,7 +88,7 @@ private:
|
||||
socket_,
|
||||
buffer_,
|
||||
request_,
|
||||
[self](boost::beast::error_code ec,
|
||||
[self](beast::error_code ec,
|
||||
std::size_t bytes_transferred)
|
||||
{
|
||||
boost::ignore_unused(bytes_transferred);
|
||||
@ -116,7 +117,7 @@ private:
|
||||
// we do not recognize the request method.
|
||||
response_.result(http::status::bad_request);
|
||||
response_.set(http::field::content_type, "text/plain");
|
||||
boost::beast::ostream(response_.body())
|
||||
beast::ostream(response_.body())
|
||||
<< "Invalid request-method '"
|
||||
<< request_.method_string().to_string()
|
||||
<< "'";
|
||||
@ -133,7 +134,7 @@ private:
|
||||
if(request_.target() == "/count")
|
||||
{
|
||||
response_.set(http::field::content_type, "text/html");
|
||||
boost::beast::ostream(response_.body())
|
||||
beast::ostream(response_.body())
|
||||
<< "<html>\n"
|
||||
<< "<head><title>Request count</title></head>\n"
|
||||
<< "<body>\n"
|
||||
@ -147,7 +148,7 @@ private:
|
||||
else if(request_.target() == "/time")
|
||||
{
|
||||
response_.set(http::field::content_type, "text/html");
|
||||
boost::beast::ostream(response_.body())
|
||||
beast::ostream(response_.body())
|
||||
<< "<html>\n"
|
||||
<< "<head><title>Current time</title></head>\n"
|
||||
<< "<body>\n"
|
||||
@ -162,7 +163,7 @@ private:
|
||||
{
|
||||
response_.result(http::status::not_found);
|
||||
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(
|
||||
socket_,
|
||||
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->deadline_.cancel();
|
||||
@ -191,7 +192,7 @@ private:
|
||||
auto self = shared_from_this();
|
||||
|
||||
deadline_.async_wait(
|
||||
[self](boost::beast::error_code ec)
|
||||
[self](beast::error_code ec)
|
||||
{
|
||||
if(!ec)
|
||||
{
|
||||
@ -207,7 +208,7 @@ void
|
||||
http_server(tcp::acceptor& acceptor, tcp::socket& socket)
|
||||
{
|
||||
acceptor.async_accept(socket,
|
||||
[&](boost::beast::error_code ec)
|
||||
[&](beast::error_code ec)
|
||||
{
|
||||
if(!ec)
|
||||
std::make_shared<http_connection>(std::move(socket))->start();
|
||||
@ -231,10 +232,10 @@ main(int argc, char* argv[])
|
||||
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]));
|
||||
|
||||
boost::asio::io_context ioc{1};
|
||||
net::io_context ioc{1};
|
||||
|
||||
tcp::acceptor acceptor{ioc, {address, port}};
|
||||
tcp::socket socket{ioc};
|
||||
|
@ -33,20 +33,22 @@
|
||||
#include <thread>
|
||||
#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 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.
|
||||
boost::beast::string_view
|
||||
mime_type(boost::beast::string_view path)
|
||||
beast::string_view
|
||||
mime_type(beast::string_view path)
|
||||
{
|
||||
using boost::beast::iequals;
|
||||
using beast::iequals;
|
||||
auto const ext = [&path]
|
||||
{
|
||||
auto const pos = path.rfind(".");
|
||||
if(pos == boost::beast::string_view::npos)
|
||||
return boost::beast::string_view{};
|
||||
if(pos == beast::string_view::npos)
|
||||
return beast::string_view{};
|
||||
return path.substr(pos);
|
||||
}();
|
||||
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.
|
||||
std::string
|
||||
path_cat(
|
||||
boost::beast::string_view base,
|
||||
boost::beast::string_view path)
|
||||
beast::string_view base,
|
||||
beast::string_view path)
|
||||
{
|
||||
if(base.empty())
|
||||
return path.to_string();
|
||||
@ -109,13 +111,13 @@ template<
|
||||
class Send>
|
||||
void
|
||||
handle_request(
|
||||
boost::beast::string_view doc_root,
|
||||
beast::string_view doc_root,
|
||||
http::request<Body, http::basic_fields<Allocator>>&& req,
|
||||
Send&& send)
|
||||
{
|
||||
// Returns a bad request response
|
||||
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()};
|
||||
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
@ -128,7 +130,7 @@ handle_request(
|
||||
|
||||
// Returns a not found response
|
||||
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()};
|
||||
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
@ -141,7 +143,7 @@ handle_request(
|
||||
|
||||
// Returns a server error response
|
||||
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()};
|
||||
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
@ -160,7 +162,7 @@ handle_request(
|
||||
// Request path must be absolute and not contain "..".
|
||||
if( req.target().empty() ||
|
||||
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"));
|
||||
|
||||
// Build the path to the requested file
|
||||
@ -169,12 +171,12 @@ handle_request(
|
||||
path.append("index.html");
|
||||
|
||||
// Attempt to open the file
|
||||
boost::beast::error_code ec;
|
||||
beast::error_code ec;
|
||||
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
|
||||
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()));
|
||||
|
||||
// Handle an unknown error
|
||||
@ -211,14 +213,14 @@ handle_request(
|
||||
|
||||
// Report a failure
|
||||
void
|
||||
fail(boost::system::error_code ec, char const* what)
|
||||
fail(beast::error_code ec, char const* what)
|
||||
{
|
||||
std::cerr << what << ": " << ec.message() << "\n";
|
||||
}
|
||||
|
||||
// Handles an HTTP server connection
|
||||
class session
|
||||
: public boost::asio::coroutine
|
||||
: public net::coroutine
|
||||
, public std::enable_shared_from_this<session>
|
||||
{
|
||||
// This is the C++11 equivalent of a generic lambda.
|
||||
@ -251,7 +253,7 @@ class session
|
||||
http::async_write(
|
||||
self_.stream_,
|
||||
*sp,
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
self_.strand_,
|
||||
std::bind(
|
||||
&session::loop,
|
||||
@ -264,9 +266,9 @@ class session
|
||||
|
||||
tcp::socket socket_;
|
||||
ssl::stream<tcp::socket&> stream_;
|
||||
boost::asio::strand<
|
||||
boost::asio::io_context::executor_type> strand_;
|
||||
boost::beast::flat_buffer buffer_;
|
||||
net::strand<
|
||||
net::io_context::executor_type> strand_;
|
||||
beast::flat_buffer buffer_;
|
||||
std::shared_ptr<std::string const> doc_root_;
|
||||
http::request<http::string_body> req_;
|
||||
std::shared_ptr<void> res_;
|
||||
@ -297,7 +299,7 @@ public:
|
||||
#include <boost/asio/yield.hpp>
|
||||
void
|
||||
loop(
|
||||
boost::system::error_code ec,
|
||||
beast::error_code ec,
|
||||
std::size_t bytes_transferred,
|
||||
bool close)
|
||||
{
|
||||
@ -307,7 +309,7 @@ public:
|
||||
// Perform the SSL handshake
|
||||
yield stream_.async_handshake(
|
||||
ssl::stream_base::server,
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&session::loop,
|
||||
@ -326,7 +328,7 @@ public:
|
||||
|
||||
// Read a request
|
||||
yield http::async_read(stream_, buffer_, req_,
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&session::loop,
|
||||
@ -359,7 +361,7 @@ public:
|
||||
|
||||
// Perform the SSL shutdown
|
||||
yield stream_.async_shutdown(
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&session::loop,
|
||||
@ -380,7 +382,7 @@ public:
|
||||
|
||||
// Accepts incoming connections and launches the sessions
|
||||
class listener
|
||||
: public boost::asio::coroutine
|
||||
: public net::coroutine
|
||||
, public std::enable_shared_from_this<listener>
|
||||
{
|
||||
ssl::context& ctx_;
|
||||
@ -390,7 +392,7 @@ class listener
|
||||
|
||||
public:
|
||||
listener(
|
||||
boost::asio::io_context& ioc,
|
||||
net::io_context& ioc,
|
||||
ssl::context& ctx,
|
||||
tcp::endpoint endpoint,
|
||||
std::shared_ptr<std::string const> const& doc_root)
|
||||
@ -399,7 +401,7 @@ public:
|
||||
, socket_(ioc)
|
||||
, doc_root_(doc_root)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
beast::error_code ec;
|
||||
|
||||
// Open the acceptor
|
||||
acceptor_.open(endpoint.protocol(), ec);
|
||||
@ -410,7 +412,7 @@ public:
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
fail(ec, "set_option");
|
||||
@ -427,7 +429,7 @@ public:
|
||||
|
||||
// Start listening for connections
|
||||
acceptor_.listen(
|
||||
boost::asio::socket_base::max_listen_connections, ec);
|
||||
net::socket_base::max_listen_connections, ec);
|
||||
if(ec)
|
||||
{
|
||||
fail(ec, "listen");
|
||||
@ -446,7 +448,7 @@ public:
|
||||
|
||||
#include <boost/asio/yield.hpp>
|
||||
void
|
||||
loop(boost::system::error_code ec = {})
|
||||
loop(beast::error_code ec = {})
|
||||
{
|
||||
reenter(*this)
|
||||
{
|
||||
@ -489,13 +491,13 @@ int main(int argc, char* argv[])
|
||||
" http-server-stackless-ssl 0.0.0.0 8080 . 1\n";
|
||||
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 doc_root = std::make_shared<std::string>(argv[3]);
|
||||
auto const threads = std::max<int>(1, std::atoi(argv[4]));
|
||||
|
||||
// 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
|
||||
ssl::context ctx{ssl::context::sslv23};
|
||||
|
@ -30,19 +30,21 @@
|
||||
#include <thread>
|
||||
#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>
|
||||
namespace http = boost::beast::http; // from <boost/beast/http.hpp>
|
||||
|
||||
// Return a reasonable mime type based on the extension of a file.
|
||||
boost::beast::string_view
|
||||
mime_type(boost::beast::string_view path)
|
||||
beast::string_view
|
||||
mime_type(beast::string_view path)
|
||||
{
|
||||
using boost::beast::iequals;
|
||||
using beast::iequals;
|
||||
auto const ext = [&path]
|
||||
{
|
||||
auto const pos = path.rfind(".");
|
||||
if(pos == boost::beast::string_view::npos)
|
||||
return boost::beast::string_view{};
|
||||
if(pos == beast::string_view::npos)
|
||||
return beast::string_view{};
|
||||
return path.substr(pos);
|
||||
}();
|
||||
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.
|
||||
std::string
|
||||
path_cat(
|
||||
boost::beast::string_view base,
|
||||
boost::beast::string_view path)
|
||||
beast::string_view base,
|
||||
beast::string_view path)
|
||||
{
|
||||
if(base.empty())
|
||||
return path.to_string();
|
||||
@ -105,13 +107,13 @@ template<
|
||||
class Send>
|
||||
void
|
||||
handle_request(
|
||||
boost::beast::string_view doc_root,
|
||||
beast::string_view doc_root,
|
||||
http::request<Body, http::basic_fields<Allocator>>&& req,
|
||||
Send&& send)
|
||||
{
|
||||
// Returns a bad request response
|
||||
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()};
|
||||
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
@ -124,7 +126,7 @@ handle_request(
|
||||
|
||||
// Returns a not found response
|
||||
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()};
|
||||
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
@ -137,7 +139,7 @@ handle_request(
|
||||
|
||||
// Returns a server error response
|
||||
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()};
|
||||
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
@ -156,7 +158,7 @@ handle_request(
|
||||
// Request path must be absolute and not contain "..".
|
||||
if( req.target().empty() ||
|
||||
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"));
|
||||
|
||||
// Build the path to the requested file
|
||||
@ -165,12 +167,12 @@ handle_request(
|
||||
path.append("index.html");
|
||||
|
||||
// Attempt to open the file
|
||||
boost::beast::error_code ec;
|
||||
beast::error_code ec;
|
||||
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
|
||||
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()));
|
||||
|
||||
// Handle an unknown error
|
||||
@ -207,14 +209,14 @@ handle_request(
|
||||
|
||||
// Report a failure
|
||||
void
|
||||
fail(boost::system::error_code ec, char const* what)
|
||||
fail(beast::error_code ec, char const* what)
|
||||
{
|
||||
std::cerr << what << ": " << ec.message() << "\n";
|
||||
}
|
||||
|
||||
// Handles an HTTP server connection
|
||||
class session
|
||||
: public boost::asio::coroutine
|
||||
: public net::coroutine
|
||||
, public std::enable_shared_from_this<session>
|
||||
{
|
||||
// This is the C++11 equivalent of a generic lambda.
|
||||
@ -248,7 +250,7 @@ class session
|
||||
http::async_write(
|
||||
self_.socket_,
|
||||
*sp,
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
self_.strand_,
|
||||
std::bind(
|
||||
&session::loop,
|
||||
@ -260,9 +262,9 @@ class session
|
||||
};
|
||||
|
||||
tcp::socket socket_;
|
||||
boost::asio::strand<
|
||||
boost::asio::io_context::executor_type> strand_;
|
||||
boost::beast::flat_buffer buffer_;
|
||||
net::strand<
|
||||
net::io_context::executor_type> strand_;
|
||||
beast::flat_buffer buffer_;
|
||||
std::shared_ptr<std::string const> doc_root_;
|
||||
http::request<http::string_body> req_;
|
||||
std::shared_ptr<void> res_;
|
||||
@ -291,7 +293,7 @@ public:
|
||||
#include <boost/asio/yield.hpp>
|
||||
void
|
||||
loop(
|
||||
boost::system::error_code ec,
|
||||
beast::error_code ec,
|
||||
std::size_t bytes_transferred,
|
||||
bool close)
|
||||
{
|
||||
@ -306,7 +308,7 @@ public:
|
||||
|
||||
// Read a request
|
||||
yield http::async_read(socket_, buffer_, req_,
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&session::loop,
|
||||
@ -350,7 +352,7 @@ public:
|
||||
|
||||
// Accepts incoming connections and launches the sessions
|
||||
class listener
|
||||
: public boost::asio::coroutine
|
||||
: public net::coroutine
|
||||
, public std::enable_shared_from_this<listener>
|
||||
{
|
||||
tcp::acceptor acceptor_;
|
||||
@ -359,14 +361,14 @@ class listener
|
||||
|
||||
public:
|
||||
listener(
|
||||
boost::asio::io_context& ioc,
|
||||
net::io_context& ioc,
|
||||
tcp::endpoint endpoint,
|
||||
std::shared_ptr<std::string const> const& doc_root)
|
||||
: acceptor_(ioc)
|
||||
, socket_(ioc)
|
||||
, doc_root_(doc_root)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
beast::error_code ec;
|
||||
|
||||
// Open the acceptor
|
||||
acceptor_.open(endpoint.protocol(), ec);
|
||||
@ -377,7 +379,7 @@ public:
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
fail(ec, "set_option");
|
||||
@ -393,7 +395,7 @@ public:
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
fail(ec, "listen");
|
||||
@ -412,7 +414,7 @@ public:
|
||||
|
||||
#include <boost/asio/yield.hpp>
|
||||
void
|
||||
loop(boost::system::error_code ec = {})
|
||||
loop(beast::error_code ec = {})
|
||||
{
|
||||
reenter(*this)
|
||||
{
|
||||
@ -454,13 +456,13 @@ int main(int argc, char* argv[])
|
||||
" http-server-stackless 0.0.0.0 8080 . 1\n";
|
||||
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 doc_root = std::make_shared<std::string>(argv[3]);
|
||||
auto const threads = std::max<int>(1, std::atoi(argv[4]));
|
||||
|
||||
// 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
|
||||
std::make_shared<listener>(
|
||||
|
@ -27,20 +27,22 @@
|
||||
#include <string>
|
||||
#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 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.
|
||||
boost::beast::string_view
|
||||
mime_type(boost::beast::string_view path)
|
||||
beast::string_view
|
||||
mime_type(beast::string_view path)
|
||||
{
|
||||
using boost::beast::iequals;
|
||||
using beast::iequals;
|
||||
auto const ext = [&path]
|
||||
{
|
||||
auto const pos = path.rfind(".");
|
||||
if(pos == boost::beast::string_view::npos)
|
||||
return boost::beast::string_view{};
|
||||
if(pos == beast::string_view::npos)
|
||||
return beast::string_view{};
|
||||
return path.substr(pos);
|
||||
}();
|
||||
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.
|
||||
std::string
|
||||
path_cat(
|
||||
boost::beast::string_view base,
|
||||
boost::beast::string_view path)
|
||||
beast::string_view base,
|
||||
beast::string_view path)
|
||||
{
|
||||
if(base.empty())
|
||||
return path.to_string();
|
||||
@ -103,13 +105,13 @@ template<
|
||||
class Send>
|
||||
void
|
||||
handle_request(
|
||||
boost::beast::string_view doc_root,
|
||||
beast::string_view doc_root,
|
||||
http::request<Body, http::basic_fields<Allocator>>&& req,
|
||||
Send&& send)
|
||||
{
|
||||
// Returns a bad request response
|
||||
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()};
|
||||
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
@ -122,7 +124,7 @@ handle_request(
|
||||
|
||||
// Returns a not found response
|
||||
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()};
|
||||
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
@ -135,7 +137,7 @@ handle_request(
|
||||
|
||||
// Returns a server error response
|
||||
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()};
|
||||
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
@ -154,7 +156,7 @@ handle_request(
|
||||
// Request path must be absolute and not contain "..".
|
||||
if( req.target().empty() ||
|
||||
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"));
|
||||
|
||||
// Build the path to the requested file
|
||||
@ -163,12 +165,12 @@ handle_request(
|
||||
path.append("index.html");
|
||||
|
||||
// Attempt to open the file
|
||||
boost::beast::error_code ec;
|
||||
beast::error_code ec;
|
||||
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
|
||||
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()));
|
||||
|
||||
// Handle an unknown error
|
||||
@ -205,7 +207,7 @@ handle_request(
|
||||
|
||||
// Report a failure
|
||||
void
|
||||
fail(boost::system::error_code ec, char const* what)
|
||||
fail(beast::error_code ec, char const* what)
|
||||
{
|
||||
std::cerr << what << ": " << ec.message() << "\n";
|
||||
}
|
||||
@ -217,13 +219,13 @@ struct send_lambda
|
||||
{
|
||||
Stream& stream_;
|
||||
bool& close_;
|
||||
boost::system::error_code& ec_;
|
||||
beast::error_code& ec_;
|
||||
|
||||
explicit
|
||||
send_lambda(
|
||||
Stream& stream,
|
||||
bool& close,
|
||||
boost::system::error_code& ec)
|
||||
beast::error_code& ec)
|
||||
: stream_(stream)
|
||||
, close_(close)
|
||||
, ec_(ec)
|
||||
@ -253,7 +255,7 @@ do_session(
|
||||
std::shared_ptr<std::string const> const& doc_root)
|
||||
{
|
||||
bool close = false;
|
||||
boost::system::error_code ec;
|
||||
beast::error_code ec;
|
||||
|
||||
// Construct the stream around the socket
|
||||
ssl::stream<tcp::socket&> stream{socket, ctx};
|
||||
@ -264,7 +266,7 @@ do_session(
|
||||
return fail(ec, "handshake");
|
||||
|
||||
// This buffer is required to persist across reads
|
||||
boost::beast::flat_buffer buffer;
|
||||
beast::flat_buffer buffer;
|
||||
|
||||
// This lambda is used to send messages
|
||||
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";
|
||||
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 doc_root = std::make_shared<std::string>(argv[3]);
|
||||
|
||||
// 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
|
||||
ssl::context ctx{ssl::context::sslv23};
|
||||
|
@ -24,21 +24,23 @@
|
||||
#include <string>
|
||||
#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>
|
||||
namespace http = boost::beast::http; // from <boost/beast/http.hpp>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Return a reasonable mime type based on the extension of a file.
|
||||
boost::beast::string_view
|
||||
mime_type(boost::beast::string_view path)
|
||||
beast::string_view
|
||||
mime_type(beast::string_view path)
|
||||
{
|
||||
using boost::beast::iequals;
|
||||
using beast::iequals;
|
||||
auto const ext = [&path]
|
||||
{
|
||||
auto const pos = path.rfind(".");
|
||||
if(pos == boost::beast::string_view::npos)
|
||||
return boost::beast::string_view{};
|
||||
if(pos == beast::string_view::npos)
|
||||
return beast::string_view{};
|
||||
return path.substr(pos);
|
||||
}();
|
||||
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.
|
||||
std::string
|
||||
path_cat(
|
||||
boost::beast::string_view base,
|
||||
boost::beast::string_view path)
|
||||
beast::string_view base,
|
||||
beast::string_view path)
|
||||
{
|
||||
if(base.empty())
|
||||
return path.to_string();
|
||||
@ -101,13 +103,13 @@ template<
|
||||
class Send>
|
||||
void
|
||||
handle_request(
|
||||
boost::beast::string_view doc_root,
|
||||
beast::string_view doc_root,
|
||||
http::request<Body, http::basic_fields<Allocator>>&& req,
|
||||
Send&& send)
|
||||
{
|
||||
// Returns a bad request response
|
||||
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()};
|
||||
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
@ -120,7 +122,7 @@ handle_request(
|
||||
|
||||
// Returns a not found response
|
||||
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()};
|
||||
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
@ -133,7 +135,7 @@ handle_request(
|
||||
|
||||
// Returns a server error response
|
||||
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()};
|
||||
res.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
@ -152,7 +154,7 @@ handle_request(
|
||||
// Request path must be absolute and not contain "..".
|
||||
if( req.target().empty() ||
|
||||
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"));
|
||||
|
||||
// Build the path to the requested file
|
||||
@ -161,12 +163,12 @@ handle_request(
|
||||
path.append("index.html");
|
||||
|
||||
// Attempt to open the file
|
||||
boost::beast::error_code ec;
|
||||
beast::error_code ec;
|
||||
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
|
||||
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()));
|
||||
|
||||
// Handle an unknown error
|
||||
@ -203,7 +205,7 @@ handle_request(
|
||||
|
||||
// Report a failure
|
||||
void
|
||||
fail(boost::system::error_code ec, char const* what)
|
||||
fail(beast::error_code ec, char const* what)
|
||||
{
|
||||
std::cerr << what << ": " << ec.message() << "\n";
|
||||
}
|
||||
@ -215,13 +217,13 @@ struct send_lambda
|
||||
{
|
||||
Stream& stream_;
|
||||
bool& close_;
|
||||
boost::system::error_code& ec_;
|
||||
beast::error_code& ec_;
|
||||
|
||||
explicit
|
||||
send_lambda(
|
||||
Stream& stream,
|
||||
bool& close,
|
||||
boost::system::error_code& ec)
|
||||
beast::error_code& ec)
|
||||
: stream_(stream)
|
||||
, close_(close)
|
||||
, ec_(ec)
|
||||
@ -250,10 +252,10 @@ do_session(
|
||||
std::shared_ptr<std::string const> const& doc_root)
|
||||
{
|
||||
bool close = false;
|
||||
boost::system::error_code ec;
|
||||
beast::error_code ec;
|
||||
|
||||
// This buffer is required to persist across reads
|
||||
boost::beast::flat_buffer buffer;
|
||||
beast::flat_buffer buffer;
|
||||
|
||||
// This lambda is used to send messages
|
||||
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";
|
||||
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 doc_root = std::make_shared<std::string>(argv[3]);
|
||||
|
||||
// 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
|
||||
tcp::acceptor acceptor{ioc, {address, port}};
|
||||
|
@ -27,15 +27,18 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp>
|
||||
namespace websocket = boost::beast::websocket; // from <boost/beast/websocket.hpp>
|
||||
namespace beast = boost::beast; // from <boost/beast.hpp>
|
||||
namespace http = beast::http; // from <boost/beast/http.hpp>
|
||||
namespace websocket = beast::websocket; // from <boost/beast/websocket.hpp>
|
||||
namespace net = boost::asio; // from <boost/asio.hpp>
|
||||
namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp>
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Report a failure
|
||||
void
|
||||
fail(boost::system::error_code ec, char const* what)
|
||||
fail(beast::error_code ec, char const* what)
|
||||
{
|
||||
std::cerr << what << ": " << ec.message() << "\n";
|
||||
}
|
||||
@ -45,14 +48,14 @@ class session : public std::enable_shared_from_this<session>
|
||||
{
|
||||
tcp::resolver resolver_;
|
||||
websocket::stream<ssl::stream<tcp::socket>> ws_;
|
||||
boost::beast::multi_buffer buffer_;
|
||||
beast::multi_buffer buffer_;
|
||||
std::string host_;
|
||||
std::string text_;
|
||||
|
||||
public:
|
||||
// Resolver and socket require an io_context
|
||||
explicit
|
||||
session(boost::asio::io_context& ioc, ssl::context& ctx)
|
||||
session(net::io_context& ioc, ssl::context& ctx)
|
||||
: resolver_(ioc)
|
||||
, ws_(ioc, ctx)
|
||||
{
|
||||
@ -82,14 +85,14 @@ public:
|
||||
|
||||
void
|
||||
on_resolve(
|
||||
boost::system::error_code ec,
|
||||
beast::error_code ec,
|
||||
tcp::resolver::results_type results)
|
||||
{
|
||||
if(ec)
|
||||
return fail(ec, "resolve");
|
||||
|
||||
// Make the connection on the IP address we get from a lookup
|
||||
boost::asio::async_connect(
|
||||
net::async_connect(
|
||||
ws_.next_layer().next_layer(),
|
||||
results.begin(),
|
||||
results.end(),
|
||||
@ -100,7 +103,7 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
on_connect(boost::system::error_code ec)
|
||||
on_connect(beast::error_code ec)
|
||||
{
|
||||
if(ec)
|
||||
return fail(ec, "connect");
|
||||
@ -115,7 +118,7 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
on_ssl_handshake(boost::system::error_code ec)
|
||||
on_ssl_handshake(beast::error_code ec)
|
||||
{
|
||||
if(ec)
|
||||
return fail(ec, "ssl_handshake");
|
||||
@ -129,14 +132,14 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
on_handshake(boost::system::error_code ec)
|
||||
on_handshake(beast::error_code ec)
|
||||
{
|
||||
if(ec)
|
||||
return fail(ec, "handshake");
|
||||
|
||||
// Send the message
|
||||
ws_.async_write(
|
||||
boost::asio::buffer(text_),
|
||||
net::buffer(text_),
|
||||
std::bind(
|
||||
&session::on_write,
|
||||
shared_from_this(),
|
||||
@ -146,7 +149,7 @@ public:
|
||||
|
||||
void
|
||||
on_write(
|
||||
boost::system::error_code ec,
|
||||
beast::error_code ec,
|
||||
std::size_t bytes_transferred)
|
||||
{
|
||||
boost::ignore_unused(bytes_transferred);
|
||||
@ -166,7 +169,7 @@ public:
|
||||
|
||||
void
|
||||
on_read(
|
||||
boost::system::error_code ec,
|
||||
beast::error_code ec,
|
||||
std::size_t bytes_transferred)
|
||||
{
|
||||
boost::ignore_unused(bytes_transferred);
|
||||
@ -183,7 +186,7 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
on_close(boost::system::error_code ec)
|
||||
on_close(beast::error_code ec)
|
||||
{
|
||||
if(ec)
|
||||
return fail(ec, "close");
|
||||
@ -191,7 +194,7 @@ public:
|
||||
// If we get here then the connection is closed gracefully
|
||||
|
||||
// The buffers() function helps print a ConstBufferSequence
|
||||
std::cout << boost::beast::buffers(buffer_.data()) << std::endl;
|
||||
std::cout << beast::buffers(buffer_.data()) << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
@ -213,7 +216,7 @@ int main(int argc, char** argv)
|
||||
auto const text = argv[3];
|
||||
|
||||
// The io_context is required for all I/O
|
||||
boost::asio::io_context ioc;
|
||||
net::io_context ioc;
|
||||
|
||||
// The SSL context is required, and holds certificates
|
||||
ssl::context ctx{ssl::context::sslv23_client};
|
||||
|
@ -23,14 +23,17 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
namespace websocket = boost::beast::websocket; // from <boost/beast/websocket.hpp>
|
||||
namespace beast = boost::beast; // from <boost/beast.hpp>
|
||||
namespace http = beast::http; // from <boost/beast/http.hpp>
|
||||
namespace websocket = beast::websocket; // from <boost/beast/websocket.hpp>
|
||||
namespace net = boost::asio; // from <boost/asio.hpp>
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Report a failure
|
||||
void
|
||||
fail(boost::system::error_code ec, char const* what)
|
||||
fail(beast::error_code ec, char const* what)
|
||||
{
|
||||
std::cerr << what << ": " << ec.message() << "\n";
|
||||
}
|
||||
@ -40,14 +43,14 @@ class session : public std::enable_shared_from_this<session>
|
||||
{
|
||||
tcp::resolver resolver_;
|
||||
websocket::stream<tcp::socket> ws_;
|
||||
boost::beast::multi_buffer buffer_;
|
||||
beast::multi_buffer buffer_;
|
||||
std::string host_;
|
||||
std::string text_;
|
||||
|
||||
public:
|
||||
// Resolver and socket require an io_context
|
||||
explicit
|
||||
session(boost::asio::io_context& ioc)
|
||||
session(net::io_context& ioc)
|
||||
: resolver_(ioc)
|
||||
, ws_(ioc)
|
||||
{
|
||||
@ -77,14 +80,14 @@ public:
|
||||
|
||||
void
|
||||
on_resolve(
|
||||
boost::system::error_code ec,
|
||||
beast::error_code ec,
|
||||
tcp::resolver::results_type results)
|
||||
{
|
||||
if(ec)
|
||||
return fail(ec, "resolve");
|
||||
|
||||
// Make the connection on the IP address we get from a lookup
|
||||
boost::asio::async_connect(
|
||||
net::async_connect(
|
||||
ws_.next_layer(),
|
||||
results.begin(),
|
||||
results.end(),
|
||||
@ -95,7 +98,7 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
on_connect(boost::system::error_code ec)
|
||||
on_connect(beast::error_code ec)
|
||||
{
|
||||
if(ec)
|
||||
return fail(ec, "connect");
|
||||
@ -109,14 +112,14 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
on_handshake(boost::system::error_code ec)
|
||||
on_handshake(beast::error_code ec)
|
||||
{
|
||||
if(ec)
|
||||
return fail(ec, "handshake");
|
||||
|
||||
// Send the message
|
||||
ws_.async_write(
|
||||
boost::asio::buffer(text_),
|
||||
net::buffer(text_),
|
||||
std::bind(
|
||||
&session::on_write,
|
||||
shared_from_this(),
|
||||
@ -126,7 +129,7 @@ public:
|
||||
|
||||
void
|
||||
on_write(
|
||||
boost::system::error_code ec,
|
||||
beast::error_code ec,
|
||||
std::size_t bytes_transferred)
|
||||
{
|
||||
boost::ignore_unused(bytes_transferred);
|
||||
@ -146,7 +149,7 @@ public:
|
||||
|
||||
void
|
||||
on_read(
|
||||
boost::system::error_code ec,
|
||||
beast::error_code ec,
|
||||
std::size_t bytes_transferred)
|
||||
{
|
||||
boost::ignore_unused(bytes_transferred);
|
||||
@ -163,7 +166,7 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
on_close(boost::system::error_code ec)
|
||||
on_close(beast::error_code ec)
|
||||
{
|
||||
if(ec)
|
||||
return fail(ec, "close");
|
||||
@ -171,7 +174,7 @@ public:
|
||||
// If we get here then the connection is closed gracefully
|
||||
|
||||
// The buffers() function helps print a ConstBufferSequence
|
||||
std::cout << boost::beast::buffers(buffer_.data()) << std::endl;
|
||||
std::cout << beast::buffers(buffer_.data()) << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
@ -193,7 +196,7 @@ int main(int argc, char** argv)
|
||||
auto const text = argv[3];
|
||||
|
||||
// The io_context is required for all I/O
|
||||
boost::asio::io_context ioc;
|
||||
net::io_context ioc;
|
||||
|
||||
// Launch the asynchronous operation
|
||||
std::make_shared<session>(ioc)->run(host, port, text);
|
||||
|
@ -27,15 +27,18 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp>
|
||||
namespace websocket = boost::beast::websocket; // from <boost/beast/websocket.hpp>
|
||||
namespace beast = boost::beast; // from <boost/beast.hpp>
|
||||
namespace http = beast::http; // from <boost/beast/http.hpp>
|
||||
namespace websocket = beast::websocket; // from <boost/beast/websocket.hpp>
|
||||
namespace net = boost::asio; // from <boost/asio.hpp>
|
||||
namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp>
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Report a failure
|
||||
void
|
||||
fail(boost::system::error_code ec, char const* what)
|
||||
fail(beast::error_code ec, char const* what)
|
||||
{
|
||||
std::cerr << what << ": " << ec.message() << "\n";
|
||||
}
|
||||
@ -46,11 +49,11 @@ do_session(
|
||||
std::string const& host,
|
||||
std::string const& port,
|
||||
std::string const& text,
|
||||
boost::asio::io_context& ioc,
|
||||
net::io_context& ioc,
|
||||
ssl::context& ctx,
|
||||
boost::asio::yield_context yield)
|
||||
net::yield_context yield)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
beast::error_code ec;
|
||||
|
||||
// These objects perform our I/O
|
||||
tcp::resolver resolver{ioc};
|
||||
@ -62,7 +65,7 @@ do_session(
|
||||
return fail(ec, "resolve");
|
||||
|
||||
// Make the connection on the IP address we get from a lookup
|
||||
boost::asio::async_connect(ws.next_layer().next_layer(), results.begin(), results.end(), yield[ec]);
|
||||
net::async_connect(ws.next_layer().next_layer(), results.begin(), results.end(), yield[ec]);
|
||||
if(ec)
|
||||
return fail(ec, "connect");
|
||||
|
||||
@ -77,12 +80,12 @@ do_session(
|
||||
return fail(ec, "handshake");
|
||||
|
||||
// Send the message
|
||||
ws.async_write(boost::asio::buffer(std::string(text)), yield[ec]);
|
||||
ws.async_write(net::buffer(std::string(text)), yield[ec]);
|
||||
if(ec)
|
||||
return fail(ec, "write");
|
||||
|
||||
// This buffer will hold the incoming message
|
||||
boost::beast::multi_buffer b;
|
||||
beast::multi_buffer b;
|
||||
|
||||
// Read a message into our buffer
|
||||
ws.async_read(b, yield[ec]);
|
||||
@ -97,7 +100,7 @@ do_session(
|
||||
// If we get here then the connection is closed gracefully
|
||||
|
||||
// The buffers() function helps print a ConstBufferSequence
|
||||
std::cout << boost::beast::buffers(b.data()) << std::endl;
|
||||
std::cout << beast::buffers(b.data()) << std::endl;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@ -118,7 +121,7 @@ int main(int argc, char** argv)
|
||||
auto const text = argv[3];
|
||||
|
||||
// The io_context is required for all I/O
|
||||
boost::asio::io_context ioc;
|
||||
net::io_context ioc;
|
||||
|
||||
// The SSL context is required, and holds certificates
|
||||
ssl::context ctx{ssl::context::sslv23_client};
|
||||
@ -127,7 +130,7 @@ int main(int argc, char** argv)
|
||||
load_root_certificates(ctx);
|
||||
|
||||
// Launch the asynchronous operation
|
||||
boost::asio::spawn(ioc, std::bind(
|
||||
net::spawn(ioc, std::bind(
|
||||
&do_session,
|
||||
std::string(host),
|
||||
std::string(port),
|
||||
|
@ -23,14 +23,17 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
namespace websocket = boost::beast::websocket; // from <boost/beast/websocket.hpp>
|
||||
namespace beast = boost::beast; // from <boost/beast.hpp>
|
||||
namespace http = beast::http; // from <boost/beast/http.hpp>
|
||||
namespace websocket = beast::websocket; // from <boost/beast/websocket.hpp>
|
||||
namespace net = boost::asio; // from <boost/asio.hpp>
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Report a failure
|
||||
void
|
||||
fail(boost::system::error_code ec, char const* what)
|
||||
fail(beast::error_code ec, char const* what)
|
||||
{
|
||||
std::cerr << what << ": " << ec.message() << "\n";
|
||||
}
|
||||
@ -41,10 +44,10 @@ do_session(
|
||||
std::string const& host,
|
||||
std::string const& port,
|
||||
std::string const& text,
|
||||
boost::asio::io_context& ioc,
|
||||
boost::asio::yield_context yield)
|
||||
net::io_context& ioc,
|
||||
net::yield_context yield)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
beast::error_code ec;
|
||||
|
||||
// These objects perform our I/O
|
||||
tcp::resolver resolver{ioc};
|
||||
@ -56,7 +59,7 @@ do_session(
|
||||
return fail(ec, "resolve");
|
||||
|
||||
// Make the connection on the IP address we get from a lookup
|
||||
boost::asio::async_connect(ws.next_layer(), results.begin(), results.end(), yield[ec]);
|
||||
net::async_connect(ws.next_layer(), results.begin(), results.end(), yield[ec]);
|
||||
if(ec)
|
||||
return fail(ec, "connect");
|
||||
|
||||
@ -66,12 +69,12 @@ do_session(
|
||||
return fail(ec, "handshake");
|
||||
|
||||
// Send the message
|
||||
ws.async_write(boost::asio::buffer(std::string(text)), yield[ec]);
|
||||
ws.async_write(net::buffer(std::string(text)), yield[ec]);
|
||||
if(ec)
|
||||
return fail(ec, "write");
|
||||
|
||||
// This buffer will hold the incoming message
|
||||
boost::beast::multi_buffer b;
|
||||
beast::multi_buffer b;
|
||||
|
||||
// Read a message into our buffer
|
||||
ws.async_read(b, yield[ec]);
|
||||
@ -86,7 +89,7 @@ do_session(
|
||||
// If we get here then the connection is closed gracefully
|
||||
|
||||
// The buffers() function helps print a ConstBufferSequence
|
||||
std::cout << boost::beast::buffers(b.data()) << std::endl;
|
||||
std::cout << beast::buffers(b.data()) << std::endl;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@ -107,10 +110,10 @@ int main(int argc, char** argv)
|
||||
auto const text = argv[3];
|
||||
|
||||
// The io_context is required for all I/O
|
||||
boost::asio::io_context ioc;
|
||||
net::io_context ioc;
|
||||
|
||||
// Launch the asynchronous operation
|
||||
boost::asio::spawn(ioc, std::bind(
|
||||
net::spawn(ioc, std::bind(
|
||||
&do_session,
|
||||
std::string(host),
|
||||
std::string(port),
|
||||
|
@ -25,9 +25,12 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp>
|
||||
namespace websocket = boost::beast::websocket; // from <boost/beast/websocket.hpp>
|
||||
namespace beast = boost::beast; // from <boost/beast.hpp>
|
||||
namespace http = beast::http; // from <boost/beast/http.hpp>
|
||||
namespace websocket = beast::websocket; // from <boost/beast/websocket.hpp>
|
||||
namespace net = boost::asio; // from <boost/asio.hpp>
|
||||
namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp>
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
|
||||
// Sends a WebSocket message and prints the response
|
||||
int main(int argc, char** argv)
|
||||
@ -48,7 +51,7 @@ int main(int argc, char** argv)
|
||||
auto const text = argv[3];
|
||||
|
||||
// The io_context is required for all I/O
|
||||
boost::asio::io_context ioc;
|
||||
net::io_context ioc;
|
||||
|
||||
// The SSL context is required, and holds certificates
|
||||
ssl::context ctx{ssl::context::sslv23_client};
|
||||
@ -64,7 +67,7 @@ int main(int argc, char** argv)
|
||||
auto const results = resolver.resolve(host, port);
|
||||
|
||||
// Make the connection on the IP address we get from a lookup
|
||||
boost::asio::connect(ws.next_layer().next_layer(), results.begin(), results.end());
|
||||
net::connect(ws.next_layer().next_layer(), results.begin(), results.end());
|
||||
|
||||
// Perform the SSL handshake
|
||||
ws.next_layer().handshake(ssl::stream_base::client);
|
||||
@ -73,10 +76,10 @@ int main(int argc, char** argv)
|
||||
ws.handshake(host, "/");
|
||||
|
||||
// Send the message
|
||||
ws.write(boost::asio::buffer(std::string(text)));
|
||||
ws.write(net::buffer(std::string(text)));
|
||||
|
||||
// This buffer will hold the incoming message
|
||||
boost::beast::multi_buffer b;
|
||||
beast::multi_buffer b;
|
||||
|
||||
// Read a message into our buffer
|
||||
ws.read(b);
|
||||
@ -87,7 +90,7 @@ int main(int argc, char** argv)
|
||||
// If we get here then the connection is closed gracefully
|
||||
|
||||
// The buffers() function helps print a ConstBufferSequence
|
||||
std::cout << boost::beast::buffers(b.data()) << std::endl;
|
||||
std::cout << beast::buffers(b.data()) << std::endl;
|
||||
}
|
||||
catch(std::exception const& e)
|
||||
{
|
||||
|
@ -23,8 +23,11 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
namespace websocket = boost::beast::websocket; // from <boost/beast/websocket.hpp>
|
||||
namespace beast = boost::beast; // from <boost/beast.hpp>
|
||||
namespace http = beast::http; // from <boost/beast/http.hpp>
|
||||
namespace websocket = beast::websocket; // from <boost/beast/websocket.hpp>
|
||||
namespace net = boost::asio; // from <boost/asio.hpp>
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
|
||||
// Sends a WebSocket message and prints the response
|
||||
int main(int argc, char** argv)
|
||||
@ -45,7 +48,7 @@ int main(int argc, char** argv)
|
||||
auto const text = argv[3];
|
||||
|
||||
// The io_context is required for all I/O
|
||||
boost::asio::io_context ioc;
|
||||
net::io_context ioc;
|
||||
|
||||
// These objects perform our I/O
|
||||
tcp::resolver resolver{ioc};
|
||||
@ -55,16 +58,16 @@ int main(int argc, char** argv)
|
||||
auto const results = resolver.resolve(host, port);
|
||||
|
||||
// Make the connection on the IP address we get from a lookup
|
||||
boost::asio::connect(ws.next_layer(), results.begin(), results.end());
|
||||
net::connect(ws.next_layer(), results.begin(), results.end());
|
||||
|
||||
// Perform the websocket handshake
|
||||
ws.handshake(host, "/");
|
||||
|
||||
// Send the message
|
||||
ws.write(boost::asio::buffer(std::string(text)));
|
||||
ws.write(net::buffer(std::string(text)));
|
||||
|
||||
// This buffer will hold the incoming message
|
||||
boost::beast::multi_buffer buffer;
|
||||
beast::multi_buffer buffer;
|
||||
|
||||
// Read a message into our buffer
|
||||
ws.read(buffer);
|
||||
@ -75,7 +78,7 @@ int main(int argc, char** argv)
|
||||
// If we get here then the connection is closed gracefully
|
||||
|
||||
// The buffers() function helps print a ConstBufferSequence
|
||||
std::cout << boost::beast::buffers(buffer.data()) << std::endl;
|
||||
std::cout << beast::buffers(buffer.data()) << std::endl;
|
||||
}
|
||||
catch(std::exception const& e)
|
||||
{
|
||||
|
@ -31,15 +31,18 @@
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp>
|
||||
namespace websocket = boost::beast::websocket; // from <boost/beast/websocket.hpp>
|
||||
namespace beast = boost::beast; // from <boost/beast.hpp>
|
||||
namespace http = beast::http; // from <boost/beast/http.hpp>
|
||||
namespace websocket = beast::websocket; // from <boost/beast/websocket.hpp>
|
||||
namespace net = boost::asio; // from <boost/asio.hpp>
|
||||
namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp>
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Report a failure
|
||||
void
|
||||
fail(boost::system::error_code ec, char const* what)
|
||||
fail(beast::error_code ec, char const* what)
|
||||
{
|
||||
std::cerr << what << ": " << ec.message() << "\n";
|
||||
}
|
||||
@ -49,9 +52,9 @@ class session : public std::enable_shared_from_this<session>
|
||||
{
|
||||
tcp::socket socket_;
|
||||
websocket::stream<ssl::stream<tcp::socket&>> ws_;
|
||||
boost::asio::strand<
|
||||
boost::asio::io_context::executor_type> strand_;
|
||||
boost::beast::multi_buffer buffer_;
|
||||
net::strand<
|
||||
net::io_context::executor_type> strand_;
|
||||
beast::multi_buffer buffer_;
|
||||
|
||||
public:
|
||||
// Take ownership of the socket
|
||||
@ -69,7 +72,7 @@ public:
|
||||
// Perform the SSL handshake
|
||||
ws_.next_layer().async_handshake(
|
||||
ssl::stream_base::server,
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&session::on_handshake,
|
||||
@ -78,14 +81,14 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
on_handshake(boost::system::error_code ec)
|
||||
on_handshake(beast::error_code ec)
|
||||
{
|
||||
if(ec)
|
||||
return fail(ec, "handshake");
|
||||
|
||||
// Accept the websocket handshake
|
||||
ws_.async_accept(
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&session::on_accept,
|
||||
@ -94,7 +97,7 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
on_accept(boost::system::error_code ec)
|
||||
on_accept(beast::error_code ec)
|
||||
{
|
||||
if(ec)
|
||||
return fail(ec, "accept");
|
||||
@ -109,7 +112,7 @@ public:
|
||||
// Read a message into our buffer
|
||||
ws_.async_read(
|
||||
buffer_,
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&session::on_read,
|
||||
@ -120,7 +123,7 @@ public:
|
||||
|
||||
void
|
||||
on_read(
|
||||
boost::system::error_code ec,
|
||||
beast::error_code ec,
|
||||
std::size_t bytes_transferred)
|
||||
{
|
||||
boost::ignore_unused(bytes_transferred);
|
||||
@ -136,7 +139,7 @@ public:
|
||||
ws_.text(ws_.got_text());
|
||||
ws_.async_write(
|
||||
buffer_.data(),
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&session::on_write,
|
||||
@ -147,7 +150,7 @@ public:
|
||||
|
||||
void
|
||||
on_write(
|
||||
boost::system::error_code ec,
|
||||
beast::error_code ec,
|
||||
std::size_t bytes_transferred)
|
||||
{
|
||||
boost::ignore_unused(bytes_transferred);
|
||||
@ -174,14 +177,14 @@ class listener : public std::enable_shared_from_this<listener>
|
||||
|
||||
public:
|
||||
listener(
|
||||
boost::asio::io_context& ioc,
|
||||
net::io_context& ioc,
|
||||
ssl::context& ctx,
|
||||
tcp::endpoint endpoint)
|
||||
: ctx_(ctx)
|
||||
, acceptor_(ioc)
|
||||
, socket_(ioc)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
beast::error_code ec;
|
||||
|
||||
// Open the acceptor
|
||||
acceptor_.open(endpoint.protocol(), ec);
|
||||
@ -192,7 +195,7 @@ public:
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
fail(ec, "set_option");
|
||||
@ -209,7 +212,7 @@ public:
|
||||
|
||||
// Start listening for connections
|
||||
acceptor_.listen(
|
||||
boost::asio::socket_base::max_listen_connections, ec);
|
||||
net::socket_base::max_listen_connections, ec);
|
||||
if(ec)
|
||||
{
|
||||
fail(ec, "listen");
|
||||
@ -238,7 +241,7 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
on_accept(boost::system::error_code ec)
|
||||
on_accept(beast::error_code ec)
|
||||
{
|
||||
if(ec)
|
||||
{
|
||||
@ -268,12 +271,12 @@ int main(int argc, char* argv[])
|
||||
" websocket-server-async-ssl 0.0.0.0 8080 1\n";
|
||||
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 threads = std::max<int>(1, std::atoi(argv[3]));
|
||||
|
||||
// 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
|
||||
ssl::context ctx{ssl::context::sslv23};
|
||||
|
@ -27,14 +27,17 @@
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
namespace websocket = boost::beast::websocket; // from <boost/beast/websocket.hpp>
|
||||
namespace beast = boost::beast; // from <boost/beast.hpp>
|
||||
namespace http = beast::http; // from <boost/beast/http.hpp>
|
||||
namespace websocket = beast::websocket; // from <boost/beast/websocket.hpp>
|
||||
namespace net = boost::asio; // from <boost/asio.hpp>
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Report a failure
|
||||
void
|
||||
fail(boost::system::error_code ec, char const* what)
|
||||
fail(beast::error_code ec, char const* what)
|
||||
{
|
||||
std::cerr << what << ": " << ec.message() << "\n";
|
||||
}
|
||||
@ -43,9 +46,9 @@ fail(boost::system::error_code ec, char const* what)
|
||||
class session : public std::enable_shared_from_this<session>
|
||||
{
|
||||
websocket::stream<tcp::socket> ws_;
|
||||
boost::asio::strand<
|
||||
boost::asio::io_context::executor_type> strand_;
|
||||
boost::beast::multi_buffer buffer_;
|
||||
net::strand<
|
||||
net::io_context::executor_type> strand_;
|
||||
beast::multi_buffer buffer_;
|
||||
|
||||
public:
|
||||
// Take ownership of the socket
|
||||
@ -62,7 +65,7 @@ public:
|
||||
{
|
||||
// Accept the websocket handshake
|
||||
ws_.async_accept(
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&session::on_accept,
|
||||
@ -71,7 +74,7 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
on_accept(boost::system::error_code ec)
|
||||
on_accept(beast::error_code ec)
|
||||
{
|
||||
if(ec)
|
||||
return fail(ec, "accept");
|
||||
@ -86,7 +89,7 @@ public:
|
||||
// Read a message into our buffer
|
||||
ws_.async_read(
|
||||
buffer_,
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&session::on_read,
|
||||
@ -97,7 +100,7 @@ public:
|
||||
|
||||
void
|
||||
on_read(
|
||||
boost::system::error_code ec,
|
||||
beast::error_code ec,
|
||||
std::size_t bytes_transferred)
|
||||
{
|
||||
boost::ignore_unused(bytes_transferred);
|
||||
@ -113,7 +116,7 @@ public:
|
||||
ws_.text(ws_.got_text());
|
||||
ws_.async_write(
|
||||
buffer_.data(),
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&session::on_write,
|
||||
@ -124,7 +127,7 @@ public:
|
||||
|
||||
void
|
||||
on_write(
|
||||
boost::system::error_code ec,
|
||||
beast::error_code ec,
|
||||
std::size_t bytes_transferred)
|
||||
{
|
||||
boost::ignore_unused(bytes_transferred);
|
||||
@ -150,12 +153,12 @@ class listener : public std::enable_shared_from_this<listener>
|
||||
|
||||
public:
|
||||
listener(
|
||||
boost::asio::io_context& ioc,
|
||||
net::io_context& ioc,
|
||||
tcp::endpoint endpoint)
|
||||
: acceptor_(ioc)
|
||||
, socket_(ioc)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
beast::error_code ec;
|
||||
|
||||
// Open the acceptor
|
||||
acceptor_.open(endpoint.protocol(), ec);
|
||||
@ -166,7 +169,7 @@ public:
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
fail(ec, "set_option");
|
||||
@ -183,7 +186,7 @@ public:
|
||||
|
||||
// Start listening for connections
|
||||
acceptor_.listen(
|
||||
boost::asio::socket_base::max_listen_connections, ec);
|
||||
net::socket_base::max_listen_connections, ec);
|
||||
if(ec)
|
||||
{
|
||||
fail(ec, "listen");
|
||||
@ -212,7 +215,7 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
on_accept(boost::system::error_code ec)
|
||||
on_accept(beast::error_code ec)
|
||||
{
|
||||
if(ec)
|
||||
{
|
||||
@ -242,12 +245,12 @@ int main(int argc, char* argv[])
|
||||
" websocket-server-async 0.0.0.0 8080 1\n";
|
||||
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 threads = std::max<int>(1, std::atoi(argv[3]));
|
||||
|
||||
// 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
|
||||
std::make_shared<listener>(ioc, tcp::endpoint{address, port})->run();
|
||||
|
@ -30,15 +30,18 @@
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp>
|
||||
namespace websocket = boost::beast::websocket; // from <boost/beast/websocket.hpp>
|
||||
namespace beast = boost::beast; // from <boost/beast.hpp>
|
||||
namespace http = beast::http; // from <boost/beast/http.hpp>
|
||||
namespace websocket = beast::websocket; // from <boost/beast/websocket.hpp>
|
||||
namespace net = boost::asio; // from <boost/asio.hpp>
|
||||
namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp>
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Report a failure
|
||||
void
|
||||
fail(boost::system::error_code ec, char const* what)
|
||||
fail(beast::error_code ec, char const* what)
|
||||
{
|
||||
std::cerr << what << ": " << ec.message() << "\n";
|
||||
}
|
||||
@ -48,9 +51,9 @@ void
|
||||
do_session(
|
||||
tcp::socket& socket,
|
||||
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
|
||||
websocket::stream<ssl::stream<tcp::socket&>> ws{socket, ctx};
|
||||
@ -68,7 +71,7 @@ do_session(
|
||||
for(;;)
|
||||
{
|
||||
// This buffer will hold the incoming message
|
||||
boost::beast::multi_buffer buffer;
|
||||
beast::multi_buffer buffer;
|
||||
|
||||
// Read a message
|
||||
ws.async_read(buffer, yield[ec]);
|
||||
@ -93,12 +96,12 @@ do_session(
|
||||
// Accepts incoming connections and launches the sessions
|
||||
void
|
||||
do_listen(
|
||||
boost::asio::io_context& ioc,
|
||||
net::io_context& ioc,
|
||||
ssl::context& ctx,
|
||||
tcp::endpoint endpoint,
|
||||
boost::asio::yield_context yield)
|
||||
net::yield_context yield)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
beast::error_code ec;
|
||||
|
||||
// Open the acceptor
|
||||
tcp::acceptor acceptor(ioc);
|
||||
@ -107,7 +110,7 @@ do_listen(
|
||||
return fail(ec, "open");
|
||||
|
||||
// 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)
|
||||
return fail(ec, "set_option");
|
||||
|
||||
@ -117,7 +120,7 @@ do_listen(
|
||||
return fail(ec, "bind");
|
||||
|
||||
// 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)
|
||||
return fail(ec, "listen");
|
||||
|
||||
@ -128,7 +131,7 @@ do_listen(
|
||||
if(ec)
|
||||
fail(ec, "accept");
|
||||
else
|
||||
boost::asio::spawn(
|
||||
net::spawn(
|
||||
acceptor.get_executor().context(),
|
||||
std::bind(
|
||||
&do_session,
|
||||
@ -149,12 +152,12 @@ int main(int argc, char* argv[])
|
||||
" websocket-server-coro-ssl 0.0.0.0 8080 1\n";
|
||||
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 threads = std::max<int>(1, std::atoi(argv[3]));
|
||||
|
||||
// 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
|
||||
ssl::context ctx{ssl::context::sslv23};
|
||||
@ -163,7 +166,7 @@ int main(int argc, char* argv[])
|
||||
load_server_certificate(ctx);
|
||||
|
||||
// Spawn a listening port
|
||||
boost::asio::spawn(ioc,
|
||||
net::spawn(ioc,
|
||||
std::bind(
|
||||
&do_listen,
|
||||
std::ref(ioc),
|
||||
|
@ -26,23 +26,26 @@
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
namespace websocket = boost::beast::websocket; // from <boost/beast/websocket.hpp>
|
||||
namespace beast = boost::beast; // from <boost/beast.hpp>
|
||||
namespace http = beast::http; // from <boost/beast/http.hpp>
|
||||
namespace websocket = beast::websocket; // from <boost/beast/websocket.hpp>
|
||||
namespace net = boost::asio; // from <boost/asio.hpp>
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Report a failure
|
||||
void
|
||||
fail(boost::system::error_code ec, char const* what)
|
||||
fail(beast::error_code ec, char const* what)
|
||||
{
|
||||
std::cerr << what << ": " << ec.message() << "\n";
|
||||
}
|
||||
|
||||
// Echoes back all received WebSocket messages
|
||||
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
|
||||
websocket::stream<tcp::socket> ws{std::move(socket)};
|
||||
@ -55,7 +58,7 @@ do_session(tcp::socket& socket, boost::asio::yield_context yield)
|
||||
for(;;)
|
||||
{
|
||||
// This buffer will hold the incoming message
|
||||
boost::beast::multi_buffer buffer;
|
||||
beast::multi_buffer buffer;
|
||||
|
||||
// Read a message
|
||||
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
|
||||
void
|
||||
do_listen(
|
||||
boost::asio::io_context& ioc,
|
||||
net::io_context& ioc,
|
||||
tcp::endpoint endpoint,
|
||||
boost::asio::yield_context yield)
|
||||
net::yield_context yield)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
beast::error_code ec;
|
||||
|
||||
// Open the acceptor
|
||||
tcp::acceptor acceptor(ioc);
|
||||
@ -93,7 +96,7 @@ do_listen(
|
||||
return fail(ec, "open");
|
||||
|
||||
// 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)
|
||||
return fail(ec, "set_option");
|
||||
|
||||
@ -103,7 +106,7 @@ do_listen(
|
||||
return fail(ec, "bind");
|
||||
|
||||
// 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)
|
||||
return fail(ec, "listen");
|
||||
|
||||
@ -114,7 +117,7 @@ do_listen(
|
||||
if(ec)
|
||||
fail(ec, "accept");
|
||||
else
|
||||
boost::asio::spawn(
|
||||
net::spawn(
|
||||
acceptor.get_executor().context(),
|
||||
std::bind(
|
||||
&do_session,
|
||||
@ -134,15 +137,15 @@ int main(int argc, char* argv[])
|
||||
" websocket-server-coro 0.0.0.0 8080 1\n";
|
||||
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 threads = std::max<int>(1, std::atoi(argv[3]));
|
||||
|
||||
// The io_context is required for all I/O
|
||||
boost::asio::io_context ioc{threads};
|
||||
net::io_context ioc{threads};
|
||||
|
||||
// Spawn a listening port
|
||||
boost::asio::spawn(ioc,
|
||||
net::spawn(ioc,
|
||||
std::bind(
|
||||
&do_listen,
|
||||
std::ref(ioc),
|
||||
|
@ -43,15 +43,17 @@
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
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>
|
||||
namespace beast = boost::beast; // from <boost/beast.hpp>
|
||||
namespace http = beast::http; // from <boost/beast/http.hpp>
|
||||
namespace websocket = beast::websocket; // from <boost/beast/websocket.hpp>
|
||||
namespace net = boost::asio; // from <boost/asio.hpp>
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Report a failure
|
||||
void
|
||||
fail(boost::system::error_code ec, char const* what)
|
||||
fail(beast::error_code ec, char const* what)
|
||||
{
|
||||
std::cerr << (std::string(what) + ": " + ec.message() + "\n");
|
||||
}
|
||||
@ -81,7 +83,7 @@ setup_stream(websocket::stream<NextLayer>& ws)
|
||||
void
|
||||
do_sync_session(tcp::socket& socket)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
beast::error_code ec;
|
||||
|
||||
websocket::stream<tcp::socket> ws{std::move(socket)};
|
||||
setup_stream(ws);
|
||||
@ -98,7 +100,7 @@ do_sync_session(tcp::socket& socket)
|
||||
|
||||
for(;;)
|
||||
{
|
||||
boost::beast::multi_buffer buffer;
|
||||
beast::multi_buffer buffer;
|
||||
|
||||
ws.read(buffer, ec);
|
||||
if(ec == websocket::error::closed)
|
||||
@ -114,10 +116,10 @@ do_sync_session(tcp::socket& socket)
|
||||
|
||||
void
|
||||
do_sync_listen(
|
||||
boost::asio::io_context& ioc,
|
||||
net::io_context& ioc,
|
||||
tcp::endpoint endpoint)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
beast::error_code ec;
|
||||
tcp::acceptor acceptor{ioc, endpoint};
|
||||
for(;;)
|
||||
{
|
||||
@ -139,9 +141,9 @@ do_sync_listen(
|
||||
class async_session : public std::enable_shared_from_this<async_session>
|
||||
{
|
||||
websocket::stream<tcp::socket> ws_;
|
||||
boost::asio::strand<
|
||||
boost::asio::io_context::executor_type> strand_;
|
||||
boost::beast::multi_buffer buffer_;
|
||||
net::strand<
|
||||
net::io_context::executor_type> strand_;
|
||||
beast::multi_buffer buffer_;
|
||||
|
||||
public:
|
||||
// Take ownership of the socket
|
||||
@ -164,7 +166,7 @@ public:
|
||||
res.set(http::field::server,
|
||||
"Boost.Beast/" + std::to_string(BOOST_BEAST_VERSION) + "-Async");
|
||||
},
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&async_session::on_accept,
|
||||
@ -173,7 +175,7 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
on_accept(boost::system::error_code ec)
|
||||
on_accept(beast::error_code ec)
|
||||
{
|
||||
if(ec)
|
||||
return fail(ec, "accept");
|
||||
@ -188,7 +190,7 @@ public:
|
||||
// Read a message into our buffer
|
||||
ws_.async_read(
|
||||
buffer_,
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&async_session::on_read,
|
||||
@ -199,7 +201,7 @@ public:
|
||||
|
||||
void
|
||||
on_read(
|
||||
boost::system::error_code ec,
|
||||
beast::error_code ec,
|
||||
std::size_t bytes_transferred)
|
||||
{
|
||||
boost::ignore_unused(bytes_transferred);
|
||||
@ -215,7 +217,7 @@ public:
|
||||
ws_.text(ws_.got_text());
|
||||
ws_.async_write(
|
||||
buffer_.data(),
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&async_session::on_write,
|
||||
@ -226,7 +228,7 @@ public:
|
||||
|
||||
void
|
||||
on_write(
|
||||
boost::system::error_code ec,
|
||||
beast::error_code ec,
|
||||
std::size_t bytes_transferred)
|
||||
{
|
||||
boost::ignore_unused(bytes_transferred);
|
||||
@ -245,20 +247,20 @@ public:
|
||||
// Accepts incoming connections and launches the sessions
|
||||
class async_listener : public std::enable_shared_from_this<async_listener>
|
||||
{
|
||||
boost::asio::strand<
|
||||
boost::asio::io_context::executor_type> strand_;
|
||||
net::strand<
|
||||
net::io_context::executor_type> strand_;
|
||||
tcp::acceptor acceptor_;
|
||||
tcp::socket socket_;
|
||||
|
||||
public:
|
||||
async_listener(
|
||||
boost::asio::io_context& ioc,
|
||||
net::io_context& ioc,
|
||||
tcp::endpoint endpoint)
|
||||
: strand_(ioc.get_executor())
|
||||
, acceptor_(ioc)
|
||||
, socket_(ioc)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
beast::error_code ec;
|
||||
|
||||
// Open the acceptor
|
||||
acceptor_.open(endpoint.protocol(), ec);
|
||||
@ -269,7 +271,7 @@ public:
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
fail(ec, "set_option");
|
||||
@ -286,7 +288,7 @@ public:
|
||||
|
||||
// Start listening for connections
|
||||
acceptor_.listen(
|
||||
boost::asio::socket_base::max_listen_connections, ec);
|
||||
net::socket_base::max_listen_connections, ec);
|
||||
if(ec)
|
||||
{
|
||||
fail(ec, "listen");
|
||||
@ -308,7 +310,7 @@ public:
|
||||
{
|
||||
acceptor_.async_accept(
|
||||
socket_,
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&async_listener::on_accept,
|
||||
@ -317,7 +319,7 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
on_accept(boost::system::error_code ec)
|
||||
on_accept(beast::error_code ec)
|
||||
{
|
||||
if(ec)
|
||||
{
|
||||
@ -337,9 +339,9 @@ public:
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
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)};
|
||||
setup_stream(ws);
|
||||
@ -356,7 +358,7 @@ do_coro_session(tcp::socket& socket, boost::asio::yield_context yield)
|
||||
|
||||
for(;;)
|
||||
{
|
||||
boost::beast::multi_buffer buffer;
|
||||
beast::multi_buffer buffer;
|
||||
|
||||
ws.async_read(buffer, yield[ec]);
|
||||
if(ec == websocket::error::closed)
|
||||
@ -373,18 +375,18 @@ do_coro_session(tcp::socket& socket, boost::asio::yield_context yield)
|
||||
|
||||
void
|
||||
do_coro_listen(
|
||||
boost::asio::io_context& ioc,
|
||||
net::io_context& ioc,
|
||||
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);
|
||||
acceptor.open(endpoint.protocol(), ec);
|
||||
if(ec)
|
||||
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)
|
||||
return fail(ec, "set_option");
|
||||
|
||||
@ -392,7 +394,7 @@ do_coro_listen(
|
||||
if(ec)
|
||||
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)
|
||||
return fail(ec, "listen");
|
||||
|
||||
@ -407,7 +409,7 @@ do_coro_listen(
|
||||
continue;
|
||||
}
|
||||
|
||||
boost::asio::spawn(
|
||||
net::spawn(
|
||||
acceptor.get_executor().context(),
|
||||
std::bind(
|
||||
&do_coro_session,
|
||||
@ -433,12 +435,12 @@ int main(int argc, char* argv[])
|
||||
" starting-port+2 for coroutine.\n";
|
||||
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 threads = std::max<int>(1, std::atoi(argv[3]));
|
||||
|
||||
// The io_context is required for all I/O
|
||||
boost::asio::io_context ioc{threads};
|
||||
net::io_context ioc{threads};
|
||||
|
||||
// Create sync port
|
||||
std::thread(std::bind(
|
||||
@ -457,7 +459,7 @@ int main(int argc, char* argv[])
|
||||
static_cast<unsigned short>(port + 1u)})->run();
|
||||
|
||||
// Create coro port
|
||||
boost::asio::spawn(ioc,
|
||||
net::spawn(ioc,
|
||||
std::bind(
|
||||
&do_coro_listen,
|
||||
std::ref(ioc),
|
||||
|
@ -32,29 +32,32 @@
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp>
|
||||
namespace websocket = boost::beast::websocket; // from <boost/beast/websocket.hpp>
|
||||
namespace beast = boost::beast; // from <boost/beast.hpp>
|
||||
namespace http = beast::http; // from <boost/beast/http.hpp>
|
||||
namespace websocket = beast::websocket; // from <boost/beast/websocket.hpp>
|
||||
namespace net = boost::asio; // from <boost/asio.hpp>
|
||||
namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp>
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Report a failure
|
||||
void
|
||||
fail(boost::system::error_code ec, char const* what)
|
||||
fail(beast::error_code ec, char const* what)
|
||||
{
|
||||
std::cerr << what << ": " << ec.message() << "\n";
|
||||
}
|
||||
|
||||
// Echoes back all received WebSocket messages
|
||||
class session
|
||||
: public boost::asio::coroutine
|
||||
: public net::coroutine
|
||||
, public std::enable_shared_from_this<session>
|
||||
{
|
||||
tcp::socket socket_;
|
||||
websocket::stream<ssl::stream<tcp::socket&>> ws_;
|
||||
boost::asio::strand<
|
||||
boost::asio::io_context::executor_type> strand_;
|
||||
boost::beast::multi_buffer buffer_;
|
||||
net::strand<
|
||||
net::io_context::executor_type> strand_;
|
||||
beast::multi_buffer buffer_;
|
||||
|
||||
public:
|
||||
// Take ownership of the socket
|
||||
@ -75,7 +78,7 @@ public:
|
||||
#include <boost/asio/yield.hpp>
|
||||
void
|
||||
loop(
|
||||
boost::system::error_code ec,
|
||||
beast::error_code ec,
|
||||
std::size_t bytes_transferred)
|
||||
{
|
||||
boost::ignore_unused(bytes_transferred);
|
||||
@ -85,7 +88,7 @@ public:
|
||||
// Perform the SSL handshake
|
||||
yield ws_.next_layer().async_handshake(
|
||||
ssl::stream_base::server,
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&session::loop,
|
||||
@ -97,7 +100,7 @@ public:
|
||||
|
||||
// Accept the websocket handshake
|
||||
yield ws_.async_accept(
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&session::loop,
|
||||
@ -112,7 +115,7 @@ public:
|
||||
// Read a message into our buffer
|
||||
yield ws_.async_read(
|
||||
buffer_,
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&session::loop,
|
||||
@ -131,7 +134,7 @@ public:
|
||||
ws_.text(ws_.got_text());
|
||||
yield ws_.async_write(
|
||||
buffer_.data(),
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&session::loop,
|
||||
@ -153,7 +156,7 @@ public:
|
||||
|
||||
// Accepts incoming connections and launches the sessions
|
||||
class listener
|
||||
: public boost::asio::coroutine
|
||||
: public net::coroutine
|
||||
, public std::enable_shared_from_this<listener>
|
||||
{
|
||||
ssl::context& ctx_;
|
||||
@ -162,14 +165,14 @@ class listener
|
||||
|
||||
public:
|
||||
listener(
|
||||
boost::asio::io_context& ioc,
|
||||
net::io_context& ioc,
|
||||
ssl::context& ctx,
|
||||
tcp::endpoint endpoint)
|
||||
: ctx_(ctx)
|
||||
, acceptor_(ioc)
|
||||
, socket_(ioc)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
beast::error_code ec;
|
||||
|
||||
// Open the acceptor
|
||||
acceptor_.open(endpoint.protocol(), ec);
|
||||
@ -180,7 +183,7 @@ public:
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
fail(ec, "set_option");
|
||||
@ -197,7 +200,7 @@ public:
|
||||
|
||||
// Start listening for connections
|
||||
acceptor_.listen(
|
||||
boost::asio::socket_base::max_listen_connections, ec);
|
||||
net::socket_base::max_listen_connections, ec);
|
||||
if(ec)
|
||||
{
|
||||
fail(ec, "listen");
|
||||
@ -216,7 +219,7 @@ public:
|
||||
|
||||
#include <boost/asio/yield.hpp>
|
||||
void
|
||||
loop(boost::system::error_code ec = {})
|
||||
loop(beast::error_code ec = {})
|
||||
{
|
||||
reenter(*this)
|
||||
{
|
||||
@ -256,12 +259,12 @@ int main(int argc, char* argv[])
|
||||
" websocket-server-async-ssl 0.0.0.0 8080 1\n";
|
||||
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 threads = std::max<int>(1, std::atoi(argv[3]));
|
||||
|
||||
// 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
|
||||
ssl::context ctx{ssl::context::sslv23};
|
||||
|
@ -28,27 +28,30 @@
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
namespace websocket = boost::beast::websocket; // from <boost/beast/websocket.hpp>
|
||||
namespace beast = boost::beast; // from <boost/beast.hpp>
|
||||
namespace http = beast::http; // from <boost/beast/http.hpp>
|
||||
namespace websocket = beast::websocket; // from <boost/beast/websocket.hpp>
|
||||
namespace net = boost::asio; // from <boost/asio.hpp>
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Report a failure
|
||||
void
|
||||
fail(boost::system::error_code ec, char const* what)
|
||||
fail(beast::error_code ec, char const* what)
|
||||
{
|
||||
std::cerr << what << ": " << ec.message() << "\n";
|
||||
}
|
||||
|
||||
// Echoes back all received WebSocket messages
|
||||
class session
|
||||
: public boost::asio::coroutine
|
||||
: public net::coroutine
|
||||
, public std::enable_shared_from_this<session>
|
||||
{
|
||||
websocket::stream<tcp::socket> ws_;
|
||||
boost::asio::strand<
|
||||
boost::asio::io_context::executor_type> strand_;
|
||||
boost::beast::multi_buffer buffer_;
|
||||
net::strand<
|
||||
net::io_context::executor_type> strand_;
|
||||
beast::multi_buffer buffer_;
|
||||
|
||||
public:
|
||||
// Take ownership of the socket
|
||||
@ -69,7 +72,7 @@ public:
|
||||
#include <boost/asio/yield.hpp>
|
||||
void
|
||||
loop(
|
||||
boost::system::error_code ec,
|
||||
beast::error_code ec,
|
||||
std::size_t bytes_transferred)
|
||||
{
|
||||
boost::ignore_unused(bytes_transferred);
|
||||
@ -77,7 +80,7 @@ public:
|
||||
{
|
||||
// Accept the websocket handshake
|
||||
yield ws_.async_accept(
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&session::loop,
|
||||
@ -92,7 +95,7 @@ public:
|
||||
// Read a message into our buffer
|
||||
yield ws_.async_read(
|
||||
buffer_,
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&session::loop,
|
||||
@ -111,7 +114,7 @@ public:
|
||||
ws_.text(ws_.got_text());
|
||||
yield ws_.async_write(
|
||||
buffer_.data(),
|
||||
boost::asio::bind_executor(
|
||||
net::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&session::loop,
|
||||
@ -133,7 +136,7 @@ public:
|
||||
|
||||
// Accepts incoming connections and launches the sessions
|
||||
class listener
|
||||
: public boost::asio::coroutine
|
||||
: public net::coroutine
|
||||
, public std::enable_shared_from_this<listener>
|
||||
{
|
||||
tcp::acceptor acceptor_;
|
||||
@ -141,12 +144,12 @@ class listener
|
||||
|
||||
public:
|
||||
listener(
|
||||
boost::asio::io_context& ioc,
|
||||
net::io_context& ioc,
|
||||
tcp::endpoint endpoint)
|
||||
: acceptor_(ioc)
|
||||
, socket_(ioc)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
beast::error_code ec;
|
||||
|
||||
// Open the acceptor
|
||||
acceptor_.open(endpoint.protocol(), ec);
|
||||
@ -157,7 +160,7 @@ public:
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
fail(ec, "set_option");
|
||||
@ -174,7 +177,7 @@ public:
|
||||
|
||||
// Start listening for connections
|
||||
acceptor_.listen(
|
||||
boost::asio::socket_base::max_listen_connections, ec);
|
||||
net::socket_base::max_listen_connections, ec);
|
||||
if(ec)
|
||||
{
|
||||
fail(ec, "listen");
|
||||
@ -193,7 +196,7 @@ public:
|
||||
|
||||
#include <boost/asio/yield.hpp>
|
||||
void
|
||||
loop(boost::system::error_code ec = {})
|
||||
loop(beast::error_code ec = {})
|
||||
{
|
||||
reenter(*this)
|
||||
{
|
||||
@ -233,12 +236,12 @@ int main(int argc, char* argv[])
|
||||
" websocket-server-stackless 0.0.0.0 8080 1\n";
|
||||
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 threads = std::max<int>(1, std::atoi(argv[3]));
|
||||
|
||||
// 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
|
||||
std::make_shared<listener>(ioc, tcp::endpoint{address, port})->run();
|
||||
|
@ -26,9 +26,12 @@
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp>
|
||||
namespace websocket = boost::beast::websocket; // from <boost/beast/websocket.hpp>
|
||||
namespace beast = boost::beast; // from <boost/beast.hpp>
|
||||
namespace http = beast::http; // from <boost/beast/http.hpp>
|
||||
namespace websocket = beast::websocket; // from <boost/beast/websocket.hpp>
|
||||
namespace net = boost::asio; // from <boost/asio.hpp>
|
||||
namespace ssl = boost::asio::ssl; // from <boost/asio/ssl.hpp>
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@ -50,7 +53,7 @@ do_session(tcp::socket& socket, ssl::context& ctx)
|
||||
for(;;)
|
||||
{
|
||||
// This buffer will hold the incoming message
|
||||
boost::beast::multi_buffer buffer;
|
||||
beast::multi_buffer buffer;
|
||||
|
||||
// Read a message
|
||||
ws.read(buffer);
|
||||
@ -60,7 +63,7 @@ do_session(tcp::socket& socket, ssl::context& ctx)
|
||||
ws.write(buffer.data());
|
||||
}
|
||||
}
|
||||
catch(boost::system::system_error const& se)
|
||||
catch(beast::system_error const& se)
|
||||
{
|
||||
// This indicates that the session was 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";
|
||||
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]));
|
||||
|
||||
// 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
|
||||
ssl::context ctx{ssl::context::sslv23};
|
||||
|
@ -22,8 +22,11 @@
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
namespace websocket = boost::beast::websocket; // from <boost/beast/websocket.hpp>
|
||||
namespace beast = boost::beast; // from <boost/beast.hpp>
|
||||
namespace http = beast::http; // from <boost/beast/http.hpp>
|
||||
namespace websocket = beast::websocket; // from <boost/beast/websocket.hpp>
|
||||
namespace net = boost::asio; // from <boost/asio.hpp>
|
||||
using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@ -42,7 +45,7 @@ do_session(tcp::socket& socket)
|
||||
for(;;)
|
||||
{
|
||||
// This buffer will hold the incoming message
|
||||
boost::beast::multi_buffer buffer;
|
||||
beast::multi_buffer buffer;
|
||||
|
||||
// Read a message
|
||||
ws.read(buffer);
|
||||
@ -52,7 +55,7 @@ do_session(tcp::socket& socket)
|
||||
ws.write(buffer.data());
|
||||
}
|
||||
}
|
||||
catch(boost::system::system_error const& se)
|
||||
catch(beast::system_error const& se)
|
||||
{
|
||||
// This indicates that the session was 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";
|
||||
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]));
|
||||
|
||||
// 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
|
||||
tcp::acceptor acceptor{ioc, {address, port}};
|
||||
|
@ -32,11 +32,11 @@ public:
|
||||
coalesce(BufferSequence const& buffers, std::size_t limit)
|
||||
{
|
||||
std::pair<std::size_t, bool> result{0, false};
|
||||
auto first = boost::asio::buffer_sequence_begin(buffers);
|
||||
auto last = boost::asio::buffer_sequence_end(buffers);
|
||||
auto first = net::buffer_sequence_begin(buffers);
|
||||
auto last = net::buffer_sequence_end(buffers);
|
||||
if(first != last)
|
||||
{
|
||||
result.first = boost::asio::buffer_size(*first);
|
||||
result.first = net::buffer_size(*first);
|
||||
if(result.first < limit)
|
||||
{
|
||||
auto it = first;
|
||||
@ -44,7 +44,7 @@ public:
|
||||
while(++it != last)
|
||||
{
|
||||
auto const n =
|
||||
boost::asio::buffer_size(*it);
|
||||
net::buffer_size(*it);
|
||||
if(result.first + n > limit)
|
||||
break;
|
||||
result.first += n;
|
||||
|
@ -15,7 +15,7 @@ namespace beast {
|
||||
namespace detail {
|
||||
|
||||
timeout_service::
|
||||
timeout_service(boost::asio::io_context& ctx)
|
||||
timeout_service(net::io_context& ctx)
|
||||
: service_base(ctx)
|
||||
, thunks_(1) // element [0] reserved for "null"
|
||||
, timer_(ctx)
|
||||
@ -272,7 +272,7 @@ void
|
||||
timeout_service::
|
||||
on_timer(error_code ec)
|
||||
{
|
||||
if(ec == boost::asio::error::operation_aborted)
|
||||
if(ec == net::error::operation_aborted)
|
||||
{
|
||||
BOOST_ASSERT(fresh_->empty());
|
||||
BOOST_ASSERT(stale_->empty());
|
||||
|
@ -17,23 +17,23 @@ namespace beast {
|
||||
namespace detail {
|
||||
|
||||
template<class T>
|
||||
class service_id : public boost::asio::execution_context::id
|
||||
class service_id : public net::execution_context::id
|
||||
{
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class service_base
|
||||
: public boost::asio::execution_context::service
|
||||
: public net::execution_context::service
|
||||
{
|
||||
protected:
|
||||
boost::asio::execution_context& ctx_;
|
||||
net::execution_context& ctx_;
|
||||
|
||||
public:
|
||||
static service_id<T> id;
|
||||
|
||||
explicit
|
||||
service_base(boost::asio::execution_context& ctx)
|
||||
: boost::asio::execution_context::service(ctx)
|
||||
service_base(net::execution_context& ctx)
|
||||
: net::execution_context::service(ctx)
|
||||
, ctx_(ctx)
|
||||
{
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ class timeout_service
|
||||
void
|
||||
operator()()
|
||||
{
|
||||
boost::asio::post(ex,
|
||||
net::post(ex,
|
||||
beast::bind_front_handler(
|
||||
std::move(*this), 0));
|
||||
}
|
||||
@ -64,7 +64,7 @@ public:
|
||||
// VFALCO Should be execution_context
|
||||
BOOST_BEAST_DECL
|
||||
explicit
|
||||
timeout_service(boost::asio::io_context& ctx);
|
||||
timeout_service(net::io_context& ctx);
|
||||
|
||||
BOOST_BEAST_DECL
|
||||
timeout_handle
|
||||
@ -119,7 +119,7 @@ private:
|
||||
thunk::list_type* stale_ = &list_[1];
|
||||
std::deque<thunk> thunks_;
|
||||
std::size_t free_thunk_ = 0;
|
||||
boost::asio::steady_timer timer_;
|
||||
net::steady_timer timer_;
|
||||
std::chrono::seconds interval_{30ul};
|
||||
long pending_ = 0;
|
||||
};
|
||||
|
@ -26,7 +26,7 @@ namespace beast {
|
||||
This wrapper flattens writes for buffer sequences having length
|
||||
greater than 1 and total size below a predefined amount, using
|
||||
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
|
||||
low-level read some and write some operations.
|
||||
|
||||
@ -49,11 +49,11 @@ namespace beast {
|
||||
operate on synchronous or asynchronous read or write streams,
|
||||
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
|
||||
stream wrappers, such as for websocket:
|
||||
@ -66,7 +66,7 @@ namespace beast {
|
||||
operations, the type must support the @b SyncStream concept. For
|
||||
asynchronous operations, the type must support the @b AsyncStream
|
||||
concept. This type will usually be some variation of
|
||||
`boost::asio::ssl::stream`.
|
||||
`net::ssl::stream`.
|
||||
|
||||
@par Concepts
|
||||
@b AsyncStream
|
||||
@ -209,7 +209,7 @@ public:
|
||||
@throws boost::system::system_error Thrown on failure.
|
||||
|
||||
@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
|
||||
completes.
|
||||
*/
|
||||
@ -230,7 +230,7 @@ public:
|
||||
@returns The number of bytes read.
|
||||
|
||||
@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
|
||||
completes.
|
||||
*/
|
||||
@ -259,7 +259,7 @@ public:
|
||||
); @endcode
|
||||
|
||||
@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
|
||||
operation completes.
|
||||
*/
|
||||
@ -285,7 +285,7 @@ public:
|
||||
@throws boost::system::system_error Thrown on failure.
|
||||
|
||||
@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.
|
||||
*/
|
||||
template<class ConstBufferSequence>
|
||||
@ -305,7 +305,7 @@ public:
|
||||
@returns The number of bytes written.
|
||||
|
||||
@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.
|
||||
*/
|
||||
template<class ConstBufferSequence>
|
||||
@ -333,7 +333,7 @@ public:
|
||||
); @endcode
|
||||
|
||||
@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.
|
||||
*/
|
||||
template<
|
||||
|
@ -25,14 +25,14 @@ namespace beast {
|
||||
template<class NextLayer>
|
||||
template<class ConstBufferSequence, class Handler>
|
||||
class flat_stream<NextLayer>::write_op
|
||||
: public boost::asio::coroutine
|
||||
: public net::coroutine
|
||||
{
|
||||
using alloc_type = typename
|
||||
#if defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
boost::asio::associated_allocator_t<Handler>::template
|
||||
net::associated_allocator_t<Handler>::template
|
||||
rebind<char>::other;
|
||||
#else
|
||||
std::allocator_traits<boost::asio::associated_allocator_t<Handler>>
|
||||
std::allocator_traits<net::associated_allocator_t<Handler>>
|
||||
::template rebind_alloc<char>;
|
||||
#endif
|
||||
|
||||
@ -68,27 +68,27 @@ public:
|
||||
: s_(s)
|
||||
, b_(b)
|
||||
, p_(nullptr, deleter{
|
||||
(boost::asio::get_associated_allocator)(h)})
|
||||
(net::get_associated_allocator)(h)})
|
||||
, h_(std::forward<DeducedHandler>(h))
|
||||
{
|
||||
}
|
||||
|
||||
using allocator_type =
|
||||
boost::asio::associated_allocator_t<Handler>;
|
||||
net::associated_allocator_t<Handler>;
|
||||
|
||||
allocator_type
|
||||
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())>;
|
||||
|
||||
executor_type
|
||||
get_executor() const noexcept
|
||||
{
|
||||
return (boost::asio::get_associated_executor)(
|
||||
return (net::get_associated_executor)(
|
||||
h_, s_.get_executor());
|
||||
}
|
||||
|
||||
@ -100,7 +100,7 @@ public:
|
||||
friend
|
||||
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(
|
||||
std::addressof(op->h_));
|
||||
}
|
||||
@ -109,7 +109,7 @@ public:
|
||||
friend
|
||||
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_));
|
||||
}
|
||||
};
|
||||
@ -133,12 +133,12 @@ operator()(
|
||||
p_.get_deleter().size = result.first;
|
||||
p_.reset(p_.get_deleter().alloc.allocate(
|
||||
p_.get_deleter().size));
|
||||
boost::asio::buffer_copy(
|
||||
boost::asio::buffer(
|
||||
net::buffer_copy(
|
||||
net::buffer(
|
||||
p_.get(), p_.get_deleter().size),
|
||||
b_, result.first);
|
||||
s_.stream_.async_write_some(
|
||||
boost::asio::buffer(
|
||||
net::buffer(
|
||||
p_.get(), p_.get_deleter().size),
|
||||
std::move(*this));
|
||||
}
|
||||
@ -172,7 +172,7 @@ read_some(MutableBufferSequence const& buffers)
|
||||
{
|
||||
static_assert(boost::beast::is_sync_read_stream<next_layer_type>::value,
|
||||
"SyncReadStream requirements not met");
|
||||
static_assert(boost::asio::is_mutable_buffer_sequence<
|
||||
static_assert(net::is_mutable_buffer_sequence<
|
||||
MutableBufferSequence>::value,
|
||||
"MutableBufferSequence requirements not met");
|
||||
error_code ec;
|
||||
@ -204,7 +204,7 @@ async_read_some(
|
||||
{
|
||||
static_assert(boost::beast::is_async_read_stream<next_layer_type>::value,
|
||||
"AsyncReadStream requirements not met");
|
||||
static_assert(boost::asio::is_mutable_buffer_sequence<
|
||||
static_assert(net::is_mutable_buffer_sequence<
|
||||
MutableBufferSequence >::value,
|
||||
"MutableBufferSequence requirements not met");
|
||||
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,
|
||||
"SyncWriteStream requirements not met");
|
||||
static_assert(boost::asio::is_const_buffer_sequence<
|
||||
static_assert(net::is_const_buffer_sequence<
|
||||
ConstBufferSequence>::value,
|
||||
"ConstBufferSequence requirements not met");
|
||||
auto const result = coalesce(buffers, coalesce_limit);
|
||||
if(result.second)
|
||||
{
|
||||
std::unique_ptr<char[]> p{new char[result.first]};
|
||||
auto const b = boost::asio::buffer(p.get(), result.first);
|
||||
boost::asio::buffer_copy(b, buffers);
|
||||
auto const b = net::buffer(p.get(), result.first);
|
||||
net::buffer_copy(b, buffers);
|
||||
return stream_.write_some(b);
|
||||
}
|
||||
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,
|
||||
"SyncWriteStream requirements not met");
|
||||
static_assert(boost::asio::is_const_buffer_sequence<
|
||||
static_assert(net::is_const_buffer_sequence<
|
||||
ConstBufferSequence>::value,
|
||||
"ConstBufferSequence requirements not met");
|
||||
auto const result = coalesce(buffers, coalesce_limit);
|
||||
if(result.second)
|
||||
{
|
||||
std::unique_ptr<char[]> p{new char[result.first]};
|
||||
auto const b = boost::asio::buffer(p.get(), result.first);
|
||||
boost::asio::buffer_copy(b, buffers);
|
||||
auto const b = net::buffer(p.get(), result.first);
|
||||
net::buffer_copy(b, buffers);
|
||||
return stream_.write_some(b, ec);
|
||||
}
|
||||
return stream_.write_some(
|
||||
@ -270,7 +270,7 @@ async_write_some(
|
||||
{
|
||||
static_assert(boost::beast::is_async_write_stream<next_layer_type>::value,
|
||||
"AsyncWriteStream requirements not met");
|
||||
static_assert(boost::asio::is_const_buffer_sequence<
|
||||
static_assert(net::is_const_buffer_sequence<
|
||||
ConstBufferSequence>::value,
|
||||
"ConstBufferSequence requirements not met");
|
||||
BOOST_BEAST_HANDLER_INIT(
|
||||
|
@ -18,9 +18,9 @@ namespace boost {
|
||||
namespace beast {
|
||||
|
||||
timeout_handle::
|
||||
timeout_handle(boost::asio::io_context& ioc)
|
||||
timeout_handle(net::io_context& ioc)
|
||||
: timeout_handle(
|
||||
boost::asio::use_service<
|
||||
net::use_service<
|
||||
detail::timeout_service>(
|
||||
ioc).make_handle())
|
||||
{
|
||||
@ -50,10 +50,10 @@ set_callback(
|
||||
|
||||
void
|
||||
set_timeout_service_options(
|
||||
boost::asio::io_context& ioc,
|
||||
net::io_context& ioc,
|
||||
std::chrono::seconds interval)
|
||||
{
|
||||
boost::asio::use_service<
|
||||
net::use_service<
|
||||
detail::timeout_service>(
|
||||
ioc).set_option(interval);
|
||||
}
|
||||
|
@ -61,30 +61,30 @@ public:
|
||||
}
|
||||
|
||||
using allocator_type =
|
||||
boost::asio::associated_allocator_t<Handler>;
|
||||
net::associated_allocator_t<Handler>;
|
||||
|
||||
allocator_type
|
||||
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<Handler,
|
||||
net::associated_executor_t<Handler,
|
||||
decltype(std::declval<basic_timeout_socket<
|
||||
Protocol, Executor>&>().get_executor())>;
|
||||
|
||||
executor_type
|
||||
get_executor() const noexcept
|
||||
{
|
||||
return boost::asio::get_associated_executor(
|
||||
return net::get_associated_executor(
|
||||
h_, s_.get_executor());
|
||||
}
|
||||
|
||||
friend
|
||||
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(
|
||||
std::addressof(op->h_));
|
||||
}
|
||||
@ -93,7 +93,7 @@ public:
|
||||
friend
|
||||
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_));
|
||||
}
|
||||
|
||||
@ -115,8 +115,8 @@ private:
|
||||
Handler h_;
|
||||
basic_timeout_socket& s_;
|
||||
timeout_work_guard work_;
|
||||
boost::asio::executor_work_guard<Executor> wg0_;
|
||||
boost::asio::executor_work_guard<executor_type> wg1_;
|
||||
net::executor_work_guard<Executor> wg0_;
|
||||
net::executor_work_guard<executor_type> wg1_;
|
||||
detail::saved_handler& saved_;
|
||||
};
|
||||
|
||||
@ -177,7 +177,7 @@ async_read_some(
|
||||
MutableBufferSequence const& buffers,
|
||||
ReadHandler&& handler)
|
||||
{
|
||||
static_assert(boost::asio::is_mutable_buffer_sequence<
|
||||
static_assert(net::is_mutable_buffer_sequence<
|
||||
MutableBufferSequence>::value,
|
||||
"MutableBufferSequence requirements not met");
|
||||
BOOST_BEAST_HANDLER_INIT(
|
||||
@ -198,7 +198,7 @@ async_write_some(
|
||||
ConstBufferSequence const& buffers,
|
||||
WriteHandler&& handler)
|
||||
{
|
||||
static_assert(boost::asio::is_const_buffer_sequence<
|
||||
static_assert(net::is_const_buffer_sequence<
|
||||
ConstBufferSequence>::value,
|
||||
"ConstBufferSequence requirements not met");
|
||||
BOOST_BEAST_HANDLER_INIT(
|
||||
@ -235,36 +235,36 @@ public:
|
||||
, wg0_(s_.get_executor())
|
||||
, wg1_(get_executor())
|
||||
{
|
||||
boost::asio::async_connect(
|
||||
net::async_connect(
|
||||
s_.next_layer(), eps, cond,
|
||||
std::move(*this));
|
||||
}
|
||||
|
||||
using allocator_type =
|
||||
boost::asio::associated_allocator_t<Handler>;
|
||||
net::associated_allocator_t<Handler>;
|
||||
|
||||
allocator_type
|
||||
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<Handler,
|
||||
net::associated_executor_t<Handler,
|
||||
decltype(std::declval<basic_timeout_socket<
|
||||
Protocol, Executor>&>().get_executor())>;
|
||||
|
||||
executor_type
|
||||
get_executor() const noexcept
|
||||
{
|
||||
return boost::asio::get_associated_executor(
|
||||
return net::get_associated_executor(
|
||||
h_, s_.get_executor());
|
||||
}
|
||||
|
||||
friend
|
||||
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(
|
||||
std::addressof(op->h_));
|
||||
}
|
||||
@ -273,7 +273,7 @@ public:
|
||||
friend
|
||||
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_));
|
||||
}
|
||||
|
||||
@ -296,8 +296,8 @@ private:
|
||||
Handler h_;
|
||||
timeout_work_guard work_;
|
||||
basic_timeout_socket<Protocol, Executor>& s_;
|
||||
boost::asio::executor_work_guard<Executor> wg0_;
|
||||
boost::asio::executor_work_guard<executor_type> wg1_;
|
||||
net::executor_work_guard<Executor> wg0_;
|
||||
net::executor_work_guard<executor_type> wg1_;
|
||||
};
|
||||
|
||||
struct any_endpoint
|
||||
|
@ -37,14 +37,14 @@ namespace beast {
|
||||
strand.
|
||||
|
||||
@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
|
||||
boost::asio::io_context ioc;
|
||||
boost::asio::ssl::context ctx{boost::asio::ssl::context::sslv23};
|
||||
boost::beast::ssl_stream<boost::asio:ip::tcp::socket> sock{ioc, ctx};
|
||||
net::io_context ioc;
|
||||
net::ssl::context ctx{net::ssl::context::sslv23};
|
||||
boost::beast::ssl_stream<net:ip::tcp::socket> sock{ioc, ctx};
|
||||
@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:
|
||||
|
||||
@li Satisfies @b MoveConstructible
|
||||
@ -54,7 +54,7 @@ namespace beast {
|
||||
@li Constructible from a moved socket.
|
||||
|
||||
@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.
|
||||
|
||||
@par Concepts:
|
||||
@ -66,9 +66,9 @@ namespace beast {
|
||||
*/
|
||||
template<class NextLayer>
|
||||
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>;
|
||||
|
||||
std::unique_ptr<stream_type> p_;
|
||||
@ -102,7 +102,7 @@ public:
|
||||
template<class Arg>
|
||||
ssl_stream(
|
||||
Arg&& arg,
|
||||
boost::asio::ssl::context& ctx)
|
||||
net::ssl::context& ctx)
|
||||
: p_(new stream_type{
|
||||
std::forward<Arg>(arg), ctx})
|
||||
{
|
||||
@ -132,7 +132,7 @@ public:
|
||||
suitable for passing to functions such as @c SSL_get_verify_result and
|
||||
@c SSL_get_peer_certificate:
|
||||
@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 ...
|
||||
|
||||
@ -225,7 +225,7 @@ public:
|
||||
@note Calls @c SSL_set_verify.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
@ -243,7 +243,7 @@ public:
|
||||
@note Calls @c SSL_set_verify.
|
||||
*/
|
||||
void
|
||||
set_verify_mode(boost::asio::ssl::verify_mode v,
|
||||
set_verify_mode(net::ssl::verify_mode v,
|
||||
boost::system::error_code& ec)
|
||||
{
|
||||
p_->next_layer().set_verify_mode(v, ec);
|
||||
@ -320,7 +320,7 @@ public:
|
||||
The function signature of the handler must be:
|
||||
@code bool verify_callback(
|
||||
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
|
||||
The return value of the callback is true if the certificate has passed
|
||||
verification, false otherwise.
|
||||
@ -527,7 +527,7 @@ public:
|
||||
@throws boost::system::system_error Thrown on failure.
|
||||
|
||||
@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.
|
||||
*/
|
||||
template<class ConstBufferSequence>
|
||||
@ -550,7 +550,7 @@ public:
|
||||
@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
|
||||
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.
|
||||
*/
|
||||
template<class ConstBufferSequence>
|
||||
@ -580,7 +580,7 @@ public:
|
||||
); @endcode
|
||||
|
||||
@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
|
||||
completes.
|
||||
*/
|
||||
@ -607,7 +607,7 @@ public:
|
||||
@throws boost::system::system_error Thrown on failure.
|
||||
|
||||
@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
|
||||
completes.
|
||||
*/
|
||||
@ -631,7 +631,7 @@ public:
|
||||
@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
|
||||
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
|
||||
completes.
|
||||
*/
|
||||
@ -662,7 +662,7 @@ public:
|
||||
); @endcode
|
||||
|
||||
@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
|
||||
the asynchronous operation completes.
|
||||
*/
|
||||
|
@ -67,7 +67,7 @@ public:
|
||||
// VFALCO should be execution_context
|
||||
BOOST_BEAST_DECL
|
||||
explicit
|
||||
timeout_handle(boost::asio::io_context& ioc);
|
||||
timeout_handle(net::io_context& ioc);
|
||||
|
||||
BOOST_BEAST_DECL
|
||||
void
|
||||
@ -126,7 +126,7 @@ public:
|
||||
BOOST_BEAST_DECL
|
||||
void
|
||||
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);
|
||||
|
||||
} // beast
|
||||
|
@ -46,7 +46,7 @@ class connect_op;
|
||||
*/
|
||||
template<
|
||||
class Protocol,
|
||||
class Executor = boost::asio::executor
|
||||
class Executor = net::executor
|
||||
>
|
||||
class basic_timeout_socket
|
||||
{
|
||||
@ -57,14 +57,14 @@ class basic_timeout_socket
|
||||
timeout_handle rd_timer_;
|
||||
timeout_handle wr_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 wr_op_;
|
||||
detail::saved_handler cn_op_;
|
||||
|
||||
public:
|
||||
/// 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.
|
||||
using lowest_layer_type = get_lowest_layer<next_layer_type>;
|
||||
@ -93,7 +93,7 @@ public:
|
||||
, class = typename std::enable_if<
|
||||
std::is_convertible<
|
||||
ExecutionContext&,
|
||||
boost::asio::execution_context&>::value &&
|
||||
net::execution_context&>::value &&
|
||||
std::is_constructible<
|
||||
executor_type,
|
||||
typename ExecutionContext::executor_type>::value
|
||||
@ -196,7 +196,7 @@ public:
|
||||
Regardless of whether the asynchronous operation completes immediately or
|
||||
not, the handler will not be invoked from within this function. Invocation
|
||||
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>
|
||||
BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
|
||||
@ -225,7 +225,7 @@ public:
|
||||
Regardless of whether the asynchronous operation completes immediately or
|
||||
not, the handler will not be invoked from within this function. Invocation
|
||||
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>
|
||||
BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
|
||||
@ -239,8 +239,8 @@ public:
|
||||
|
||||
/// A TCP/IP socket wrapper which has a built-in asynchronous timeout
|
||||
using timeout_socket = basic_timeout_socket<
|
||||
boost::asio::ip::tcp,
|
||||
boost::asio::io_context::executor_type>;
|
||||
net::ip::tcp,
|
||||
net::io_context::executor_type>;
|
||||
|
||||
/**
|
||||
@defgroup async_connect boost::beast::async_connect
|
||||
@ -267,7 +267,7 @@ using timeout_socket = basic_timeout_socket<
|
||||
@code
|
||||
void handler(
|
||||
// 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_code const& error,
|
||||
|
||||
@ -280,13 +280,13 @@ using timeout_socket = basic_timeout_socket<
|
||||
Regardless of whether the asynchronous operation completes immediately or
|
||||
not, the handler will not be invoked from within this function. Invocation
|
||||
of the handler will be performed in a manner equivalent to using
|
||||
`boost::asio::io_context::post()`.
|
||||
`net::io_context::post()`.
|
||||
|
||||
@par Example
|
||||
|
||||
@code
|
||||
boost::asio::tcp::resolver r(ioc);
|
||||
boost::asio::tcp::resolver::query q("host", "service");
|
||||
net::tcp::resolver r(ioc);
|
||||
net::tcp::resolver::query q("host", "service");
|
||||
timeout_socket s(ioc.get_executor());
|
||||
|
||||
// ...
|
||||
@ -321,7 +321,7 @@ template<
|
||||
class RangeConnectHandler
|
||||
#if ! BOOST_BEAST_DOXYGEN
|
||||
,class = typename std::enable_if<
|
||||
boost::asio::is_endpoint_sequence<
|
||||
net::is_endpoint_sequence<
|
||||
EndpointSequence>::value>::type
|
||||
#endif
|
||||
>
|
||||
@ -365,7 +365,7 @@ async_connect(
|
||||
@code
|
||||
void handler(
|
||||
// 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_code const& error,
|
||||
|
||||
@ -378,7 +378,7 @@ async_connect(
|
||||
Regardless of whether the asynchronous operation completes immediately or
|
||||
not, the handler will not be invoked from within this function. Invocation
|
||||
of the handler will be performed in a manner equivalent to using
|
||||
`boost::asio::io_context::post()`.
|
||||
`net::io_context::post()`.
|
||||
|
||||
@par Example
|
||||
|
||||
@ -390,7 +390,7 @@ async_connect(
|
||||
{
|
||||
bool operator()(
|
||||
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;
|
||||
std::cout << "Trying: " << next << std::endl;
|
||||
@ -403,8 +403,8 @@ async_connect(
|
||||
function as follows:
|
||||
|
||||
@code
|
||||
boost::asio::tcp::resolver r(ioc);
|
||||
boost::asio::tcp::resolver::query q("host", "service");
|
||||
net::tcp::resolver r(ioc);
|
||||
net::tcp::resolver::query q("host", "service");
|
||||
timeout_socket s(ioc.get_executor());
|
||||
|
||||
// ...
|
||||
@ -440,7 +440,7 @@ template<
|
||||
class RangeConnectHandler
|
||||
#if ! BOOST_BEAST_DOXYGEN
|
||||
,class = typename std::enable_if<
|
||||
boost::asio::is_endpoint_sequence<
|
||||
net::is_endpoint_sequence<
|
||||
EndpointSequence>::value>::type
|
||||
#endif
|
||||
>
|
||||
@ -472,7 +472,7 @@ async_connect(
|
||||
@code
|
||||
void handler(
|
||||
// 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_code const& error,
|
||||
|
||||
@ -485,7 +485,7 @@ async_connect(
|
||||
Regardless of whether the asynchronous operation completes immediately or
|
||||
not, the handler will not be invoked from within this function. Invocation
|
||||
of the handler will be performed in a manner equivalent to using
|
||||
`boost::asio::io_context::post()`.
|
||||
`net::io_context::post()`.
|
||||
|
||||
@par Example
|
||||
|
||||
@ -511,7 +511,7 @@ template<
|
||||
class IteratorConnectHandler
|
||||
#if ! BOOST_BEAST_DOXYGEN
|
||||
,class = typename std::enable_if<
|
||||
! boost::asio::is_endpoint_sequence<
|
||||
! net::is_endpoint_sequence<
|
||||
Iterator>::value>::type
|
||||
#endif
|
||||
>
|
||||
@ -551,7 +551,7 @@ async_connect(
|
||||
@code
|
||||
void handler(
|
||||
// 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_code const& error,
|
||||
|
||||
@ -564,7 +564,7 @@ async_connect(
|
||||
Regardless of whether the asynchronous operation completes immediately or
|
||||
not, the handler will not be invoked from within this function. Invocation
|
||||
of the handler will be performed in a manner equivalent to using
|
||||
`boost::asio::io_context::post()`.
|
||||
`net::io_context::post()`.
|
||||
|
||||
@par Example
|
||||
|
||||
@ -576,7 +576,7 @@ async_connect(
|
||||
{
|
||||
bool operator()(
|
||||
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;
|
||||
std::cout << "Trying: " << next << std::endl;
|
||||
@ -610,7 +610,7 @@ template<
|
||||
class IteratorConnectHandler
|
||||
#if ! BOOST_BEAST_DOXYGEN
|
||||
,class = typename std::enable_if<
|
||||
! boost::asio::is_endpoint_sequence<
|
||||
! net::is_endpoint_sequence<
|
||||
Iterator>::value>::type
|
||||
#endif
|
||||
>
|
||||
|
@ -76,7 +76,7 @@ class icy_stream
|
||||
char buf_[8];
|
||||
|
||||
static
|
||||
boost::asio::const_buffer
|
||||
net::const_buffer
|
||||
version()
|
||||
{
|
||||
return {"HTTP/1.1", 8};
|
||||
@ -199,7 +199,7 @@ public:
|
||||
@throws boost::system::system_error Thrown on failure.
|
||||
|
||||
@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
|
||||
completes.
|
||||
*/
|
||||
@ -220,7 +220,7 @@ public:
|
||||
@returns The number of bytes read.
|
||||
|
||||
@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
|
||||
completes.
|
||||
*/
|
||||
@ -249,7 +249,7 @@ public:
|
||||
); @endcode
|
||||
|
||||
@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
|
||||
operation completes.
|
||||
*/
|
||||
@ -275,7 +275,7 @@ public:
|
||||
@throws boost::system::system_error Thrown on failure.
|
||||
|
||||
@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.
|
||||
*/
|
||||
template<class ConstBufferSequence>
|
||||
@ -295,7 +295,7 @@ public:
|
||||
@returns The number of bytes written.
|
||||
|
||||
@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.
|
||||
*/
|
||||
template<class ConstBufferSequence>
|
||||
@ -323,7 +323,7 @@ public:
|
||||
); @endcode
|
||||
|
||||
@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.
|
||||
*/
|
||||
template<
|
||||
|
@ -103,7 +103,7 @@ public:
|
||||
|
||||
template<class DynamicBuffer>
|
||||
typename std::enable_if<
|
||||
boost::asio::is_dynamic_buffer<DynamicBuffer>::value,
|
||||
net::is_dynamic_buffer<DynamicBuffer>::value,
|
||||
dynamic_buffer_ref<DynamicBuffer>>::type
|
||||
ref(DynamicBuffer& b)
|
||||
{
|
||||
@ -114,16 +114,16 @@ template<class MutableBuffers, class ConstBuffers>
|
||||
void
|
||||
buffer_shift(MutableBuffers const& out, ConstBuffers const& in)
|
||||
{
|
||||
using boost::asio::buffer_size;
|
||||
auto in_pos = boost::asio::buffer_sequence_end(in);
|
||||
auto out_pos = boost::asio::buffer_sequence_end(out);
|
||||
auto const in_begin = boost::asio::buffer_sequence_begin(in);
|
||||
auto const out_begin = boost::asio::buffer_sequence_begin(out);
|
||||
using net::buffer_size;
|
||||
auto in_pos = net::buffer_sequence_end(in);
|
||||
auto out_pos = net::buffer_sequence_end(out);
|
||||
auto const in_begin = net::buffer_sequence_begin(in);
|
||||
auto const out_begin = net::buffer_sequence_begin(out);
|
||||
BOOST_ASSERT(buffer_size(in) == buffer_size(out));
|
||||
if(in_pos == in_begin || out_pos == out_begin)
|
||||
return;
|
||||
boost::asio::const_buffer cb{*--in_pos};
|
||||
boost::asio::mutable_buffer mb{*--out_pos};
|
||||
net::const_buffer cb{*--in_pos};
|
||||
net::mutable_buffer mb{*--out_pos};
|
||||
for(;;)
|
||||
{
|
||||
if(mb.size() >= cb.size())
|
||||
@ -133,7 +133,7 @@ buffer_shift(MutableBuffers const& out, ConstBuffers const& in)
|
||||
mb.data()) + mb.size() - cb.size(),
|
||||
cb.data(),
|
||||
cb.size());
|
||||
mb = boost::asio::mutable_buffer{
|
||||
mb = net::mutable_buffer{
|
||||
mb.data(), mb.size() - cb.size()};
|
||||
if(in_pos == in_begin)
|
||||
break;
|
||||
@ -146,7 +146,7 @@ buffer_shift(MutableBuffers const& out, ConstBuffers const& in)
|
||||
static_cast<char const*>(
|
||||
cb.data()) + cb.size() - mb.size(),
|
||||
mb.size());
|
||||
cb = boost::asio::const_buffer{
|
||||
cb = net::const_buffer{
|
||||
cb.data(), cb.size() - mb.size()};
|
||||
if(out_pos == out_begin)
|
||||
break;
|
||||
@ -194,14 +194,14 @@ public:
|
||||
template<class NextLayer>
|
||||
template<class MutableBufferSequence, class Handler>
|
||||
class icy_stream<NextLayer>::read_op
|
||||
: public boost::asio::coroutine
|
||||
: public net::coroutine
|
||||
{
|
||||
using alloc_type = typename
|
||||
#if defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
boost::asio::associated_allocator_t<Handler>::template
|
||||
net::associated_allocator_t<Handler>::template
|
||||
rebind<char>::other;
|
||||
#else
|
||||
std::allocator_traits<boost::asio::associated_allocator_t<Handler>>
|
||||
std::allocator_traits<net::associated_allocator_t<Handler>>
|
||||
::template rebind_alloc<char>;
|
||||
#endif
|
||||
|
||||
@ -237,21 +237,21 @@ public:
|
||||
}
|
||||
|
||||
using allocator_type =
|
||||
boost::asio::associated_allocator_t<Handler>;
|
||||
net::associated_allocator_t<Handler>;
|
||||
|
||||
allocator_type
|
||||
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())>;
|
||||
|
||||
executor_type
|
||||
get_executor() const noexcept
|
||||
{
|
||||
return (boost::asio::get_associated_executor)(
|
||||
return (net::get_associated_executor)(
|
||||
d_.handler(), d_->s.get_executor());
|
||||
}
|
||||
|
||||
@ -264,7 +264,7 @@ public:
|
||||
friend
|
||||
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()));
|
||||
}
|
||||
};
|
||||
@ -278,9 +278,9 @@ operator()(
|
||||
error_code ec,
|
||||
std::size_t bytes_transferred)
|
||||
{
|
||||
using boost::asio::buffer_copy;
|
||||
using boost::asio::buffer_size;
|
||||
using iterator = boost::asio::buffers_iterator<
|
||||
using net::buffer_copy;
|
||||
using net::buffer_size;
|
||||
using iterator = net::buffers_iterator<
|
||||
typename detail::dynamic_buffer_ref<
|
||||
buffers_adapter<MutableBufferSequence>>::const_buffers_type>;
|
||||
auto& d = *d_;
|
||||
@ -289,7 +289,7 @@ operator()(
|
||||
if(d.b.max_size() == 0)
|
||||
{
|
||||
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));
|
||||
goto upcall;
|
||||
}
|
||||
@ -300,7 +300,7 @@ operator()(
|
||||
auto const n = buffer_copy(
|
||||
d.b.prepare(std::min<std::size_t>(
|
||||
d.s.copy_, d.b.max_size())),
|
||||
boost::asio::buffer(d.s.buf_));
|
||||
net::buffer(d.s.buf_));
|
||||
d.b.commit(n);
|
||||
d.s.copy_ = static_cast<unsigned char>(
|
||||
d.s.copy_ - n);
|
||||
@ -326,9 +326,9 @@ operator()(
|
||||
if(d.b.max_size() < 8)
|
||||
{
|
||||
BOOST_ASIO_CORO_YIELD
|
||||
boost::asio::async_read(
|
||||
net::async_read(
|
||||
d.s.next_layer(),
|
||||
boost::asio::buffer(d.s.buf_, 3),
|
||||
net::buffer(d.s.buf_, 3),
|
||||
std::move(*this));
|
||||
if(ec)
|
||||
goto upcall;
|
||||
@ -341,7 +341,7 @@ operator()(
|
||||
{
|
||||
buffer_copy(
|
||||
d.b.value(),
|
||||
boost::asio::buffer(d.s.buf_, n));
|
||||
net::buffer(d.s.buf_, n));
|
||||
if(d.b.max_size() < 3)
|
||||
{
|
||||
d.s.copy_ = static_cast<unsigned char>(
|
||||
@ -358,7 +358,7 @@ operator()(
|
||||
}
|
||||
d.s.copy_ = static_cast<unsigned char>(
|
||||
buffer_copy(
|
||||
boost::asio::buffer(d.s.buf_),
|
||||
net::buffer(d.s.buf_),
|
||||
icy_stream::version() + d.b.max_size()));
|
||||
bytes_transferred = buffer_copy(
|
||||
d.b.value(),
|
||||
@ -367,7 +367,7 @@ operator()(
|
||||
}
|
||||
|
||||
BOOST_ASIO_CORO_YIELD
|
||||
boost::asio::async_read_until(
|
||||
net::async_read_until(
|
||||
d.s.next_layer(),
|
||||
detail::ref(d.b),
|
||||
detail::match_icy<iterator>(d.match),
|
||||
@ -384,8 +384,8 @@ operator()(
|
||||
d.s.copy_ = static_cast<unsigned char>(
|
||||
n + 5 - d.b.max_size());
|
||||
std::copy(
|
||||
boost::asio::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.copy_,
|
||||
net::buffers_begin(d.b.value()) + n,
|
||||
d.s.buf_);
|
||||
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,
|
||||
"SyncReadStream requirements not met");
|
||||
static_assert(boost::asio::is_mutable_buffer_sequence<
|
||||
static_assert(net::is_mutable_buffer_sequence<
|
||||
MutableBufferSequence>::value,
|
||||
"MutableBufferSequence requirements not met");
|
||||
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,
|
||||
"SyncReadStream requirements not met");
|
||||
static_assert(boost::asio::is_mutable_buffer_sequence<
|
||||
static_assert(net::is_mutable_buffer_sequence<
|
||||
MutableBufferSequence>::value,
|
||||
"MutableBufferSequence requirements not met");
|
||||
using boost::asio::buffer_copy;
|
||||
using boost::asio::buffer_size;
|
||||
using iterator = boost::asio::buffers_iterator<
|
||||
using net::buffer_copy;
|
||||
using net::buffer_size;
|
||||
using iterator = net::buffers_iterator<
|
||||
typename detail::dynamic_buffer_ref<
|
||||
buffers_adapter<MutableBufferSequence>>::const_buffers_type>;
|
||||
buffers_adapter<MutableBufferSequence> b(buffers);
|
||||
@ -464,7 +464,7 @@ read_some(MutableBufferSequence const& buffers, error_code& ec)
|
||||
auto const n = buffer_copy(
|
||||
b.prepare(std::min<std::size_t>(
|
||||
copy_, b.max_size())),
|
||||
boost::asio::buffer(buf_));
|
||||
net::buffer(buf_));
|
||||
b.commit(n);
|
||||
copy_ = static_cast<unsigned char>(
|
||||
copy_ - n);
|
||||
@ -483,9 +483,9 @@ read_some(MutableBufferSequence const& buffers, error_code& ec)
|
||||
detect_ = false;
|
||||
if(b.max_size() < 8)
|
||||
{
|
||||
auto n = boost::asio::read(
|
||||
auto n = net::read(
|
||||
stream_,
|
||||
boost::asio::buffer(buf_, 3),
|
||||
net::buffer(buf_, 3),
|
||||
ec);
|
||||
if(ec)
|
||||
return 0;
|
||||
@ -497,7 +497,7 @@ read_some(MutableBufferSequence const& buffers, error_code& ec)
|
||||
{
|
||||
buffer_copy(
|
||||
buffers,
|
||||
boost::asio::buffer(buf_, n));
|
||||
net::buffer(buf_, n));
|
||||
if(b.max_size() < 3)
|
||||
{
|
||||
copy_ = static_cast<unsigned char>(
|
||||
@ -512,7 +512,7 @@ read_some(MutableBufferSequence const& buffers, error_code& ec)
|
||||
}
|
||||
copy_ = static_cast<unsigned char>(
|
||||
buffer_copy(
|
||||
boost::asio::buffer(buf_),
|
||||
net::buffer(buf_),
|
||||
version() + b.max_size()));
|
||||
return buffer_copy(
|
||||
buffers,
|
||||
@ -520,7 +520,7 @@ read_some(MutableBufferSequence const& buffers, error_code& ec)
|
||||
}
|
||||
|
||||
bool match = false;
|
||||
auto n = boost::asio::read_until(
|
||||
auto n = net::read_until(
|
||||
stream_,
|
||||
detail::ref(b),
|
||||
detail::match_icy<iterator>(match),
|
||||
@ -535,8 +535,8 @@ read_some(MutableBufferSequence const& buffers, error_code& ec)
|
||||
copy_ = static_cast<unsigned char>(
|
||||
n + 5 - b.max_size());
|
||||
std::copy(
|
||||
boost::asio::buffers_begin(buffers) + n - copy_,
|
||||
boost::asio::buffers_begin(buffers) + n,
|
||||
net::buffers_begin(buffers) + n - copy_,
|
||||
net::buffers_begin(buffers) + n,
|
||||
buf_);
|
||||
n = b.max_size() - 5;
|
||||
}
|
||||
@ -565,7 +565,7 @@ async_read_some(
|
||||
{
|
||||
static_assert(boost::beast::is_async_read_stream<next_layer_type>::value,
|
||||
"AsyncReadStream requirements not met");
|
||||
static_assert(boost::asio::is_mutable_buffer_sequence<
|
||||
static_assert(net::is_mutable_buffer_sequence<
|
||||
MutableBufferSequence >::value,
|
||||
"MutableBufferSequence requirements not met");
|
||||
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,
|
||||
"SyncWriteStream requirements not met");
|
||||
static_assert(boost::asio::is_const_buffer_sequence<
|
||||
static_assert(net::is_const_buffer_sequence<
|
||||
MutableBufferSequence>::value,
|
||||
"MutableBufferSequence requirements not met");
|
||||
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,
|
||||
"SyncWriteStream requirements not met");
|
||||
static_assert(boost::asio::is_const_buffer_sequence<
|
||||
static_assert(net::is_const_buffer_sequence<
|
||||
MutableBufferSequence>::value,
|
||||
"MutableBufferSequence requirements not met");
|
||||
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,
|
||||
"AsyncWriteStream requirements not met");
|
||||
static_assert(boost::asio::is_const_buffer_sequence<
|
||||
static_assert(net::is_const_buffer_sequence<
|
||||
MutableBufferSequence>::value,
|
||||
"MutableBufferSequence requirements not met");
|
||||
return stream_.async_write_some(buffers, std::forward<WriteHandler>(handler));
|
||||
|
@ -62,7 +62,7 @@ operator=(stream&& other)
|
||||
|
||||
inline
|
||||
stream::
|
||||
stream(boost::asio::io_context& ioc)
|
||||
stream(net::io_context& ioc)
|
||||
: in_(std::make_shared<state>(ioc, nullptr))
|
||||
{
|
||||
}
|
||||
@ -70,7 +70,7 @@ stream(boost::asio::io_context& ioc)
|
||||
inline
|
||||
stream::
|
||||
stream(
|
||||
boost::asio::io_context& ioc,
|
||||
net::io_context& ioc,
|
||||
fail_count& fc)
|
||||
: in_(std::make_shared<state>(ioc, &fc))
|
||||
{
|
||||
@ -79,12 +79,12 @@ stream(
|
||||
inline
|
||||
stream::
|
||||
stream(
|
||||
boost::asio::io_context& ioc,
|
||||
net::io_context& ioc,
|
||||
string_view s)
|
||||
: in_(std::make_shared<state>(ioc, nullptr))
|
||||
{
|
||||
using boost::asio::buffer;
|
||||
using boost::asio::buffer_copy;
|
||||
using net::buffer;
|
||||
using net::buffer_copy;
|
||||
in_->b.commit(buffer_copy(
|
||||
in_->b.prepare(s.size()),
|
||||
buffer(s.data(), s.size())));
|
||||
@ -93,13 +93,13 @@ stream(
|
||||
inline
|
||||
stream::
|
||||
stream(
|
||||
boost::asio::io_context& ioc,
|
||||
net::io_context& ioc,
|
||||
fail_count& fc,
|
||||
string_view s)
|
||||
: in_(std::make_shared<state>(ioc, &fc))
|
||||
{
|
||||
using boost::asio::buffer;
|
||||
using boost::asio::buffer_copy;
|
||||
using net::buffer;
|
||||
using net::buffer_copy;
|
||||
in_->b.commit(buffer_copy(
|
||||
in_->b.prepare(s.size()),
|
||||
buffer(s.data(), s.size())));
|
||||
@ -121,7 +121,7 @@ stream::
|
||||
str() const
|
||||
{
|
||||
auto const bs = in_->b.data();
|
||||
if(boost::asio::buffer_size(bs) == 0)
|
||||
if(net::buffer_size(bs) == 0)
|
||||
return {};
|
||||
auto const b = buffers_front(bs);
|
||||
return {static_cast<char const*>(b.data()), b.size()};
|
||||
@ -132,8 +132,8 @@ void
|
||||
stream::
|
||||
append(string_view s)
|
||||
{
|
||||
using boost::asio::buffer;
|
||||
using boost::asio::buffer_copy;
|
||||
using net::buffer;
|
||||
using net::buffer_copy;
|
||||
std::lock_guard<std::mutex> lock{in_->m};
|
||||
in_->b.commit(buffer_copy(
|
||||
in_->b.prepare(s.size()),
|
||||
@ -184,7 +184,7 @@ std::size_t
|
||||
stream::
|
||||
read_some(MutableBufferSequence const& buffers)
|
||||
{
|
||||
static_assert(boost::asio::is_mutable_buffer_sequence<
|
||||
static_assert(net::is_mutable_buffer_sequence<
|
||||
MutableBufferSequence>::value,
|
||||
"MutableBufferSequence requirements not met");
|
||||
error_code ec;
|
||||
@ -200,11 +200,11 @@ stream::
|
||||
read_some(MutableBufferSequence const& buffers,
|
||||
error_code& ec)
|
||||
{
|
||||
static_assert(boost::asio::is_mutable_buffer_sequence<
|
||||
static_assert(net::is_mutable_buffer_sequence<
|
||||
MutableBufferSequence>::value,
|
||||
"MutableBufferSequence requirements not met");
|
||||
using boost::asio::buffer_copy;
|
||||
using boost::asio::buffer_size;
|
||||
using net::buffer_copy;
|
||||
using net::buffer_size;
|
||||
if(in_->fc && in_->fc->fail(ec))
|
||||
return 0;
|
||||
if(buffer_size(buffers) == 0)
|
||||
@ -234,9 +234,9 @@ read_some(MutableBufferSequence const& buffers,
|
||||
BOOST_ASSERT(in_->code != status::ok);
|
||||
bytes_transferred = 0;
|
||||
if(in_->code == status::eof)
|
||||
ec = boost::asio::error::eof;
|
||||
ec = net::error::eof;
|
||||
else if(in_->code == status::reset)
|
||||
ec = boost::asio::error::connection_reset;
|
||||
ec = net::error::connection_reset;
|
||||
}
|
||||
++in_->nread;
|
||||
return bytes_transferred;
|
||||
@ -250,18 +250,18 @@ async_read_some(
|
||||
MutableBufferSequence const& buffers,
|
||||
ReadHandler&& handler)
|
||||
{
|
||||
static_assert(boost::asio::is_mutable_buffer_sequence<
|
||||
static_assert(net::is_mutable_buffer_sequence<
|
||||
MutableBufferSequence>::value,
|
||||
"MutableBufferSequence requirements not met");
|
||||
using boost::asio::buffer_copy;
|
||||
using boost::asio::buffer_size;
|
||||
using net::buffer_copy;
|
||||
using net::buffer_size;
|
||||
BOOST_BEAST_HANDLER_INIT(
|
||||
ReadHandler, void(error_code, std::size_t));
|
||||
|
||||
error_code ec;
|
||||
if(in_->fc && in_->fc->fail(ec))
|
||||
{
|
||||
boost::asio::post(
|
||||
net::post(
|
||||
in_->ioc.get_executor(),
|
||||
beast::bind_front_handler(
|
||||
std::move(init.completion_handler),
|
||||
@ -280,7 +280,7 @@ async_read_some(
|
||||
in_->b.consume(bytes_transferred);
|
||||
lock.unlock();
|
||||
++in_->nread;
|
||||
boost::asio::post(
|
||||
net::post(
|
||||
in_->ioc.get_executor(),
|
||||
beast::bind_front_handler(
|
||||
std::move(init.completion_handler),
|
||||
@ -292,10 +292,10 @@ async_read_some(
|
||||
lock.unlock();
|
||||
++in_->nread;
|
||||
if(in_->code == status::eof)
|
||||
ec = boost::asio::error::eof;
|
||||
ec = net::error::eof;
|
||||
else if(in_->code == status::reset)
|
||||
ec = boost::asio::error::connection_reset;
|
||||
boost::asio::post(
|
||||
ec = net::error::connection_reset;
|
||||
net::post(
|
||||
in_->ioc.get_executor(),
|
||||
beast::bind_front_handler(
|
||||
std::move(init.completion_handler),
|
||||
@ -318,7 +318,7 @@ std::size_t
|
||||
stream::
|
||||
write_some(ConstBufferSequence const& buffers)
|
||||
{
|
||||
static_assert(boost::asio::is_const_buffer_sequence<
|
||||
static_assert(net::is_const_buffer_sequence<
|
||||
ConstBufferSequence>::value,
|
||||
"ConstBufferSequence requirements not met");
|
||||
error_code ec;
|
||||
@ -335,15 +335,15 @@ stream::
|
||||
write_some(
|
||||
ConstBufferSequence const& buffers, error_code& ec)
|
||||
{
|
||||
static_assert(boost::asio::is_const_buffer_sequence<
|
||||
static_assert(net::is_const_buffer_sequence<
|
||||
ConstBufferSequence>::value,
|
||||
"ConstBufferSequence requirements not met");
|
||||
using boost::asio::buffer_copy;
|
||||
using boost::asio::buffer_size;
|
||||
using net::buffer_copy;
|
||||
using net::buffer_size;
|
||||
auto out = out_.lock();
|
||||
if(! out)
|
||||
{
|
||||
ec = boost::asio::error::connection_reset;
|
||||
ec = net::error::connection_reset;
|
||||
return 0;
|
||||
}
|
||||
BOOST_ASSERT(out->code == status::ok);
|
||||
@ -369,21 +369,21 @@ stream::
|
||||
async_write_some(ConstBufferSequence const& buffers,
|
||||
WriteHandler&& handler)
|
||||
{
|
||||
static_assert(boost::asio::is_const_buffer_sequence<
|
||||
static_assert(net::is_const_buffer_sequence<
|
||||
ConstBufferSequence>::value,
|
||||
"ConstBufferSequence requirements not met");
|
||||
using boost::asio::buffer_copy;
|
||||
using boost::asio::buffer_size;
|
||||
using net::buffer_copy;
|
||||
using net::buffer_size;
|
||||
BOOST_BEAST_HANDLER_INIT(
|
||||
WriteHandler, void(error_code, std::size_t));
|
||||
auto out = out_.lock();
|
||||
if(! out)
|
||||
{
|
||||
boost::asio::post(
|
||||
net::post(
|
||||
in_->ioc.get_executor(),
|
||||
beast::bind_front_handler(
|
||||
std::move(init.completion_handler),
|
||||
boost::asio::error::connection_reset,
|
||||
net::error::connection_reset,
|
||||
0));
|
||||
}
|
||||
else
|
||||
@ -392,7 +392,7 @@ async_write_some(ConstBufferSequence const& buffers,
|
||||
error_code ec;
|
||||
if(in_->fc && in_->fc->fail(ec))
|
||||
{
|
||||
boost::asio::post(
|
||||
net::post(
|
||||
in_->ioc.get_executor(),
|
||||
beast::bind_front_handler(
|
||||
std::move(init.completion_handler),
|
||||
@ -410,7 +410,7 @@ async_write_some(ConstBufferSequence const& buffers,
|
||||
out->on_write();
|
||||
lock.unlock();
|
||||
++in_->nwrite;
|
||||
boost::asio::post(
|
||||
net::post(
|
||||
in_->ioc.get_executor(),
|
||||
beast::bind_front_handler(
|
||||
std::move(init.completion_handler),
|
||||
@ -437,7 +437,7 @@ boost::system::error_code& ec)
|
||||
|
||||
if( s.in_->fc &&
|
||||
s.in_->fc->fail(ec))
|
||||
ec = boost::asio::error::eof;
|
||||
ec = net::error::eof;
|
||||
else
|
||||
ec.assign(0, ec.category());
|
||||
}
|
||||
@ -453,17 +453,17 @@ TeardownHandler&& handler)
|
||||
error_code ec;
|
||||
if( s.in_->fc &&
|
||||
s.in_->fc->fail(ec))
|
||||
return boost::asio::post(
|
||||
return net::post(
|
||||
s.get_executor(),
|
||||
beast::bind_front_handler(std::move(handler), ec));
|
||||
s.close();
|
||||
if( s.in_->fc &&
|
||||
s.in_->fc->fail(ec))
|
||||
ec = boost::asio::error::eof;
|
||||
ec = net::error::eof;
|
||||
else
|
||||
ec.assign(0, ec.category());
|
||||
|
||||
boost::asio::post(
|
||||
net::post(
|
||||
s.get_executor(),
|
||||
beast::bind_front_handler(std::move(handler), ec));
|
||||
}
|
||||
@ -478,8 +478,8 @@ class stream::read_op : public stream::read_op_base
|
||||
state& s_;
|
||||
Buffers b_;
|
||||
Handler h_;
|
||||
boost::asio::executor_work_guard<
|
||||
boost::asio::io_context::executor_type> work_;
|
||||
net::executor_work_guard<
|
||||
net::io_context::executor_type> work_;
|
||||
|
||||
public:
|
||||
lambda(lambda&&) = default;
|
||||
@ -497,7 +497,7 @@ class stream::read_op : public stream::read_op_base
|
||||
void
|
||||
post()
|
||||
{
|
||||
boost::asio::post(
|
||||
net::post(
|
||||
s_.ioc.get_executor(),
|
||||
std::move(*this));
|
||||
work_.reset();
|
||||
@ -506,8 +506,8 @@ class stream::read_op : public stream::read_op_base
|
||||
void
|
||||
operator()()
|
||||
{
|
||||
using boost::asio::buffer_copy;
|
||||
using boost::asio::buffer_size;
|
||||
using net::buffer_copy;
|
||||
using net::buffer_size;
|
||||
std::unique_lock<std::mutex> lock{s_.m};
|
||||
BOOST_ASSERT(! s_.op);
|
||||
if(s_.b.size() > 0)
|
||||
@ -519,7 +519,7 @@ class stream::read_op : public stream::read_op_base
|
||||
Handler h{std::move(h_)};
|
||||
lock.unlock();
|
||||
++s.nread;
|
||||
boost::asio::post(
|
||||
net::post(
|
||||
s.ioc.get_executor(),
|
||||
beast::bind_front_handler(
|
||||
std::move(h),
|
||||
@ -535,10 +535,10 @@ class stream::read_op : public stream::read_op_base
|
||||
++s.nread;
|
||||
error_code ec;
|
||||
if(s.code == status::eof)
|
||||
ec = boost::asio::error::eof;
|
||||
ec = net::error::eof;
|
||||
else if(s.code == status::reset)
|
||||
ec = boost::asio::error::connection_reset;
|
||||
boost::asio::post(
|
||||
ec = net::error::connection_reset;
|
||||
net::post(
|
||||
s.ioc.get_executor(),
|
||||
beast::bind_front_handler(std::move(h), ec, 0));
|
||||
}
|
||||
|
@ -49,11 +49,11 @@ namespace test {
|
||||
These streams may be used anywhere an algorithm accepts a
|
||||
reference to a synchronous or asynchronous read or write
|
||||
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.
|
||||
|
||||
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
|
||||
stream follows the same rules as a traditional asio socket
|
||||
with respect to how completion handlers for asynchronous
|
||||
@ -120,7 +120,7 @@ class stream
|
||||
flat_buffer b;
|
||||
std::condition_variable cv;
|
||||
std::unique_ptr<read_op_base> op;
|
||||
boost::asio::io_context& ioc;
|
||||
net::io_context& ioc;
|
||||
status code = status::ok;
|
||||
fail_count* fc = nullptr;
|
||||
std::size_t nread = 0;
|
||||
@ -137,7 +137,7 @@ class stream
|
||||
|
||||
explicit
|
||||
state(
|
||||
boost::asio::io_context& ioc_,
|
||||
net::io_context& ioc_,
|
||||
fail_count* fc_)
|
||||
: ioc(ioc_)
|
||||
, fc(fc_)
|
||||
@ -175,7 +175,7 @@ public:
|
||||
handler.
|
||||
|
||||
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.
|
||||
*/
|
||||
~stream();
|
||||
@ -203,7 +203,7 @@ public:
|
||||
dispatch handlers for any asynchronous operations.
|
||||
*/
|
||||
explicit
|
||||
stream(boost::asio::io_context& ioc);
|
||||
stream(net::io_context& ioc);
|
||||
|
||||
/** Construct a stream
|
||||
|
||||
@ -218,7 +218,7 @@ public:
|
||||
a simulated failure error will be raised.
|
||||
*/
|
||||
stream(
|
||||
boost::asio::io_context& ioc,
|
||||
net::io_context& ioc,
|
||||
fail_count& fc);
|
||||
|
||||
/** Construct a stream
|
||||
@ -232,7 +232,7 @@ public:
|
||||
including the null terminator.
|
||||
*/
|
||||
stream(
|
||||
boost::asio::io_context& ioc,
|
||||
net::io_context& ioc,
|
||||
string_view s);
|
||||
|
||||
/** Construct a stream
|
||||
@ -251,7 +251,7 @@ public:
|
||||
including the null terminator.
|
||||
*/
|
||||
stream(
|
||||
boost::asio::io_context& ioc,
|
||||
net::io_context& ioc,
|
||||
fail_count& fc,
|
||||
string_view s);
|
||||
|
||||
@ -261,10 +261,10 @@ public:
|
||||
|
||||
/// The type of the executor associated with the object.
|
||||
using executor_type =
|
||||
boost::asio::io_context::executor_type;
|
||||
net::io_context::executor_type;
|
||||
|
||||
/// Return the executor associated with the object.
|
||||
boost::asio::io_context::executor_type
|
||||
net::io_context::executor_type
|
||||
get_executor() noexcept
|
||||
{
|
||||
return in_->ioc.get_executor();
|
||||
@ -374,7 +374,7 @@ public:
|
||||
@throws boost::system::system_error Thrown on failure.
|
||||
|
||||
@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
|
||||
completes.
|
||||
*/
|
||||
@ -395,7 +395,7 @@ public:
|
||||
@returns The number of bytes read.
|
||||
|
||||
@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
|
||||
completes.
|
||||
*/
|
||||
@ -423,7 +423,7 @@ public:
|
||||
); @endcode
|
||||
|
||||
@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
|
||||
operation completes.
|
||||
*/
|
||||
@ -446,7 +446,7 @@ public:
|
||||
@throws boost::system::system_error Thrown on failure.
|
||||
|
||||
@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.
|
||||
*/
|
||||
template<class ConstBufferSequence>
|
||||
@ -466,7 +466,7 @@ public:
|
||||
@returns The number of bytes written.
|
||||
|
||||
@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.
|
||||
*/
|
||||
template<class ConstBufferSequence>
|
||||
@ -493,7 +493,7 @@ public:
|
||||
); @endcode
|
||||
|
||||
@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.
|
||||
*/
|
||||
template<class ConstBufferSequence, class WriteHandler>
|
||||
|
@ -38,10 +38,10 @@ namespace beast {
|
||||
void
|
||||
signal_aborted(AsyncReadStream& stream, ReadHandler&& handler)
|
||||
{
|
||||
boost::asio::post(
|
||||
net::post(
|
||||
stream.get_executor(),
|
||||
bind_handler(std::forward<ReadHandler>(handler),
|
||||
boost::asio::error::operation_aborted, 0));
|
||||
net::error::operation_aborted, 0));
|
||||
}
|
||||
@endcode
|
||||
|
||||
@ -90,10 +90,10 @@ bind_handler(Handler&& handler, Args&&... args)
|
||||
void
|
||||
signal_aborted(AsyncReadStream& stream, ReadHandler&& handler)
|
||||
{
|
||||
boost::asio::post(
|
||||
net::post(
|
||||
stream.get_executor(),
|
||||
bind_front_handler(std::forward<ReadHandler>(handler),
|
||||
boost::asio::error::operation_aborted, 0));
|
||||
net::error::operation_aborted, 0));
|
||||
}
|
||||
@endcode
|
||||
|
||||
|
@ -31,17 +31,17 @@ namespace beast {
|
||||
is part of the object.
|
||||
|
||||
The use-case for this class is different than that of the
|
||||
`boost::asio::buffered_readstream`. It is designed to facilitate
|
||||
the use of `boost::asio::read_until`, and to allow buffers
|
||||
`net::buffered_readstream`. It is designed to facilitate
|
||||
the use of `net::read_until`, and to allow buffers
|
||||
acquired during detection of handshakes to be made transparently
|
||||
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.
|
||||
|
||||
Uses:
|
||||
|
||||
@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
|
||||
from other sources.
|
||||
@ -62,7 +62,7 @@ namespace beast {
|
||||
// part up to the end of the delimiter.
|
||||
//
|
||||
std::size_t bytes_transferred =
|
||||
boost::asio::read_until(
|
||||
net::read_until(
|
||||
stream.next_layer(), stream.buffer(), "\r\n\r\n");
|
||||
|
||||
// Use buffers_prefix() to limit the input
|
||||
@ -92,7 +92,7 @@ template<class Stream, class DynamicBuffer>
|
||||
class buffered_read_stream
|
||||
{
|
||||
static_assert(
|
||||
boost::asio::is_dynamic_buffer<DynamicBuffer>::value,
|
||||
net::is_dynamic_buffer<DynamicBuffer>::value,
|
||||
"DynamicBuffer requirements not met");
|
||||
|
||||
template<class Buffers, class Handler>
|
||||
@ -283,7 +283,7 @@ public:
|
||||
Regardless of whether the asynchronous operation completes
|
||||
immediately or not, the handler will not be invoked from within
|
||||
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>
|
||||
BOOST_ASIO_INITFN_RESULT_TYPE(
|
||||
@ -355,7 +355,7 @@ public:
|
||||
Regardless of whether the asynchronous operation completes
|
||||
immediately or not, the handler will not be invoked from within
|
||||
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>
|
||||
BOOST_ASIO_INITFN_RESULT_TYPE(
|
||||
|
@ -36,7 +36,7 @@ namespace beast {
|
||||
template<class MutableBufferSequence>
|
||||
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");
|
||||
|
||||
using iter_type = typename
|
||||
|
@ -30,8 +30,8 @@ public:
|
||||
/** The type of buffer returned when dereferencing an iterator.
|
||||
|
||||
If every buffer sequence in the view is a @b MutableBufferSequence,
|
||||
then `value_type` will be `boost::asio::mutable_buffer`.
|
||||
Otherwise, `value_type` will be `boost::asio::const_buffer`.
|
||||
then `value_type` will be `net::mutable_buffer`.
|
||||
Otherwise, `value_type` will be `net::const_buffer`.
|
||||
*/
|
||||
#if BOOST_BEAST_DOXYGEN
|
||||
using value_type = __implementation_defined__;
|
||||
|
@ -60,9 +60,9 @@ public:
|
||||
using value_type = typename std::conditional<
|
||||
std::is_convertible<typename
|
||||
std::iterator_traits<iter_type>::value_type,
|
||||
boost::asio::mutable_buffer>::value,
|
||||
boost::asio::mutable_buffer,
|
||||
boost::asio::const_buffer>::type;
|
||||
net::mutable_buffer>::value,
|
||||
net::mutable_buffer,
|
||||
net::const_buffer>::type;
|
||||
|
||||
#if BOOST_BEAST_DOXYGEN
|
||||
/// A bidirectional iterator type that may be used to read elements.
|
||||
@ -139,9 +139,9 @@ public:
|
||||
bytes of the original buffer.
|
||||
*/
|
||||
inline
|
||||
boost::asio::const_buffer
|
||||
net::const_buffer
|
||||
buffers_prefix(std::size_t size,
|
||||
boost::asio::const_buffer buffer)
|
||||
net::const_buffer buffer)
|
||||
{
|
||||
return {buffer.data(),
|
||||
(std::min)(size, buffer.size())};
|
||||
@ -162,9 +162,9 @@ buffers_prefix(std::size_t size,
|
||||
of the original buffer.
|
||||
*/
|
||||
inline
|
||||
boost::asio::mutable_buffer
|
||||
net::mutable_buffer
|
||||
buffers_prefix(std::size_t size,
|
||||
boost::asio::mutable_buffer buffer)
|
||||
net::mutable_buffer buffer)
|
||||
{
|
||||
return {buffer.data(),
|
||||
(std::min)(size, buffer.size())};
|
||||
@ -193,16 +193,16 @@ buffers_prefix_view<BufferSequence>
|
||||
inline
|
||||
typename std::enable_if<
|
||||
! std::is_same<BufferSequence,
|
||||
boost::asio::const_buffer>::value &&
|
||||
net::const_buffer>::value &&
|
||||
! std::is_same<BufferSequence,
|
||||
boost::asio::mutable_buffer>::value,
|
||||
net::mutable_buffer>::value,
|
||||
buffers_prefix_view<BufferSequence>>::type
|
||||
#endif
|
||||
buffers_prefix(std::size_t size, BufferSequence const& buffers)
|
||||
{
|
||||
static_assert(
|
||||
boost::asio::is_const_buffer_sequence<BufferSequence>::value ||
|
||||
boost::asio::is_mutable_buffer_sequence<BufferSequence>::value,
|
||||
net::is_const_buffer_sequence<BufferSequence>::value ||
|
||||
net::is_mutable_buffer_sequence<BufferSequence>::value,
|
||||
"BufferSequence requirements not met");
|
||||
return buffers_prefix_view<BufferSequence>(size, buffers);
|
||||
}
|
||||
@ -219,14 +219,14 @@ buffers_prefix(std::size_t size, BufferSequence const& buffers)
|
||||
*/
|
||||
template<class BufferSequence>
|
||||
typename std::conditional<
|
||||
boost::asio::is_mutable_buffer_sequence<BufferSequence>::value,
|
||||
boost::asio::mutable_buffer,
|
||||
boost::asio::const_buffer>::type
|
||||
net::is_mutable_buffer_sequence<BufferSequence>::value,
|
||||
net::mutable_buffer,
|
||||
net::const_buffer>::type
|
||||
buffers_front(BufferSequence const& buffers)
|
||||
{
|
||||
auto const first =
|
||||
boost::asio::buffer_sequence_begin(buffers);
|
||||
if(first == boost::asio::buffer_sequence_end(buffers))
|
||||
net::buffer_sequence_begin(buffers);
|
||||
if(first == net::buffer_sequence_end(buffers))
|
||||
return {};
|
||||
return *first;
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ detail::buffers_range_adaptor<ConstBufferSequence>
|
||||
buffers_range(ConstBufferSequence const& buffers)
|
||||
{
|
||||
static_assert(
|
||||
boost::asio::is_const_buffer_sequence<ConstBufferSequence>::value,
|
||||
net::is_const_buffer_sequence<ConstBufferSequence>::value,
|
||||
"ConstBufferSequence requirements not met");
|
||||
return detail::buffers_range_adaptor<ConstBufferSequence>(buffers);
|
||||
}
|
||||
@ -78,7 +78,7 @@ detail::buffers_range_adaptor<ConstBufferSequence const&>
|
||||
buffers_range(std::reference_wrapper<ConstBufferSequence> buffers)
|
||||
{
|
||||
static_assert(
|
||||
boost::asio::is_const_buffer_sequence<ConstBufferSequence>::value,
|
||||
net::is_const_buffer_sequence<ConstBufferSequence>::value,
|
||||
"ConstBufferSequence requirements not met");
|
||||
return detail::buffers_range_adaptor<ConstBufferSequence const&>(buffers.get());
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ namespace beast {
|
||||
void send(SyncWriteStream& stream, ConstBufferSequence const& 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));
|
||||
}
|
||||
@endcode
|
||||
@ -67,7 +67,7 @@ class buffers_suffix
|
||||
buffers_suffix(Deduced&& other, std::size_t dist)
|
||||
: bs_(std::forward<Deduced>(other).bs_)
|
||||
, begin_(std::next(
|
||||
boost::asio::buffer_sequence_begin(bs_),
|
||||
net::buffer_sequence_begin(bs_),
|
||||
dist))
|
||||
, skip_(other.skip_)
|
||||
{
|
||||
@ -77,9 +77,9 @@ public:
|
||||
/** The type for each element in the list of buffers.
|
||||
|
||||
If the buffers in the underlying sequence are convertible to
|
||||
`boost::asio::mutable_buffer`, then this type will be
|
||||
`boost::asio::mutable_buffer`, else this type will be
|
||||
`boost::asio::const_buffer`.
|
||||
`net::mutable_buffer`, then this type will be
|
||||
`net::mutable_buffer`, else this type will be
|
||||
`net::const_buffer`.
|
||||
*/
|
||||
#if BOOST_BEAST_DOXYGEN
|
||||
using value_type = __implementation_defined__;
|
||||
@ -87,9 +87,9 @@ public:
|
||||
using value_type = typename std::conditional<
|
||||
std::is_convertible<typename
|
||||
std::iterator_traits<iter_type>::value_type,
|
||||
boost::asio::mutable_buffer>::value,
|
||||
boost::asio::mutable_buffer,
|
||||
boost::asio::const_buffer>::type;
|
||||
net::mutable_buffer>::value,
|
||||
net::mutable_buffer,
|
||||
net::const_buffer>::type;
|
||||
#endif
|
||||
|
||||
#if BOOST_BEAST_DOXYGEN
|
||||
|
@ -45,10 +45,10 @@ std::string
|
||||
buffers_to_string(ConstBufferSequence const& buffers)
|
||||
{
|
||||
static_assert(
|
||||
boost::asio::is_const_buffer_sequence<ConstBufferSequence>::value,
|
||||
net::is_const_buffer_sequence<ConstBufferSequence>::value,
|
||||
"ConstBufferSequence requirements not met");
|
||||
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)))
|
||||
result.append(static_cast<char const*>(
|
||||
buffer.data()), buffer.size());
|
||||
|
@ -40,7 +40,7 @@ class bind_wrapper
|
||||
// Can't friend partial specializations,
|
||||
// so we just friend the whole thing.
|
||||
template<class T, class Executor>
|
||||
friend struct boost::asio::associated_executor;
|
||||
friend struct net::associated_executor;
|
||||
|
||||
template<class Arg, class Vals>
|
||||
static
|
||||
@ -123,7 +123,7 @@ public:
|
||||
using result_type = void;
|
||||
|
||||
using allocator_type =
|
||||
boost::asio::associated_allocator_t<Handler>;
|
||||
net::associated_allocator_t<Handler>;
|
||||
|
||||
bind_wrapper(bind_wrapper&&) = default;
|
||||
bind_wrapper(bind_wrapper const&) = default;
|
||||
@ -140,14 +140,14 @@ public:
|
||||
allocator_type
|
||||
get_allocator() const noexcept
|
||||
{
|
||||
return (boost::asio::get_associated_allocator)(h_);
|
||||
return (net::get_associated_allocator)(h_);
|
||||
}
|
||||
|
||||
friend
|
||||
bool
|
||||
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_));
|
||||
}
|
||||
|
||||
@ -155,7 +155,7 @@ public:
|
||||
friend
|
||||
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_));
|
||||
}
|
||||
|
||||
@ -194,13 +194,13 @@ class bind_front_wrapper<Handler>
|
||||
// Can't friend partial specializations,
|
||||
// so we just friend the whole thing.
|
||||
template<class T, class Executor>
|
||||
friend struct boost::asio::associated_executor;
|
||||
friend struct net::associated_executor;
|
||||
|
||||
public:
|
||||
using result_type = void;
|
||||
|
||||
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 const&) = default;
|
||||
@ -215,14 +215,14 @@ public:
|
||||
allocator_type
|
||||
get_allocator() const noexcept
|
||||
{
|
||||
return boost::asio::get_associated_allocator(h_);
|
||||
return net::get_associated_allocator(h_);
|
||||
}
|
||||
|
||||
friend
|
||||
bool
|
||||
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_));
|
||||
}
|
||||
|
||||
@ -230,7 +230,7 @@ public:
|
||||
friend
|
||||
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_));
|
||||
}
|
||||
|
||||
@ -251,13 +251,13 @@ class bind_front_wrapper<Handler, Arg>
|
||||
// Can't friend partial specializations,
|
||||
// so we just friend the whole thing.
|
||||
template<class T, class Executor>
|
||||
friend struct boost::asio::associated_executor;
|
||||
friend struct net::associated_executor;
|
||||
|
||||
public:
|
||||
using result_type = void;
|
||||
|
||||
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 const&) = default;
|
||||
@ -273,14 +273,14 @@ public:
|
||||
allocator_type
|
||||
get_allocator() const noexcept
|
||||
{
|
||||
return boost::asio::get_associated_allocator(h_);
|
||||
return net::get_associated_allocator(h_);
|
||||
}
|
||||
|
||||
friend
|
||||
bool
|
||||
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_));
|
||||
}
|
||||
|
||||
@ -288,7 +288,7 @@ public:
|
||||
friend
|
||||
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_));
|
||||
}
|
||||
|
||||
@ -311,13 +311,13 @@ class bind_front_wrapper<Handler, Arg1, Arg2>
|
||||
// Can't friend partial specializations,
|
||||
// so we just friend the whole thing.
|
||||
template<class T, class Executor>
|
||||
friend struct boost::asio::associated_executor;
|
||||
friend struct net::associated_executor;
|
||||
|
||||
public:
|
||||
using result_type = void;
|
||||
|
||||
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 const&) = default;
|
||||
@ -334,14 +334,14 @@ public:
|
||||
allocator_type
|
||||
get_allocator() const noexcept
|
||||
{
|
||||
return boost::asio::get_associated_allocator(h_);
|
||||
return net::get_associated_allocator(h_);
|
||||
}
|
||||
|
||||
friend
|
||||
bool
|
||||
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_));
|
||||
}
|
||||
|
||||
@ -349,7 +349,7 @@ public:
|
||||
friend
|
||||
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_));
|
||||
}
|
||||
|
||||
@ -379,7 +379,7 @@ class bind_front_wrapper<Handler, Arg1, Arg2, Arg3, Args...>
|
||||
// Can't friend partial specializations,
|
||||
// so we just friend the whole thing.
|
||||
template<class T, class Executor>
|
||||
friend struct boost::asio::associated_executor;
|
||||
friend struct net::associated_executor;
|
||||
|
||||
template<std::size_t... I, class... Ts>
|
||||
void
|
||||
@ -395,7 +395,7 @@ public:
|
||||
using result_type = void;
|
||||
|
||||
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 const&) = default;
|
||||
@ -416,14 +416,14 @@ public:
|
||||
allocator_type
|
||||
get_allocator() const noexcept
|
||||
{
|
||||
return boost::asio::get_associated_allocator(h_);
|
||||
return net::get_associated_allocator(h_);
|
||||
}
|
||||
|
||||
friend
|
||||
bool
|
||||
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_));
|
||||
}
|
||||
|
||||
@ -431,7 +431,7 @@ public:
|
||||
friend
|
||||
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_));
|
||||
}
|
||||
|
||||
@ -461,7 +461,7 @@ public:
|
||||
using result_type = void;
|
||||
|
||||
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 const&) = default;
|
||||
@ -478,14 +478,14 @@ public:
|
||||
allocator_type
|
||||
get_allocator() const noexcept
|
||||
{
|
||||
return boost::asio::get_associated_allocator(h_);
|
||||
return net::get_associated_allocator(h_);
|
||||
}
|
||||
|
||||
friend
|
||||
bool
|
||||
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_));
|
||||
}
|
||||
|
||||
@ -493,7 +493,7 @@ public:
|
||||
friend
|
||||
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_));
|
||||
}
|
||||
|
||||
|
@ -33,9 +33,9 @@ public:
|
||||
typename std::iterator_traits<
|
||||
typename detail::buffer_sequence_iterator<
|
||||
BufferSequence>::type>::value_type,
|
||||
boost::asio::mutable_buffer>::value,
|
||||
boost::asio::mutable_buffer,
|
||||
boost::asio::const_buffer>::type;
|
||||
net::mutable_buffer>::value,
|
||||
net::mutable_buffer,
|
||||
net::const_buffer>::type;
|
||||
#endif
|
||||
|
||||
class const_iterator
|
||||
@ -124,13 +124,13 @@ public:
|
||||
const_iterator
|
||||
begin() const noexcept
|
||||
{
|
||||
return boost::asio::buffer_sequence_begin(b_);
|
||||
return net::buffer_sequence_begin(b_);
|
||||
}
|
||||
|
||||
const_iterator
|
||||
end() const noexcept
|
||||
{
|
||||
return boost::asio::buffer_sequence_end(b_);
|
||||
return net::buffer_sequence_end(b_);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -42,13 +42,13 @@ public:
|
||||
const_iterator
|
||||
begin() const
|
||||
{
|
||||
return boost::asio::buffer_sequence_begin(*buffers_);
|
||||
return net::buffer_sequence_begin(*buffers_);
|
||||
}
|
||||
|
||||
const_iterator
|
||||
end() const
|
||||
{
|
||||
return boost::asio::buffer_sequence_end(*buffers_);
|
||||
return net::buffer_sequence_end(*buffers_);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -262,21 +262,21 @@ struct BufferSequence
|
||||
const_iterator end() const noexcept;
|
||||
};
|
||||
using ConstBufferSequence =
|
||||
BufferSequence<boost::asio::const_buffer>;
|
||||
BufferSequence<net::const_buffer>;
|
||||
using MutableBufferSequence =
|
||||
BufferSequence<boost::asio::mutable_buffer>;
|
||||
BufferSequence<net::mutable_buffer>;
|
||||
|
||||
template<class B1, class... Bn>
|
||||
struct is_all_const_buffer_sequence
|
||||
: 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>
|
||||
{
|
||||
};
|
||||
|
||||
template<class 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
|
||||
{
|
||||
using type = decltype(
|
||||
boost::asio::buffer_sequence_begin(
|
||||
net::buffer_sequence_begin(
|
||||
std::declval<B const&>()));
|
||||
};
|
||||
|
||||
template<>
|
||||
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<>
|
||||
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<>
|
||||
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<>
|
||||
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<
|
||||
boost::is_convertible<
|
||||
typename buffer_sequence_value_type<Bn>::type,
|
||||
boost::asio::mutable_buffer>...>::value,
|
||||
boost::asio::mutable_buffer,
|
||||
boost::asio::const_buffer>::type;
|
||||
net::mutable_buffer>...>::value,
|
||||
net::mutable_buffer,
|
||||
net::const_buffer>::type;
|
||||
};
|
||||
|
||||
// Types that meet the requirements,
|
||||
@ -366,7 +366,7 @@ using WriteHandler = StreamHandler;
|
||||
static_assert(boost::beast::is_completion_handler< \
|
||||
BOOST_ASIO_HANDLER_TYPE(type, sig), sig>::value, \
|
||||
"CompletionHandler signature requirements not met"); \
|
||||
boost::asio::async_completion<type, sig> init{handler}
|
||||
net::async_completion<type, sig> init{handler}
|
||||
|
||||
} // detail
|
||||
} // beast
|
||||
|
@ -281,13 +281,13 @@ public:
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/// 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.
|
||||
using mutable_data_type = boost::asio::mutable_buffer;
|
||||
using mutable_data_type = net::mutable_buffer;
|
||||
|
||||
/// 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.
|
||||
std::size_t
|
||||
|
@ -92,13 +92,13 @@ public:
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/// 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.
|
||||
using mutable_data_type = boost::asio::mutable_buffer;
|
||||
using mutable_data_type = net::mutable_buffer;
|
||||
|
||||
/// 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.
|
||||
std::size_t
|
||||
|
@ -33,7 +33,7 @@ class buffered_read_stream<
|
||||
Stream, DynamicBuffer>::read_some_op
|
||||
{
|
||||
buffered_read_stream& s_;
|
||||
boost::asio::executor_work_guard<decltype(
|
||||
net::executor_work_guard<decltype(
|
||||
std::declval<Stream&>().get_executor())> wg_;
|
||||
MutableBufferSequence b_;
|
||||
Handler h_;
|
||||
@ -55,22 +55,22 @@ public:
|
||||
}
|
||||
|
||||
using allocator_type =
|
||||
boost::asio::associated_allocator_t<Handler>;
|
||||
net::associated_allocator_t<Handler>;
|
||||
|
||||
allocator_type
|
||||
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<Handler, decltype(
|
||||
net::associated_executor_t<Handler, decltype(
|
||||
std::declval<buffered_read_stream&>().get_executor())>;
|
||||
|
||||
executor_type
|
||||
get_executor() const noexcept
|
||||
{
|
||||
return (boost::asio::get_associated_executor)(
|
||||
return (net::get_associated_executor)(
|
||||
h_, s_.get_executor());
|
||||
}
|
||||
|
||||
@ -81,7 +81,7 @@ public:
|
||||
friend
|
||||
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(
|
||||
std::addressof(op->h_));
|
||||
}
|
||||
@ -90,7 +90,7 @@ public:
|
||||
friend
|
||||
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_));
|
||||
}
|
||||
};
|
||||
@ -124,7 +124,7 @@ read_some_op<MutableBufferSequence, Handler>::operator()(
|
||||
|
||||
}
|
||||
step_ = 3;
|
||||
return boost::asio::post(
|
||||
return net::post(
|
||||
s_.get_executor(),
|
||||
beast::bind_front_handler(std::move(*this), ec, 0));
|
||||
|
||||
@ -138,7 +138,7 @@ read_some_op<MutableBufferSequence, Handler>::operator()(
|
||||
|
||||
case 3:
|
||||
bytes_transferred =
|
||||
boost::asio::buffer_copy(b_, s_.buffer_.data());
|
||||
net::buffer_copy(b_, s_.buffer_.data());
|
||||
s_.buffer_.consume(bytes_transferred);
|
||||
break;
|
||||
}
|
||||
@ -166,7 +166,7 @@ async_write_some(
|
||||
{
|
||||
static_assert(is_async_write_stream<next_layer_type>::value,
|
||||
"AsyncWriteStream requirements not met");
|
||||
static_assert(boost::asio::is_const_buffer_sequence<
|
||||
static_assert(net::is_const_buffer_sequence<
|
||||
ConstBufferSequence>::value,
|
||||
"ConstBufferSequence requirements not met");
|
||||
static_assert(is_completion_handler<WriteHandler,
|
||||
@ -185,7 +185,7 @@ read_some(
|
||||
{
|
||||
static_assert(is_sync_read_stream<next_layer_type>::value,
|
||||
"SyncReadStream requirements not met");
|
||||
static_assert(boost::asio::is_mutable_buffer_sequence<
|
||||
static_assert(net::is_mutable_buffer_sequence<
|
||||
MutableBufferSequence>::value,
|
||||
"MutableBufferSequence requirements not met");
|
||||
error_code ec;
|
||||
@ -204,11 +204,11 @@ read_some(MutableBufferSequence const& buffers,
|
||||
{
|
||||
static_assert(is_sync_read_stream<next_layer_type>::value,
|
||||
"SyncReadStream requirements not met");
|
||||
static_assert(boost::asio::is_mutable_buffer_sequence<
|
||||
static_assert(net::is_mutable_buffer_sequence<
|
||||
MutableBufferSequence>::value,
|
||||
"MutableBufferSequence requirements not met");
|
||||
using boost::asio::buffer_size;
|
||||
using boost::asio::buffer_copy;
|
||||
using net::buffer_size;
|
||||
using net::buffer_copy;
|
||||
if(buffer_.size() == 0)
|
||||
{
|
||||
if(capacity_ == 0)
|
||||
@ -240,7 +240,7 @@ async_read_some(
|
||||
{
|
||||
static_assert(is_async_read_stream<next_layer_type>::value,
|
||||
"AsyncReadStream requirements not met");
|
||||
static_assert(boost::asio::is_mutable_buffer_sequence<
|
||||
static_assert(net::is_mutable_buffer_sequence<
|
||||
MutableBufferSequence>::value,
|
||||
"MutableBufferSequence requirements not met");
|
||||
if(buffer_.size() == 0 && capacity_ == 0)
|
||||
|
@ -29,7 +29,7 @@ class buffers_adapter<MutableBufferSequence>::
|
||||
buffers_adapter const* b_;
|
||||
|
||||
public:
|
||||
using value_type = boost::asio::const_buffer;
|
||||
using value_type = net::const_buffer;
|
||||
|
||||
class const_iterator;
|
||||
|
||||
@ -62,7 +62,7 @@ class buffers_adapter<MutableBufferSequence>::
|
||||
buffers_adapter const* b_ = nullptr;
|
||||
|
||||
public:
|
||||
using value_type = boost::asio::const_buffer;
|
||||
using value_type = net::const_buffer;
|
||||
using pointer = value_type const*;
|
||||
using reference = value_type;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
@ -105,7 +105,7 @@ public:
|
||||
{
|
||||
value_type const b = *it_;
|
||||
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_->begin_ ? b_->in_pos_ : 0);
|
||||
}
|
||||
@ -181,7 +181,7 @@ mutable_buffers_type
|
||||
buffers_adapter const* b_;
|
||||
|
||||
public:
|
||||
using value_type = boost::asio::mutable_buffer;
|
||||
using value_type = net::mutable_buffer;
|
||||
|
||||
class const_iterator;
|
||||
|
||||
@ -215,7 +215,7 @@ mutable_buffers_type::const_iterator
|
||||
buffers_adapter const* b_ = nullptr;
|
||||
|
||||
public:
|
||||
using value_type = boost::asio::mutable_buffer;
|
||||
using value_type = net::mutable_buffer;
|
||||
using pointer = value_type const*;
|
||||
using reference = value_type;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
@ -344,9 +344,9 @@ template<class MutableBufferSequence>
|
||||
buffers_adapter<MutableBufferSequence>::
|
||||
buffers_adapter(buffers_adapter&& other)
|
||||
: buffers_adapter(std::move(other),
|
||||
std::distance<iter_type>(boost::asio::buffer_sequence_begin(other.bs_), other.begin_),
|
||||
std::distance<iter_type>(boost::asio::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.begin_),
|
||||
std::distance<iter_type>(net::buffer_sequence_begin(other.bs_), other.out_),
|
||||
std::distance<iter_type>(net::buffer_sequence_begin(other.bs_), other.end_))
|
||||
{
|
||||
}
|
||||
|
||||
@ -354,9 +354,9 @@ template<class MutableBufferSequence>
|
||||
buffers_adapter<MutableBufferSequence>::
|
||||
buffers_adapter(buffers_adapter const& other)
|
||||
: buffers_adapter(other,
|
||||
std::distance<iter_type>(boost::asio::buffer_sequence_begin(other.bs_), other.begin_),
|
||||
std::distance<iter_type>(boost::asio::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.begin_),
|
||||
std::distance<iter_type>(net::buffer_sequence_begin(other.bs_), other.out_),
|
||||
std::distance<iter_type>(net::buffer_sequence_begin(other.bs_), other.end_))
|
||||
{
|
||||
}
|
||||
|
||||
@ -367,18 +367,18 @@ operator=(buffers_adapter&& other) ->
|
||||
buffers_adapter&
|
||||
{
|
||||
auto const nbegin = std::distance<iter_type>(
|
||||
boost::asio::buffer_sequence_begin(other.bs_),
|
||||
net::buffer_sequence_begin(other.bs_),
|
||||
other.begin_);
|
||||
auto const nout = std::distance<iter_type>(
|
||||
boost::asio::buffer_sequence_begin(other.bs_),
|
||||
net::buffer_sequence_begin(other.bs_),
|
||||
other.out_);
|
||||
auto const nend = std::distance<iter_type>(
|
||||
boost::asio::buffer_sequence_begin(other.bs_),
|
||||
net::buffer_sequence_begin(other.bs_),
|
||||
other.end_);
|
||||
bs_ = std::move(other.bs_);
|
||||
begin_ = std::next(boost::asio::buffer_sequence_begin(bs_), nbegin);
|
||||
out_ = std::next(boost::asio::buffer_sequence_begin(bs_), nout);
|
||||
end_ = std::next(boost::asio::buffer_sequence_begin(bs_), nend);
|
||||
begin_ = std::next(net::buffer_sequence_begin(bs_), nbegin);
|
||||
out_ = std::next(net::buffer_sequence_begin(bs_), nout);
|
||||
end_ = std::next(net::buffer_sequence_begin(bs_), nend);
|
||||
max_size_ = other.max_size_;
|
||||
in_pos_ = other.in_pos_;
|
||||
in_size_ = other.in_size_;
|
||||
@ -394,18 +394,18 @@ operator=(buffers_adapter const& other) ->
|
||||
buffers_adapter&
|
||||
{
|
||||
auto const nbegin = std::distance<iter_type>(
|
||||
boost::asio::buffer_sequence_begin(other.bs_),
|
||||
net::buffer_sequence_begin(other.bs_),
|
||||
other.begin_);
|
||||
auto const nout = std::distance<iter_type>(
|
||||
boost::asio::buffer_sequence_begin(other.bs_),
|
||||
net::buffer_sequence_begin(other.bs_),
|
||||
other.out_);
|
||||
auto const nend = std::distance<iter_type>(
|
||||
boost::asio::buffer_sequence_begin(other.bs_),
|
||||
net::buffer_sequence_begin(other.bs_),
|
||||
other.end_);
|
||||
bs_ = other.bs_;
|
||||
begin_ = std::next(boost::asio::buffer_sequence_begin(bs_), nbegin);
|
||||
out_ = std::next(boost::asio::buffer_sequence_begin(bs_), nout);
|
||||
end_ = std::next(boost::asio::buffer_sequence_begin(bs_), nend);
|
||||
begin_ = std::next(net::buffer_sequence_begin(bs_), nbegin);
|
||||
out_ = std::next(net::buffer_sequence_begin(bs_), nout);
|
||||
end_ = std::next(net::buffer_sequence_begin(bs_), nend);
|
||||
max_size_ = other.max_size_;
|
||||
in_pos_ = other.in_pos_;
|
||||
in_size_ = other.in_size_;
|
||||
@ -418,10 +418,10 @@ template<class MutableBufferSequence>
|
||||
buffers_adapter<MutableBufferSequence>::
|
||||
buffers_adapter(MutableBufferSequence const& bs)
|
||||
: bs_(bs)
|
||||
, begin_(boost::asio::buffer_sequence_begin(bs_))
|
||||
, out_ (boost::asio::buffer_sequence_begin(bs_))
|
||||
, end_ (boost::asio::buffer_sequence_begin(bs_))
|
||||
, max_size_(boost::asio::buffer_size(bs_))
|
||||
, begin_(net::buffer_sequence_begin(bs_))
|
||||
, out_ (net::buffer_sequence_begin(bs_))
|
||||
, end_ (net::buffer_sequence_begin(bs_))
|
||||
, max_size_(net::buffer_size(bs_))
|
||||
{
|
||||
}
|
||||
|
||||
@ -430,10 +430,10 @@ template<class... Args>
|
||||
buffers_adapter<MutableBufferSequence>::
|
||||
buffers_adapter(boost::in_place_init_t, Args&&... args)
|
||||
: bs_{std::forward<Args>(args)...}
|
||||
, begin_(boost::asio::buffer_sequence_begin(bs_))
|
||||
, out_ (boost::asio::buffer_sequence_begin(bs_))
|
||||
, end_ (boost::asio::buffer_sequence_begin(bs_))
|
||||
, max_size_(boost::asio::buffer_size(bs_))
|
||||
, begin_(net::buffer_sequence_begin(bs_))
|
||||
, out_ (net::buffer_sequence_begin(bs_))
|
||||
, end_ (net::buffer_sequence_begin(bs_))
|
||||
, max_size_(net::buffer_size(bs_))
|
||||
{
|
||||
}
|
||||
|
||||
@ -443,16 +443,16 @@ buffers_adapter<MutableBufferSequence>::
|
||||
prepare(std::size_t n) ->
|
||||
mutable_buffers_type
|
||||
{
|
||||
using boost::asio::buffer_size;
|
||||
using net::buffer_size;
|
||||
end_ = out_;
|
||||
if(end_ != boost::asio::buffer_sequence_end(bs_))
|
||||
if(end_ != net::buffer_sequence_end(bs_))
|
||||
{
|
||||
auto size = buffer_size(*end_) - out_pos_;
|
||||
if(n > size)
|
||||
{
|
||||
n -= size;
|
||||
while(++end_ !=
|
||||
boost::asio::buffer_sequence_end(bs_))
|
||||
net::buffer_sequence_end(bs_))
|
||||
{
|
||||
size = buffer_size(*end_);
|
||||
if(n < size)
|
||||
@ -484,7 +484,7 @@ void
|
||||
buffers_adapter<MutableBufferSequence>::
|
||||
commit(std::size_t n)
|
||||
{
|
||||
using boost::asio::buffer_size;
|
||||
using net::buffer_size;
|
||||
if(out_ == end_)
|
||||
return;
|
||||
auto const last = std::prev(end_);
|
||||
@ -530,7 +530,7 @@ void
|
||||
buffers_adapter<MutableBufferSequence>::
|
||||
consume(std::size_t n)
|
||||
{
|
||||
using boost::asio::buffer_size;
|
||||
using net::buffer_size;
|
||||
while(begin_ != out_)
|
||||
{
|
||||
auto const avail =
|
||||
|
@ -32,7 +32,7 @@ struct buffers_cat_view_iterator_base
|
||||
{
|
||||
char unused = 0; // make g++8 happy
|
||||
|
||||
boost::asio::mutable_buffer
|
||||
net::mutable_buffer
|
||||
operator*() const
|
||||
{
|
||||
BOOST_THROW_EXCEPTION(std::logic_error{
|
||||
@ -119,11 +119,11 @@ private:
|
||||
void
|
||||
next(C<I> const&)
|
||||
{
|
||||
if(boost::asio::buffer_size(
|
||||
if(net::buffer_size(
|
||||
detail::get<I>(*bn_)) != 0)
|
||||
{
|
||||
it_.template emplace<I+1>(
|
||||
boost::asio::buffer_sequence_begin(
|
||||
net::buffer_sequence_begin(
|
||||
detail::get<I>(*bn_)));
|
||||
return;
|
||||
}
|
||||
@ -142,11 +142,11 @@ private:
|
||||
void
|
||||
prev(C<I> const&)
|
||||
{
|
||||
if(boost::asio::buffer_size(
|
||||
if(net::buffer_size(
|
||||
detail::get<I>(*bn_)) != 0)
|
||||
{
|
||||
it_.template emplace<I+1>(
|
||||
boost::asio::buffer_sequence_end(
|
||||
net::buffer_sequence_end(
|
||||
detail::get<I>(*bn_)));
|
||||
return;
|
||||
}
|
||||
@ -158,7 +158,7 @@ private:
|
||||
{
|
||||
auto constexpr I = 0;
|
||||
it_.template emplace<I+1>(
|
||||
boost::asio::buffer_sequence_end(
|
||||
net::buffer_sequence_end(
|
||||
detail::get<I>(*bn_)));
|
||||
}
|
||||
|
||||
@ -205,7 +205,7 @@ private:
|
||||
operator()(mp11::mp_size_t<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_)))
|
||||
self.next(C<I>());
|
||||
}
|
||||
@ -227,7 +227,7 @@ private:
|
||||
if(it_.index() == I+1)
|
||||
{
|
||||
if(it_.template get<I+1>() !=
|
||||
boost::asio::buffer_sequence_begin(
|
||||
net::buffer_sequence_begin(
|
||||
detail::get<I>(*bn_)))
|
||||
{
|
||||
--it_.template get<I+1>();
|
||||
@ -243,7 +243,7 @@ private:
|
||||
{
|
||||
auto constexpr I = 0;
|
||||
if(it_.template get<I+1>() !=
|
||||
boost::asio::buffer_sequence_begin(
|
||||
net::buffer_sequence_begin(
|
||||
detail::get<I>(*bn_)))
|
||||
{
|
||||
--it_.template get<I+1>();
|
||||
|
@ -23,18 +23,18 @@ namespace beast {
|
||||
namespace detail {
|
||||
|
||||
inline
|
||||
boost::asio::const_buffer
|
||||
net::const_buffer
|
||||
buffers_prefix(std::size_t size,
|
||||
boost::asio::const_buffer buffer)
|
||||
net::const_buffer buffer)
|
||||
{
|
||||
return {buffer.data(),
|
||||
(std::min)(size, buffer.size())};
|
||||
}
|
||||
|
||||
inline
|
||||
boost::asio::mutable_buffer
|
||||
net::mutable_buffer
|
||||
buffers_prefix(std::size_t size,
|
||||
boost::asio::mutable_buffer buffer)
|
||||
net::mutable_buffer buffer)
|
||||
{
|
||||
return {buffer.data(),
|
||||
(std::min)(size, buffer.size())};
|
||||
@ -55,9 +55,9 @@ public:
|
||||
using value_type = typename std::conditional<
|
||||
boost::is_convertible<typename
|
||||
std::iterator_traits<iter_type>::value_type,
|
||||
boost::asio::mutable_buffer>::value,
|
||||
boost::asio::mutable_buffer,
|
||||
boost::asio::const_buffer>::type;
|
||||
net::mutable_buffer>::value,
|
||||
net::mutable_buffer,
|
||||
net::const_buffer>::type;
|
||||
using pointer = value_type const*;
|
||||
using reference = value_type;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
@ -107,7 +107,7 @@ public:
|
||||
const_iterator&
|
||||
operator++()
|
||||
{
|
||||
remain_ -= boost::asio::buffer_size(*it_++);
|
||||
remain_ -= net::buffer_size(*it_++);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -115,14 +115,14 @@ public:
|
||||
operator++(int)
|
||||
{
|
||||
auto temp = *this;
|
||||
remain_ -= boost::asio::buffer_size(*it_++);
|
||||
remain_ -= net::buffer_size(*it_++);
|
||||
return temp;
|
||||
}
|
||||
|
||||
const_iterator&
|
||||
operator--()
|
||||
{
|
||||
remain_ += boost::asio::buffer_size(*--it_);
|
||||
remain_ += net::buffer_size(*--it_);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -130,7 +130,7 @@ public:
|
||||
operator--(int)
|
||||
{
|
||||
auto temp = *this;
|
||||
remain_ += boost::asio::buffer_size(*--it_);
|
||||
remain_ += net::buffer_size(*--it_);
|
||||
return temp;
|
||||
}
|
||||
|
||||
@ -147,7 +147,7 @@ private:
|
||||
std::false_type)
|
||||
: b_(&b)
|
||||
, 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;
|
||||
remain_ = 0;
|
||||
end_ = boost::asio::buffer_sequence_begin(bs_);
|
||||
end_ = net::buffer_sequence_begin(bs_);
|
||||
auto const last = bs_.end();
|
||||
while(end_ != last)
|
||||
{
|
||||
auto const len =
|
||||
boost::asio::buffer_size(*end_++);
|
||||
net::buffer_size(*end_++);
|
||||
if(len >= size)
|
||||
{
|
||||
size_ += size;
|
||||
@ -183,7 +183,7 @@ buffers_prefix_view<BufferSequence>::
|
||||
buffers_prefix_view(buffers_prefix_view&& other)
|
||||
: buffers_prefix_view(std::move(other),
|
||||
std::distance<iter_type>(
|
||||
boost::asio::buffer_sequence_begin(other.bs_),
|
||||
net::buffer_sequence_begin(other.bs_),
|
||||
other.end_))
|
||||
{
|
||||
}
|
||||
@ -193,7 +193,7 @@ buffers_prefix_view<BufferSequence>::
|
||||
buffers_prefix_view(buffers_prefix_view const& other)
|
||||
: buffers_prefix_view(other,
|
||||
std::distance<iter_type>(
|
||||
boost::asio::buffer_sequence_begin(other.bs_),
|
||||
net::buffer_sequence_begin(other.bs_),
|
||||
other.end_))
|
||||
{
|
||||
}
|
||||
@ -205,13 +205,13 @@ operator=(buffers_prefix_view&& other) ->
|
||||
buffers_prefix_view&
|
||||
{
|
||||
auto const dist = std::distance<iter_type>(
|
||||
boost::asio::buffer_sequence_begin(other.bs_),
|
||||
net::buffer_sequence_begin(other.bs_),
|
||||
other.end_);
|
||||
bs_ = std::move(other.bs_);
|
||||
size_ = other.size_;
|
||||
remain_ = other.remain_;
|
||||
end_ = std::next(
|
||||
boost::asio::buffer_sequence_begin(bs_),
|
||||
net::buffer_sequence_begin(bs_),
|
||||
dist);
|
||||
return *this;
|
||||
}
|
||||
@ -223,13 +223,13 @@ operator=(buffers_prefix_view const& other) ->
|
||||
buffers_prefix_view&
|
||||
{
|
||||
auto const dist = std::distance<iter_type>(
|
||||
boost::asio::buffer_sequence_begin(other.bs_),
|
||||
net::buffer_sequence_begin(other.bs_),
|
||||
other.end_);
|
||||
bs_ = other.bs_;
|
||||
size_ = other.size_;
|
||||
remain_ = other.remain_;
|
||||
end_ = std::next(
|
||||
boost::asio::buffer_sequence_begin(bs_),
|
||||
net::buffer_sequence_begin(bs_),
|
||||
dist);
|
||||
return *this;
|
||||
}
|
||||
|
@ -36,9 +36,9 @@ public:
|
||||
using value_type = typename std::conditional<
|
||||
boost::is_convertible<typename
|
||||
std::iterator_traits<iter_type>::value_type,
|
||||
boost::asio::mutable_buffer>::value,
|
||||
boost::asio::mutable_buffer,
|
||||
boost::asio::const_buffer>::type;
|
||||
net::mutable_buffer>::value,
|
||||
net::mutable_buffer,
|
||||
net::const_buffer>::type;
|
||||
using pointer = value_type const*;
|
||||
using reference = value_type;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
@ -58,11 +58,11 @@ public:
|
||||
(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) ?
|
||||
(
|
||||
it_ == boost::asio::buffer_sequence_end(b_->bs_)
|
||||
it_ == net::buffer_sequence_end(b_->bs_)
|
||||
): (
|
||||
b_ == other.b_ &&
|
||||
it_ == other.it_
|
||||
@ -131,7 +131,7 @@ private:
|
||||
template<class Buffers>
|
||||
buffers_suffix<Buffers>::
|
||||
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(std::move(other),
|
||||
std::distance<iter_type>(
|
||||
boost::asio::buffer_sequence_begin(
|
||||
net::buffer_sequence_begin(
|
||||
other.bs_), other.begin_))
|
||||
{
|
||||
}
|
||||
@ -150,7 +150,7 @@ buffers_suffix<Buffers>::
|
||||
buffers_suffix(buffers_suffix const& other)
|
||||
: buffers_suffix(other,
|
||||
std::distance<iter_type>(
|
||||
boost::asio::buffer_sequence_begin(
|
||||
net::buffer_sequence_begin(
|
||||
other.bs_), other.begin_))
|
||||
{
|
||||
}
|
||||
@ -159,11 +159,11 @@ template<class Buffers>
|
||||
buffers_suffix<Buffers>::
|
||||
buffers_suffix(Buffers const& bs)
|
||||
: bs_(bs)
|
||||
, begin_(boost::asio::buffer_sequence_begin(bs_))
|
||||
, begin_(net::buffer_sequence_begin(bs_))
|
||||
{
|
||||
static_assert(
|
||||
boost::asio::is_const_buffer_sequence<Buffers>::value||
|
||||
boost::asio::is_mutable_buffer_sequence<Buffers>::value,
|
||||
net::is_const_buffer_sequence<Buffers>::value||
|
||||
net::is_mutable_buffer_sequence<Buffers>::value,
|
||||
"BufferSequence requirements not met");
|
||||
}
|
||||
|
||||
@ -172,7 +172,7 @@ template<class... Args>
|
||||
buffers_suffix<Buffers>::
|
||||
buffers_suffix(boost::in_place_init_t, 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,
|
||||
"Missing constructor arguments");
|
||||
@ -188,11 +188,11 @@ operator=(buffers_suffix&& other) ->
|
||||
buffers_suffix&
|
||||
{
|
||||
auto const dist = std::distance<iter_type>(
|
||||
boost::asio::buffer_sequence_begin(other.bs_),
|
||||
net::buffer_sequence_begin(other.bs_),
|
||||
other.begin_);
|
||||
bs_ = std::move(other.bs_);
|
||||
begin_ = std::next(
|
||||
boost::asio::buffer_sequence_begin(bs_),
|
||||
net::buffer_sequence_begin(bs_),
|
||||
dist);
|
||||
skip_ = other.skip_;
|
||||
return *this;
|
||||
@ -205,11 +205,11 @@ operator=(buffers_suffix const& other) ->
|
||||
buffers_suffix&
|
||||
{
|
||||
auto const dist = std::distance<iter_type>(
|
||||
boost::asio::buffer_sequence_begin(other.bs_),
|
||||
net::buffer_sequence_begin(other.bs_),
|
||||
other.begin_);
|
||||
bs_ = other.bs_;
|
||||
begin_ = std::next(
|
||||
boost::asio::buffer_sequence_begin(bs_), dist);
|
||||
net::buffer_sequence_begin(bs_), dist);
|
||||
skip_ = other.skip_;
|
||||
return *this;
|
||||
}
|
||||
@ -232,7 +232,7 @@ end() const ->
|
||||
const_iterator
|
||||
{
|
||||
return const_iterator{*this,
|
||||
boost::asio::buffer_sequence_end(bs_)};
|
||||
net::buffer_sequence_end(bs_)};
|
||||
}
|
||||
|
||||
template<class Buffers>
|
||||
@ -240,9 +240,9 @@ void
|
||||
buffers_suffix<Buffers>::
|
||||
consume(std::size_t amount)
|
||||
{
|
||||
using boost::asio::buffer_size;
|
||||
using net::buffer_size;
|
||||
auto const end =
|
||||
boost::asio::buffer_sequence_end(bs_);
|
||||
net::buffer_sequence_end(bs_);
|
||||
for(;amount > 0 && begin_ != end; ++begin_)
|
||||
{
|
||||
auto const len =
|
||||
|
@ -351,7 +351,7 @@ copy_from(DynamicBuffer const& buffer)
|
||||
{
|
||||
if(buffer.size() == 0)
|
||||
return;
|
||||
commit(boost::asio::buffer_copy(
|
||||
commit(net::buffer_copy(
|
||||
prepare(buffer.size()), buffer.data()));
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,7 @@ flat_static_buffer<N>::
|
||||
flat_static_buffer(flat_static_buffer const& other)
|
||||
: flat_static_buffer_base(buf_, N)
|
||||
{
|
||||
using boost::asio::buffer_copy;
|
||||
using net::buffer_copy;
|
||||
this->commit(buffer_copy(
|
||||
this->prepare(other.size()), other.data()));
|
||||
}
|
||||
@ -101,7 +101,7 @@ flat_static_buffer<N>::
|
||||
operator=(flat_static_buffer const& other) ->
|
||||
flat_static_buffer<N>&
|
||||
{
|
||||
using boost::asio::buffer_copy;
|
||||
using net::buffer_copy;
|
||||
this->consume(this->size());
|
||||
this->commit(buffer_copy(
|
||||
this->prepare(other.size()), other.data()));
|
||||
|
@ -23,9 +23,9 @@ handler_ptr<T, Handler>::
|
||||
clear()
|
||||
{
|
||||
typename beast::detail::allocator_traits<
|
||||
boost::asio::associated_allocator_t<
|
||||
net::associated_allocator_t<
|
||||
Handler>>::template rebind_alloc<T> alloc(
|
||||
boost::asio::get_associated_allocator(
|
||||
net::get_associated_allocator(
|
||||
handler()));
|
||||
beast::detail::allocator_traits<
|
||||
decltype(alloc)>::destroy(alloc, t_);
|
||||
@ -65,9 +65,9 @@ handler_ptr(DeducedHandler&& h, Args&&... args)
|
||||
{
|
||||
BOOST_STATIC_ASSERT(! std::is_array<T>::value);
|
||||
typename beast::detail::allocator_traits<
|
||||
boost::asio::associated_allocator_t<
|
||||
net::associated_allocator_t<
|
||||
Handler>>::template rebind_alloc<T> alloc{
|
||||
boost::asio::get_associated_allocator(h)};
|
||||
net::get_associated_allocator(h)};
|
||||
using A = decltype(alloc);
|
||||
bool destroy = false;
|
||||
auto deleter = [&alloc, &destroy](T* p)
|
||||
|
@ -143,8 +143,8 @@ class basic_multi_buffer<Allocator>::readable_bytes
|
||||
public:
|
||||
using value_type = typename std::conditional<
|
||||
IsMutable,
|
||||
boost::asio::mutable_buffer,
|
||||
boost::asio::const_buffer>::type;
|
||||
net::mutable_buffer,
|
||||
net::const_buffer>::type;
|
||||
|
||||
class const_iterator;
|
||||
|
||||
@ -881,7 +881,7 @@ copy_from(DynamicBuffer const& buffer)
|
||||
{
|
||||
if(buffer.size() == 0)
|
||||
return;
|
||||
using boost::asio::buffer_copy;
|
||||
using net::buffer_copy;
|
||||
commit(buffer_copy(
|
||||
prepare(buffer.size()), buffer.data()));
|
||||
}
|
||||
@ -1018,7 +1018,7 @@ basic_multi_buffer<Allocator>::
|
||||
debug_check() const
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
using boost::asio::buffer_size;
|
||||
using net::buffer_size;
|
||||
BOOST_ASSERT(buffer_size(data()) == in_size_);
|
||||
if(list_.empty())
|
||||
{
|
||||
|
@ -43,7 +43,7 @@ read_size(DynamicBuffer& buffer,
|
||||
std::size_t max_size, std::false_type)
|
||||
{
|
||||
static_assert(
|
||||
boost::asio::is_dynamic_buffer<DynamicBuffer>::value,
|
||||
net::is_dynamic_buffer<DynamicBuffer>::value,
|
||||
"DynamicBuffer requirements not met");
|
||||
BOOST_ASSERT(max_size >= 1);
|
||||
auto const size = buffer.size();
|
||||
|
@ -35,7 +35,7 @@ static_buffer_base::
|
||||
data() const noexcept ->
|
||||
const_buffers_type
|
||||
{
|
||||
using boost::asio::const_buffer;
|
||||
using net::const_buffer;
|
||||
const_buffers_type result;
|
||||
if(in_off_ + in_size_ <= capacity_)
|
||||
{
|
||||
@ -56,7 +56,7 @@ static_buffer_base::
|
||||
data() noexcept ->
|
||||
mutable_data_type
|
||||
{
|
||||
using boost::asio::mutable_buffer;
|
||||
using net::mutable_buffer;
|
||||
mutable_data_type result;
|
||||
if(in_off_ + in_size_ <= capacity_)
|
||||
{
|
||||
@ -77,7 +77,7 @@ static_buffer_base::
|
||||
prepare(std::size_t n) ->
|
||||
mutable_buffers_type
|
||||
{
|
||||
using boost::asio::mutable_buffer;
|
||||
using net::mutable_buffer;
|
||||
if(n > capacity_ - in_size_)
|
||||
BOOST_THROW_EXCEPTION(std::length_error{
|
||||
"buffer overflow"});
|
||||
@ -145,7 +145,7 @@ static_buffer<N>::
|
||||
static_buffer(static_buffer const& other)
|
||||
: static_buffer_base(buf_, N)
|
||||
{
|
||||
using boost::asio::buffer_copy;
|
||||
using net::buffer_copy;
|
||||
this->commit(buffer_copy(
|
||||
this->prepare(other.size()), other.data()));
|
||||
}
|
||||
@ -156,7 +156,7 @@ static_buffer<N>::
|
||||
operator=(static_buffer const& other) ->
|
||||
static_buffer<N>&
|
||||
{
|
||||
using boost::asio::buffer_copy;
|
||||
using net::buffer_copy;
|
||||
this->consume(this->size());
|
||||
this->commit(buffer_copy(
|
||||
this->prepare(other.size()), other.data()));
|
||||
|
@ -86,8 +86,8 @@ class basic_multi_buffer
|
||||
using const_iter = typename list_type::const_iterator;
|
||||
|
||||
using size_type = typename alloc_traits::size_type;
|
||||
using const_buffer = boost::asio::const_buffer;
|
||||
using mutable_buffer = boost::asio::mutable_buffer;
|
||||
using const_buffer = net::const_buffer;
|
||||
using mutable_buffer = net::mutable_buffer;
|
||||
|
||||
static_assert(std::is_base_of<std::bidirectional_iterator_tag,
|
||||
typename std::iterator_traits<iter>::iterator_category>::value,
|
||||
|
@ -49,7 +49,7 @@ detail::buffers_helper<ConstBufferSequence>
|
||||
#endif
|
||||
buffers(ConstBufferSequence const& b)
|
||||
{
|
||||
static_assert(boost::asio::is_const_buffer_sequence<
|
||||
static_assert(net::is_const_buffer_sequence<
|
||||
ConstBufferSequence>::value,
|
||||
"ConstBufferSequence requirements not met");
|
||||
return detail::buffers_helper<
|
||||
@ -91,7 +91,7 @@ detail::ostream_helper<
|
||||
ostream(DynamicBuffer& buffer)
|
||||
{
|
||||
static_assert(
|
||||
boost::asio::is_dynamic_buffer<DynamicBuffer>::value,
|
||||
net::is_dynamic_buffer<DynamicBuffer>::value,
|
||||
"DynamicBuffer requirements not met");
|
||||
return detail::ostream_helper<
|
||||
DynamicBuffer, char, std::char_traits<char>,
|
||||
|
@ -64,23 +64,23 @@ class static_buffer_base
|
||||
|
||||
class mutable_buffer_pair
|
||||
{
|
||||
boost::asio::mutable_buffer b_[2];
|
||||
net::mutable_buffer b_[2];
|
||||
|
||||
friend class const_buffer_pair;
|
||||
|
||||
public:
|
||||
using const_iterator =
|
||||
boost::asio::mutable_buffer const*;
|
||||
net::mutable_buffer const*;
|
||||
|
||||
// workaround for buffers_iterator bug
|
||||
using value_type =
|
||||
boost::asio::mutable_buffer;
|
||||
net::mutable_buffer;
|
||||
|
||||
mutable_buffer_pair() = default;
|
||||
mutable_buffer_pair(
|
||||
mutable_buffer_pair const&) = default;
|
||||
|
||||
boost::asio::mutable_buffer&
|
||||
net::mutable_buffer&
|
||||
operator[](int i) noexcept
|
||||
{
|
||||
BOOST_ASSERT(i >= 0 && i < 2);
|
||||
@ -105,15 +105,15 @@ class static_buffer_base
|
||||
|
||||
class const_buffer_pair
|
||||
{
|
||||
boost::asio::const_buffer b_[2];
|
||||
net::const_buffer b_[2];
|
||||
|
||||
public:
|
||||
using const_iterator =
|
||||
boost::asio::const_buffer const*;
|
||||
net::const_buffer const*;
|
||||
|
||||
// workaround for buffers_iterator bug
|
||||
using value_type =
|
||||
boost::asio::const_buffer;
|
||||
net::const_buffer;
|
||||
|
||||
const_buffer_pair() = default;
|
||||
const_buffer_pair(
|
||||
@ -125,7 +125,7 @@ class static_buffer_base
|
||||
{
|
||||
}
|
||||
|
||||
boost::asio::const_buffer&
|
||||
net::const_buffer&
|
||||
operator[](int i) noexcept
|
||||
{
|
||||
BOOST_ASSERT(i >= 0 && i < 2);
|
||||
|
@ -76,7 +76,7 @@ using is_completion_handler = std::integral_constant<bool,
|
||||
template<class T>
|
||||
void maybe_hello(T& t, std::true_type)
|
||||
{
|
||||
boost::asio::post(
|
||||
net::post(
|
||||
t.get_executor(),
|
||||
[]
|
||||
{
|
||||
@ -102,7 +102,7 @@ using is_completion_handler = std::integral_constant<bool,
|
||||
@code
|
||||
struct stream
|
||||
{
|
||||
using executor_type = boost::asio::io_context::executor_type;
|
||||
using executor_type = net::io_context::executor_type;
|
||||
executor_type get_executor() noexcept;
|
||||
};
|
||||
|
||||
|
@ -34,7 +34,7 @@ template<class DynamicBuffer>
|
||||
struct basic_dynamic_body
|
||||
{
|
||||
static_assert(
|
||||
boost::asio::is_dynamic_buffer<DynamicBuffer>::value,
|
||||
net::is_dynamic_buffer<DynamicBuffer>::value,
|
||||
"DynamicBuffer requirements not met");
|
||||
|
||||
/** The type of container used for the body
|
||||
@ -88,8 +88,8 @@ struct basic_dynamic_body
|
||||
put(ConstBufferSequence const& buffers,
|
||||
error_code& ec)
|
||||
{
|
||||
using boost::asio::buffer_copy;
|
||||
using boost::asio::buffer_size;
|
||||
using net::buffer_copy;
|
||||
using net::buffer_size;
|
||||
auto const n = buffer_size(buffers);
|
||||
if(body_.size() > body_.max_size() - n)
|
||||
{
|
||||
|
@ -235,7 +235,7 @@ public:
|
||||
// The type of buffer sequence returned by `get`.
|
||||
//
|
||||
using const_buffers_type =
|
||||
boost::asio::const_buffer;
|
||||
net::const_buffer;
|
||||
|
||||
// Constructor.
|
||||
//
|
||||
@ -492,11 +492,11 @@ put(ConstBufferSequence const& buffers, error_code& ec)
|
||||
|
||||
// Loop over all the buffers in the sequence,
|
||||
// and write each one to the file.
|
||||
for(auto it = boost::asio::buffer_sequence_begin(buffers);
|
||||
it != boost::asio::buffer_sequence_end(buffers); ++it)
|
||||
for(auto it = net::buffer_sequence_begin(buffers);
|
||||
it != net::buffer_sequence_end(buffers); ++it)
|
||||
{
|
||||
// Write this buffer to the file
|
||||
boost::asio::const_buffer buffer = *it;
|
||||
net::const_buffer buffer = *it;
|
||||
nwritten += body_.file_.write(
|
||||
buffer.data(), buffer.size(), ec);
|
||||
if(ec)
|
||||
|
@ -526,7 +526,7 @@ public:
|
||||
|
||||
#if ! BOOST_BEAST_DOXYGEN
|
||||
std::size_t
|
||||
put(boost::asio::const_buffer const& buffer,
|
||||
put(net::const_buffer const& buffer,
|
||||
error_code& ec);
|
||||
#endif
|
||||
|
||||
@ -540,7 +540,7 @@ public:
|
||||
|
||||
This is typically called when a read from the
|
||||
underlying stream object sets the error code to
|
||||
`boost::asio::error::eof`.
|
||||
`net::error::eof`.
|
||||
|
||||
@note Only valid after parsing a complete header.
|
||||
|
||||
|
@ -121,15 +121,15 @@ struct buffer_body
|
||||
put(ConstBufferSequence const& buffers,
|
||||
error_code& ec)
|
||||
{
|
||||
using boost::asio::buffer_size;
|
||||
using boost::asio::buffer_copy;
|
||||
using net::buffer_size;
|
||||
using net::buffer_copy;
|
||||
if(! body_.data)
|
||||
{
|
||||
ec = error::need_buffer;
|
||||
return 0;
|
||||
}
|
||||
auto const bytes_transferred =
|
||||
buffer_copy(boost::asio::buffer(
|
||||
buffer_copy(net::buffer(
|
||||
body_.data, body_.size), buffers);
|
||||
body_.data = static_cast<char*>(
|
||||
body_.data) + bytes_transferred;
|
||||
@ -163,7 +163,7 @@ struct buffer_body
|
||||
|
||||
public:
|
||||
using const_buffers_type =
|
||||
boost::asio::const_buffer;
|
||||
net::const_buffer;
|
||||
|
||||
template<bool isRequest, class Fields>
|
||||
explicit
|
||||
|
@ -32,7 +32,7 @@ namespace http {
|
||||
stream algorithm as the buffer sequence:
|
||||
@code
|
||||
// writes "\r\n"
|
||||
boost::asio::write(stream, chunk_crlf{});
|
||||
net::write(stream, chunk_crlf{});
|
||||
@endcode
|
||||
|
||||
@see https://tools.ietf.org/html/rfc7230#section-4.1
|
||||
@ -97,7 +97,7 @@ struct chunk_crlf
|
||||
stream algorithm as the buffer sequence:
|
||||
@code
|
||||
// writes "400;x\r\n"
|
||||
boost::asio::write(stream, chunk_header{1024, "x"});
|
||||
net::write(stream, chunk_header{1024, "x"});
|
||||
@endcode
|
||||
|
||||
@see https://tools.ietf.org/html/rfc7230#section-4.1
|
||||
@ -106,7 +106,7 @@ class chunk_header
|
||||
{
|
||||
using view_type = buffers_cat_view<
|
||||
detail::chunk_size, // chunk-size
|
||||
boost::asio::const_buffer, // chunk-extensions
|
||||
net::const_buffer, // chunk-extensions
|
||||
chunk_crlf>; // CRLF
|
||||
|
||||
std::shared_ptr<
|
||||
@ -285,7 +285,7 @@ class chunk_body
|
||||
{
|
||||
using view_type = buffers_cat_view<
|
||||
detail::chunk_size, // chunk-size
|
||||
boost::asio::const_buffer, // chunk-extensions
|
||||
net::const_buffer, // chunk-extensions
|
||||
chunk_crlf, // CRLF
|
||||
ConstBufferSequence, // chunk-body
|
||||
chunk_crlf>; // CRLF
|
||||
@ -459,7 +459,7 @@ class chunk_last
|
||||
{
|
||||
static_assert(
|
||||
is_fields<Trailer>::value ||
|
||||
boost::asio::is_const_buffer_sequence<Trailer>::value,
|
||||
net::is_const_buffer_sequence<Trailer>::value,
|
||||
"Trailer requirements not met");
|
||||
|
||||
using buffers_type = typename
|
||||
|
@ -26,7 +26,7 @@ namespace detail {
|
||||
struct chunk_extensions
|
||||
{
|
||||
virtual ~chunk_extensions() = default;
|
||||
virtual boost::asio::const_buffer str() = 0;
|
||||
virtual net::const_buffer str() = 0;
|
||||
};
|
||||
|
||||
template<class ChunkExtensions>
|
||||
@ -44,7 +44,7 @@ struct chunk_extensions_impl : chunk_extensions
|
||||
{
|
||||
}
|
||||
|
||||
boost::asio::const_buffer
|
||||
net::const_buffer
|
||||
str() override
|
||||
{
|
||||
auto const s = ext_.str();
|
||||
@ -88,7 +88,7 @@ class chunk_size
|
||||
|
||||
struct sequence
|
||||
{
|
||||
boost::asio::const_buffer b;
|
||||
net::const_buffer b;
|
||||
char data[1 + 2 * sizeof(std::size_t)];
|
||||
|
||||
explicit
|
||||
@ -104,7 +104,7 @@ class chunk_size
|
||||
std::shared_ptr<sequence> sp_;
|
||||
|
||||
public:
|
||||
using value_type = boost::asio::const_buffer;
|
||||
using value_type = net::const_buffer;
|
||||
|
||||
using const_iterator = value_type const*;
|
||||
|
||||
@ -136,7 +136,7 @@ public:
|
||||
|
||||
/// Returns a buffer sequence holding a CRLF for chunk encoding
|
||||
inline
|
||||
boost::asio::const_buffer
|
||||
net::const_buffer
|
||||
chunk_crlf()
|
||||
{
|
||||
return {"\r\n", 2};
|
||||
@ -144,7 +144,7 @@ chunk_crlf()
|
||||
|
||||
/// Returns a buffer sequence holding a final chunk header
|
||||
inline
|
||||
boost::asio::const_buffer
|
||||
net::const_buffer
|
||||
chunk_last()
|
||||
{
|
||||
return {"0\r\n", 3};
|
||||
@ -163,7 +163,7 @@ struct chunk_crlf_iter_type
|
||||
value_type() = default;
|
||||
|
||||
operator
|
||||
boost::asio::const_buffer() const
|
||||
net::const_buffer() const
|
||||
{
|
||||
return {s, sizeof(s)};
|
||||
}
|
||||
@ -190,7 +190,7 @@ struct chunk_size0_iter_type
|
||||
value_type() = default;
|
||||
|
||||
operator
|
||||
boost::asio::const_buffer() const
|
||||
net::const_buffer() const
|
||||
{
|
||||
return {s, sizeof(s)};
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ struct empty_body
|
||||
struct writer
|
||||
{
|
||||
using const_buffers_type =
|
||||
boost::asio::const_buffer;
|
||||
net::const_buffer;
|
||||
|
||||
template<bool isRequest, class Fields>
|
||||
explicit
|
||||
|
@ -23,7 +23,7 @@ enum class error
|
||||
/** The end of the stream was reached.
|
||||
|
||||
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
|
||||
been received.
|
||||
*/
|
||||
|
@ -85,7 +85,7 @@ public:
|
||||
char*
|
||||
data() const;
|
||||
|
||||
boost::asio::const_buffer
|
||||
net::const_buffer
|
||||
buffer() const;
|
||||
|
||||
protected:
|
||||
|
@ -91,13 +91,13 @@ basic_parser<isRequest, Derived>::
|
||||
put(ConstBufferSequence const& buffers,
|
||||
error_code& ec)
|
||||
{
|
||||
static_assert(boost::asio::is_const_buffer_sequence<
|
||||
static_assert(net::is_const_buffer_sequence<
|
||||
ConstBufferSequence>::value,
|
||||
"ConstBufferSequence requirements not met");
|
||||
using boost::asio::buffer_copy;
|
||||
using boost::asio::buffer_size;
|
||||
auto const p = boost::asio::buffer_sequence_begin(buffers);
|
||||
auto const last = boost::asio::buffer_sequence_end(buffers);
|
||||
using net::buffer_copy;
|
||||
using net::buffer_size;
|
||||
auto const p = net::buffer_sequence_begin(buffers);
|
||||
auto const last = net::buffer_sequence_end(buffers);
|
||||
if(p == last)
|
||||
{
|
||||
ec.assign(0, ec.category());
|
||||
@ -106,7 +106,7 @@ put(ConstBufferSequence const& buffers,
|
||||
if(std::next(p) == last)
|
||||
{
|
||||
// single buffer
|
||||
return put(boost::asio::const_buffer(*p), ec);
|
||||
return put(net::const_buffer(*p), ec);
|
||||
}
|
||||
auto const size = buffer_size(buffers);
|
||||
if(size <= max_stack_buffer)
|
||||
@ -118,20 +118,20 @@ put(ConstBufferSequence const& buffers,
|
||||
buf_len_ = size;
|
||||
}
|
||||
// flatten
|
||||
buffer_copy(boost::asio::buffer(
|
||||
buffer_copy(net::buffer(
|
||||
buf_.get(), buf_len_), buffers);
|
||||
return put(boost::asio::const_buffer{
|
||||
return put(net::const_buffer{
|
||||
buf_.get(), buf_len_}, ec);
|
||||
}
|
||||
|
||||
template<bool isRequest, class Derived>
|
||||
std::size_t
|
||||
basic_parser<isRequest, Derived>::
|
||||
put(boost::asio::const_buffer const& buffer,
|
||||
put(net::const_buffer const& buffer,
|
||||
error_code& ec)
|
||||
{
|
||||
BOOST_ASSERT(state_ != state::complete);
|
||||
using boost::asio::buffer_size;
|
||||
using net::buffer_size;
|
||||
auto p = static_cast<char const*>(buffer.data());
|
||||
auto n = buffer.size();
|
||||
auto const p0 = p;
|
||||
@ -304,10 +304,10 @@ put_from_stack(std::size_t size,
|
||||
error_code& ec)
|
||||
{
|
||||
char buf[max_stack_buffer];
|
||||
using boost::asio::buffer;
|
||||
using boost::asio::buffer_copy;
|
||||
using net::buffer;
|
||||
using net::buffer_copy;
|
||||
buffer_copy(buffer(buf, sizeof(buf)), buffers);
|
||||
return put(boost::asio::const_buffer{
|
||||
return put(net::const_buffer{
|
||||
buf, size}, ec);
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ chunk_header::
|
||||
chunk_header(std::size_t size)
|
||||
: view_(
|
||||
size,
|
||||
boost::asio::const_buffer{nullptr, 0},
|
||||
net::const_buffer{nullptr, 0},
|
||||
chunk_crlf{})
|
||||
{
|
||||
BOOST_ASSERT(size > 0);
|
||||
@ -37,7 +37,7 @@ chunk_header(
|
||||
string_view extensions)
|
||||
: view_(
|
||||
size,
|
||||
boost::asio::const_buffer{
|
||||
net::const_buffer{
|
||||
extensions.data(), extensions.size()},
|
||||
chunk_crlf{})
|
||||
{
|
||||
@ -89,8 +89,8 @@ template<class ConstBufferSequence>
|
||||
chunk_body<ConstBufferSequence>::
|
||||
chunk_body(ConstBufferSequence const& buffers)
|
||||
: view_(
|
||||
boost::asio::buffer_size(buffers),
|
||||
boost::asio::const_buffer{nullptr, 0},
|
||||
net::buffer_size(buffers),
|
||||
net::const_buffer{nullptr, 0},
|
||||
chunk_crlf{},
|
||||
buffers,
|
||||
chunk_crlf{})
|
||||
@ -103,8 +103,8 @@ chunk_body(
|
||||
ConstBufferSequence const& buffers,
|
||||
string_view extensions)
|
||||
: view_(
|
||||
boost::asio::buffer_size(buffers),
|
||||
boost::asio::const_buffer{
|
||||
net::buffer_size(buffers),
|
||||
net::const_buffer{
|
||||
extensions.data(), extensions.size()},
|
||||
chunk_crlf{},
|
||||
buffers,
|
||||
@ -122,7 +122,7 @@ chunk_body(
|
||||
typename std::decay<ChunkExtensions>::type>>(
|
||||
std::forward<ChunkExtensions>(extensions)))
|
||||
, view_(
|
||||
boost::asio::buffer_size(buffers),
|
||||
net::buffer_size(buffers),
|
||||
exts_->str(),
|
||||
chunk_crlf{},
|
||||
buffers,
|
||||
@ -141,7 +141,7 @@ chunk_body(
|
||||
typename std::decay<ChunkExtensions>::type>>(allocator,
|
||||
std::forward<ChunkExtensions>(extensions)))
|
||||
, view_(
|
||||
boost::asio::buffer_size(buffers),
|
||||
net::buffer_size(buffers),
|
||||
exts_->str(),
|
||||
chunk_crlf{},
|
||||
buffers,
|
||||
|
@ -44,7 +44,7 @@ public:
|
||||
{
|
||||
iter_type it_;
|
||||
|
||||
using value_type = boost::asio::const_buffer;
|
||||
using value_type = net::const_buffer;
|
||||
using pointer = value_type const*;
|
||||
using reference = value_type const;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
@ -144,9 +144,9 @@ public:
|
||||
};
|
||||
|
||||
using view_type = buffers_cat_view<
|
||||
boost::asio::const_buffer,
|
||||
boost::asio::const_buffer,
|
||||
boost::asio::const_buffer,
|
||||
net::const_buffer,
|
||||
net::const_buffer,
|
||||
net::const_buffer,
|
||||
field_range,
|
||||
chunk_crlf>;
|
||||
|
||||
@ -179,9 +179,9 @@ writer(basic_fields const& f)
|
||||
: f_(f)
|
||||
{
|
||||
view_.emplace(
|
||||
boost::asio::const_buffer{nullptr, 0},
|
||||
boost::asio::const_buffer{nullptr, 0},
|
||||
boost::asio::const_buffer{nullptr, 0},
|
||||
net::const_buffer{nullptr, 0},
|
||||
net::const_buffer{nullptr, 0},
|
||||
net::const_buffer{nullptr, 0},
|
||||
field_range(f_.list_.begin(), f_.list_.end()),
|
||||
chunk_crlf());
|
||||
}
|
||||
@ -219,11 +219,11 @@ writer(basic_fields const& f,
|
||||
buf_[10]= '\n';
|
||||
|
||||
view_.emplace(
|
||||
boost::asio::const_buffer{sv.data(), sv.size()},
|
||||
boost::asio::const_buffer{
|
||||
net::const_buffer{sv.data(), sv.size()},
|
||||
net::const_buffer{
|
||||
f_.target_or_reason_.data(),
|
||||
f_.target_or_reason_.size()},
|
||||
boost::asio::const_buffer{buf_, 11},
|
||||
net::const_buffer{buf_, 11},
|
||||
field_range(f_.list_.begin(), f_.list_.end()),
|
||||
chunk_crlf());
|
||||
}
|
||||
@ -261,9 +261,9 @@ writer(basic_fields const& f,
|
||||
sv = obsolete_reason(static_cast<status>(code));
|
||||
|
||||
view_.emplace(
|
||||
boost::asio::const_buffer{buf_, 13},
|
||||
boost::asio::const_buffer{sv.data(), sv.size()},
|
||||
boost::asio::const_buffer{"\r\n", 2},
|
||||
net::const_buffer{buf_, 13},
|
||||
net::const_buffer{sv.data(), sv.size()},
|
||||
net::const_buffer{"\r\n", 2},
|
||||
field_range(f_.list_.begin(), f_.list_.end()),
|
||||
chunk_crlf{});
|
||||
}
|
||||
@ -282,12 +282,12 @@ data() const
|
||||
}
|
||||
|
||||
template<class Allocator>
|
||||
boost::asio::const_buffer
|
||||
net::const_buffer
|
||||
basic_fields<Allocator>::
|
||||
value_type::
|
||||
buffer() const
|
||||
{
|
||||
return boost::asio::const_buffer{data(),
|
||||
return net::const_buffer{data(),
|
||||
static_cast<std::size_t>(off_) + len_ + 2};
|
||||
}
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user