diff --git a/daemon/face/datagram-transport.hpp b/daemon/face/datagram-transport.hpp index 51f06a0d..cbef9baf 100644 --- a/daemon/face/datagram-transport.hpp +++ b/daemon/face/datagram-transport.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2022, Regents of the University of California, + * Copyright (c) 2014-2023, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -32,6 +32,8 @@ #include +#include + namespace nfd::face { struct Unicast {}; @@ -149,7 +151,7 @@ DatagramTransport::doClose() // Ensure that the Transport stays alive at least until // all pending handlers are dispatched - getGlobalIoService().post([this] { + boost::asio::defer(getGlobalIoService(), [this] { this->setState(TransportState::CLOSED); }); } diff --git a/daemon/face/ethernet-transport.cpp b/daemon/face/ethernet-transport.cpp index a1c23f27..a76b0b60 100644 --- a/daemon/face/ethernet-transport.cpp +++ b/daemon/face/ethernet-transport.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2022, Regents of the University of California, + * Copyright (c) 2014-2023, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -29,6 +29,7 @@ #include +#include #include namespace nfd::face { @@ -87,7 +88,7 @@ EthernetTransport::doClose() // Ensure that the Transport stays alive at least // until all pending handlers are dispatched - getGlobalIoService().post([this] { + boost::asio::defer(getGlobalIoService(), [this] { this->setState(TransportState::CLOSED); }); } diff --git a/daemon/face/internal-transport.cpp b/daemon/face/internal-transport.cpp index 2eeab511..a61f2275 100644 --- a/daemon/face/internal-transport.cpp +++ b/daemon/face/internal-transport.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2022, Regents of the University of California, + * Copyright (c) 2014-2023, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -26,6 +26,8 @@ #include "internal-transport.hpp" #include "common/global.hpp" +#include + namespace nfd::face { NFD_LOG_MEMBER_INIT(InternalForwarderTransport, InternalForwarderTransport); @@ -47,7 +49,7 @@ InternalForwarderTransport::InternalForwarderTransport(const FaceUri& localUri, void InternalForwarderTransport::receivePacket(const Block& packet) { - getGlobalIoService().post([this, packet] { + boost::asio::post(getGlobalIoService(), [this, packet] { NFD_LOG_FACE_TRACE("Received: " << packet.size() << " bytes"); receive(packet); }); @@ -105,7 +107,7 @@ InternalClientTransport::connectToForwarder(InternalForwarderTransport* forwarde void InternalClientTransport::receivePacket(const Block& packet) { - getGlobalIoService().post([this, packet] { + boost::asio::post(getGlobalIoService(), [this, packet] { NFD_LOG_TRACE("Received: " << packet.size() << " bytes"); if (m_receiveCallback) { m_receiveCallback(packet); diff --git a/daemon/face/stream-transport.hpp b/daemon/face/stream-transport.hpp index b6ad18b4..c8b0ac37 100644 --- a/daemon/face/stream-transport.hpp +++ b/daemon/face/stream-transport.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2022, Regents of the University of California, + * Copyright (c) 2014-2023, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -32,6 +32,7 @@ #include +#include #include namespace nfd::face { @@ -149,7 +150,7 @@ StreamTransport::doClose() // Ensure that the Transport stays alive at least until // all pending handlers are dispatched - getGlobalIoService().post([this] { deferredClose(); }); + boost::asio::defer(getGlobalIoService(), [this] { deferredClose(); }); // Some bug or feature of Boost.Asio (see https://redmine.named-data.net/issues/1856): // diff --git a/daemon/face/tcp-transport.cpp b/daemon/face/tcp-transport.cpp index 45bc952c..15c07699 100644 --- a/daemon/face/tcp-transport.cpp +++ b/daemon/face/tcp-transport.cpp @@ -26,6 +26,8 @@ #include "tcp-transport.hpp" #include "common/global.hpp" +#include + #if defined(__linux__) #include #include @@ -105,7 +107,7 @@ TcpTransport::handleError(const boost::system::error_code& error) m_socket.cancel(ec); // do this asynchronously because there could be some callbacks still pending - getGlobalIoService().post([this] { reconnect(); }); + boost::asio::defer(getGlobalIoService(), [this] { reconnect(); }); } else { StreamTransport::handleError(error); @@ -175,7 +177,7 @@ TcpTransport::handleReconnectTimeout() MAX_RECONNECT_DELAY); // do this asynchronously because there could be some callbacks still pending - getGlobalIoService().post([this] { reconnect(); }); + boost::asio::defer(getGlobalIoService(), [this] { reconnect(); }); } void diff --git a/daemon/fw/face-table.cpp b/daemon/fw/face-table.cpp index fe3a6ab4..9a2fe4ce 100644 --- a/daemon/fw/face-table.cpp +++ b/daemon/fw/face-table.cpp @@ -28,6 +28,8 @@ #include "common/logger.hpp" #include "face/channel.hpp" +#include + namespace nfd { NFD_LOG_INIT(FaceTable); @@ -100,7 +102,7 @@ FaceTable::remove(FaceId faceId) " local=" << face->getLocalUri()); // defer Face deallocation, so that Transport isn't deallocated during afterStateChange signal - getGlobalIoService().post([face] {}); + boost::asio::defer(getGlobalIoService(), [face] {}); } FaceTable::ForwardRange diff --git a/daemon/mgmt/rib-manager.cpp b/daemon/mgmt/rib-manager.cpp index 49436726..71496806 100644 --- a/daemon/mgmt/rib-manager.cpp +++ b/daemon/mgmt/rib-manager.cpp @@ -30,6 +30,8 @@ #include "rib/rib.hpp" #include "table/fib.hpp" +#include + #include #include #include @@ -446,11 +448,12 @@ RibManager::removeInvalidFaces(const std::vector& activeFa { NFD_LOG_DEBUG("Checking for invalid face registrations"); - std::set activeFaceIds; + std::set activeIds; for (const auto& faceStatus : activeFaces) { - activeFaceIds.insert(faceStatus.getFaceId()); + activeIds.insert(faceStatus.getFaceId()); } - getGlobalIoService().post([=] { m_rib.beginRemoveFailedFaces(activeFaceIds); }); + boost::asio::defer(getGlobalIoService(), + [this, active = std::move(activeIds)] { m_rib.beginRemoveFailedFaces(active); }); // Reschedule the check for future clean up scheduleActiveFaceFetch(ACTIVE_FACE_FETCH_INTERVAL); @@ -463,7 +466,8 @@ RibManager::onNotification(const ndn::nfd::FaceEventNotification& notification) if (notification.getKind() == ndn::nfd::FACE_EVENT_DESTROYED) { NFD_LOG_DEBUG("Received notification for destroyed FaceId " << notification.getFaceId()); - getGlobalIoService().post([this, id = notification.getFaceId()] { m_rib.beginRemoveFace(id); }); + boost::asio::defer(getGlobalIoService(), + [this, id = notification.getFaceId()] { m_rib.beginRemoveFace(id); }); } } diff --git a/tests/daemon/face/tcp-channel-fixture.hpp b/tests/daemon/face/tcp-channel-fixture.hpp index b6eb99c0..557eeb83 100644 --- a/tests/daemon/face/tcp-channel-fixture.hpp +++ b/tests/daemon/face/tcp-channel-fixture.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2022, Regents of the University of California, + * Copyright (c) 2014-2023, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -31,6 +31,8 @@ #include "channel-fixture.hpp" +#include + namespace nfd::tests { using face::TcpChannel; @@ -57,7 +59,7 @@ protected: void connect(TcpChannel& channel) final { - g_io.post([&] { + boost::asio::defer(g_io, [&] { channel.connect(listenerEp, {}, [this] (const shared_ptr& newFace) { BOOST_REQUIRE(newFace != nullptr); diff --git a/tests/daemon/face/udp-channel-fixture.hpp b/tests/daemon/face/udp-channel-fixture.hpp index a314a8c2..63caf9ac 100644 --- a/tests/daemon/face/udp-channel-fixture.hpp +++ b/tests/daemon/face/udp-channel-fixture.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2022, Regents of the University of California, + * Copyright (c) 2014-2023, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -31,6 +31,8 @@ #include "channel-fixture.hpp" +#include + namespace nfd::tests { using face::UdpChannel; @@ -52,7 +54,7 @@ protected: void connect(UdpChannel& channel) final { - g_io.post([&] { + boost::asio::defer(g_io, [&] { channel.connect(listenerEp, {}, [this] (const shared_ptr& newFace) { BOOST_REQUIRE(newFace != nullptr); diff --git a/tests/daemon/mgmt/rib-manager.t.cpp b/tests/daemon/mgmt/rib-manager.t.cpp index 8ae96aed..0b407f6d 100644 --- a/tests/daemon/mgmt/rib-manager.t.cpp +++ b/tests/daemon/mgmt/rib-manager.t.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2022, Regents of the University of California, + * Copyright (c) 2014-2023, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -185,7 +185,7 @@ private: data->setContent(resp.wireEncode()); m_keyChain.sign(*data, ndn::security::SigningInfo(ndn::security::SigningInfo::SIGNER_TYPE_SHA256)); - m_face.getIoService().post([this, data] { m_face.receive(*data); }); + boost::asio::post(m_face.getIoService(), [this, data] { m_face.receive(*data); }); }; const Name commandPrefix("/localhost/nfd/fib/add-nexthop"); diff --git a/tests/daemon/rib/fib-updates-common.hpp b/tests/daemon/rib/fib-updates-common.hpp index 33b549d2..15e623f9 100644 --- a/tests/daemon/rib/fib-updates-common.hpp +++ b/tests/daemon/rib/fib-updates-common.hpp @@ -33,6 +33,8 @@ #include "tests/daemon/global-io-fixture.hpp" #include "tests/daemon/rib/create-route.hpp" +#include + #include namespace nfd::tests { @@ -80,7 +82,7 @@ private: uint32_t nTimeouts) { updates.push_back(update); - getGlobalIoService().post([=] { + boost::asio::defer(getGlobalIoService(), [=] { if (mockSuccess) { onUpdateSuccess(update, onSuccess, onFailure); } diff --git a/tests/tools/mock-nfd-mgmt-fixture.hpp b/tests/tools/mock-nfd-mgmt-fixture.hpp index ede5568a..eed9846e 100644 --- a/tests/tools/mock-nfd-mgmt-fixture.hpp +++ b/tests/tools/mock-nfd-mgmt-fixture.hpp @@ -34,6 +34,7 @@ #include #include +#include #include namespace nfd::tests { @@ -52,7 +53,7 @@ protected: { face.onSendInterest.connect([this] (const Interest& interest) { if (processInterest) { - m_io.post([=] { processInterest(interest); }); + boost::asio::defer(m_io, [=] { processInterest(interest); }); } }); }