blob: be94be6aa3683558df3d3daba0671439639c8e48 [file] [log] [blame]
Laurent Carlier749294b2020-06-01 09:03:17 +01001//
Jim Flynn6da6a452020-07-14 14:26:27 +01002// Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
Rob Hughes25b74362020-01-13 11:14:59 +00003// 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
Jim Flynne195a042022-04-12 17:19:28 +010011#if !defined(ARMNN_DISABLE_SOCKETS)
12
Rob Hughes25b74362020-01-13 11:14:59 +000013#pragma once
14
Jim Flynn6da6a452020-07-14 14:26:27 +010015#if defined(__unix__) || defined(__APPLE__)
Rob Hughes25b74362020-01-13 11:14:59 +000016#include <poll.h>
17#include <sys/ioctl.h>
18#include <sys/socket.h>
19#include <sys/un.h>
20#elif defined(_MSC_VER)
Rob Hughesbc873d22020-05-20 13:11:37 +010021#include <WindowsWrapper.hpp>
Rob Hughes25b74362020-01-13 11:14:59 +000022#include <winsock2.h>
23#include <afunix.h>
Jim Flynnbbfe6032020-07-20 16:57:44 +010024#elif defined(__MINGW32__)
25#include <WindowsWrapper.hpp>
26#include <winsock2.h>
Rob Hughes25b74362020-01-13 11:14:59 +000027#endif
28
Jim Flynnbbfe6032020-07-20 16:57:44 +010029namespace arm
Rob Hughes25b74362020-01-13 11:14:59 +000030{
Jim Flynnbbfe6032020-07-20 16:57:44 +010031namespace pipe
Rob Hughes25b74362020-01-13 11:14:59 +000032{
33
34#if defined(__unix__)
35
36using Socket = int;
37using PollFd = pollfd;
38
Jim Flynn6da6a452020-07-14 14:26:27 +010039#elif defined(__APPLE__)
40
41using Socket = int;
42using PollFd = pollfd;
43#define SOCK_CLOEXEC 0
44
Rob Hughes25b74362020-01-13 11:14:59 +000045#elif defined(_MSC_VER)
46
47using Socket = SOCKET;
48using PollFd = WSAPOLLFD;
Rob Hughesb98032f2020-04-24 11:41:34 +010049using nfds_t = int;
50using socklen_t = int;
Rob Hughes25b74362020-01-13 11:14:59 +000051#define SOCK_CLOEXEC 0
52
Jim Flynnbbfe6032020-07-20 16:57:44 +010053#elif defined(__MINGW32__)
54
55using Socket = SOCKET;
56using PollFd = WSAPOLLFD;
57using nfds_t = int;
58using socklen_t = int;
59#define SOCK_CLOEXEC 0
60
Rob Hughes25b74362020-01-13 11:14:59 +000061#endif
62
63/// Performs any required one-time setup.
64bool Initialize();
65
66int Close(Socket s);
67
68bool SetNonBlocking(Socket s);
69
70long Write(Socket s, const void* buf, size_t len);
71
72long Read(Socket s, void* buf, size_t len);
73
David Monahan5277ad52020-01-22 15:40:34 +000074int Ioctl(Socket s, unsigned long int cmd, void* arg);
Rob Hughes25b74362020-01-13 11:14:59 +000075
David Monahan5277ad52020-01-22 15:40:34 +000076int Poll(PollFd* fds, nfds_t numFds, int timeout);
Rob Hughes25b74362020-01-13 11:14:59 +000077
David Monahana0d18962020-01-24 09:13:33 +000078Socket Accept(Socket s, sockaddr* addr, socklen_t* addrlen, int flags);
Rob Hughes25b74362020-01-13 11:14:59 +000079
Jim Flynnbbfe6032020-07-20 16:57:44 +010080} // namespace arm
81} // namespace pipe
Jim Flynne195a042022-04-12 17:19:28 +010082
83#endif