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 <netinet/in.h>
11#include <netinet/tcp.h> // TCP_NODELAY
12#include <poll.h>
13#include <sys/ioctl.h>
14#include <sys/socket.h>
15#include <sys/types.h>
16#include <unistd.h>
17
18namespace arduino {
19
20using SocketHandle = int;
21constexpr SocketHandle INVALID_SOCKET_HANDLE = -1;
22using SocketLength = socklen_t;
23
24class SocketRuntime {
25 public:
26 SocketRuntime() = default;
27 ~SocketRuntime() = default;
28};
29
30inline void ensureSocketRuntime() {
31 static SocketRuntime runtime;
32 (void)runtime;
33}
34
35inline void closeSocket(SocketHandle socket) { ::close(socket); }
36inline int socketLastError() { return errno; }
37
38inline bool socketWouldBlock(int error) {
39 return error == EWOULDBLOCK || error == EAGAIN;
40}
41inline bool socketConnectionReset(int error) { return error == ECONNRESET; }
42
43inline bool setSocketNonBlocking(SocketHandle socket, bool enabled = true) {
44 int flags = fcntl(socket, F_GETFL, 0);
45 return flags >= 0 && fcntl(socket, F_SETFL, enabled ? flags | O_NONBLOCK
46 : flags & ~O_NONBLOCK) == 0;
47}
48
49} // namespace arduino
Definition DesktopSocketPosix.h:24
We provide the WiFi class to simulate the Arduino WIFI. In in Linux we can expect that networking is ...
Definition CanMsg.cpp:31