Update for Net-TS Asio (API Change):

fix #769

The following classes are removed:

* handler_type
* async_result
* async_completion
* is_dynamic_buffer
* is_const_buffer_sequence
* is_mutable_buffer_sequence
* handler_alloc

Actions Required:

* Use BOOST_ASIO_HANDLER_TYPE instead of handler_type
* Use BOOST_ASIO_INITFN_RESULT_TYPE instead of async_result
* Use boost::asio::async_completion
* Use boost::asio::is_dynamic_buffer
* Use boost::asio::is_const_buffer_sequence
* Use boost::asio::is_mutable_buffer_sequence
* boost::asio::associated_allocator_t replaces handler_alloc
This commit is contained in:
Vinnie Falco
2017-09-07 07:39:52 -07:00
parent 9dc9ca13b9
commit 3a28e999af
173 changed files with 3214 additions and 4138 deletions
+66 -50
View File
@@ -19,6 +19,7 @@
#include <boost/beast/core.hpp>
#include <boost/beast/http.hpp>
#include <boost/beast/version.hpp>
#include <boost/asio/bind_executor.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/ssl/stream.hpp>
#include <boost/asio/strand.hpp>
@@ -255,12 +256,14 @@ class session
http::async_write(
self_.derived().stream(),
*sp,
self_.strand_.wrap(std::bind(
&session::on_write,
self_.derived().shared_from_this(),
std::placeholders::_1,
std::placeholders::_2,
! sp->keep_alive())));
boost::asio::bind_executor(
self_.strand_,
std::bind(
&session::on_write,
self_.derived().shared_from_this(),
std::placeholders::_1,
std::placeholders::_2,
! sp->keep_alive())));
}
};
@@ -270,19 +273,20 @@ class session
send_lambda lambda_;
protected:
boost::asio::io_service::strand strand_;
boost::asio::strand<
boost::asio::io_context::executor_type> strand_;
boost::beast::flat_buffer buffer_;
public:
// Take ownership of the buffer
explicit
session(
boost::asio::io_service& ios,
boost::asio::io_context& ioc,
boost::beast::flat_buffer buffer,
std::string const& doc_root)
: doc_root_(doc_root)
, lambda_(*this)
, strand_(ios)
, strand_(ioc.get_executor())
, buffer_(std::move(buffer))
{
}
@@ -295,11 +299,13 @@ public:
derived().stream(),
buffer_,
req_,
strand_.wrap(std::bind(
&session::on_read,
derived().shared_from_this(),
std::placeholders::_1,
std::placeholders::_2)));
boost::asio::bind_executor(
strand_,
std::bind(
&session::on_read,
derived().shared_from_this(),
std::placeholders::_1,
std::placeholders::_2)));
}
void
@@ -352,7 +358,8 @@ class plain_session
, public std::enable_shared_from_this<plain_session>
{
tcp::socket socket_;
boost::asio::io_service::strand strand_;
boost::asio::strand<
boost::asio::io_context::executor_type> strand_;
public:
// Create the session
@@ -361,11 +368,11 @@ public:
boost::beast::flat_buffer buffer,
std::string const& doc_root)
: session<plain_session>(
socket.get_io_service(),
socket.get_executor().context(),
std::move(buffer),
doc_root)
, socket_(std::move(socket))
, strand_(socket_.get_io_service())
, strand_(socket_.get_executor())
{
}
@@ -401,7 +408,8 @@ class ssl_session
{
tcp::socket socket_;
ssl::stream<tcp::socket&> stream_;
boost::asio::io_service::strand strand_;
boost::asio::strand<
boost::asio::io_context::executor_type> strand_;
public:
// Create the session
@@ -411,12 +419,12 @@ public:
boost::beast::flat_buffer buffer,
std::string const& doc_root)
: session<ssl_session>(
socket.get_io_service(),
socket.get_executor().context(),
std::move(buffer),
doc_root)
, socket_(std::move(socket))
, stream_(socket_, ctx)
, strand_(stream_.get_io_service())
, strand_(stream_.get_executor())
{
}
@@ -436,11 +444,13 @@ public:
stream_.async_handshake(
ssl::stream_base::server,
buffer_.data(),
strand_.wrap(std::bind(
&ssl_session::on_handshake,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2)));
boost::asio::bind_executor(
strand_,
std::bind(
&ssl_session::on_handshake,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2)));
}
void
on_handshake(
@@ -461,10 +471,12 @@ public:
{
// Perform the SSL shutdown
stream_.async_shutdown(
strand_.wrap(std::bind(
&ssl_session::on_shutdown,
shared_from_this(),
std::placeholders::_1)));
boost::asio::bind_executor(
strand_,
std::bind(
&ssl_session::on_shutdown,
shared_from_this(),
std::placeholders::_1)));
}
void
@@ -484,7 +496,8 @@ class detect_session : public std::enable_shared_from_this<detect_session>
{
tcp::socket socket_;
ssl::context& ctx_;
boost::asio::io_service::strand strand_;
boost::asio::strand<
boost::asio::io_context::executor_type> strand_;
std::string const& doc_root_;
boost::beast::flat_buffer buffer_;
@@ -496,7 +509,7 @@ public:
std::string const& doc_root)
: socket_(std::move(socket))
, ctx_(ctx)
, strand_(socket_.get_io_service())
, strand_(socket_.get_executor())
, doc_root_(doc_root)
{
}
@@ -508,11 +521,13 @@ public:
async_detect_ssl(
socket_,
buffer_,
strand_.wrap(std::bind(
&detect_session::on_detect,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2)));
boost::asio::bind_executor(
strand_,
std::bind(
&detect_session::on_detect,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2)));
}
@@ -545,21 +560,22 @@ public:
class listener : public std::enable_shared_from_this<listener>
{
ssl::context& ctx_;
boost::asio::io_service::strand strand_;
boost::asio::strand<
boost::asio::io_context::executor_type> strand_;
tcp::acceptor acceptor_;
tcp::socket socket_;
std::string const& doc_root_;
public:
listener(
boost::asio::io_service& ios,
boost::asio::io_context& ioc,
ssl::context& ctx,
tcp::endpoint endpoint,
std::string const& doc_root)
: ctx_(ctx)
, strand_(ios)
, acceptor_(ios)
, socket_(ios)
, strand_(ioc.get_executor())
, acceptor_(ioc)
, socket_(ioc)
, doc_root_(doc_root)
{
boost::system::error_code ec;
@@ -582,7 +598,7 @@ public:
// Start listening for connections
acceptor_.listen(
boost::asio::socket_base::max_connections, ec);
boost::asio::socket_base::max_listen_connections, ec);
if(ec)
{
fail(ec, "listen");
@@ -644,13 +660,13 @@ int main(int argc, char* argv[])
" http-server-sync 0.0.0.0 8080 .\n";
return EXIT_FAILURE;
}
auto const address = boost::asio::ip::address::from_string(argv[1]);
auto const address = boost::asio::ip::make_address(argv[1]);
auto const port = static_cast<unsigned short>(std::atoi(argv[2]));
std::string const doc_root = argv[3];
auto const threads = std::max<std::size_t>(1, std::atoi(argv[4]));
auto const threads = std::max<int>(1, std::atoi(argv[4]));
// The io_service is required for all I/O
boost::asio::io_service ios{threads};
// The io_context is required for all I/O
boost::asio::io_context ioc{threads};
// The SSL context is required, and holds certificates
ssl::context ctx{ssl::context::sslv23};
@@ -660,7 +676,7 @@ int main(int argc, char* argv[])
// Create and launch a listening port
std::make_shared<listener>(
ios,
ioc,
ctx,
tcp::endpoint{address, port},
doc_root)->run();
@@ -670,11 +686,11 @@ int main(int argc, char* argv[])
v.reserve(threads - 1);
for(auto i = threads - 1; i > 0; --i)
v.emplace_back(
[&ios]
[&ioc]
{
ios.run();
ioc.run();
});
ios.run();
ioc.run();
return EXIT_SUCCESS;
}