face: Fixing small bug: after unregistering prefix, close transport if
there are no outstanding interests and prefix table is empty

Change-Id: Ie1a121fb34dfdeb10258e1ac46a8be1c9b7cdca9
diff --git a/src/face.cpp b/src/face.cpp
index 7e62fe4..fc064f1 100644
--- a/src/face.cpp
+++ b/src/face.cpp
@@ -167,13 +167,27 @@
   if (i != registeredPrefixTable_.end())
     {
       m_fwController->selfDeregisterPrefix((*i)->getPrefix(),
-                                           bind(&RegisteredPrefixTable::erase, &registeredPrefixTable_, i),
+                                           bind(&Face::finalizeUnsertInterestFilter, this, i),
                                            Controller::FailCallback());
     }
 
   // there cannot be two registered prefixes with the same id. if there are, then something is broken
 }
 
+void
+Face::finalizeUnsertInterestFilter(RegisteredPrefixTable::iterator item)
+{
+  registeredPrefixTable_.erase(item);
+
+  if (!pitTimeoutCheckTimerActive_ && registeredPrefixTable_.empty())
+    {
+      transport_->close();
+      if (!ioServiceWork_) {
+        processEventsTimeoutTimer_->cancel();
+      }
+    }
+}
+
 void 
 Face::processEvents(Milliseconds timeout/* = 0 */, bool keepThread/* = false*/)
 {
diff --git a/src/face.hpp b/src/face.hpp
index e312016..42f4fd1 100644
--- a/src/face.hpp
+++ b/src/face.hpp
@@ -209,6 +209,9 @@
 
   void
   asyncUnsetInterestFilter(const RegisteredPrefixId *registeredPrefixId);
+
+  void
+  finalizeUnsertInterestFilter(RegisteredPrefixTable::iterator item);
   
   void 
   onReceiveElement(const Block &wire);