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