Rob Hughes | 25b7436 | 2020-01-13 11:14:59 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2020 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | // This file (along with its corresponding .cpp) defines a very thin platform abstraction layer for the use of |
| 7 | // networking sockets. Thankfully the underlying APIs on Windows and Linux are very similar so not much conversion |
| 8 | // is needed (typically just forwarding the parameters to a differently named function). |
| 9 | // Some of the APIs are in fact completely identical and so no forwarding function is needed. |
| 10 | |
| 11 | #pragma once |
| 12 | |
| 13 | #if defined(__unix__) |
| 14 | #include <poll.h> |
| 15 | #include <sys/ioctl.h> |
| 16 | #include <sys/socket.h> |
| 17 | #include <sys/un.h> |
| 18 | #elif defined(_MSC_VER) |
| 19 | #include <winsock2.h> |
| 20 | #include <afunix.h> |
| 21 | #endif |
| 22 | |
| 23 | namespace armnnUtils |
| 24 | { |
| 25 | namespace Sockets |
| 26 | { |
| 27 | |
| 28 | #if defined(__unix__) |
| 29 | |
| 30 | using Socket = int; |
| 31 | using PollFd = pollfd; |
| 32 | |
| 33 | #elif defined(_MSC_VER) |
| 34 | |
| 35 | using Socket = SOCKET; |
| 36 | using PollFd = WSAPOLLFD; |
| 37 | #define SOCK_CLOEXEC 0 |
| 38 | |
| 39 | #endif |
| 40 | |
| 41 | /// Performs any required one-time setup. |
| 42 | bool Initialize(); |
| 43 | |
| 44 | int Close(Socket s); |
| 45 | |
| 46 | bool SetNonBlocking(Socket s); |
| 47 | |
| 48 | long Write(Socket s, const void* buf, size_t len); |
| 49 | |
| 50 | long Read(Socket s, void* buf, size_t len); |
| 51 | |
David Monahan | 5277ad5 | 2020-01-22 15:40:34 +0000 | [diff] [blame] | 52 | int Ioctl(Socket s, unsigned long int cmd, void* arg); |
Rob Hughes | 25b7436 | 2020-01-13 11:14:59 +0000 | [diff] [blame] | 53 | |
David Monahan | 5277ad5 | 2020-01-22 15:40:34 +0000 | [diff] [blame] | 54 | int Poll(PollFd* fds, nfds_t numFds, int timeout); |
Rob Hughes | 25b7436 | 2020-01-13 11:14:59 +0000 | [diff] [blame] | 55 | |
David Monahan | a0d1896 | 2020-01-24 09:13:33 +0000 | [diff] [blame] | 56 | Socket Accept(Socket s, sockaddr* addr, socklen_t* addrlen, int flags); |
Rob Hughes | 25b7436 | 2020-01-13 11:14:59 +0000 | [diff] [blame] | 57 | |
| 58 | } |
| 59 | } |