daemon: Properly handle exception from NetworkMonitor when the platform doesn't support it
Change-Id: I713a6b6ebe4ac1e49f939325c7372954cb28e159
Refs: #3195
diff --git a/daemon/nfd.cpp b/daemon/nfd.cpp
index 7d68de3..44b0579 100644
--- a/daemon/nfd.cpp
+++ b/daemon/nfd.cpp
@@ -49,17 +49,29 @@
static const std::string INTERNAL_CONFIG = "internal://nfd.conf";
+static inline ndn::util::NetworkMonitor*
+makeNetworkMonitor()
+{
+ try {
+ return new ndn::util::NetworkMonitor(getGlobalIoService());
+ }
+ catch (const ndn::util::NetworkMonitor::Error& e) {
+ NFD_LOG_WARN(e.what());
+ return nullptr;
+ }
+}
+
Nfd::Nfd(const std::string& configFile, ndn::KeyChain& keyChain)
: m_configFile(configFile)
, m_keyChain(keyChain)
- , m_networkMonitor(getGlobalIoService())
+ , m_networkMonitor(makeNetworkMonitor())
{
}
Nfd::Nfd(const ConfigSection& config, ndn::KeyChain& keyChain)
: m_configSection(config)
, m_keyChain(keyChain)
- , m_networkMonitor(getGlobalIoService())
+ , m_networkMonitor(makeNetworkMonitor())
{
}
@@ -85,15 +97,17 @@
PrivilegeHelper::drop();
- m_networkMonitor.onNetworkStateChanged.connect([this] {
- // delay stages, so if multiple events are triggered in short sequence,
- // only one auto-detection procedure is triggered
- m_reloadConfigEvent = scheduler::schedule(time::seconds(5),
- [this] {
- NFD_LOG_INFO("Network change detected, reloading face section of the config file...");
- this->reloadConfigFileFaceSection();
- });
- });
+ if (m_networkMonitor) {
+ m_networkMonitor->onNetworkStateChanged.connect([this] {
+ // delay stages, so if multiple events are triggered in short sequence,
+ // only one auto-detection procedure is triggered
+ m_reloadConfigEvent = scheduler::schedule(time::seconds(5),
+ [this] {
+ NFD_LOG_INFO("Network change detected, reloading face section of the config file...");
+ this->reloadConfigFileFaceSection();
+ });
+ });
+ }
}
void
diff --git a/daemon/nfd.hpp b/daemon/nfd.hpp
index 34111b3..5801499 100644
--- a/daemon/nfd.hpp
+++ b/daemon/nfd.hpp
@@ -107,10 +107,10 @@
unique_ptr<Forwarder> m_forwarder;
- ndn::KeyChain& m_keyChain;
- shared_ptr<InternalFace> m_internalFace;
- shared_ptr<InternalClientFace> m_internalClientFace;
- unique_ptr<CommandValidator> m_validator;
+ ndn::KeyChain& m_keyChain;
+ shared_ptr<InternalFace> m_internalFace;
+ shared_ptr<InternalClientFace> m_internalClientFace;
+ unique_ptr<CommandValidator> m_validator;
unique_ptr<ndn::mgmt::Dispatcher> m_dispatcher;
unique_ptr<FibManager> m_fibManager;
@@ -118,8 +118,8 @@
unique_ptr<StrategyChoiceManager> m_strategyChoiceManager;
unique_ptr<ForwarderStatusManager> m_forwarderStatusManager;
- ndn::util::NetworkMonitor m_networkMonitor;
- scheduler::ScopedEventId m_reloadConfigEvent;
+ unique_ptr<ndn::util::NetworkMonitor> m_networkMonitor;
+ scheduler::ScopedEventId m_reloadConfigEvent;
};
} // namespace nfd