add WiFiClientSecure::peek(); (#1310)

This commit is contained in:
copercini 2018-04-14 04:44:21 -03:00 committed by Me No Dev
parent 69f72eca84
commit febcda0095
2 changed files with 29 additions and 9 deletions

View File

@ -39,7 +39,7 @@ WiFiClientSecure::WiFiClientSecure()
_CA_cert = NULL; _CA_cert = NULL;
_cert = NULL; _cert = NULL;
_private_key = NULL; _private_key = NULL;
next = NULL; next = NULL;
} }
@ -64,7 +64,7 @@ WiFiClientSecure::WiFiClientSecure(int sock)
WiFiClientSecure::~WiFiClientSecure() WiFiClientSecure::~WiFiClientSecure()
{ {
stop(); stop();
delete sslclient; delete sslclient;
} }
WiFiClientSecure &WiFiClientSecure::operator=(const WiFiClientSecure &other) WiFiClientSecure &WiFiClientSecure::operator=(const WiFiClientSecure &other)
@ -113,6 +113,14 @@ int WiFiClientSecure::connect(const char *host, uint16_t port, const char *_CA_c
return 1; return 1;
} }
int WiFiClientSecure::peek(){
if(_peek >= 0){
return _peek;
}
_peek = read();
return _peek;
}
size_t WiFiClientSecure::write(uint8_t data) size_t WiFiClientSecure::write(uint8_t data)
{ {
return write(&data, 1); return write(&data, 1);
@ -120,7 +128,14 @@ size_t WiFiClientSecure::write(uint8_t data)
int WiFiClientSecure::read() int WiFiClientSecure::read()
{ {
uint8_t data = 0; uint8_t data = -1;
if(_peek >= 0){
data = _peek;
_peek = -1;
return data;
}
int res = read(&data, 1); int res = read(&data, 1);
if (res < 0) { if (res < 0) {
return res; return res;
@ -143,6 +158,13 @@ size_t WiFiClientSecure::write(const uint8_t *buf, size_t size)
int WiFiClientSecure::read(uint8_t *buf, size_t size) int WiFiClientSecure::read(uint8_t *buf, size_t size)
{ {
if(_peek >= 0){
uint8_t data = -1;
data = _peek;
_peek = -1;
return data;
}
if (!available()) { if (!available()) {
return -1; return -1;
} }

View File

@ -31,6 +31,7 @@ protected:
sslclient_context *sslclient; sslclient_context *sslclient;
int _lastError = 0; int _lastError = 0;
int _peek = -1;
const char *_CA_cert; const char *_CA_cert;
const char *_cert; const char *_cert;
const char *_private_key; const char *_private_key;
@ -44,15 +45,12 @@ public:
int connect(const char *host, uint16_t port); int connect(const char *host, uint16_t port);
int connect(IPAddress ip, uint16_t port, const char *rootCABuff, const char *cli_cert, const char *cli_key); int connect(IPAddress ip, uint16_t port, const char *rootCABuff, const char *cli_cert, const char *cli_key);
int connect(const char *host, uint16_t port, const char *rootCABuff, const char *cli_cert, const char *cli_key); int connect(const char *host, uint16_t port, const char *rootCABuff, const char *cli_cert, const char *cli_key);
int peek();
size_t write(uint8_t data); size_t write(uint8_t data);
size_t write(const uint8_t *buf, size_t size); size_t write(const uint8_t *buf, size_t size);
int available(); int available();
int read(); int read();
int read(uint8_t *buf, size_t size); int read(uint8_t *buf, size_t size);
int peek()
{
return 0;
}
void flush() {} void flush() {}
void stop(); void stop();
uint8_t connected(); uint8_t connected();