Skip to content

Commit c111d5b

Browse files
Merge pull request me-no-dev#42 from ESP32Async/const
Immutable methods should be marked as const
2 parents e2ca2fa + 2476cd9 commit c111d5b

File tree

2 files changed

+61
-61
lines changed

2 files changed

+61
-61
lines changed

src/AsyncTCP.cpp

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ AsyncClient &AsyncClient::operator=(const AsyncClient &other) {
762762
return *this;
763763
}
764764

765-
bool AsyncClient::operator==(const AsyncClient &other) {
765+
bool AsyncClient::operator==(const AsyncClient &other) const {
766766
return _pcb == other._pcb;
767767
}
768768

@@ -930,7 +930,7 @@ int8_t AsyncClient::abort() {
930930
return ERR_ABRT;
931931
}
932932

933-
size_t AsyncClient::space() {
933+
size_t AsyncClient::space() const {
934934
if ((_pcb != NULL) && (_pcb->state == ESTABLISHED)) {
935935
return tcp_sndbuf(_pcb);
936936
}
@@ -1218,19 +1218,19 @@ void AsyncClient::setRxTimeout(uint32_t timeout) {
12181218
_rx_timeout = timeout;
12191219
}
12201220

1221-
uint32_t AsyncClient::getRxTimeout() {
1221+
uint32_t AsyncClient::getRxTimeout() const {
12221222
return _rx_timeout;
12231223
}
12241224

1225-
uint32_t AsyncClient::getAckTimeout() {
1225+
uint32_t AsyncClient::getAckTimeout() const {
12261226
return _ack_timeout;
12271227
}
12281228

12291229
void AsyncClient::setAckTimeout(uint32_t timeout) {
12301230
_ack_timeout = timeout;
12311231
}
12321232

1233-
void AsyncClient::setNoDelay(bool nodelay) {
1233+
void AsyncClient::setNoDelay(bool nodelay) const {
12341234
if (!_pcb) {
12351235
return;
12361236
}
@@ -1260,14 +1260,14 @@ void AsyncClient::setKeepAlive(uint32_t ms, uint8_t cnt) {
12601260
}
12611261
}
12621262

1263-
uint16_t AsyncClient::getMss() {
1263+
uint16_t AsyncClient::getMss() const {
12641264
if (!_pcb) {
12651265
return 0;
12661266
}
12671267
return tcp_mss(_pcb);
12681268
}
12691269

1270-
uint32_t AsyncClient::getRemoteAddress() {
1270+
uint32_t AsyncClient::getRemoteAddress() const {
12711271
if (!_pcb) {
12721272
return 0;
12731273
}
@@ -1279,7 +1279,7 @@ uint32_t AsyncClient::getRemoteAddress() {
12791279
}
12801280

12811281
#if LWIP_IPV6
1282-
ip6_addr_t AsyncClient::getRemoteAddress6() {
1282+
ip6_addr_t AsyncClient::getRemoteAddress6() const {
12831283
if (!_pcb) {
12841284
ip6_addr_t nulladdr;
12851285
ip6_addr_set_zero(&nulladdr);
@@ -1288,7 +1288,7 @@ ip6_addr_t AsyncClient::getRemoteAddress6() {
12881288
return _pcb->remote_ip.u_addr.ip6;
12891289
}
12901290

1291-
ip6_addr_t AsyncClient::getLocalAddress6() {
1291+
ip6_addr_t AsyncClient::getLocalAddress6() const {
12921292
if (!_pcb) {
12931293
ip6_addr_t nulladdr;
12941294
ip6_addr_set_zero(&nulladdr);
@@ -1297,15 +1297,15 @@ ip6_addr_t AsyncClient::getLocalAddress6() {
12971297
return _pcb->local_ip.u_addr.ip6;
12981298
}
12991299
#if ESP_IDF_VERSION_MAJOR < 5
1300-
IPv6Address AsyncClient::remoteIP6() {
1300+
IPv6Address AsyncClient::remoteIP6() const {
13011301
return IPv6Address(getRemoteAddress6().addr);
13021302
}
13031303

1304-
IPv6Address AsyncClient::localIP6() {
1304+
IPv6Address AsyncClient::localIP6() const {
13051305
return IPv6Address(getLocalAddress6().addr);
13061306
}
13071307
#else
1308-
IPAddress AsyncClient::remoteIP6() {
1308+
IPAddress AsyncClient::remoteIP6() const {
13091309
if (!_pcb) {
13101310
return IPAddress(IPType::IPv6);
13111311
}
@@ -1314,7 +1314,7 @@ IPAddress AsyncClient::remoteIP6() {
13141314
return ip;
13151315
}
13161316

1317-
IPAddress AsyncClient::localIP6() {
1317+
IPAddress AsyncClient::localIP6() const {
13181318
if (!_pcb) {
13191319
return IPAddress(IPType::IPv6);
13201320
}
@@ -1325,14 +1325,14 @@ IPAddress AsyncClient::localIP6() {
13251325
#endif
13261326
#endif
13271327

1328-
uint16_t AsyncClient::getRemotePort() {
1328+
uint16_t AsyncClient::getRemotePort() const {
13291329
if (!_pcb) {
13301330
return 0;
13311331
}
13321332
return _pcb->remote_port;
13331333
}
13341334

1335-
uint32_t AsyncClient::getLocalAddress() {
1335+
uint32_t AsyncClient::getLocalAddress() const {
13361336
if (!_pcb) {
13371337
return 0;
13381338
}
@@ -1343,14 +1343,14 @@ uint32_t AsyncClient::getLocalAddress() {
13431343
#endif
13441344
}
13451345

1346-
uint16_t AsyncClient::getLocalPort() {
1346+
uint16_t AsyncClient::getLocalPort() const {
13471347
if (!_pcb) {
13481348
return 0;
13491349
}
13501350
return _pcb->local_port;
13511351
}
13521352

1353-
IPAddress AsyncClient::remoteIP() {
1353+
IPAddress AsyncClient::remoteIP() const {
13541354
#if ESP_IDF_VERSION_MAJOR < 5
13551355
return IPAddress(getRemoteAddress());
13561356
#else
@@ -1363,11 +1363,11 @@ IPAddress AsyncClient::remoteIP() {
13631363
#endif
13641364
}
13651365

1366-
uint16_t AsyncClient::remotePort() {
1366+
uint16_t AsyncClient::remotePort() const {
13671367
return getRemotePort();
13681368
}
13691369

1370-
IPAddress AsyncClient::localIP() {
1370+
IPAddress AsyncClient::localIP() const {
13711371
#if ESP_IDF_VERSION_MAJOR < 5
13721372
return IPAddress(getLocalAddress());
13731373
#else
@@ -1380,53 +1380,53 @@ IPAddress AsyncClient::localIP() {
13801380
#endif
13811381
}
13821382

1383-
uint16_t AsyncClient::localPort() {
1383+
uint16_t AsyncClient::localPort() const {
13841384
return getLocalPort();
13851385
}
13861386

1387-
uint8_t AsyncClient::state() {
1387+
uint8_t AsyncClient::state() const {
13881388
if (!_pcb) {
13891389
return 0;
13901390
}
13911391
return _pcb->state;
13921392
}
13931393

1394-
bool AsyncClient::connected() {
1394+
bool AsyncClient::connected() const {
13951395
if (!_pcb) {
13961396
return false;
13971397
}
13981398
return _pcb->state == ESTABLISHED;
13991399
}
14001400

1401-
bool AsyncClient::connecting() {
1401+
bool AsyncClient::connecting() const {
14021402
if (!_pcb) {
14031403
return false;
14041404
}
14051405
return _pcb->state > CLOSED && _pcb->state < ESTABLISHED;
14061406
}
14071407

1408-
bool AsyncClient::disconnecting() {
1408+
bool AsyncClient::disconnecting() const {
14091409
if (!_pcb) {
14101410
return false;
14111411
}
14121412
return _pcb->state > ESTABLISHED && _pcb->state < TIME_WAIT;
14131413
}
14141414

1415-
bool AsyncClient::disconnected() {
1415+
bool AsyncClient::disconnected() const {
14161416
if (!_pcb) {
14171417
return true;
14181418
}
14191419
return _pcb->state == CLOSED || _pcb->state == TIME_WAIT;
14201420
}
14211421

1422-
bool AsyncClient::freeable() {
1422+
bool AsyncClient::freeable() const {
14231423
if (!_pcb) {
14241424
return true;
14251425
}
14261426
return _pcb->state == CLOSED || _pcb->state > ESTABLISHED;
14271427
}
14281428

1429-
bool AsyncClient::canSend() {
1429+
bool AsyncClient::canSend() const {
14301430
return space() > 0;
14311431
}
14321432

@@ -1453,7 +1453,7 @@ const char *AsyncClient::errorToString(int8_t error) {
14531453
}
14541454
}
14551455

1456-
const char *AsyncClient::stateToString() {
1456+
const char *AsyncClient::stateToString() const {
14571457
switch (state()) {
14581458
case 0: return "Closed";
14591459
case 1: return "Listen";
@@ -1660,11 +1660,11 @@ void AsyncServer::setNoDelay(bool nodelay) {
16601660
_noDelay = nodelay;
16611661
}
16621662

1663-
bool AsyncServer::getNoDelay() {
1663+
bool AsyncServer::getNoDelay() const {
16641664
return _noDelay;
16651665
}
16661666

1667-
uint8_t AsyncServer::status() {
1667+
uint8_t AsyncServer::status() const {
16681668
if (!_pcb) {
16691669
return 0;
16701670
}

src/AsyncTCP.h

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ class AsyncClient {
7878
AsyncClient &operator=(const AsyncClient &other);
7979
AsyncClient &operator+=(const AsyncClient &other);
8080

81-
bool operator==(const AsyncClient &other);
81+
bool operator==(const AsyncClient &other) const;
8282

83-
bool operator!=(const AsyncClient &other) {
83+
bool operator!=(const AsyncClient &other) const {
8484
return !(*this == other);
8585
}
8686
bool connect(const IPAddress &ip, uint16_t port);
@@ -102,9 +102,9 @@ class AsyncClient {
102102
bool free();
103103

104104
// ack is not pending
105-
bool canSend();
105+
bool canSend() const;
106106
// TCP buffer space available
107-
size_t space();
107+
size_t space() const;
108108

109109
/**
110110
* @brief add data to be send (but do not send yet)
@@ -154,51 +154,51 @@ class AsyncClient {
154154
return data == NULL ? 0 : write(data, strlen(data));
155155
};
156156

157-
uint8_t state();
158-
bool connecting();
159-
bool connected();
160-
bool disconnecting();
161-
bool disconnected();
157+
uint8_t state() const;
158+
bool connecting() const;
159+
bool connected() const;
160+
bool disconnecting() const;
161+
bool disconnected() const;
162162

163163
// disconnected or disconnecting
164-
bool freeable();
164+
bool freeable() const;
165165

166-
uint16_t getMss();
166+
uint16_t getMss() const;
167167

168-
uint32_t getRxTimeout();
168+
uint32_t getRxTimeout() const;
169169
// no RX data timeout for the connection in seconds
170170
void setRxTimeout(uint32_t timeout);
171171

172-
uint32_t getAckTimeout();
172+
uint32_t getAckTimeout() const;
173173
// no ACK timeout for the last sent packet in milliseconds
174174
void setAckTimeout(uint32_t timeout);
175175

176-
void setNoDelay(bool nodelay);
176+
void setNoDelay(bool nodelay) const;
177177
bool getNoDelay();
178178

179179
void setKeepAlive(uint32_t ms, uint8_t cnt);
180180

181-
uint32_t getRemoteAddress();
182-
uint16_t getRemotePort();
183-
uint32_t getLocalAddress();
184-
uint16_t getLocalPort();
181+
uint32_t getRemoteAddress() const;
182+
uint16_t getRemotePort() const;
183+
uint32_t getLocalAddress() const;
184+
uint16_t getLocalPort() const;
185185
#if LWIP_IPV6
186-
ip6_addr_t getRemoteAddress6();
187-
ip6_addr_t getLocalAddress6();
186+
ip6_addr_t getRemoteAddress6() const;
187+
ip6_addr_t getLocalAddress6() const;
188188
#if ESP_IDF_VERSION_MAJOR < 5
189-
IPv6Address remoteIP6();
190-
IPv6Address localIP6();
189+
IPv6Address remoteIP6() const;
190+
IPv6Address localIP6() const;
191191
#else
192-
IPAddress remoteIP6();
193-
IPAddress localIP6();
192+
IPAddress remoteIP6() const;
193+
IPAddress localIP6() const;
194194
#endif
195195
#endif
196196

197197
// compatibility
198-
IPAddress remoteIP();
199-
uint16_t remotePort();
200-
IPAddress localIP();
201-
uint16_t localPort();
198+
IPAddress remoteIP() const;
199+
uint16_t remotePort() const;
200+
IPAddress localIP() const;
201+
uint16_t localPort() const;
202202

203203
// set callback - on successful connect
204204
void onConnect(AcConnectHandler cb, void *arg = 0);
@@ -228,7 +228,7 @@ class AsyncClient {
228228
}
229229

230230
static const char *errorToString(int8_t error);
231-
const char *stateToString();
231+
const char *stateToString() const;
232232

233233
// internal callbacks - Do NOT call any of the functions below in user code!
234234
static int8_t _s_poll(void *arg, struct tcp_pcb *tpcb);
@@ -308,8 +308,8 @@ class AsyncServer {
308308
void begin();
309309
void end();
310310
void setNoDelay(bool nodelay);
311-
bool getNoDelay();
312-
uint8_t status();
311+
bool getNoDelay() const;
312+
uint8_t status() const;
313313

314314
// Do not use any of the functions below!
315315
static int8_t _s_accept(void *arg, tcp_pcb *newpcb, int8_t err);

0 commit comments

Comments
 (0)