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