ArmNN
 20.02
NetworkSockets.hpp
Go to the documentation of this file.
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 
52 int Ioctl(Socket s, unsigned long int cmd, void* arg);
53 
54 int Poll(PollFd* fds, nfds_t numFds, int timeout);
55 
56 Socket Accept(Socket s, sockaddr* addr, socklen_t* addrlen, int flags);
57 
58 }
59 }
int Poll(PollFd *fds, nfds_t numFds, int timeout)
int Ioctl(Socket s, unsigned long int cmd, void *arg)
bool Initialize()
Performs any required one-time setup.
bool SetNonBlocking(Socket s)
armnnUtils::Sockets::Socket Accept(Socket s, sockaddr *addr, socklen_t *addrlen, int flags)
long Write(Socket s, const void *buf, size_t len)
long Read(Socket s, void *buf, size_t len)