Added UdpTransport
diff --git a/ndn-cpp/transport/UdpTransport.cpp b/ndn-cpp/transport/UdpTransport.cpp
new file mode 100644
index 0000000..ae0124f
--- /dev/null
+++ b/ndn-cpp/transport/UdpTransport.cpp
@@ -0,0 +1,54 @@
+/**
+ * @author: Jeff Thompson
+ * See COPYING for copyright and distribution information.
+ */
+
+#include <stdexcept>
+#include "../NDN.hpp"
+#include "../c/util/ndn_realloc.h"
+#include "UdpTransport.hpp"
+
+using namespace std;
+
+namespace ndn {
+
+void UdpTransport::connect(NDN &ndn)
+{
+ ndn_Error error;
+ if (error = ndn_UdpTransport_connect(&transport_, (char *)ndn.getHost(), ndn.getPort()))
+ throw std::runtime_error(ndn_getErrorString(error));
+
+ // TODO: This belongs in the socket listener.
+ const unsigned int initialLength = 1000;
+ // Automatically cast ndn_ to (struct ndn_ElementListener *)
+ ndn_BinaryXMLElementReader_init
+ (&elementReader_, &ndn, (unsigned char *)malloc(initialLength), initialLength, ndn_realloc);
+
+ // TODO: Properly indicate connected status.
+ ndn_ = &ndn;
+}
+
+void UdpTransport::send(unsigned char *data, unsigned int dataLength)
+{
+ ndn_Error error;
+ if (error = ndn_UdpTransport_send(&transport_, data, dataLength))
+ throw std::runtime_error(ndn_getErrorString(error));
+}
+
+void UdpTransport::tempReceive()
+{
+ try {
+ ndn_Error error;
+ unsigned char buffer[8000];
+ unsigned int nBytes;
+ if (error = ndn_UdpTransport_receive(&transport_, buffer, sizeof(buffer), &nBytes))
+ throw std::runtime_error(ndn_getErrorString(error));
+
+ ndn_BinaryXMLElementReader_onReceivedData(&elementReader_, buffer, nBytes);
+ } catch (...) {
+ // This function is called by the socket callback, so don't send an exception back to it.
+ // TODO: Log the exception?
+ }
+}
+
+}
diff --git a/ndn-cpp/transport/UdpTransport.hpp b/ndn-cpp/transport/UdpTransport.hpp
new file mode 100644
index 0000000..a24a4dc
--- /dev/null
+++ b/ndn-cpp/transport/UdpTransport.hpp
@@ -0,0 +1,42 @@
+/**
+ * @author: Jeff Thompson
+ * See COPYING for copyright and distribution information.
+ */
+
+#ifndef NDN_TCPTRANSPORT_HPP
+#define NDN_TCPTRANSPORT_HPP
+
+#include "../c/transport/UdpTransport.h"
+#include "../c/encoding/BinaryXMLElementReader.h"
+#include "Transport.hpp"
+
+namespace ndn {
+
+class UdpTransport : public Transport {
+public:
+ UdpTransport()
+ {
+ ndn_UdpTransport_init(&transport_);
+ ndn_ = 0;
+ }
+
+ /**
+ *
+ * @param ndn Not a shared_ptr because we assume that it will remain valid during the life of this Transport object.
+ */
+ virtual void connect(NDN &ndn);
+
+ virtual void send(unsigned char *data, unsigned int dataLength);
+
+ virtual void tempReceive();
+
+private:
+ struct ndn_UdpTransport transport_;
+ NDN *ndn_;
+ // TODO: This belongs in the socket listener.
+ ndn_BinaryXMLElementReader elementReader_;
+};
+
+}
+
+#endif