diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/armnnUtils/NetworkSockets.cpp | 101 | ||||
-rw-r--r-- | src/armnnUtils/NetworkSockets.hpp | 59 | ||||
-rw-r--r-- | src/profiling/SocketProfilingConnection.hpp | 2 |
3 files changed, 1 insertions, 161 deletions
diff --git a/src/armnnUtils/NetworkSockets.cpp b/src/armnnUtils/NetworkSockets.cpp deleted file mode 100644 index 3f17a1bcb3..0000000000 --- a/src/armnnUtils/NetworkSockets.cpp +++ /dev/null @@ -1,101 +0,0 @@ -// -// Copyright © 2020 Arm Ltd. All rights reserved. -// SPDX-License-Identifier: MIT -// - -#include "NetworkSockets.hpp" - -#if defined(__unix__) -#include <unistd.h> -#include <fcntl.h> -#endif - -namespace armnnUtils -{ -namespace Sockets -{ - -bool Initialize() -{ -#if defined(__unix__) - return true; -#elif defined(_MSC_VER) - WSADATA wsaData; - return WSAStartup(MAKEWORD(2, 2), &wsaData) == 0; -#endif -} - -int Close(Socket s) -{ -#if defined(__unix__) - return close(s); -#elif defined(_MSC_VER) - return closesocket(s); -#endif -} - - -bool SetNonBlocking(Socket s) -{ -#if defined(__unix__) - const int currentFlags = fcntl(s, F_GETFL); - return fcntl(s, F_SETFL, currentFlags | O_NONBLOCK) == 0; -#elif defined(_MSC_VER) - u_long mode = 1; - return ioctlsocket(s, FIONBIO, &mode) == 0; -#endif -} - - -long Write(Socket s, const void* buf, size_t len) -{ -#if defined(__unix__) - return write(s, buf, len); -#elif defined(_MSC_VER) - return send(s, static_cast<const char*>(buf), len, 0); -#endif -} - - -long Read(Socket s, void* buf, size_t len) -{ -#if defined(__unix__) - return read(s, buf, len); -#elif defined(_MSC_VER) - return recv(s, static_cast<char*>(buf), len, 0); -#endif -} - -int Ioctl(Socket s, unsigned long int cmd, void* arg) -{ -#if defined(__ANDROID__) - return ioctl(s, static_cast<int>(cmd), arg); -#elif defined(__unix__) - return ioctl(s, cmd, arg); -#elif defined(_MSC_VER) - return ioctlsocket(s, cmd, static_cast<u_long*>(arg)); -#endif -} - - -int Poll(PollFd* fds, nfds_t numFds, int timeout) -{ -#if defined(__unix__) - return poll(fds, numFds, timeout); -#elif defined(_MSC_VER) - return WSAPoll(fds, numFds, timeout); -#endif -} - - -armnnUtils::Sockets::Socket Accept(Socket s, sockaddr* addr, socklen_t* addrlen, int flags) -{ -#if defined(__unix__) - return accept4(s, addr, addrlen, flags); -#elif defined(_MSC_VER) - return accept(s, addr, reinterpret_cast<int*>(addrlen)); -#endif -} - -} -} diff --git a/src/armnnUtils/NetworkSockets.hpp b/src/armnnUtils/NetworkSockets.hpp deleted file mode 100644 index b9e58aac1d..0000000000 --- a/src/armnnUtils/NetworkSockets.hpp +++ /dev/null @@ -1,59 +0,0 @@ -// -// 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 int cmd, void* arg); - -int Poll(PollFd* fds, nfds_t numFds, int timeout); - -Socket Accept(Socket s, sockaddr* addr, socklen_t* addrlen, int flags); - -} -} diff --git a/src/profiling/SocketProfilingConnection.hpp b/src/profiling/SocketProfilingConnection.hpp index 05c7130de7..259ee131f1 100644 --- a/src/profiling/SocketProfilingConnection.hpp +++ b/src/profiling/SocketProfilingConnection.hpp @@ -6,7 +6,7 @@ #include "IProfilingConnection.hpp" #include <Runtime.hpp> -#include <NetworkSockets.hpp> +#include <common/include/NetworkSockets.hpp> #pragma once |