REDAC HybridController
Firmware for LUCIDAC/REDAC Teensy
Loading...
Searching...
No Matches
native_ethernet_server.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef _WIN64
4#include <winsock2.h>
5#include <ws2tcpip.h>
6#pragma comment(lib, "ws2_32.lib")
7#else
8#include <arpa/inet.h>
9#include <fcntl.h>
10#include <netinet/in.h>
11#include <sys/socket.h>
12#include <unistd.h>
13#endif
14
15#include <net/ethernet_server_hal.h>
16
17#include <Arduino.h>
18#include <stdexcept>
19
20namespace net {
21
22class NativeEthernetServerHAL : public EthernetServerHAL {
23public:
24 ~NativeEthernetServerHAL() override;
25
26 // Returns the maximum number of TCP listeners.
27 static constexpr int maxListeners() { return 8; }
28
29 // Returns the server port. This will return -1 if it has not been set.
30 //
31 // Note that the value is still a 16-bit quantity if it is non-negative.
32 int32_t port() const { return 0; }
33
34 // Starts listening on the server port, if set. This does not set the
35 // SO_REUSEADDR socket option.
36 //
37 // This first calls end() if the _reuse_ socket option differs.
38 void begin() override { throw std::runtime_error("not impl"); }
39
40 // Starts listening on the server port, if set, and sets the SO_REUSEADDR
41 // socket option. This returns whether the server started listening. This will
42 // always return false if the port is not set.
43 //
44 // This first calls end() if the _reuse_ socket option differs.
45 bool beginWithReuse() override { throw std::runtime_error("not impl"); }
46
47 // Starts listening on the specified port. This does not set the SO_REUSEADDR
48 // socket option. This returns whether the server started listening.
49 //
50 // This first calls end() if the port or _reuse_ socket option differ.
51 bool begin(uint16_t port) override;
52
53 // Starts listening on the specified port, if set, and sets the SO_REUSEADDR
54 // socket option. This returns whether the server started listening.
55 //
56 // If the port or _reuse_ socket option differ then this first calls end() to
57 // prevent a single server object from representing more than one
58 // listening socket.
59 bool beginWithReuse(uint16_t port) override { throw std::runtime_error("not impl"); }
60
61 // Stops listening. This does nothing if the port is not set or the server is
62 // not listening.
63 void end() override { throw std::runtime_error("not impl"); }
64
65 // Accepts a connection and returns a client, possibly unconnected. This
66 // returns an unconnected client if the port is not set.
67 EthernetClient accept();
68
69 // Finds a connection with available data. This returns an unconnected client
70 // if there is no client with available data or if the port is not set.
71 EthernetClient available() const override { throw std::runtime_error("not impl"); }
72
73 // Writes a byte to all the connections. This does nothing and returns 1 if
74 // the port is not set.
75 size_t write(uint8_t b) override { throw std::runtime_error("not impl"); }
76
77 // Writes data to all the connections. This does nothing and returns size if
78 // the port is not set.
79 size_t write(const uint8_t *buffer, size_t size) override { throw std::runtime_error("not impl"); }
80
81 // Returns the minimum availability of all the connections, or zero if there
82 // are no connections or if the port is not set.
83 int availableForWrite() override { throw std::runtime_error("not impl"); }
84
85 // Flushes all the connections, but does nothing is the port is not set.
86 void flush() override { throw std::runtime_error("not impl"); }
87
88 explicit operator bool() override { throw std::runtime_error("not impl"); }
89
90private:
91 int server_fd;
92 sockaddr_in address;
93 bool running;
94};
95
96} // namespace net
size_t write(uint8_t b) override
size_t write(const uint8_t *buffer, size_t size) override
EthernetClient available() const override
static constexpr int maxListeners()
bool beginWithReuse(uint16_t port) override
uint32_t uint32_t size
Definition flasher.cpp:63