face: Avoid resuming transport after connect if the transmission queue empty
Change-Id: I53763b62a8fc12d1d2613daa8d4f9d2b5109b7aa
Refs: #3957
diff --git a/src/transport/stream-transport-impl.hpp b/src/transport/stream-transport-impl.hpp
index d542741..c2dab39 100644
--- a/src/transport/stream-transport-impl.hpp
+++ b/src/transport/stream-transport-impl.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016 Regents of the University of California.
+ * Copyright (c) 2013-2017 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -132,10 +132,10 @@
m_connectTimer.cancel();
if (!error) {
- resume();
m_transport.m_isConnected = true;
if (!m_transmissionQueue.empty()) {
+ resume();
asyncWrite();
}
}
diff --git a/tests/integrated/face.cpp b/tests/integrated/face.cpp
index 9d358a5..12e7a99 100644
--- a/tests/integrated/face.cpp
+++ b/tests/integrated/face.cpp
@@ -30,6 +30,9 @@
#include "boost-test.hpp"
#include <stdio.h>
+#include <thread>
+#include <mutex>
+#include <condition_variable>
namespace ndn {
namespace tests {
@@ -565,6 +568,33 @@
BOOST_CHECK_NO_THROW(face.processEvents(time::seconds(1)));
}
+BOOST_AUTO_TEST_CASE(ProcessEventsBlocksForeverWhenNothingScheduled) // Bug #3957
+{
+ ndn::Face face;
+ std::mutex m;
+ std::condition_variable cv;
+ bool processEventsFinished = false;
+
+ std::thread faceThread([&] {
+ face.processEvents();
+
+ processEventsFinished = true;
+ std::lock_guard<std::mutex> lk(m);
+ cv.notify_one();
+ });
+
+ {
+ std::unique_lock<std::mutex> lk(m);
+ cv.wait_for(lk, std::chrono::seconds(5), [&] { return processEventsFinished; });
+ }
+
+ BOOST_CHECK_EQUAL(processEventsFinished, true);
+ if (!processEventsFinished) {
+ face.shutdown();
+ }
+ faceThread.join();
+}
+
BOOST_AUTO_TEST_SUITE_END()
} // namespace tests