initialize a new thread to wait instead of directly sleep
diff --git a/model/sync-logic.cc b/model/sync-logic.cc
index 3637076..ea341e1 100644
--- a/model/sync-logic.cc
+++ b/model/sync-logic.cc
@@ -186,6 +186,33 @@
}
void
+SyncLogic::checkAgain (const string &interest, DigestPtr digest)
+{
+ int wait = rand() % 80 + 20;
+ sleep(wait/1000.0);
+
+ if (*m_state.getDigest() == *digest)
+ {
+ m_syncInterestTable.insert(interest);
+ return;
+ }
+
+ DiffStateContainer::iterator ii = m_log.find (digest);
+ if (ii != m_log.end ())
+ {
+ stringstream ss;
+ ss << *(*ii)->diff();
+ m_ccnxHandle->publishData(interest, ss.str(), m_syncResponseFreshness);
+ }
+ else
+ {
+ stringstream ss;
+ ss << m_state;
+ m_ccnxHandle->publishData(interest + "/state", ss.str(), m_syncResponseFreshness);
+ }
+}
+
+void
SyncLogic::respondSyncInterest (const string &interest)
{
string hash = interest.substr(interest.find_last_of("/") + 1);
@@ -209,28 +236,8 @@
}
else
{
- int wait = rand() % 80 + 20;
- sleep(wait/1000.0); // ??? sleep in this thread???
- }
-
- if (*m_state.getDigest() == *digest)
- {
- m_syncInterestTable.insert(interest);
- return;
- }
-
- ii = m_log.find (digest);
- if (ii != m_log.end ())
- {
- stringstream ss;
- ss << *(*ii)->diff();
- m_ccnxHandle->publishData(interest, ss.str(), m_syncResponseFreshness);
- }
- else
- {
- stringstream ss;
- ss << m_state;
- m_ccnxHandle->publishData(interest + "/state", ss.str(), m_syncResponseFreshness);
+ m_thread.join();
+ m_thread = thread(&SyncLogic::checkAgain, this, interest, digest);
}
}
diff --git a/model/sync-logic.h b/model/sync-logic.h
index 87b82fc..d5e6a0f 100644
--- a/model/sync-logic.h
+++ b/model/sync-logic.h
@@ -60,6 +60,8 @@
*/
void addLocalNames (const std::string &prefix, uint32_t session, uint32_t seq);
+ void checkAgain (const std::string &interest, DigestPtr digest);
+
/**
* @brief respond to the Sync Interest; a lot of logic needs to go in here
* @param interest the Sync Interest in string format
@@ -68,7 +70,7 @@
/**
* @brief process the fetched sync data
- * @param name name ???
+ * @param name the data name
* @param dataBuffer the sync data
*/
void processSyncData (const std::string &name, const std::string &dataBuffer);
@@ -85,6 +87,8 @@
LogicCallback m_fetch;
CcnxWrapperPtr m_ccnxHandle;
+ boost::thread m_thread;
+
static const int m_syncResponseFreshness = 2;
};