xref: /aosp_15_r20/external/armnn/profiling/common/include/NetworkSockets.hpp (revision 89c4ff92f2867872bb9e2354d150bf0c8c502810)
1 //
2 // Copyright © 2020 Arm Ltd and Contributors. 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 #if !defined(ARMNN_DISABLE_SOCKETS)
12 
13 #pragma once
14 
15 #if defined(__unix__) || defined(__APPLE__)
16 #include <poll.h>
17 #include <sys/ioctl.h>
18 #include <sys/socket.h>
19 #include <sys/un.h>
20 #elif defined(_MSC_VER)
21 #include <WindowsWrapper.hpp>
22 #include <winsock2.h>
23 #include <afunix.h>
24 #elif defined(__MINGW32__)
25 #include <WindowsWrapper.hpp>
26 #include <winsock2.h>
27 #endif
28 
29 namespace arm
30 {
31 namespace pipe
32 {
33 
34 #if defined(__unix__)
35 
36 using Socket = int;
37 using PollFd = pollfd;
38 
39 #elif defined(__APPLE__)
40 
41 using Socket = int;
42 using PollFd = pollfd;
43 #define SOCK_CLOEXEC 0
44 
45 #elif defined(_MSC_VER)
46 
47 using Socket = SOCKET;
48 using PollFd = WSAPOLLFD;
49 using nfds_t = int;
50 using socklen_t = int;
51 #define SOCK_CLOEXEC 0
52 
53 #elif defined(__MINGW32__)
54 
55 using Socket = SOCKET;
56 using PollFd = WSAPOLLFD;
57 using nfds_t = int;
58 using socklen_t = int;
59 #define SOCK_CLOEXEC 0
60 
61 #endif
62 
63 /// Performs any required one-time setup.
64 bool Initialize();
65 
66 int Close(Socket s);
67 
68 bool SetNonBlocking(Socket s);
69 
70 long Write(Socket s, const void* buf, size_t len);
71 
72 long Read(Socket s, void* buf, size_t len);
73 
74 int Ioctl(Socket s, unsigned long int cmd, void* arg);
75 
76 int Poll(PollFd* fds, nfds_t numFds, int timeout);
77 
78 Socket Accept(Socket s, sockaddr* addr, socklen_t* addrlen, int flags);
79 
80 } // namespace arm
81 } // namespace pipe
82 
83 #endif
84