arduino-emulator
Loading...
Searching...
No Matches
DesktopSocketWindows.h
1#pragma once
2
3#ifndef WIN32_LEAN_AND_MEAN
4#define WIN32_LEAN_AND_MEAN
5#endif
6#define INPUT ARDUINO_WINDOWS_INPUT
7#include <winsock2.h>
8#include <ws2tcpip.h>
9#undef INPUT
10#undef INADDR_NONE
11
12#ifndef SHUT_RDWR
13#define SHUT_RDWR SD_BOTH
14#endif
15
16namespace arduino {
17
18using SocketHandle = SOCKET;
19constexpr SocketHandle INVALID_SOCKET_HANDLE = INVALID_SOCKET;
20using SocketLength = int;
21
22class SocketRuntime {
23 public:
24 SocketRuntime() {
25 WSADATA data;
26 WSAStartup(MAKEWORD(2, 2), &data);
27 }
28 ~SocketRuntime() { WSACleanup(); }
29};
30
31inline void ensureSocketRuntime() {
32 static SocketRuntime runtime;
33 (void)runtime;
34}
35
36inline void closeSocket(SocketHandle socket) { closesocket(socket); }
37inline int socketLastError() { return WSAGetLastError(); }
38inline bool socketWouldBlock(int error) { return error == WSAEWOULDBLOCK; }
39inline bool socketConnectionReset(int error) { return error == WSAECONNRESET; }
40
41inline bool setSocketNonBlocking(SocketHandle socket, bool enabled = true) {
42 u_long mode = enabled ? 1UL : 0UL;
43 return ioctlsocket(socket, FIONBIO, &mode) == 0;
44}
45
46} // namespace arduino
We provide the WiFi class to simulate the Arduino WIFI. In in Linux we can expect that networking is ...
Definition CanMsg.cpp:31