diff --git a/daemon/face/datagram-face.hpp b/daemon/face/datagram-face.hpp index e6a6929a..2dbe8fa8 100644 --- a/daemon/face/datagram-face.hpp +++ b/daemon/face/datagram-face.hpp @@ -1,11 +1,12 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /** - * Copyright (c) 2014 Regents of the University of California, - * Arizona Board of Regents, - * Colorado State University, - * University Pierre & Marie Curie, Sorbonne University, - * Washington University in St. Louis, - * Beijing Institute of Technology + * Copyright (c) 2014, Regents of the University of California, + * Arizona Board of Regents, + * Colorado State University, + * University Pierre & Marie Curie, Sorbonne University, + * Washington University in St. Louis, + * Beijing Institute of Technology, + * The University of Memphis * * This file is part of NFD (Named Data Networking Forwarding Daemon). * See AUTHORS.md for complete list of NFD authors and contributors. @@ -155,7 +156,7 @@ DatagramFace::handleSend(const boost::system::error_code& error, if (!m_socket->is_open()) { - onFail("Tunnel closed"); + fail("Tunnel closed"); return; } @@ -168,11 +169,11 @@ DatagramFace::handleSend(const boost::system::error_code& error, if (error == boost::asio::error::eof) { - onFail("Tunnel closed"); + fail("Tunnel closed"); } else { - onFail("Send operation failed, closing socket: " + + fail("Send operation failed, closing socket: " + error.category().message(error.value())); } return; @@ -196,7 +197,7 @@ DatagramFace::close() << "] Close tunnel"); closeSocket(); - onFail("Close tunnel"); + fail("Close tunnel"); } template @@ -224,7 +225,7 @@ DatagramFace::receiveDatagram(const uint8_t* buffer, // this should be unnecessary, but just in case if (!m_socket->is_open()) { - onFail("Tunnel closed"); + fail("Tunnel closed"); return; } @@ -237,11 +238,11 @@ DatagramFace::receiveDatagram(const uint8_t* buffer, if (error == boost::asio::error::eof) { - onFail("Tunnel closed"); + fail("Tunnel closed"); } else { - onFail("Receive operation failed, closing socket: " + + fail("Receive operation failed, closing socket: " + error.category().message(error.value())); } return; diff --git a/daemon/face/ethernet-face.cpp b/daemon/face/ethernet-face.cpp index 27d49686..27f34eea 100644 --- a/daemon/face/ethernet-face.cpp +++ b/daemon/face/ethernet-face.cpp @@ -1,11 +1,12 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /** - * Copyright (c) 2014 Regents of the University of California, - * Arizona Board of Regents, - * Colorado State University, - * University Pierre & Marie Curie, Sorbonne University, - * Washington University in St. Louis, - * Beijing Institute of Technology + * Copyright (c) 2014, Regents of the University of California, + * Arizona Board of Regents, + * Colorado State University, + * University Pierre & Marie Curie, Sorbonne University, + * Washington University in St. Louis, + * Beijing Institute of Technology, + * The University of Memphis * * This file is part of NFD (Named Data Networking Forwarding Daemon). * See AUTHORS.md for complete list of NFD authors and contributors. @@ -110,7 +111,7 @@ EthernetFace::close() pcap_close(m_pcap); m_pcap = 0; - onFail("Face closed"); + fail("Face closed"); } } @@ -166,7 +167,7 @@ EthernetFace::sendPacket(const ndn::Block& block) { NFD_LOG_WARN("[id:" << getId() << ",endpoint:" << m_interfaceName << "] Trying to send on closed face"); - onFail("Face closed"); + fail("Face closed"); return; } @@ -278,7 +279,7 @@ EthernetFace::processErrorCode(const boost::system::error_code& error) if (!m_pcap) { - onFail("Face closed"); + fail("Face closed"); return; } @@ -295,7 +296,7 @@ EthernetFace::processErrorCode(const boost::system::error_code& error) } close(); - onFail(msg); + fail(msg); } size_t diff --git a/daemon/face/face.cpp b/daemon/face/face.cpp index 75600b48..9d2368b6 100644 --- a/daemon/face/face.cpp +++ b/daemon/face/face.cpp @@ -1,11 +1,12 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /** - * Copyright (c) 2014 Regents of the University of California, - * Arizona Board of Regents, - * Colorado State University, - * University Pierre & Marie Curie, Sorbonne University, - * Washington University in St. Louis, - * Beijing Institute of Technology + * Copyright (c) 2014, Regents of the University of California, + * Arizona Board of Regents, + * Colorado State University, + * University Pierre & Marie Curie, Sorbonne University, + * Washington University in St. Louis, + * Beijing Institute of Technology, + * The University of Memphis * * This file is part of NFD (Named Data Networking Forwarding Daemon). * See AUTHORS.md for complete list of NFD authors and contributors. @@ -39,6 +40,7 @@ Face::Face(const FaceUri& remoteUri, const FaceUri& localUri, bool isLocal) , m_remoteUri(remoteUri) , m_localUri(localUri) , m_isOnDemand(false) + , m_isFailed(false) { onReceiveInterest += bind(&increaseCounter, ref(m_counters.getNInInterests())); onReceiveData += bind(&increaseCounter, ref(m_counters.getNInDatas())); @@ -115,4 +117,15 @@ Face::decodeAndDispatchInput(const Block& element) } } +void +Face::fail(const std::string& reason) +{ + if (m_isFailed) { + return; + } + + m_isFailed = true; + this->onFail(reason); +} + } //namespace nfd diff --git a/daemon/face/face.hpp b/daemon/face/face.hpp index c5e6ee8a..987853ee 100644 --- a/daemon/face/face.hpp +++ b/daemon/face/face.hpp @@ -1,11 +1,12 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /** - * Copyright (c) 2014 Regents of the University of California, - * Arizona Board of Regents, - * Colorado State University, - * University Pierre & Marie Curie, Sorbonne University, - * Washington University in St. Louis, - * Beijing Institute of Technology + * Copyright (c) 2014, Regents of the University of California, + * Arizona Board of Regents, + * Colorado State University, + * University Pierre & Marie Curie, Sorbonne University, + * Washington University in St. Louis, + * Beijing Institute of Technology, + * The University of Memphis * * This file is part of NFD (Named Data Networking Forwarding Daemon). * See AUTHORS.md for complete list of NFD authors and contributors. @@ -159,6 +160,11 @@ protected: void setOnDemand(bool isOnDemand); + /** \brief fail the face and raise onFail event if it's UP; otherwise do nothing + */ + void + fail(const std::string& reason); + private: void setId(FaceId faceId); @@ -171,6 +177,7 @@ private: FaceUri m_remoteUri; FaceUri m_localUri; bool m_isOnDemand; + bool m_isFailed; // allow setting FaceId friend class FaceTable; diff --git a/daemon/face/stream-face.hpp b/daemon/face/stream-face.hpp index daf8ddfe..12cc2bc9 100644 --- a/daemon/face/stream-face.hpp +++ b/daemon/face/stream-face.hpp @@ -1,11 +1,12 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /** - * Copyright (c) 2014 Regents of the University of California, - * Arizona Board of Regents, - * Colorado State University, - * University Pierre & Marie Curie, Sorbonne University, - * Washington University in St. Louis, - * Beijing Institute of Technology + * Copyright (c) 2014, Regents of the University of California, + * Arizona Board of Regents, + * Colorado State University, + * University Pierre & Marie Curie, Sorbonne University, + * Washington University in St. Louis, + * Beijing Institute of Technology, + * The University of Memphis * * This file is part of NFD (Named Data Networking Forwarding Daemon). * See AUTHORS.md for complete list of NFD authors and contributors. @@ -211,7 +212,7 @@ StreamFace::close() << "] Close connection"); closeSocket(); - this->onFail("Close connection"); + this->fail("Close connection"); } template @@ -223,7 +224,7 @@ StreamFace::processErrorCode(const boost::system::error_code& error) if (!m_socket->is_open()) { - this->onFail("Connection closed"); + this->fail("Connection closed"); return; } @@ -245,11 +246,11 @@ StreamFace::processErrorCode(const boost::system::error_code& error) if (error == boost::asio::error::eof) { - this->onFail("Connection closed"); + this->fail("Connection closed"); } else { - this->onFail("Send or receive operation failed, closing socket: " + + this->fail("Send or receive operation failed, closing socket: " + error.category().message(error.value())); } } @@ -327,7 +328,7 @@ StreamFace::handleReceive(const boost::system::error_code& error, << "closing down the face"); closeSocket(); - this->onFail("Failed to parse incoming packet or it is too large to process, " + this->fail("Failed to parse incoming packet or it is too large to process, " "closing down the face"); return; } diff --git a/daemon/face/websocket-face.cpp b/daemon/face/websocket-face.cpp index 5dfe5169..9e56bb53 100644 --- a/daemon/face/websocket-face.cpp +++ b/daemon/face/websocket-face.cpp @@ -1,12 +1,12 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /** - * Copyright (c) 2014 Regents of the University of California, - * Arizona Board of Regents, - * Colorado State University, - * University Pierre & Marie Curie, Sorbonne University, - * Washington University in St. Louis, - * Beijing Institute of Technology, - * The University of Memphis + * Copyright (c) 2014, Regents of the University of California, + * Arizona Board of Regents, + * Colorado State University, + * University Pierre & Marie Curie, Sorbonne University, + * Washington University in St. Louis, + * Beijing Institute of Technology, + * The University of Memphis * * This file is part of NFD (Named Data Networking Forwarding Daemon). * See AUTHORS.md for complete list of NFD authors and contributors. @@ -65,7 +65,7 @@ WebSocketFace::close() websocketpp::lib::error_code ecode; m_server.close(m_handle, websocketpp::close::status::normal, "closed by nfd", ecode); - onFail("Face closed"); + fail("Face closed"); } } diff --git a/tests/daemon/face/dummy-face.hpp b/tests/daemon/face/dummy-face.hpp index 70392862..ca45722c 100644 --- a/tests/daemon/face/dummy-face.hpp +++ b/tests/daemon/face/dummy-face.hpp @@ -1,11 +1,12 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /** - * Copyright (c) 2014 Regents of the University of California, - * Arizona Board of Regents, - * Colorado State University, - * University Pierre & Marie Curie, Sorbonne University, - * Washington University in St. Louis, - * Beijing Institute of Technology + * Copyright (c) 2014, Regents of the University of California, + * Arizona Board of Regents, + * Colorado State University, + * University Pierre & Marie Curie, Sorbonne University, + * Washington University in St. Louis, + * Beijing Institute of Technology, + * The University of Memphis * * This file is part of NFD (Named Data Networking Forwarding Daemon). * See AUTHORS.md for complete list of NFD authors and contributors. @@ -20,10 +21,10 @@ * * You should have received a copy of the GNU General Public License along with * NFD, e.g., in COPYING.md file. If not, see . - **/ + */ -#ifndef NFD_TESTS_NFD_FACE_DUMMY_FACE_HPP -#define NFD_TESTS_NFD_FACE_DUMMY_FACE_HPP +#ifndef NFD_TESTS_DAEMON_FACE_DUMMY_FACE_HPP +#define NFD_TESTS_DAEMON_FACE_DUMMY_FACE_HPP #include "face/face.hpp" #include "face/local-face.hpp" @@ -90,4 +91,4 @@ typedef DummyFaceImpl DummyLocalFace; } // namespace tests } // namespace nfd -#endif // NFD_TESTS_NFD_FACE_DUMMY_FACE_HPP +#endif // NFD_TESTS_DAEMON_FACE_DUMMY_FACE_HPP diff --git a/tests/daemon/face/face.cpp b/tests/daemon/face/face.cpp index 46c03451..b82e0fac 100644 --- a/tests/daemon/face/face.cpp +++ b/tests/daemon/face/face.cpp @@ -1,11 +1,12 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /** - * Copyright (c) 2014 Regents of the University of California, - * Arizona Board of Regents, - * Colorado State University, - * University Pierre & Marie Curie, Sorbonne University, - * Washington University in St. Louis, - * Beijing Institute of Technology + * Copyright (c) 2014, Regents of the University of California, + * Arizona Board of Regents, + * Colorado State University, + * University Pierre & Marie Curie, Sorbonne University, + * Washington University in St. Louis, + * Beijing Institute of Technology, + * The University of Memphis * * This file is part of NFD (Named Data Networking Forwarding Daemon). * See AUTHORS.md for complete list of NFD authors and contributors. @@ -68,6 +69,43 @@ BOOST_AUTO_TEST_CASE(Counters) BOOST_CHECK_EQUAL(counters.getNOutDatas() , 0); } +class FaceFailTestFace : public DummyFace +{ +public: + FaceFailTestFace() + : failCount(0) + { + this->onFail += bind(&FaceFailTestFace::failHandler, this, _1); + } + + void + failOnce() + { + this->fail("reason"); + } + +private: + void + failHandler(const std::string& reason) + { + BOOST_CHECK_EQUAL(reason, "reason"); + ++this->failCount; + } + +public: + int failCount; +}; + +BOOST_AUTO_TEST_CASE(FailTwice) +{ + FaceFailTestFace face; + BOOST_CHECK_EQUAL(face.failCount, 0); + face.failOnce(); + BOOST_CHECK_EQUAL(face.failCount, 1); + face.failOnce(); + BOOST_CHECK_EQUAL(face.failCount, 1); +} + BOOST_AUTO_TEST_SUITE_END() } // namespace tests