ping: print short stats summary on SIGQUIT

refs #2782

Change-Id: If0b85dabc7fdee6ea5ab19297122e7f322d55f22
diff --git a/tools/ping/client/ndn-ping.cpp b/tools/ping/client/ndn-ping.cpp
index 2115b81..c3e12f7 100644
--- a/tools/ping/client/ndn-ping.cpp
+++ b/tools/ping/client/ndn-ping.cpp
@@ -55,12 +55,15 @@
   exit(2);
 }
 
+/**
+ * @brief SIGINT handler: print statistics and exit
+ */
 static void
-signalHandler(Face& face, StatisticsCollector& statisticsCollector)
+onSigInt(Face& face, StatisticsCollector& statisticsCollector)
 {
   face.shutdown();
   Statistics statistics = statisticsCollector.computeStatistics();
-  std::cout << statistics << "\n";
+  std::cout << statistics << std::endl;
 
   if (statistics.nReceived == statistics.nSent) {
     exit(0);
@@ -70,6 +73,16 @@
   }
 }
 
+/**
+ * @brief SIGQUIT handler: print statistics summary and continue
+ */
+static void
+onSigQuit(StatisticsCollector& statisticsCollector, boost::asio::signal_set& signalSet)
+{
+  statisticsCollector.computeStatistics().printSummary(std::cout);
+  signalSet.async_wait(bind(&onSigQuit, ref(statisticsCollector), ref(signalSet)));
+}
+
 int
 main(int argc, char* argv[])
 {
@@ -191,8 +204,11 @@
   StatisticsCollector statisticsCollector(ping, options);
   Tracer tracer(ping, options);
 
-  boost::asio::signal_set signalSet(face.getIoService(), SIGINT);
-  signalSet.async_wait(bind(&signalHandler, ref(face), ref(statisticsCollector)));
+  boost::asio::signal_set signalSetInt(face.getIoService(), SIGINT);
+  signalSetInt.async_wait(bind(&onSigInt, ref(face), ref(statisticsCollector)));
+
+  boost::asio::signal_set signalSetQuit(face.getIoService(), SIGQUIT);
+  signalSetQuit.async_wait(bind(&onSigQuit, ref(statisticsCollector), ref(signalSetQuit)));
 
   std::cout << "PING " << options.prefix << std::endl;
 
diff --git a/tools/ping/client/statistics-collector.cpp b/tools/ping/client/statistics-collector.cpp
index b02db12..bc1956e 100644
--- a/tools/ping/client/statistics-collector.cpp
+++ b/tools/ping/client/statistics-collector.cpp
@@ -83,6 +83,16 @@
 }
 
 std::ostream&
+Statistics::printSummary(std::ostream& os) const
+{
+  os << nReceived << "/" << nSent << " packets, " << packetLossRate * 100.0
+     << "% loss, min/avg/max/mdev = " << minRtt << "/" << avgRtt << "/" << maxRtt << "/"
+     << stdDevRtt << " ms" << std::endl;
+
+  return os;
+}
+
+std::ostream&
 operator<<(std::ostream& os, const Statistics& statistics)
 {
   os << "\n";
diff --git a/tools/ping/client/statistics-collector.hpp b/tools/ping/client/statistics-collector.hpp
index 6e98577..685ff1f 100644
--- a/tools/ping/client/statistics-collector.hpp
+++ b/tools/ping/client/statistics-collector.hpp
@@ -46,6 +46,9 @@
   double sumRtt;                                //!< sum of round trip times
   double avgRtt;                                //!< average round trip time
   double stdDevRtt;                             //!< std dev of round trip time
+
+  std::ostream&
+  printSummary(std::ostream& os) const;
 };
 
 /**