mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
8bd0b2a110
@ -40,6 +40,47 @@ IPAddress::IPAddress(const uint8_t *address) {
|
|||||||
memcpy(_address.bytes, address, sizeof(_address.bytes));
|
memcpy(_address.bytes, address, sizeof(_address.bytes));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IPAddress::fromString(const char *address) {
|
||||||
|
// TODO: add support for "a", "a.b", "a.b.c" formats
|
||||||
|
|
||||||
|
uint16_t acc = 0; // Accumulator
|
||||||
|
uint8_t dots = 0;
|
||||||
|
|
||||||
|
while (*address)
|
||||||
|
{
|
||||||
|
char c = *address++;
|
||||||
|
if (c >= '0' && c <= '9')
|
||||||
|
{
|
||||||
|
acc = acc * 10 + (c - '0');
|
||||||
|
if (acc > 255) {
|
||||||
|
// Value out of [0..255] range
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (c == '.')
|
||||||
|
{
|
||||||
|
if (dots == 3) {
|
||||||
|
// Too much dots (there must be 3 dots)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
_address.bytes[dots++] = acc;
|
||||||
|
acc = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Invalid char
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dots != 3) {
|
||||||
|
// Too few dots (there must be 3 dots)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
_address.bytes[3] = acc;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
IPAddress& IPAddress::operator=(const uint8_t *address) {
|
IPAddress& IPAddress::operator=(const uint8_t *address) {
|
||||||
memcpy(_address.bytes, address, sizeof(_address.bytes));
|
memcpy(_address.bytes, address, sizeof(_address.bytes));
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -48,6 +48,9 @@ class IPAddress: public Printable {
|
|||||||
IPAddress(uint32_t address);
|
IPAddress(uint32_t address);
|
||||||
IPAddress(const uint8_t *address);
|
IPAddress(const uint8_t *address);
|
||||||
|
|
||||||
|
bool fromString(const char *address);
|
||||||
|
bool fromString(const String &address) { return fromString(address.c_str()); }
|
||||||
|
|
||||||
// Overloaded cast operator to allow IPAddress objects to be used where a pointer
|
// Overloaded cast operator to allow IPAddress objects to be used where a pointer
|
||||||
// to a four-byte uint8_t array is expected
|
// to a four-byte uint8_t array is expected
|
||||||
operator uint32_t() const {
|
operator uint32_t() const {
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <string.h>
|
||||||
#include "c_types.h"
|
#include "c_types.h"
|
||||||
|
|
||||||
static const uint8_t ICACHE_FLASH_ATTR phy_init_data[128] =
|
static const uint8_t ICACHE_FLASH_ATTR phy_init_data[128] =
|
||||||
|
@ -193,6 +193,12 @@ void HTTPClient::begin(String host, uint16_t port, String url, bool https, Strin
|
|||||||
*/
|
*/
|
||||||
void HTTPClient::end(void) {
|
void HTTPClient::end(void) {
|
||||||
if(connected()) {
|
if(connected()) {
|
||||||
|
if(_tcp->available() > 0) {
|
||||||
|
DEBUG_HTTPCLIENT("[HTTP-Client][end] still data in buffer (%d), clean up.\n", _tcp->available());
|
||||||
|
while(_tcp->available() > 0) {
|
||||||
|
_tcp->read();
|
||||||
|
}
|
||||||
|
}
|
||||||
if(_reuse && _canReuse) {
|
if(_reuse && _canReuse) {
|
||||||
DEBUG_HTTPCLIENT("[HTTP-Client][end] tcp keep open for reuse\n");
|
DEBUG_HTTPCLIENT("[HTTP-Client][end] tcp keep open for reuse\n");
|
||||||
} else {
|
} else {
|
||||||
@ -711,6 +717,9 @@ bool HTTPClient::connect(void) {
|
|||||||
|
|
||||||
if(connected()) {
|
if(connected()) {
|
||||||
DEBUG_HTTPCLIENT("[HTTP-Client] connect. already connected, try reuse!\n");
|
DEBUG_HTTPCLIENT("[HTTP-Client] connect. already connected, try reuse!\n");
|
||||||
|
while(_tcp->available() > 0) {
|
||||||
|
_tcp->read();
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user