REDAC HybridController
Firmware for LUCIDAC/REDAC Teensy
Loading...
Searching...
No Matches
teensy_ethernet_client.h
Go to the documentation of this file.
1#pragma once
2
3#include <IPAddress.h>
4#include <QNEthernet.h>
5
6#include <net/ethernet_client_hal.h>
7
8namespace qn = qindesign::network;
9
10namespace net {
11
12class EthernetServer;
13
14class TeensyEthernetClientHAL : public EthernetClientHAL {
15public:
17 ~TeensyEthernetClientHAL() override = default;
18
19 int connect(IPAddress ip, uint16_t port) override;
20 // Returns INVALID_SERVER (-2) if DNS is disabled.
21 int connect(const char *host, uint16_t port) override;
22
23 // These functions start the connection process but don't wait for the
24 // connection to be complete. Note that DNS lookup might still take some time.
25 // Neither of these will return TIMED_OUT (-1).
26 int connectNoWait(const IPAddress &ip, uint16_t port) override;
27
28 // Returns INVALID_SERVER (-2) if DNS is disabled.
29 int connectNoWait(const char *host, uint16_t port) override;
30
31 uint8_t connected() override;
32 operator bool() override;
33
34 void setConnectionTimeout(uint16_t timeout) override;
35
36 // Returns the current timeout value.
37 uint16_t connectionTimeout() const override;
38
39 void stop() override;
40
41 // Closes the connection. This works the same as stop(), but without waiting
42 // for the connection to close.
43 void close() override;
44
45 // Closes the sending side of this connection.
46 void closeOutput() override;
47
48 // Kills the connection without going through the TCP close process.
49 void abort() override;
50
51 uint16_t localPort() override;
52 IPAddress remoteIP() override;
53 uint16_t remotePort() override;
54
55 // Returns the local IP address for this connection, or INADDR_NONE if this
56 // client is not connected.
57 IPAddress localIP() override;
58
59 // Returns an ID for the connection to which this client refers. It will
60 // return non-zero if connected and zero if not connected.
61 //
62 // This is useful because of the way EthernetClient objects can be passed
63 // around, copied, and moved, etc. Just taking an address of the object won't
64 // work because more than one object could refer to the same connection.
65 //
66 // Note that while multiple active connections won't share the same ID, it's
67 // possible for new connections to reuse IDs that aren't currently in use. In
68 // other words, there is a one-to-one correspondence between the set of
69 // connection IDs and currently active connections.
70 uintptr_t connectionId() override;
71
72 // Functions that loop until all bytes are written. If the connection is
73 // closed before all bytes are sent then these break early and return the
74 // actual number of bytes sent. In other words, these only return a value less
75 // than the specified size if the connection was closed.
76 size_t writeFully(uint8_t b) override;
77 size_t writeFully(const char *s) override;
78 size_t writeFully(const char *s, size_t size) override;
79 size_t writeFully(const uint8_t *buf, size_t size) override;
80
81 size_t write(uint8_t b) override;
82 size_t write(const uint8_t *buf, size_t size) override;
83 int availableForWrite() override;
84 void flush() override;
85
86 int available() override;
87 int read() override;
88
89 // A NULL buffer allows the caller to skip bytes without having to read into
90 // a buffer.
91 int read(uint8_t *buf, size_t size) override;
92
93 int peek() override;
94
95 // ----------------
96 // Socket Options
97 // ----------------
98
99 // Disables or enables Nagle's algorithm. This sets or clears the TCP_NODELAY
100 // flag. If the flag is set then Nagle's algorithm is disabled, otherwise it
101 // is enabled. Note that this option must be set for each new connection.
102 void setNoDelay(bool flag) override;
103
104 // Returns the value of the TCP_NODELAY flag for the current connection. This
105 // returns false if not connected.
106 bool isNoDelay() override;
107
108public:
109 TeensyEthernetClientHAL(qn::EthernetClient impl);
110 qn::EthernetClient impl_;
112};
113
114} // namespace net
~TeensyEthernetClientHAL() override=default
size_t write(uint8_t b) override
void setConnectionTimeout(uint16_t timeout) override
uint16_t connectionTimeout() const override
size_t writeFully(uint8_t b) override
int connectNoWait(const IPAddress &ip, uint16_t port) override
int connect(IPAddress ip, uint16_t port) override
uint32_t uint32_t size
Definition flasher.cpp:63