Skip to content

Commit

Permalink
Avoid deprecated Boost.Asio interfaces
Browse files Browse the repository at this point in the history
Change-Id: I00d285893ff61619f49dff8a8a55d0d0e2c309a7
  • Loading branch information
Pesa committed Nov 10, 2023
1 parent 550d8c9 commit 2f46d65
Show file tree
Hide file tree
Showing 69 changed files with 605 additions and 712 deletions.
6 changes: 5 additions & 1 deletion .waf-tools/default-compiler-flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ def getCompilerVersion(self, conf):

def getGeneralFlags(self, conf):
"""Get dict of CXXFLAGS, LINKFLAGS, and DEFINES that are always needed"""
return {'CXXFLAGS': [], 'LINKFLAGS': [], 'DEFINES': []}
return {
'CXXFLAGS': [],
'LINKFLAGS': [],
'DEFINES': ['BOOST_ASIO_NO_DEPRECATED', 'BOOST_FILESYSTEM_NO_DEPRECATED'],
}

def getDebugFlags(self, conf):
"""Get dict of CXXFLAGS, LINKFLAGS, and DEFINES that are needed only in debug mode"""
Expand Down
12 changes: 6 additions & 6 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ Consumer that uses Scheduler
The following example demonstrates how to use :ndn-cxx:`Scheduler` to schedule arbitrary
events for execution at specific points of time.

The library internally uses `boost::asio::io_service
<https://www.boost.org/doc/libs/1_65_1/doc/html/boost_asio/reference/io_service.html>`_ to
implement fully asynchronous NDN operations (i.e., sending and receiving Interests and
Data). In addition to network-related operations, ``boost::asio::io_service`` can be used
The library internally uses `boost::asio::io_context
<https://www.boost.org/doc/libs/1_71_0/doc/html/boost_asio/reference/io_context.html>`__
to implement fully asynchronous NDN operations (i.e., sending and receiving Interests and
Data). In addition to network-related operations, ``boost::asio::io_context`` can be used
to execute any arbitrary callback within the processing thread (run either explicitly via
``io_service::run()`` or implicitly via :ndn-cxx:`Face::processEvents` as in previous
examples). :ndn-cxx:`Scheduler` is just a wrapper on top of ``io_service``, providing a
``io_context::run()`` or implicitly via :ndn-cxx:`Face::processEvents` as in previous
examples). :ndn-cxx:`Scheduler` is just a wrapper on top of ``io_context``, providing a
simple interface to schedule tasks at specific times.

The highlighted lines in the example demonstrate all that is needed to express a second
Expand Down
2 changes: 1 addition & 1 deletion docs/release-notes/release-notes-0.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ Deprecated

Use versions that accept reference to ``io_service`` object.

- ``Face::ioService`` method, use :ndn-cxx:`Face::getIoService` instead.
- ``Face::ioService`` method, use ``Face::getIoService`` instead.

- :ndn-cxx:`Interest` constructor that accepts name, individual selectors, and individual
guiders as constructor parameters.
Expand Down
16 changes: 8 additions & 8 deletions examples/consumer-with-timer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2013-2022 Regents of the University of California.
* Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
Expand All @@ -22,7 +22,7 @@
#include <ndn-cxx/face.hpp>
#include <ndn-cxx/util/scheduler.hpp>

#include <boost/asio/io_service.hpp>
#include <boost/asio/io_context.hpp>
#include <iostream>

// Enclosing code in ndn simplifies coding (can also use `using namespace ndn`)
Expand Down Expand Up @@ -52,8 +52,8 @@ class ConsumerWithTimer
// Schedule a new event
m_scheduler.schedule(3_s, [this] { delayedInterest(); });

// m_ioService.run() will block until all events finished or m_ioService.stop() is called
m_ioService.run();
// m_ioCtx.run() will block until all events finished or m_ioCtx.stop() is called
m_ioCtx.run();

// Alternatively, m_face.processEvents() can also be called.
// processEvents will block until the requested data received or timeout occurs.
Expand Down Expand Up @@ -100,10 +100,10 @@ class ConsumerWithTimer
}

private:
// Explicitly create io_service object, which will be shared between Face and Scheduler
boost::asio::io_service m_ioService;
Face m_face{m_ioService};
Scheduler m_scheduler{m_ioService};
// Explicitly create io_context object, which will be shared between Face and Scheduler
boost::asio::io_context m_ioCtx;
Face m_face{m_ioCtx};
Scheduler m_scheduler{m_ioCtx};
};

} // namespace examples
Expand Down
5 changes: 0 additions & 5 deletions ndn-cxx/detail/asio-fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,8 @@
#ifndef NDN_CXX_DETAIL_ASIO_FWD_HPP
#define NDN_CXX_DETAIL_ASIO_FWD_HPP

#include <boost/version.hpp>

namespace boost::asio {

class io_context;
using io_service = io_context;

} // namespace boost::asio

#endif // NDN_CXX_DETAIL_ASIO_FWD_HPP
4 changes: 0 additions & 4 deletions ndn-cxx/detail/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ using std::weak_ptr;
using std::make_shared;
using std::make_unique;

using std::static_pointer_cast;
using std::dynamic_pointer_cast;
using std::const_pointer_cast;

using std::to_string;
using namespace std::string_literals;
using namespace std::string_view_literals;
Expand Down
2 changes: 1 addition & 1 deletion ndn-cxx/detail/tag-host.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ TagHost::getTag() const
static_assert(std::is_convertible_v<T*, Tag*>, "T must inherit from ndn::Tag");

if (auto it = m_tags.find(T::getTypeId()); it != m_tags.end()) {
return static_pointer_cast<T>(it->second);
return std::static_pointer_cast<T>(it->second);
}
return nullptr;
}
Expand Down
2 changes: 1 addition & 1 deletion ndn-cxx/encoding/encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Encoder::Encoder(size_t totalReserve, size_t reserveFromBack)
}

Encoder::Encoder(const Block& block)
: m_buffer(const_pointer_cast<Buffer>(block.getBuffer()))
: m_buffer(std::const_pointer_cast<Buffer>(block.getBuffer()))
, m_begin(m_buffer->begin() + (block.begin() - m_buffer->begin()))
, m_end(m_buffer->begin() + (block.end() - m_buffer->begin()))
{
Expand Down
Loading

0 comments on commit 2f46d65

Please sign in to comment.