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 --- profiling/common/src/NetworkSockets.cpp | 101 ++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 profiling/common/src/NetworkSockets.cpp (limited to 'profiling/common/src') 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 +} + +} +} -- cgit v1.2.1