aboutsummaryrefslogtreecommitdiff
path: root/src/armnnUtils/NetworkSockets.hpp
diff options
context:
space:
mode:
authorRob Hughes <robert.hughes@arm.com>2020-01-13 11:14:59 +0000
committerRob Hughes <robert.hughes@arm.com>2020-01-21 16:01:58 +0000
commit25b7436b02514145a0289daff78f5b9f64cdd0db (patch)
treeef574302d4dda7e67e5c05b999bcd5b09d3c9190 /src/armnnUtils/NetworkSockets.hpp
parent41e92b085aa543cba57610135168185632ed0799 (diff)
downloadarmnn-25b7436b02514145a0289daff78f5b9f64cdd0db.tar.gz
Add thin abstraction layer for network sockets
This makes SocketProfilingConnection and GatordMock work on Windows as well as Linux Change-Id: I4b10c079b653a1c3f61eb20694e5b5f8a6f5fdfb Signed-off-by: Robert Hughes <robert.hughes@arm.com>
Diffstat (limited to 'src/armnnUtils/NetworkSockets.hpp')
-rw-r--r--src/armnnUtils/NetworkSockets.hpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/armnnUtils/NetworkSockets.hpp b/src/armnnUtils/NetworkSockets.hpp
new file mode 100644
index 0000000000..9e4770793c
--- /dev/null
+++ b/src/armnnUtils/NetworkSockets.hpp
@@ -0,0 +1,59 @@
+//
+// Copyright © 2020 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+// This file (along with its corresponding .cpp) defines a very thin platform abstraction layer for the use of
+// networking sockets. Thankfully the underlying APIs on Windows and Linux are very similar so not much conversion
+// is needed (typically just forwarding the parameters to a differently named function).
+// Some of the APIs are in fact completely identical and so no forwarding function is needed.
+
+#pragma once
+
+#if defined(__unix__)
+#include <poll.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#elif defined(_MSC_VER)
+#include <winsock2.h>
+#include <afunix.h>
+#endif
+
+namespace armnnUtils
+{
+namespace Sockets
+{
+
+#if defined(__unix__)
+
+using Socket = int;
+using PollFd = pollfd;
+
+#elif defined(_MSC_VER)
+
+using Socket = SOCKET;
+using PollFd = WSAPOLLFD;
+#define SOCK_CLOEXEC 0
+
+#endif
+
+/// Performs any required one-time setup.
+bool Initialize();
+
+int Close(Socket s);
+
+bool SetNonBlocking(Socket s);
+
+long Write(Socket s, const void* buf, size_t len);
+
+long Read(Socket s, void* buf, size_t len);
+
+int Ioctl(Socket s, unsigned long cmd, void* arg);
+
+int Poll(PollFd* fds, size_t numFds, int timeout);
+
+Socket Accept(Socket s, sockaddr* addr, unsigned int* addrlen, int flags);
+
+}
+}