examples: handle Nack in consumer
refs #3701
Change-Id: Ia6cfcefcf5a9541b09a50d1e5edaa55227908191
diff --git a/docs/examples.rst b/docs/examples.rst
index c1ad084..8689e4f 100644
--- a/docs/examples.rst
+++ b/docs/examples.rst
@@ -12,13 +12,13 @@
In the following trivial example, a consumer creates a :ndn-cxx:`Face` with default
transport (:ndn-cxx:`UnixTransport`) and sends an Interest for
-``/localhost/testApp/randomData``. While expressing Interest, the app specifies two
-callbacks to be called when Data is retrieved or Interest times out.
+``/localhost/testApp/randomData``. While expressing Interest, the app specifies three
+callbacks to be called when Data/Nack is retrieved or Interest times out.
.. literalinclude:: ../examples/consumer.cpp
:language: c++
:linenos:
- :emphasize-lines: 24-27,39,43-46,50,57,67
+ :emphasize-lines: 24-27,39,43-47,51,58,75
Trivial producer
@@ -66,5 +66,5 @@
.. literalinclude:: ../examples/consumer-with-timer.cpp
:language: c++
:linenos:
- :emphasize-lines: 39-40,51-54,58-59,61-62,99-100
+ :emphasize-lines: 39-40,51-55,59-60,62-63,108-109
diff --git a/examples/consumer-with-timer.cpp b/examples/consumer-with-timer.cpp
index c08a312..8c82cf6 100644
--- a/examples/consumer-with-timer.cpp
+++ b/examples/consumer-with-timer.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2015 Regents of the University of California.
+ * Copyright (c) 2013-2016 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -50,6 +50,7 @@
m_face.expressInterest(interest,
bind(&ConsumerWithTimer::onData, this, _1, _2),
+ bind(&ConsumerWithTimer::onNack, this, _1, _2),
bind(&ConsumerWithTimer::onTimeout, this, _1));
std::cout << "Sending " << interest << std::endl;
@@ -74,6 +75,13 @@
}
void
+ onNack(const Interest& interest, const lp::Nack& nack)
+ {
+ std::cout << "received Nack with reason " << nack.getReason()
+ << " for interest " << interest << std::endl;
+ }
+
+ void
onTimeout(const Interest& interest)
{
std::cout << "Timeout " << interest << std::endl;
@@ -90,6 +98,7 @@
m_face.expressInterest(interest,
bind(&ConsumerWithTimer::onData, this, _1, _2),
+ bind(&ConsumerWithTimer::onNack, this, _1, _2),
bind(&ConsumerWithTimer::onTimeout, this, _1));
std::cout << "Sending " << interest << std::endl;
diff --git a/examples/consumer.cpp b/examples/consumer.cpp
index 4042565..0e0ff43 100644
--- a/examples/consumer.cpp
+++ b/examples/consumer.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2015 Regents of the University of California.
+ * Copyright (c) 2013-2016 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -42,6 +42,7 @@
m_face.expressInterest(interest,
bind(&Consumer::onData, this, _1, _2),
+ bind(&Consumer::onNack, this, _1, _2),
bind(&Consumer::onTimeout, this, _1));
std::cout << "Sending " << interest << std::endl;
@@ -58,6 +59,13 @@
}
void
+ onNack(const Interest& interest, const lp::Nack& nack)
+ {
+ std::cout << "received Nack with reason " << nack.getReason()
+ << " for interest " << interest << std::endl;
+ }
+
+ void
onTimeout(const Interest& interest)
{
std::cout << "Timeout " << interest << std::endl;