修改红绿灯服务,使用 boost::asio::placeholders::error 代替 boost::bind
This commit is contained in:
parent
052c983fce
commit
2ff5de97c7
@ -5,10 +5,12 @@
|
||||
#include <boost/asio/signal_set.hpp>
|
||||
#include <boost/asio/strand.hpp>
|
||||
#include <boost/asio/bind_executor.hpp>
|
||||
#include <boost/asio/placeholders.hpp>
|
||||
#include <boost/beast/core.hpp>
|
||||
#include <boost/beast/http.hpp>
|
||||
#include <boost/beast/version.hpp>
|
||||
#include <boost/bind/bind.hpp>
|
||||
#include <boost/bind/placeholders.hpp>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
@ -103,12 +105,12 @@ namespace network {
|
||||
explicit TrafficLightSession(tcp::socket&& socket, std::string const& doc_root, net::io_context& ioc, System& system_ref)
|
||||
: socket_(std::move(socket)),
|
||||
doc_root_(doc_root),
|
||||
strand_(net::make_strand(ioc.get_executor())),
|
||||
strand_(ioc.get_executor()),
|
||||
ioc_(ioc),
|
||||
system_(system_ref) {}
|
||||
|
||||
void run() {
|
||||
net::dispatch(strand_, beast::bind_front_handler(&TrafficLightSession::do_read, shared_from_this()));
|
||||
net::dispatch(strand_, boost::bind(&TrafficLightSession::do_read, shared_from_this()));
|
||||
}
|
||||
|
||||
private:
|
||||
@ -116,7 +118,9 @@ namespace network {
|
||||
req_ = {};
|
||||
http::async_read(socket_, buffer_, req_,
|
||||
net::bind_executor(strand_,
|
||||
beast::bind_front_handler(&TrafficLightSession::on_read, shared_from_this())
|
||||
boost::bind(&TrafficLightSession::on_read, shared_from_this(),
|
||||
boost::asio::placeholders::error,
|
||||
boost::asio::placeholders::bytes_transferred)
|
||||
));
|
||||
}
|
||||
|
||||
@ -270,9 +274,11 @@ namespace network {
|
||||
void do_accept() {
|
||||
acceptor_.async_accept(
|
||||
net::bind_executor(acceptor_.get_executor(),
|
||||
beast::bind_front_handler(
|
||||
&TrafficLightListener::on_accept,
|
||||
shared_from_this())));
|
||||
boost::bind(&TrafficLightListener::on_accept, shared_from_this(),
|
||||
boost::asio::placeholders::error,
|
||||
boost::placeholders::_2)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
void on_accept(beast::error_code ec, tcp::socket socket) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user