face: avoid multiple onFail events

refs #1497

Change-Id: I8fda3fea5cd8a314b30eef45da104109e9748afc
This commit is contained in:
Junxiao Shi
2014-06-09 23:17:57 -07:00
parent 281b916a35
commit 08d07a764e
8 changed files with 132 additions and 70 deletions
+14 -13
View File
@@ -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<T>::handleSend(const boost::system::error_code& error,
if (!m_socket->is_open())
{
onFail("Tunnel closed");
fail("Tunnel closed");
return;
}
@@ -168,11 +169,11 @@ DatagramFace<T>::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<T>::close()
<< "] Close tunnel");
closeSocket();
onFail("Close tunnel");
fail("Close tunnel");
}
template <class T>
@@ -224,7 +225,7 @@ DatagramFace<T>::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<T>::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;
+11 -10
View File
@@ -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
+19 -6
View File
@@ -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
+13 -6
View File
@@ -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;
+12 -11
View File
@@ -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<T, U>::close()
<< "] Close connection");
closeSocket();
this->onFail("Close connection");
this->fail("Close connection");
}
template<class T, class U>
@@ -223,7 +224,7 @@ StreamFace<T, U>::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<T, U>::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<T, U>::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;
}
+8 -8
View File
@@ -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");
}
}
+11 -10
View File
@@ -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 <http://www.gnu.org/licenses/>.
**/
*/
#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<LocalFace> DummyLocalFace;
} // namespace tests
} // namespace nfd
#endif // NFD_TESTS_NFD_FACE_DUMMY_FACE_HPP
#endif // NFD_TESTS_DAEMON_FACE_DUMMY_FACE_HPP
+44 -6
View File
@@ -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