arduino-emulator
Loading...
Searching...
No Matches
SocketImpl.h
1/*
2 SocketImpl.h
3 Copyright (c) 2025 Phil Schatzmann. All right reserved.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18*/
19
20#pragma once
21#include "DesktopSocket.h"
22#include <cstdint>
23#if !ARDUINO_EMULATOR_WINDOWS
24#include <netinet/in.h>
25#endif
26#include <cstring>
27
28namespace arduino {
29
31 public:
32 SocketImpl() = default;
34 sock = socket;
35 is_connected = true;
36 memset(&serv_addr, 0, sizeof(serv_addr));
37 };
38 SocketImpl(SocketHandle socket, struct sockaddr_in* address) {
39 sock = socket;
40 is_connected = true;
41 serv_addr = *address;
42 };
43 virtual ~SocketImpl() {
44 if (sock != INVALID_SOCKET_HANDLE) {
45 close();
46 }
47 }
48 // checks if we are connected
49 virtual uint8_t connected();
50 // opens a conection
51 virtual int connect(const char* address, uint16_t port);
52 // opens a connection with a timeout in milliseconds
53 virtual int connect(const char* address, uint16_t port, int32_t timeout_ms);
54 // sends some data
55 virtual size_t write(const uint8_t* str, size_t len);
56 // provides the available bytes
57 virtual size_t available();
58 // direct read
59 virtual int read(uint8_t* buffer, size_t len);
60 // peeks one character
61 virtual int peek();
62 // coloses the connection
63 virtual void close();
64
65 // determines the IP Adress
66 const char* getIPAddress();
67 // determines the IP Adress
68 const char* getIPAddress(const char* validEntries[]);
69
70 virtual void setCACert(const char* cert) {}
71 virtual void setInsecure() {}
72 SocketHandle fd() { return sock; }
73
74 protected:
75 bool is_connected = false;
76 SocketHandle sock = INVALID_SOCKET_HANDLE;
77 int valread = 0;
78 struct sockaddr_in serv_addr;
79};
80
81} // namespace arduino
Definition DMAPool.h:103
Definition SocketImpl.h:30
We provide the WiFi class to simulate the Arduino WIFI. In in Linux we can expect that networking is ...
Definition CanMsg.cpp:31