forked from espressif/arduino-esp32
add WiFiClientSecure::peek(); (#1310)
This commit is contained in:
@ -39,7 +39,7 @@ WiFiClientSecure::WiFiClientSecure()
|
||||
_CA_cert = NULL;
|
||||
_cert = NULL;
|
||||
_private_key = NULL;
|
||||
next = NULL;
|
||||
next = NULL;
|
||||
}
|
||||
|
||||
|
||||
@ -58,13 +58,13 @@ WiFiClientSecure::WiFiClientSecure(int sock)
|
||||
_CA_cert = NULL;
|
||||
_cert = NULL;
|
||||
_private_key = NULL;
|
||||
next = NULL;
|
||||
next = NULL;
|
||||
}
|
||||
|
||||
WiFiClientSecure::~WiFiClientSecure()
|
||||
{
|
||||
stop();
|
||||
delete sslclient;
|
||||
delete sslclient;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
int WiFiClientSecure::peek(){
|
||||
if(_peek >= 0){
|
||||
return _peek;
|
||||
}
|
||||
_peek = read();
|
||||
return _peek;
|
||||
}
|
||||
|
||||
size_t WiFiClientSecure::write(uint8_t data)
|
||||
{
|
||||
return write(&data, 1);
|
||||
@ -120,7 +128,14 @@ size_t WiFiClientSecure::write(uint8_t data)
|
||||
|
||||
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);
|
||||
if (res < 0) {
|
||||
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)
|
||||
{
|
||||
if(_peek >= 0){
|
||||
uint8_t data = -1;
|
||||
data = _peek;
|
||||
_peek = -1;
|
||||
return data;
|
||||
}
|
||||
|
||||
if (!available()) {
|
||||
return -1;
|
||||
}
|
||||
@ -161,7 +183,7 @@ int WiFiClientSecure::available()
|
||||
int res = data_to_read(sslclient);
|
||||
if (res < 0 ) {
|
||||
stop();
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user