Skip to content

Commit 8bd0b2a

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents d68b971 + 68701bf commit 8bd0b2a

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

cores/esp8266/IPAddress.cpp

+41
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,47 @@ IPAddress::IPAddress(const uint8_t *address) {
4040
memcpy(_address.bytes, address, sizeof(_address.bytes));
4141
}
4242

43+
bool IPAddress::fromString(const char *address) {
44+
// TODO: add support for "a", "a.b", "a.b.c" formats
45+
46+
uint16_t acc = 0; // Accumulator
47+
uint8_t dots = 0;
48+
49+
while (*address)
50+
{
51+
char c = *address++;
52+
if (c >= '0' && c <= '9')
53+
{
54+
acc = acc * 10 + (c - '0');
55+
if (acc > 255) {
56+
// Value out of [0..255] range
57+
return false;
58+
}
59+
}
60+
else if (c == '.')
61+
{
62+
if (dots == 3) {
63+
// Too much dots (there must be 3 dots)
64+
return false;
65+
}
66+
_address.bytes[dots++] = acc;
67+
acc = 0;
68+
}
69+
else
70+
{
71+
// Invalid char
72+
return false;
73+
}
74+
}
75+
76+
if (dots != 3) {
77+
// Too few dots (there must be 3 dots)
78+
return false;
79+
}
80+
_address.bytes[3] = acc;
81+
return true;
82+
}
83+
4384
IPAddress& IPAddress::operator=(const uint8_t *address) {
4485
memcpy(_address.bytes, address, sizeof(_address.bytes));
4586
return *this;

cores/esp8266/IPAddress.h

+3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ class IPAddress: public Printable {
4848
IPAddress(uint32_t address);
4949
IPAddress(const uint8_t *address);
5050

51+
bool fromString(const char *address);
52+
bool fromString(const String &address) { return fromString(address.c_str()); }
53+
5154
// Overloaded cast operator to allow IPAddress objects to be used where a pointer
5255
// to a four-byte uint8_t array is expected
5356
operator uint32_t() const {

cores/esp8266/core_esp8266_phy.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
#include <stdint.h>
2424
#include <stddef.h>
2525
#include <stdbool.h>
26-
27-
#include "c_types.h"
26+
#include <string.h>
27+
#include "c_types.h"
2828

2929
static const uint8_t ICACHE_FLASH_ATTR phy_init_data[128] =
3030
{

libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,12 @@ void HTTPClient::begin(String host, uint16_t port, String url, bool https, Strin
193193
*/
194194
void HTTPClient::end(void) {
195195
if(connected()) {
196+
if(_tcp->available() > 0) {
197+
DEBUG_HTTPCLIENT("[HTTP-Client][end] still data in buffer (%d), clean up.\n", _tcp->available());
198+
while(_tcp->available() > 0) {
199+
_tcp->read();
200+
}
201+
}
196202
if(_reuse && _canReuse) {
197203
DEBUG_HTTPCLIENT("[HTTP-Client][end] tcp keep open for reuse\n");
198204
} else {
@@ -711,6 +717,9 @@ bool HTTPClient::connect(void) {
711717

712718
if(connected()) {
713719
DEBUG_HTTPCLIENT("[HTTP-Client] connect. already connected, try reuse!\n");
720+
while(_tcp->available() > 0) {
721+
_tcp->read();
722+
}
714723
return true;
715724
}
716725

0 commit comments

Comments
 (0)