daemon: use asio::defer() instead of asio::post() where appropriate
Change-Id: I24d0fab6499d6430dd500ca157daa87f48960d15
diff --git a/daemon/face/datagram-transport.hpp b/daemon/face/datagram-transport.hpp
index 51f06a0..cbef9ba 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 <array>
+#include <boost/asio/defer.hpp>
+
namespace nfd::face {
struct Unicast {};
@@ -149,7 +151,7 @@
// 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 a1c23f2..a76b0b6 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 <pcap/pcap.h>
+#include <boost/asio/defer.hpp>
#include <boost/endian/conversion.hpp>
namespace nfd::face {
@@ -87,7 +88,7 @@
// 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 2eeab51..a61f227 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 <boost/asio/post.hpp>
+
namespace nfd::face {
NFD_LOG_MEMBER_INIT(InternalForwarderTransport, InternalForwarderTransport);
@@ -47,7 +49,7 @@
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 @@
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 b6ad18b..c8b0ac3 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 <queue>
+#include <boost/asio/defer.hpp>
#include <boost/asio/write.hpp>
namespace nfd::face {
@@ -149,7 +150,7 @@
// 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 45bc952..15c0769 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 <boost/asio/defer.hpp>
+
#if defined(__linux__)
#include <linux/sockios.h>
#include <sys/ioctl.h>
@@ -105,7 +107,7 @@
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 @@
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 fe3a6ab..9a2fe4c 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 <boost/asio/defer.hpp>
+
namespace nfd {
NFD_LOG_INIT(FaceTable);
@@ -100,7 +102,7 @@
" 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 4943672..7149680 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 <boost/asio/defer.hpp>
+
#include <ndn-cxx/lp/tags.hpp>
#include <ndn-cxx/mgmt/nfd/rib-entry.hpp>
#include <ndn-cxx/mgmt/nfd/status-dataset.hpp>
@@ -446,11 +448,12 @@
{
NFD_LOG_DEBUG("Checking for invalid face registrations");
- std::set<uint64_t> activeFaceIds;
+ std::set<uint64_t> 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 @@
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); });
}
}