Skip to content

Commit eee27b0

Browse files
Splitting the definition of client into 2 interfaces
- ClientConnect provides the abstraction required to address connection methods for TCP like sessions. - Client provides the same Features as before, but it is specialized to handle connections that are then handled like a stream, like a classical TCP connection This distinction will be used to differentiate stream like communication protocols, i.e. websocket, tcp, http streaming, from discrete sized packets communication, like MQTT.
1 parent 4a02bfc commit eee27b0

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

api/Client.h

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,28 @@
2424

2525
namespace arduino {
2626

27-
class Client : public Stream {
27+
// The objective of this interface is to split the definition of a Client that
28+
// works with streams and one that works with discrete sized messages
29+
class ClientConnect {
30+
public:
31+
virtual ~ClientConnect() = default;
32+
33+
virtual int connect(IPAddress ip, uint16_t port) = 0;
34+
virtual int connect(const char *host, uint16_t port) = 0;
35+
virtual void disconnect() = 0;
36+
37+
virtual uint8_t connected() = 0;
38+
virtual operator bool() = 0;
39+
};
2840

41+
class Client : public Stream, ClientConnect {
2942
public:
30-
virtual int connect(IPAddress ip, uint16_t port) =0;
31-
virtual int connect(const char *host, uint16_t port) =0;
32-
virtual size_t write(uint8_t) =0;
33-
virtual size_t write(const uint8_t *buf, size_t size) =0;
34-
virtual int available() = 0;
35-
virtual int read() = 0;
43+
virtual size_t write(uint8_t) = 0;
44+
virtual size_t write(const uint8_t *buf, size_t size) = 0;
3645
virtual int read(uint8_t *buf, size_t size) = 0;
37-
virtual int peek() = 0;
38-
virtual void flush() = 0;
3946
virtual void stop() = 0;
40-
virtual uint8_t connected() = 0;
41-
virtual operator bool() = 0;
4247
protected:
43-
uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); };
48+
uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); }; // FIXME this is a utility function
4449
};
4550

46-
}
51+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy