In processEvents, if an interest has timed out, remove it from the PIT before calling the callback.
diff --git a/include/ndn-cpp/node.hpp b/include/ndn-cpp/node.hpp
index 1e4c001..d428378 100644
--- a/include/ndn-cpp/node.hpp
+++ b/include/ndn-cpp/node.hpp
@@ -170,13 +170,21 @@
}
/**
- * If this interest is timed out, call onTimeout_ (if defined) and return true.
- * @param parent The parent Node for the UpcallInfo.
+ * Check if this interest is timed out.
* @param nowMilliseconds The current time in milliseconds from ndn_getNowMilliseconds.
- * @return true if this interest timed out and the timeout callback was called, otherwise false.
+ * @return true if this interest timed out, otherwise false.
*/
bool
- checkTimeout(Node *parent, MillisecondsSince1970 nowMilliseconds);
+ isTimedOut(MillisecondsSince1970 nowMilliseconds)
+ {
+ return timeoutTimeMilliseconds_ >= 0.0 && nowMilliseconds >= timeoutTimeMilliseconds_;
+ }
+
+ /**
+ * Call onTimeout_ (if defined). This ignores exceptions from the onTimeout_.
+ */
+ void
+ callTimeout();
private:
ptr_lib::shared_ptr<const Interest> interest_;
diff --git a/src/node.cpp b/src/node.cpp
index d8bcb09..ade4a6e 100644
--- a/src/node.cpp
+++ b/src/node.cpp
@@ -242,8 +242,11 @@
// Check for PIT entry timeouts. Go backwards through the list so we can erase entries.
MillisecondsSince1970 nowMilliseconds = ndn_getNowMilliseconds();
for (int i = (int)pendingInterestTable_.size() - 1; i >= 0; --i) {
- if (pendingInterestTable_[i]->checkTimeout(this, nowMilliseconds)) {
+ if (pendingInterestTable_[i]->isTimedOut(nowMilliseconds)) {
+ // Save the PendingInterest and remove it from the PIT. Then call the callback.
+ shared_ptr<PendingInterest> pendingInterest = pendingInterestTable_[i];
pendingInterestTable_.erase(pendingInterestTable_.begin() + i);
+ pendingInterest->callTimeout();
// Refresh now since the timeout callback might have delayed.
nowMilliseconds = ndn_getNowMilliseconds();
@@ -351,22 +354,16 @@
interest_->get(*interestStruct_);
}
-bool
-Node::PendingInterest::checkTimeout(Node *parent, MillisecondsSince1970 nowMilliseconds)
+void
+Node::PendingInterest::callTimeout()
{
- if (timeoutTimeMilliseconds_ >= 0.0 && nowMilliseconds >= timeoutTimeMilliseconds_) {
- if (onTimeout_) {
- // Ignore all exceptions.
- try {
- onTimeout_(interest_);
- }
- catch (...) { }
+ if (onTimeout_) {
+ // Ignore all exceptions.
+ try {
+ onTimeout_(interest_);
}
-
- return true;
+ catch (...) { }
}
- else
- return false;
}
}