blob: 77507644e6997b30455fd9825b2353490ca2ac04 [file] [log] [blame]
Rob Hughes25b74362020-01-13 11:14:59 +00001//
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
23namespace armnnUtils
24{
25namespace Sockets
26{
27
28#if defined(__unix__)
29
30using Socket = int;
31using PollFd = pollfd;
32
33#elif defined(_MSC_VER)
34
35using Socket = SOCKET;
36using PollFd = WSAPOLLFD;
Rob Hughesb98032f2020-04-24 11:41:34 +010037using nfds_t = int;
38using socklen_t = int;
Rob Hughes25b74362020-01-13 11:14:59 +000039#define SOCK_CLOEXEC 0
40
41#endif
42
43/// Performs any required one-time setup.
44bool Initialize();
45
46int Close(Socket s);
47
48bool SetNonBlocking(Socket s);
49
50long Write(Socket s, const void* buf, size_t len);
51
52long Read(Socket s, void* buf, size_t len);
53
David Monahan5277ad52020-01-22 15:40:34 +000054int Ioctl(Socket s, unsigned long int cmd, void* arg);
Rob Hughes25b74362020-01-13 11:14:59 +000055
David Monahan5277ad52020-01-22 15:40:34 +000056int Poll(PollFd* fds, nfds_t numFds, int timeout);
Rob Hughes25b74362020-01-13 11:14:59 +000057
David Monahana0d18962020-01-24 09:13:33 +000058Socket Accept(Socket s, sockaddr* addr, socklen_t* addrlen, int flags);
Rob Hughes25b74362020-01-13 11:14:59 +000059
60}
61}