util: Move getNowMilliseconds from node.cpp to c/util/time.c.
diff --git a/ndn-cpp/c/util/time.c b/ndn-cpp/c/util/time.c
new file mode 100644
index 0000000..a794047
--- /dev/null
+++ b/ndn-cpp/c/util/time.c
@@ -0,0 +1,16 @@
+/**
+ * Copyright (C) 2013 Regents of the University of California.
+ * @author: Jeff Thompson <jefft0@remap.ucla.edu>
+ * See COPYING for copyright and distribution information.
+ */
+
+#include <sys/time.h>
+#include "time.h"
+
+double
+ndn_getNowMilliseconds()
+{
+ struct timeval t;
+ gettimeofday(&t, 0);
+ return t.tv_sec * 1000.0 + t.tv_usec / 1000.0;
+}
diff --git a/ndn-cpp/c/util/time.h b/ndn-cpp/c/util/time.h
new file mode 100644
index 0000000..36b4dad
--- /dev/null
+++ b/ndn-cpp/c/util/time.h
@@ -0,0 +1,25 @@
+/**
+ * Copyright (C) 2013 Regents of the University of California.
+ * @author: Jeff Thompson <jefft0@remap.ucla.edu>
+ * See COPYING for copyright and distribution information.
+ */
+
+#ifndef NDN_TIME_H
+#define NDN_TIME_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Use gettimeofday to return the current time in milliseconds.
+ * @return The current time in milliseconds since 1/1/1970, including fractions of a millisecond according to timeval.tv_usec.
+ */
+double
+ndn_getNowMilliseconds();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/ndn-cpp/node.cpp b/ndn-cpp/node.cpp
index 1ce715c..35a295a 100644
--- a/ndn-cpp/node.cpp
+++ b/ndn-cpp/node.cpp
@@ -5,11 +5,11 @@
* See COPYING for copyright and distribution information.
*/
-#include <sys/time.h>
#include <stdexcept>
#include "c/name.h"
#include "c/interest.h"
#include "c/util/crypto.h"
+#include "c/util/time.h"
#include "c/encoding/binary-xml.h"
#include "encoding/binary-xml-decoder.hpp"
#include <ndn-cpp/forwarding-entry.hpp>
@@ -111,15 +111,6 @@
signature->setSignature(signatureBits, (size_t)signatureBitsLength);
}
-// Use gettimeofday to return the current time in milliseconds.
-static inline double
-getNowMilliseconds()
-{
- timeval t;
- gettimeofday(&t, NULL);
- return t.tv_sec * 1000.0 + t.tv_usec / 1000.0;
-}
-
Node::Node(const shared_ptr<Transport>& transport, const shared_ptr<const Transport::ConnectionInfo>& connectionInfo)
: transport_(transport), connectionInfo_(connectionInfo),
ndndIdFetcherInterest_(Name("/%C1.M.S.localhost/%C1.M.SRV/ndnd/KEY"), 4000.0)
@@ -249,13 +240,13 @@
transport_->processEvents();
// Check for PIT entry timeouts. Go backwards through the list so we can erase entries.
- double nowMilliseconds = getNowMilliseconds();
+ double nowMilliseconds = ndn_getNowMilliseconds();
for (int i = (int)pendingInterestTable_.size() - 1; i >= 0; --i) {
if (pendingInterestTable_[i]->checkTimeout(this, nowMilliseconds)) {
pendingInterestTable_.erase(pendingInterestTable_.begin() + i);
// Refresh now since the timeout callback might have delayed.
- nowMilliseconds = getNowMilliseconds();
+ nowMilliseconds = ndn_getNowMilliseconds();
}
}
}
@@ -346,7 +337,7 @@
{
// Set up timeoutTime_.
if (interest_->getInterestLifetimeMilliseconds() >= 0.0)
- timeoutTimeMilliseconds_ = getNowMilliseconds() + interest_->getInterestLifetimeMilliseconds();
+ timeoutTimeMilliseconds_ = ndn_getNowMilliseconds() + interest_->getInterestLifetimeMilliseconds();
else
// No timeout.
timeoutTimeMilliseconds_ = -1.0;