From 9937f9359ac4eeefc3535b66eddddd1b4f067c54 Mon Sep 17 00:00:00 2001 From: Finn Williams Date: Wed, 29 Apr 2020 12:00:24 +0100 Subject: IVGCVSW-4732 Move NetworkSockets class needs to profiling/common Signed-off-by: Finn Williams Change-Id: Ie1bd73e6c1818277943e70eaf73b4d9a26da4758 --- Android.mk | 2 +- CMakeLists.txt | 4 +- profiling/common/include/NetworkSockets.hpp | 59 ++++++++++++ profiling/common/src/NetworkSockets.cpp | 101 +++++++++++++++++++++ .../server/src/basePipeServer/BasePipeServer.cpp | 3 +- .../server/src/basePipeServer/BasePipeServer.hpp | 8 +- .../src/basePipeServer/ConnectionHandler.hpp | 1 - src/armnnUtils/NetworkSockets.cpp | 101 --------------------- src/armnnUtils/NetworkSockets.hpp | 59 ------------ src/profiling/SocketProfilingConnection.hpp | 2 +- tests/profiling/gatordmock/GatordMockService.cpp | 2 +- 11 files changed, 171 insertions(+), 171 deletions(-) create mode 100644 profiling/common/include/NetworkSockets.hpp create mode 100644 profiling/common/src/NetworkSockets.cpp delete mode 100644 src/armnnUtils/NetworkSockets.cpp delete mode 100644 src/armnnUtils/NetworkSockets.hpp diff --git a/Android.mk b/Android.mk index 9ae4a993b9..99b169471e 100644 --- a/Android.mk +++ b/Android.mk @@ -86,6 +86,7 @@ LOCAL_C_INCLUDES := \ LOCAL_SRC_FILES := \ $(ARMNN_BACKEND_SOURCES) \ + profiling/common/src/NetworkSockets.cpp \ src/armnn/BackendHelper.cpp \ src/armnn/BackendRegistry.cpp \ src/armnn/Descriptors.cpp \ @@ -122,7 +123,6 @@ LOCAL_SRC_FILES := \ src/armnnUtils/Permute.cpp \ src/armnnUtils/TensorUtils.cpp \ src/armnnUtils/VerificationHelpers.cpp \ - src/armnnUtils/NetworkSockets.cpp \ src/armnnUtils/Filesystem.cpp \ src/armnnUtils/Processes.cpp \ src/armnnUtils/Transpose.cpp \ diff --git a/CMakeLists.txt b/CMakeLists.txt index 586d64c89c..dba41a3f55 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,8 +72,6 @@ list(APPEND armnnUtils_sources src/armnnUtils/TensorIOUtils.hpp src/armnnUtils/TensorUtils.cpp src/armnnUtils/Transpose.cpp - src/armnnUtils/NetworkSockets.hpp - src/armnnUtils/NetworkSockets.cpp ) add_library_ex(armnnUtils STATIC ${armnnUtils_sources}) @@ -254,6 +252,8 @@ list(APPEND armnn_sources include/armnn/utility/StringUtils.hpp profiling/common/include/ProfilingException.hpp profiling/common/include/SocketConnectionException.hpp + profiling/common/include/NetworkSockets.hpp + profiling/common/src/NetworkSockets.cpp src/armnn/layers/LayerCloneBase.hpp src/armnn/layers/LayerWithParameters.hpp src/armnn/layers/ActivationLayer.hpp diff --git a/profiling/common/include/NetworkSockets.hpp b/profiling/common/include/NetworkSockets.hpp new file mode 100644 index 0000000000..b9e58aac1d --- /dev/null +++ b/profiling/common/include/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 +#include +#include +#include +#elif defined(_MSC_VER) +#include +#include +#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/profiling/common/src/NetworkSockets.cpp b/profiling/common/src/NetworkSockets.cpp new file mode 100644 index 0000000000..8ce5f197c1 --- /dev/null +++ b/profiling/common/src/NetworkSockets.cpp @@ -0,0 +1,101 @@ +// +// Copyright © 2020 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "common/include/NetworkSockets.hpp" + +#if defined(__unix__) +#include +#include +#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(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(buf), len, 0); +#endif +} + +int Ioctl(Socket s, unsigned long int cmd, void* arg) +{ +#if defined(__ANDROID__) + return ioctl(s, static_cast(cmd), arg); +#elif defined(__unix__) + return ioctl(s, cmd, arg); +#elif defined(_MSC_VER) + return ioctlsocket(s, cmd, static_cast(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(addrlen)); +#endif +} + +} +} diff --git a/profiling/server/src/basePipeServer/BasePipeServer.cpp b/profiling/server/src/basePipeServer/BasePipeServer.cpp index fde5684160..1d5e0b6414 100644 --- a/profiling/server/src/basePipeServer/BasePipeServer.cpp +++ b/profiling/server/src/basePipeServer/BasePipeServer.cpp @@ -3,11 +3,12 @@ // SPDX-License-Identifier: MIT // +#include "BasePipeServer.hpp" + #include #include #include #include -#include "BasePipeServer.hpp" using namespace armnnUtils; diff --git a/profiling/server/src/basePipeServer/BasePipeServer.hpp b/profiling/server/src/basePipeServer/BasePipeServer.hpp index a150d76278..c03774e452 100644 --- a/profiling/server/src/basePipeServer/BasePipeServer.hpp +++ b/profiling/server/src/basePipeServer/BasePipeServer.hpp @@ -5,13 +5,13 @@ #pragma once -//#include -#include -#include -#include "../../../../src/armnnUtils/NetworkSockets.hpp" +#include "common/include/NetworkSockets.hpp" #include "../../../../src/profiling/Packet.hpp" #include "common/include/SocketConnectionException.hpp" +#include +#include + namespace armnnProfiling { diff --git a/profiling/server/src/basePipeServer/ConnectionHandler.hpp b/profiling/server/src/basePipeServer/ConnectionHandler.hpp index e7317dc355..661935b885 100644 --- a/profiling/server/src/basePipeServer/ConnectionHandler.hpp +++ b/profiling/server/src/basePipeServer/ConnectionHandler.hpp @@ -5,7 +5,6 @@ #pragma once -#include "../../../../src/armnnUtils/NetworkSockets.hpp" #include "BasePipeServer.hpp" #include 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 -#include -#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(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(buf), len, 0); -#endif -} - -int Ioctl(Socket s, unsigned long int cmd, void* arg) -{ -#if defined(__ANDROID__) - return ioctl(s, static_cast(cmd), arg); -#elif defined(__unix__) - return ioctl(s, cmd, arg); -#elif defined(_MSC_VER) - return ioctlsocket(s, cmd, static_cast(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(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 -#include -#include -#include -#elif defined(_MSC_VER) -#include -#include -#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 -#include +#include #pragma once diff --git a/tests/profiling/gatordmock/GatordMockService.cpp b/tests/profiling/gatordmock/GatordMockService.cpp index 13f688225b..53974fec3f 100644 --- a/tests/profiling/gatordmock/GatordMockService.cpp +++ b/tests/profiling/gatordmock/GatordMockService.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include -- cgit v1.2.1