forked from arduino/ArduinoCore-mbed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAClient.cpp
150 lines (124 loc) · 2.85 KB
/
AClient.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include "AClient.h"
#include "MbedSSLClient.h"
void arduino::AClient::newMbedClient() {
client.reset(new MbedClient());
client->setNetwork(getNetwork());
}
arduino::AClient::operator bool() {
return client && *client;
}
void arduino::AClient::setSocket(Socket *sock) {
if (!client) {
newMbedClient();
}
client->setSocket(sock);
}
void arduino::AClient::setConnectionTimeout(unsigned long timeout) {
setSocketTimeout(timeout);
}
void arduino::AClient::setSocketTimeout(unsigned long timeout) {
if (!client) {
newMbedClient();
}
client->setSocketTimeout(timeout);
}
int arduino::AClient::connect(IPAddress ip, uint16_t port) {
if (!client) {
newMbedClient();
}
return client->connect(ip, port);
}
int arduino::AClient::connect(const char *host, uint16_t port) {
if (!client) {
newMbedClient();
}
return client->connect(host, port);
}
int arduino::AClient::connectSSL(IPAddress ip, uint16_t port) {
if (!client) {
newMbedClient();
}
return client->connectSSL(ip, port);
}
int arduino::AClient::connectSSL(const char *host, uint16_t port, bool disableSNI) {
if (!client) {
newMbedClient();
}
return client->connectSSL(host, port, disableSNI);
}
void arduino::AClient::stop() {
if (!client)
return;
client->stop();
}
uint8_t arduino::AClient::connected() {
if (!client)
return false;
return client->connected();
}
uint8_t arduino::AClient::status() {
if (!client)
return false;
return client->status();
}
IPAddress arduino::AClient::remoteIP() {
if (!client)
return INADDR_NONE;
return client->remoteIP();
}
uint16_t arduino::AClient::remotePort() {
if (!client)
return 0;
return client->remotePort();
}
size_t arduino::AClient::write(uint8_t b) {
if (!client)
return 0;
return client->write(b);
}
size_t arduino::AClient::write(const uint8_t *buf, size_t size) {
if (!client)
return 0;
return client->write(buf, size);
}
void arduino::AClient::flush() {
if (!client)
return;
client->flush();
}
int arduino::AClient::available() {
if (!client)
return 0;
return client->available();
}
int arduino::AClient::read() {
if (!client)
return -1;
return client->read();
}
int arduino::AClient::read(uint8_t *buf, size_t size) {
if (!client)
return 0;
return client->read(buf, size);
}
int arduino::AClient::peek() {
if (!client)
return -1;
return client->peek();
}
void arduino::ASslClient::newMbedClient() {
client.reset(new MbedSSLClient());
client->setNetwork(getNetwork());
}
void arduino::ASslClient::disableSNI(bool statusSNI) {
if (!client) {
newMbedClient();
}
static_cast<MbedSSLClient*>(client.get())->disableSNI(statusSNI);
}
void arduino::ASslClient::appendCustomCACert(const char* ca_cert) {
if (!client) {
newMbedClient();
}
static_cast<MbedSSLClient*>(client.get())->appendCustomCACert(ca_cert);
}