Skip to content

add WiFiClientSecure::peek(); #1310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions libraries/WiFiClientSecure/src/WiFiClientSecure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ WiFiClientSecure::WiFiClientSecure()
_CA_cert = NULL;
_cert = NULL;
_private_key = NULL;
next = NULL;
next = NULL;
}


Expand All @@ -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)
Expand Down Expand Up @@ -113,14 +113,29 @@ 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);
}

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;
Expand All @@ -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;
}
Expand All @@ -161,7 +183,7 @@ int WiFiClientSecure::available()
int res = data_to_read(sslclient);
if (res < 0 ) {
stop();
}
}
return res;
}

Expand Down
6 changes: 2 additions & 4 deletions libraries/WiFiClientSecure/src/WiFiClientSecure.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class WiFiClientSecure : public WiFiClient
sslclient_context *sslclient;

int _lastError = 0;
int _peek = -1;
const char *_CA_cert;
const char *_cert;
const char *_private_key;
Expand All @@ -44,15 +45,12 @@ class WiFiClientSecure : public WiFiClient
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(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(const uint8_t *buf, size_t size);
int available();
int read();
int read(uint8_t *buf, size_t size);
int peek()
{
return 0;
}
void flush() {}
void stop();
uint8_t connected();
Expand Down