Change receiveIsReady and processEvents to return immediately, with comment warnings that the caller needs to sleep to avoid using 100% CPU.
diff --git a/ndn-cpp/c/transport/socket-transport.c b/ndn-cpp/c/transport/socket-transport.c
index 2a537db..6195e80 100644
--- a/ndn-cpp/c/transport/socket-transport.c
+++ b/ndn-cpp/c/transport/socket-transport.c
@@ -98,7 +98,7 @@
pollInfo[0].fd = self->socketDescriptor;
pollInfo[0].events = POLLIN;
- int pollResult = poll(pollInfo, 1, 200);
+ int pollResult = poll(pollInfo, 1, 0);
if (pollResult < 0)
return NDN_ERROR_SocketTransport_error_in_poll;
diff --git a/ndn-cpp/c/transport/socket-transport.h b/ndn-cpp/c/transport/socket-transport.h
index 6c2da6e..148c3d3 100644
--- a/ndn-cpp/c/transport/socket-transport.h
+++ b/ndn-cpp/c/transport/socket-transport.h
@@ -52,6 +52,7 @@
/**
* Check if there is data ready on the socket to be received with ndn_SocketTransport_receive.
+ * This does not block, and returns immediately.
* @param self A pointer to the ndn_SocketTransport struct.
* @param receiveIsReady This will be set to 1 if data is ready, 0 if not.
* @return 0 for success, else an error code.
diff --git a/ndn-cpp/c/transport/tcp-transport.h b/ndn-cpp/c/transport/tcp-transport.h
index 1860002..73e4e7f 100644
--- a/ndn-cpp/c/transport/tcp-transport.h
+++ b/ndn-cpp/c/transport/tcp-transport.h
@@ -53,6 +53,7 @@
/**
* Check if there is data ready on the socket to be received with ndn_TcpTransport_receive.
+ * This does not block, and returns immediately.
* @param self A pointer to the ndn_TcpTransport struct.
* @param receiveIsReady This will be set to 1 if data is ready, 0 if not.
* @return 0 for success, else an error code.
diff --git a/ndn-cpp/c/transport/udp-transport.h b/ndn-cpp/c/transport/udp-transport.h
index c9f0d55..be60ab6 100644
--- a/ndn-cpp/c/transport/udp-transport.h
+++ b/ndn-cpp/c/transport/udp-transport.h
@@ -53,6 +53,7 @@
/**
* Check if there is data ready on the socket to be received with ndn_UdpTransport_receive.
+ * This does not block, and returns immediately.
* @param self A pointer to the ndn_UdpTransport struct.
* @param receiveIsReady This will be set to 1 if data is ready, 0 if not.
* @return 0 for success, else an error code.
diff --git a/ndn-cpp/face.hpp b/ndn-cpp/face.hpp
index e0c1598..64d835c 100644
--- a/ndn-cpp/face.hpp
+++ b/ndn-cpp/face.hpp
@@ -68,8 +68,8 @@
/**
* Process any data to receive. For each element received, call face.onReceivedElement.
- * This is non-blocking and will silently time out after a brief period if there is no data to receive.
- * You should repeatedly call this from an event loop.
+ * This is non-blocking and will return immediately if there is no data to receive.
+ * You should repeatedly call this from an event loop, with calls to sleep as needed so that the loop doesn't use 100% of the CPU.
* @throw This may throw an exception for reading data or in the callback for processing the data. If you
* call this from an main event loop, you may want to catch and log/disregard all exceptions.
*/
diff --git a/ndn-cpp/transport/tcp-transport.hpp b/ndn-cpp/transport/tcp-transport.hpp
index 57d9554..f3c5e91 100644
--- a/ndn-cpp/transport/tcp-transport.hpp
+++ b/ndn-cpp/transport/tcp-transport.hpp
@@ -36,8 +36,8 @@
/**
* Process any data to receive. For each element received, call face.onReceivedElement.
- * This is non-blocking and will silently time out after a brief period if there is no data to receive.
- * You should repeatedly call this from an event loop.
+ * This is non-blocking and will return immediately if there is no data to receive.
+ * You should normally not call this directly since it is called by Face.processEvents.
* @throw This may throw an exception for reading data or in the callback for processing the data. If you
* call this from an main event loop, you may want to catch and log/disregard all exceptions.
*/
diff --git a/ndn-cpp/transport/udp-transport.hpp b/ndn-cpp/transport/udp-transport.hpp
index 17f6e25..4ea6324 100644
--- a/ndn-cpp/transport/udp-transport.hpp
+++ b/ndn-cpp/transport/udp-transport.hpp
@@ -36,8 +36,8 @@
/**
* Process any data to receive. For each element received, call face.onReceivedElement.
- * This is non-blocking and will silently time out after a brief period if there is no data to receive.
- * You should repeatedly call this from an event loop.
+ * This is non-blocking and will return immediately if there is no data to receive.
+ * You should normally not call this directly since it is called by Face.processEvents.
* @throw This may throw an exception for reading data or in the callback for processing the data. If you
* call this from an main event loop, you may want to catch and log/disregard all exceptions.
*/
diff --git a/tests/test-get-async.cpp b/tests/test-get-async.cpp
index 4b66e7d..4d7d202 100644
--- a/tests/test-get-async.cpp
+++ b/tests/test-get-async.cpp
@@ -48,8 +48,11 @@
face.expressInterest(Name("/ndn/ucla.edu/apps/ndn-js-test/hello.txt/level2/%FD%05%0B%16%7D%95%0E"), &closure);
// The main event loop.
- while (!closure.gotContent_)
- face.processEvents();
+ while (!closure.gotContent_) {
+ face.processEvents();
+ // We need to sleep for a few milliseconds so we don't use 100% of the CPU.
+ usleep(10000);
+ }
} catch (std::exception &e) {
cout << "exception: " << e.what() << endl;
}