In Transport, added getIsConnected
diff --git a/ndn-cpp/node.cpp b/ndn-cpp/node.cpp
index b5d61d9..44bd7e9 100644
--- a/ndn-cpp/node.cpp
+++ b/ndn-cpp/node.cpp
@@ -76,8 +76,10 @@
shared_ptr<vector<unsigned char> > encoding = pitEntry->getInterest()->wireEncode();
- // TODO: Check if we are already connected.
- transport_->connect(*this);
+ // TODO: Properly check if we are already connected to the expected host.
+ if (!transport_->getIsConnected())
+ transport_->connect(*this);
+
transport_->send(*encoding);
}
diff --git a/ndn-cpp/transport/tcp-transport.cpp b/ndn-cpp/transport/tcp-transport.cpp
index a0a53de..248a613 100644
--- a/ndn-cpp/transport/tcp-transport.cpp
+++ b/ndn-cpp/transport/tcp-transport.cpp
@@ -25,6 +25,7 @@
(&elementReader_, &node, (unsigned char *)malloc(initialLength), initialLength, ndn_realloc);
// TODO: Properly indicate connected status.
+ isConnected_ = true;
node_ = &node;
}
@@ -52,6 +53,11 @@
ndn_BinaryXmlElementReader_onReceivedData(&elementReader_, buffer, nBytes);
}
+bool TcpTransport::getIsConnected()
+{
+ return isConnected_;
+}
+
void TcpTransport::close()
{
ndn_Error error;
diff --git a/ndn-cpp/transport/tcp-transport.hpp b/ndn-cpp/transport/tcp-transport.hpp
index 1028def..4190600 100644
--- a/ndn-cpp/transport/tcp-transport.hpp
+++ b/ndn-cpp/transport/tcp-transport.hpp
@@ -15,7 +15,7 @@
class TcpTransport : public Transport {
public:
TcpTransport()
- : node_(0)
+ : node_(0), isConnected_(false)
{
ndn_TcpTransport_init(&transport_);
elementReader_.partialData.array = 0;
@@ -43,6 +43,8 @@
*/
virtual void processEvents();
+ virtual bool getIsConnected();
+
/**
* Close the connection to the host.
*/
@@ -52,6 +54,7 @@
private:
struct ndn_TcpTransport transport_;
+ bool isConnected_;
Node *node_;
// TODO: This belongs in the socket listener.
ndn_BinaryXmlElementReader elementReader_;
diff --git a/ndn-cpp/transport/transport.cpp b/ndn-cpp/transport/transport.cpp
index cbcb659..feb1345 100644
--- a/ndn-cpp/transport/transport.cpp
+++ b/ndn-cpp/transport/transport.cpp
@@ -25,6 +25,11 @@
throw logic_error("unimplemented");
}
+bool Transport::getIsConnected()
+{
+ throw logic_error("unimplemented");
+}
+
void Transport::close()
{
}
diff --git a/ndn-cpp/transport/transport.hpp b/ndn-cpp/transport/transport.hpp
index 9159b99..6fe4534 100644
--- a/ndn-cpp/transport/transport.hpp
+++ b/ndn-cpp/transport/transport.hpp
@@ -40,6 +40,8 @@
*/
virtual void processEvents() = 0;
+ virtual bool getIsConnected();
+
/**
* Close the connection. This base class implementation does nothing, but your derived class can override.
*/
diff --git a/ndn-cpp/transport/udp-transport.cpp b/ndn-cpp/transport/udp-transport.cpp
index b1d90e8..42551ad 100644
--- a/ndn-cpp/transport/udp-transport.cpp
+++ b/ndn-cpp/transport/udp-transport.cpp
@@ -25,6 +25,7 @@
(&elementReader_, &node, (unsigned char *)malloc(initialLength), initialLength, ndn_realloc);
// TODO: Properly indicate connected status.
+ isConnected_ = true;
node_ = &node;
}
@@ -52,6 +53,11 @@
ndn_BinaryXmlElementReader_onReceivedData(&elementReader_, buffer, nBytes);
}
+bool UdpTransport::getIsConnected()
+{
+ return isConnected_;
+}
+
void UdpTransport::close()
{
ndn_Error error;
diff --git a/ndn-cpp/transport/udp-transport.hpp b/ndn-cpp/transport/udp-transport.hpp
index ceeda72..76c3f36 100644
--- a/ndn-cpp/transport/udp-transport.hpp
+++ b/ndn-cpp/transport/udp-transport.hpp
@@ -15,7 +15,7 @@
class UdpTransport : public Transport {
public:
UdpTransport()
- : node_(0)
+ : node_(0), isConnected_(false)
{
ndn_UdpTransport_init(&transport_);
elementReader_.partialData.array = 0;
@@ -43,6 +43,8 @@
*/
virtual void processEvents();
+ virtual bool getIsConnected();
+
/**
* Close the connection to the host.
*/
@@ -52,6 +54,7 @@
private:
struct ndn_UdpTransport transport_;
+ bool isConnected_;
Node *node_;
// TODO: This belongs in the socket listener.
ndn_BinaryXmlElementReader elementReader_;