Skip to content

Commit

Permalink
Fix build for Ubuntu 20.04 LTS (#451)
Browse files Browse the repository at this point in the history
* Fix deprecated API in Boost.Asio
* Use BOOST_VERSION macro to make it work for both old and new Boost versions

Cherry-pick: 52840b8
  • Loading branch information
tan-wei authored and chenshuo committed Apr 28, 2020
1 parent bd50e5c commit 46d4694
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions examples/ace/ttcp/ttcp_asio_async.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ class TtcpServerConnection : public std::enable_shared_from_this<TtcpServerConne
muduo::noncopyable
{
public:
#if BOOST_VERSION < 107000L
TtcpServerConnection(boost::asio::io_service& io_service)
: socket_(io_service), count_(0), payload_(NULL), ack_(0)
#else
TtcpServerConnection(const boost::asio::executor& executor)
: socket_(executor), count_(0), payload_(NULL), ack_(0)
#endif
{
sessionMessage_.number = 0;
sessionMessage_.length = 0;
Expand Down Expand Up @@ -143,8 +148,12 @@ typedef std::shared_ptr<TtcpServerConnection> TtcpServerConnectionPtr;

void doAccept(tcp::acceptor& acceptor)
{
#if BOOST_VERSION < 107000L
// no need to pre-create new_connection if we use asio 1.12 or boost 1.66+
TtcpServerConnectionPtr new_connection(new TtcpServerConnection(acceptor.get_io_service()));
#else
TtcpServerConnectionPtr new_connection(new TtcpServerConnection(acceptor.get_executor()));
#endif
acceptor.async_accept(
new_connection->socket(),
[&acceptor, new_connection](boost::system::error_code error) // move new_connection in C++14
Expand Down

0 comments on commit 46d4694

Please sign in to comment.