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