Pass the NDN object to connect. Added TcpTransport::tempReceive()
diff --git a/ndn-cpp/transport/TcpTransport.cpp b/ndn-cpp/transport/TcpTransport.cpp
index c3abab6..5da7baa 100644
--- a/ndn-cpp/transport/TcpTransport.cpp
+++ b/ndn-cpp/transport/TcpTransport.cpp
@@ -4,17 +4,22 @@
*/
#include <stdexcept>
+#include "../NDN.hpp"
+#include "../c/encoding/BinaryXMLElementReader.h"
#include "TcpTransport.hpp"
using namespace std;
namespace ndn {
-void TcpTransport::connect(const char *host, unsigned short port)
+void TcpTransport::connect(NDN &ndn)
{
ndn_Error error;
- if (error = ndn_TcpTransport_connect(&transport_, (char *)host, port))
- throw std::runtime_error(ndn_getErrorString(error));
+ if (error = ndn_TcpTransport_connect(&transport_, (char *)ndn.getHost(), ndn.getPort()))
+ throw std::runtime_error(ndn_getErrorString(error));
+
+ // TODO: Properly indicate connected status.
+ ndn_ = &ndn;
}
void TcpTransport::send(unsigned char *data, unsigned int dataLength)
@@ -24,14 +29,21 @@
throw std::runtime_error(ndn_getErrorString(error));
}
-unsigned int TcpTransport::receive(unsigned char *buffer, unsigned int bufferLength)
+void TcpTransport::tempReceive()
{
+ if (!ndn_)
+ // TODO: Properly check if connected.
+ return;
+ ndn_BinaryXMLElementReader elementReader;
+ // Automaticall cast ndn_ to (struct ndn_ElementListener *)
+ ndn_BinaryXMLElementReader_init(&elementReader, ndn_);
+
+ unsigned char buffer[8000];
ndn_Error error;
unsigned int nBytes;
- if (error = ndn_TcpTransport_receive(&transport_, buffer, bufferLength, &nBytes))
+ if (error = ndn_TcpTransport_receive(&transport_, buffer, sizeof(buffer), &nBytes))
throw std::runtime_error(ndn_getErrorString(error));
-
- return nBytes;
+ ndn_BinaryXMLElementReader_onReceivedData(&elementReader, buffer, nBytes);
}
}