Add simple UDP socket wrapper classes
Change-Id: Iad836899a1c91c9a5a7e95ff3cf2d2687a1bbdf8
diff --git a/aos/vision/events/udp.h b/aos/vision/events/udp.h
new file mode 100644
index 0000000..a12a8bf
--- /dev/null
+++ b/aos/vision/events/udp.h
@@ -0,0 +1,51 @@
+#ifndef AOS_VISION_IMAGE_UDP_H_
+#define AOS_VISION_IMAGE_UDP_H_
+
+#include <arpa/inet.h>
+#include <sys/socket.h>
+#include <math.h>
+#include <unistd.h>
+#include <vector>
+
+#include "aos/common/macros.h"
+#include "aos/common/scoped_fd.h"
+
+namespace aos {
+namespace vision {
+
+// Simple wrapper around a transmitting UDP socket.
+//
+// LOG(FATAL)s for all errors, including from Send.
+class TXUdpSocket {
+ public:
+ TXUdpSocket(const char *ip_addr, int port);
+
+ // Returns the number of bytes actually sent.
+ int Send(const void *data, int size);
+
+ private:
+ ScopedFD fd_;
+
+ DISALLOW_COPY_AND_ASSIGN(TXUdpSocket);
+};
+
+// Simple wrapper around a receiving UDP socket.
+//
+// LOG(FATAL)s for all errors, including from Recv.
+class RXUdpSocket {
+ public:
+ RXUdpSocket(int port);
+
+ // Returns the number of bytes received.
+ int Recv(void *data, int size);
+
+ private:
+ ScopedFD fd_;
+
+ DISALLOW_COPY_AND_ASSIGN(RXUdpSocket);
+};
+
+} // namespace vision
+} // namespace aos
+
+#endif // AOS_VISION_IMAGE_UDP_H_