Skip to content

Commit 80dc5c1

Browse files
committed
Merge branch 'master' into master
2 parents 7f7a1ac + 68701bf commit 80dc5c1

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

cores/esp8266/IPAddress.cpp

Lines changed: 41 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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 {

libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp

Lines changed: 9 additions & 0 deletions
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)