Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 2 | /** |
Junxiao Shi | 446de3c | 2016-07-25 22:38:16 +0000 | [diff] [blame^] | 3 | * Copyright (c) 2013-2016 Regents of the University of California. |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #ifndef NDN_DETAIL_FACE_IMPL_HPP |
| 23 | #define NDN_DETAIL_FACE_IMPL_HPP |
| 24 | |
| 25 | #include "../common.hpp" |
| 26 | #include "../face.hpp" |
| 27 | |
| 28 | #include "registered-prefix.hpp" |
| 29 | #include "pending-interest.hpp" |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 30 | #include "container-with-on-empty-signal.hpp" |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 31 | |
| 32 | #include "../util/scheduler.hpp" |
| 33 | #include "../util/config-file.hpp" |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 34 | #include "../util/signal.hpp" |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 35 | |
Junxiao Shi | 0fa2845 | 2014-12-13 22:02:36 -0700 | [diff] [blame] | 36 | #include "../transport/transport.hpp" |
| 37 | #include "../transport/unix-transport.hpp" |
| 38 | #include "../transport/tcp-transport.hpp" |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 39 | |
Junxiao Shi | 0fa2845 | 2014-12-13 22:02:36 -0700 | [diff] [blame] | 40 | #include "../management/nfd-controller.hpp" |
| 41 | #include "../management/nfd-command-options.hpp" |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 42 | |
| 43 | #include "../lp/packet.hpp" |
Junxiao Shi | 4b46998 | 2015-12-03 18:20:19 +0000 | [diff] [blame] | 44 | #include "../lp/tags.hpp" |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 45 | |
| 46 | namespace ndn { |
| 47 | |
| 48 | class Face::Impl : noncopyable |
| 49 | { |
| 50 | public: |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 51 | typedef ContainerWithOnEmptySignal<shared_ptr<PendingInterest>> PendingInterestTable; |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 52 | typedef std::list<shared_ptr<InterestFilterRecord> > InterestFilterTable; |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 53 | typedef ContainerWithOnEmptySignal<shared_ptr<RegisteredPrefix>> RegisteredPrefixTable; |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 54 | |
| 55 | explicit |
| 56 | Impl(Face& face) |
| 57 | : m_face(face) |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 58 | , m_scheduler(m_face.getIoService()) |
| 59 | , m_processEventsTimeoutEvent(m_scheduler) |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 60 | { |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 61 | auto postOnEmptyPitOrNoRegisteredPrefixes = [this] { |
| 62 | this->m_face.getIoService().post(bind(&Impl::onEmptyPitOrNoRegisteredPrefixes, this)); |
| 63 | // without this extra "post", transport can get paused (-async_read) and then resumed |
| 64 | // (+async_read) from within onInterest/onData callback. After onInterest/onData |
| 65 | // finishes, there is another +async_read with the same memory block. A few of such |
| 66 | // async_read duplications can cause various effects and result in segfault. |
| 67 | }; |
| 68 | |
| 69 | m_pendingInterestTable.onEmpty.connect(postOnEmptyPitOrNoRegisteredPrefixes); |
| 70 | m_registeredPrefixTable.onEmpty.connect(postOnEmptyPitOrNoRegisteredPrefixes); |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | ///////////////////////////////////////////////////////////////////////////////////////////////// |
| 74 | ///////////////////////////////////////////////////////////////////////////////////////////////// |
| 75 | |
| 76 | void |
| 77 | satisfyPendingInterests(Data& data) |
| 78 | { |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 79 | for (auto entry = m_pendingInterestTable.begin(); entry != m_pendingInterestTable.end(); ) { |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 80 | if ((*entry)->getInterest()->matchesData(data)) { |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 81 | shared_ptr<PendingInterest> matchedEntry = *entry; |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 82 | |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 83 | entry = m_pendingInterestTable.erase(entry); |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 84 | |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 85 | matchedEntry->invokeDataCallback(data); |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 86 | } |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 87 | else |
| 88 | ++entry; |
| 89 | } |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | void |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 93 | nackPendingInterests(const lp::Nack& nack) |
| 94 | { |
| 95 | for (auto entry = m_pendingInterestTable.begin(); entry != m_pendingInterestTable.end(); ) { |
| 96 | const Interest& pendingInterest = *(*entry)->getInterest(); |
| 97 | if (pendingInterest == nack.getInterest()) { |
| 98 | shared_ptr<PendingInterest> matchedEntry = *entry; |
| 99 | |
| 100 | entry = m_pendingInterestTable.erase(entry); |
| 101 | |
| 102 | matchedEntry->invokeNackCallback(nack); |
| 103 | } |
| 104 | else { |
| 105 | ++entry; |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | void |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 111 | processInterestFilters(Interest& interest) |
| 112 | { |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 113 | for (const auto& filter : m_interestFilterTable) { |
| 114 | if (filter->doesMatch(interest.getName())) { |
| 115 | filter->invokeInterestCallback(interest); |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 116 | } |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 117 | } |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | ///////////////////////////////////////////////////////////////////////////////////////////////// |
| 121 | ///////////////////////////////////////////////////////////////////////////////////////////////// |
| 122 | |
| 123 | void |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 124 | ensureConnected(bool wantResume) |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 125 | { |
Alexander Afanasyev | 407e949 | 2014-07-10 18:50:44 -0700 | [diff] [blame] | 126 | if (!m_face.m_transport->isConnected()) |
Junxiao Shi | 2cced06 | 2014-11-02 21:27:38 -0700 | [diff] [blame] | 127 | m_face.m_transport->connect(m_face.m_ioService, |
Alexander Afanasyev | 407e949 | 2014-07-10 18:50:44 -0700 | [diff] [blame] | 128 | bind(&Face::onReceiveElement, &m_face, _1)); |
| 129 | |
Junxiao Shi | 446de3c | 2016-07-25 22:38:16 +0000 | [diff] [blame^] | 130 | if (wantResume && !m_face.m_transport->isReceiving()) |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 131 | m_face.m_transport->resume(); |
Junxiao Shi | a1ea506 | 2014-12-27 22:33:39 -0700 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | void |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 135 | asyncExpressInterest(shared_ptr<const Interest> interest, |
| 136 | const DataCallback& afterSatisfied, |
| 137 | const NackCallback& afterNacked, |
| 138 | const TimeoutCallback& afterTimeout) |
Junxiao Shi | a1ea506 | 2014-12-27 22:33:39 -0700 | [diff] [blame] | 139 | { |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 140 | this->ensureConnected(true); |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 141 | |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 142 | auto entry = |
| 143 | m_pendingInterestTable.insert(make_shared<PendingInterest>(interest, |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 144 | afterSatisfied, |
| 145 | afterNacked, |
| 146 | afterTimeout, |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 147 | ref(m_scheduler))).first; |
| 148 | (*entry)->setDeleter([this, entry] { m_pendingInterestTable.erase(entry); }); |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 149 | |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 150 | lp::Packet packet; |
| 151 | |
Junxiao Shi | 4b46998 | 2015-12-03 18:20:19 +0000 | [diff] [blame] | 152 | shared_ptr<lp::NextHopFaceIdTag> nextHopFaceIdTag = interest->getTag<lp::NextHopFaceIdTag>(); |
| 153 | if (nextHopFaceIdTag != nullptr) { |
| 154 | packet.add<lp::NextHopFaceIdField>(*nextHopFaceIdTag); |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 155 | } |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 156 | |
| 157 | packet.add<lp::FragmentField>(std::make_pair(interest->wireEncode().begin(), |
| 158 | interest->wireEncode().end())); |
| 159 | |
| 160 | m_face.m_transport->send(packet.wireEncode()); |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | void |
| 164 | asyncRemovePendingInterest(const PendingInterestId* pendingInterestId) |
| 165 | { |
| 166 | m_pendingInterestTable.remove_if(MatchPendingInterestId(pendingInterestId)); |
| 167 | } |
| 168 | |
Alexander Afanasyev | 6a05b4b | 2014-07-18 17:23:00 -0700 | [diff] [blame] | 169 | void |
Ilya Moiseenko | 56b0bf8 | 2015-11-08 11:14:28 -0500 | [diff] [blame] | 170 | asyncRemoveAllPendingInterests() |
| 171 | { |
| 172 | m_pendingInterestTable.clear(); |
| 173 | } |
| 174 | |
| 175 | void |
Alexander Afanasyev | 6a05b4b | 2014-07-18 17:23:00 -0700 | [diff] [blame] | 176 | asyncPutData(const shared_ptr<const Data>& data) |
| 177 | { |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 178 | this->ensureConnected(true); |
Alexander Afanasyev | 6a05b4b | 2014-07-18 17:23:00 -0700 | [diff] [blame] | 179 | |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 180 | lp::Packet packet; |
| 181 | |
Junxiao Shi | 4b46998 | 2015-12-03 18:20:19 +0000 | [diff] [blame] | 182 | shared_ptr<lp::CachePolicyTag> cachePolicyTag = data->getTag<lp::CachePolicyTag>(); |
| 183 | if (cachePolicyTag != nullptr) { |
| 184 | packet.add<lp::CachePolicyField>(*cachePolicyTag); |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 185 | } |
Eric Newberry | 83872fd | 2015-08-06 17:01:24 -0700 | [diff] [blame] | 186 | |
| 187 | packet.add<lp::FragmentField>(std::make_pair(data->wireEncode().begin(), |
| 188 | data->wireEncode().end())); |
| 189 | |
| 190 | m_face.m_transport->send(packet.wireEncode()); |
| 191 | } |
| 192 | |
| 193 | void |
| 194 | asyncPutNack(shared_ptr<const lp::Nack> nack) |
| 195 | { |
| 196 | this->ensureConnected(true); |
| 197 | |
| 198 | lp::Packet packet; |
| 199 | packet.add<lp::NackField>(nack->getHeader()); |
| 200 | |
| 201 | Block interest = nack->getInterest().wireEncode(); |
| 202 | packet.add<lp::FragmentField>(std::make_pair(interest.begin(), interest.end())); |
| 203 | |
| 204 | m_face.m_transport->send(packet.wireEncode()); |
Alexander Afanasyev | 6a05b4b | 2014-07-18 17:23:00 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 207 | ///////////////////////////////////////////////////////////////////////////////////////////////// |
| 208 | ///////////////////////////////////////////////////////////////////////////////////////////////// |
| 209 | |
| 210 | void |
| 211 | asyncSetInterestFilter(const shared_ptr<InterestFilterRecord>& interestFilterRecord) |
| 212 | { |
| 213 | m_interestFilterTable.push_back(interestFilterRecord); |
| 214 | } |
| 215 | |
| 216 | void |
| 217 | asyncUnsetInterestFilter(const InterestFilterId* interestFilterId) |
| 218 | { |
| 219 | InterestFilterTable::iterator i = std::find_if(m_interestFilterTable.begin(), |
| 220 | m_interestFilterTable.end(), |
| 221 | MatchInterestFilterId(interestFilterId)); |
| 222 | if (i != m_interestFilterTable.end()) |
| 223 | { |
| 224 | m_interestFilterTable.erase(i); |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | ///////////////////////////////////////////////////////////////////////////////////////////////// |
| 229 | ///////////////////////////////////////////////////////////////////////////////////////////////// |
| 230 | |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 231 | const RegisteredPrefixId* |
| 232 | registerPrefix(const Name& prefix, |
| 233 | const shared_ptr<InterestFilterRecord>& filter, |
| 234 | const RegisterPrefixSuccessCallback& onSuccess, |
| 235 | const RegisterPrefixFailureCallback& onFailure, |
Alexander Afanasyev | 0866f51 | 2014-08-11 13:25:09 -0700 | [diff] [blame] | 236 | uint64_t flags, |
Junxiao Shi | 388ec25 | 2014-11-02 15:19:57 -0700 | [diff] [blame] | 237 | const nfd::CommandOptions& options) |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 238 | { |
| 239 | using namespace nfd; |
| 240 | |
Joao Pereira | ba1e3b9 | 2015-06-01 17:50:37 -0400 | [diff] [blame] | 241 | ControlParameters params; |
| 242 | params.setName(prefix); |
| 243 | params.setFlags(flags); |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 244 | |
Joao Pereira | ba1e3b9 | 2015-06-01 17:50:37 -0400 | [diff] [blame] | 245 | auto prefixToRegister = make_shared<RegisteredPrefix>(prefix, filter, options); |
Alexander Afanasyev | 0866f51 | 2014-08-11 13:25:09 -0700 | [diff] [blame] | 246 | |
Joao Pereira | ba1e3b9 | 2015-06-01 17:50:37 -0400 | [diff] [blame] | 247 | m_face.m_nfdController->start<RibRegisterCommand>(params, |
| 248 | bind(&Impl::afterPrefixRegistered, this, |
| 249 | prefixToRegister, onSuccess), |
| 250 | bind(onFailure, prefixToRegister->getPrefix(), _2), |
| 251 | options); |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 252 | |
| 253 | return reinterpret_cast<const RegisteredPrefixId*>(prefixToRegister.get()); |
| 254 | } |
| 255 | |
| 256 | void |
| 257 | afterPrefixRegistered(const shared_ptr<RegisteredPrefix>& registeredPrefix, |
| 258 | const RegisterPrefixSuccessCallback& onSuccess) |
| 259 | { |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 260 | m_registeredPrefixTable.insert(registeredPrefix); |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 261 | |
| 262 | if (static_cast<bool>(registeredPrefix->getFilter())) { |
| 263 | // it was a combined operation |
| 264 | m_interestFilterTable.push_back(registeredPrefix->getFilter()); |
| 265 | } |
| 266 | |
| 267 | if (static_cast<bool>(onSuccess)) { |
| 268 | onSuccess(registeredPrefix->getPrefix()); |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | void |
| 273 | asyncUnregisterPrefix(const RegisteredPrefixId* registeredPrefixId, |
| 274 | const UnregisterPrefixSuccessCallback& onSuccess, |
| 275 | const UnregisterPrefixFailureCallback& onFailure) |
| 276 | { |
Joao Pereira | ba1e3b9 | 2015-06-01 17:50:37 -0400 | [diff] [blame] | 277 | using namespace nfd; |
| 278 | auto i = std::find_if(m_registeredPrefixTable.begin(), |
| 279 | m_registeredPrefixTable.end(), |
| 280 | MatchRegisteredPrefixId(registeredPrefixId)); |
| 281 | if (i != m_registeredPrefixTable.end()) { |
| 282 | RegisteredPrefix& record = **i; |
| 283 | |
| 284 | const shared_ptr<InterestFilterRecord>& filter = record.getFilter(); |
| 285 | |
| 286 | if (filter != nullptr) { |
| 287 | // it was a combined operation |
| 288 | m_interestFilterTable.remove(filter); |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 289 | } |
Joao Pereira | ba1e3b9 | 2015-06-01 17:50:37 -0400 | [diff] [blame] | 290 | |
| 291 | ControlParameters params; |
| 292 | params.setName(record.getPrefix()); |
| 293 | m_face.m_nfdController->start<RibUnregisterCommand>(params, |
| 294 | bind(&Impl::finalizeUnregisterPrefix, this, i, onSuccess), |
| 295 | bind(onFailure, _2), |
| 296 | record.getCommandOptions()); |
| 297 | } |
Alexander Afanasyev | 851228a | 2014-10-20 15:55:28 -0400 | [diff] [blame] | 298 | else { |
Joao Pereira | ba1e3b9 | 2015-06-01 17:50:37 -0400 | [diff] [blame] | 299 | if (onFailure != nullptr) { |
Alexander Afanasyev | 851228a | 2014-10-20 15:55:28 -0400 | [diff] [blame] | 300 | onFailure("Unrecognized PrefixId"); |
| 301 | } |
| 302 | } |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 303 | |
| 304 | // there cannot be two registered prefixes with the same id |
| 305 | } |
| 306 | |
| 307 | void |
| 308 | finalizeUnregisterPrefix(RegisteredPrefixTable::iterator item, |
| 309 | const UnregisterPrefixSuccessCallback& onSuccess) |
| 310 | { |
| 311 | m_registeredPrefixTable.erase(item); |
| 312 | |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 313 | if (static_cast<bool>(onSuccess)) { |
| 314 | onSuccess(); |
| 315 | } |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 316 | } |
| 317 | |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 318 | void |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 319 | onEmptyPitOrNoRegisteredPrefixes() |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 320 | { |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 321 | if (m_pendingInterestTable.empty() && m_registeredPrefixTable.empty()) { |
| 322 | m_face.m_transport->pause(); |
| 323 | if (!m_ioServiceWork) { |
| 324 | m_processEventsTimeoutEvent.cancel(); |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 325 | } |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | private: |
| 330 | Face& m_face; |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 331 | util::Scheduler m_scheduler; |
| 332 | util::scheduler::ScopedEventId m_processEventsTimeoutEvent; |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 333 | |
| 334 | PendingInterestTable m_pendingInterestTable; |
| 335 | InterestFilterTable m_interestFilterTable; |
| 336 | RegisteredPrefixTable m_registeredPrefixTable; |
| 337 | |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 338 | unique_ptr<boost::asio::io_service::work> m_ioServiceWork; // if thread needs to be preserved |
Alexander Afanasyev | 258ec2b | 2014-05-14 16:15:37 -0700 | [diff] [blame] | 339 | |
| 340 | friend class Face; |
| 341 | }; |
| 342 | |
| 343 | } // namespace ndn |
| 344 | |
| 345 | #endif // NDN_DETAIL_FACE_IMPL_HPP |