arduino-emulator
Loading...
Searching...
No Matches
DesktopSocketPosix.h
1#pragma once
2
3#include <arpa/inet.h>
4// Collide with existing definitions
5#undef INADDR_NONE
6
7#include <errno.h>
8#include <fcntl.h>
9#include <netdb.h>
10#include <poll.h>
11#include <sys/ioctl.h>
12#include <sys/socket.h>
13#include <sys/types.h>
14#include <unistd.h>
15
16namespace arduino {
17
18using SocketHandle = int;
19constexpr SocketHandle INVALID_SOCKET_HANDLE = -1;
20using SocketLength = socklen_t;
21
23 public:
24 SocketRuntime() = default;
25 ~SocketRuntime() = default;
26};
27
28inline void ensureSocketRuntime() {
31}
32
33inline void closeSocket(SocketHandle socket) { ::close(socket); }
34inline int socketLastError() { return errno; }
35
36inline bool socketWouldBlock(int error) {
37 return error == EWOULDBLOCK || error == EAGAIN;
38}
39inline bool socketConnectionReset(int error) { return error == ECONNRESET; }
40
41inline bool setSocketNonBlocking(SocketHandle socket, bool enabled = true) {
42 int flags = fcntl(socket, F_GETFL, 0);
43 return flags >= 0 && fcntl(socket, F_SETFL, enabled ? flags | O_NONBLOCK
44 : flags & ~O_NONBLOCK) == 0;
45}
46
47} // namespace arduino
Definition DMAPool.h:103
Definition DesktopSocketPosix.h:22
We provide the WiFi class to simulate the Arduino WIFI. In in Linux we can expect that networking is ...
Definition CanMsg.cpp:31