Skip to content

Commit

Permalink
Fix flush issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Aug 12, 2023
1 parent 8298ebc commit ce6df21
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 36 deletions.
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ESP_SSLClient",
"version": "2.1.2",
"version": "2.1.3",
"keywords": "communication, REST, esp32, esp8266, arduino",
"description": "This library provided the Secure Layer Networking (SSL/TLS) TCP Client for ESP8266, ESP32 and Raspberry Pi RP2040, Teensy, SAMD, AVR and other Arduino devices (except for avr) that support external networking interfaces e.g., WiFiClient, EthernetClient and GSMClient.",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name=ESP_SSLClient

version=2.1.2
version=2.1.3

author=Mobizt

Expand Down
6 changes: 3 additions & 3 deletions src/ESP_SSLClient.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
*
* The ESP SSL Client Class, ESP_SSLClient.h v2.1.2
* The ESP SSL Client Class, ESP_SSLClient.h v2.1.3
*
* Created August 11, 2023
* Created August 13, 2023
*
* The MIT License (MIT)
* Copyright (c) 2023 K. Suwatchai (Mobizt)
Expand Down Expand Up @@ -44,7 +44,7 @@ class ESP_SSLClient
{
public:
ESP_SSLClient(){};
virtual ~ESP_SSLClient(){};
~ESP_SSLClient(){};
};

#endif
45 changes: 21 additions & 24 deletions src/client/BSSL_SSL_Client.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* BSSL_SSL_Client library v1.0.8 for Arduino devices.
* BSSL_SSL_Client library v1.0.9 for Arduino devices.
*
* Created August 11, 2003
* Created August 13, 2003
*
* This work contains codes based on WiFiClientSecure from Earle F. Philhower and SSLClient from OSU OPEnS Lab.
*
Expand Down Expand Up @@ -180,6 +180,7 @@ uint8_t BSSL_SSL_Client::connected()
}

// set the write error so the engine doesn't try to close the connection
_is_connected = false;
stop();
}
else if (!wr_ok)
Expand Down Expand Up @@ -444,34 +445,30 @@ int BSSL_SSL_Client::connectSSL(const char *host, uint16_t port)

void BSSL_SSL_Client::stop()
{

if (!_is_connected)
if (!_secure)
return;

if (_secure)
{
// Only if we've already connected, store session params and clear the connection options
if (_session)
br_ssl_engine_get_session_parameters(_eng, _session->getSession());
// Only if we've already connected, store session params and clear the connection options
if (_session)
br_ssl_engine_get_session_parameters(_eng, _session->getSession());

// tell the SSL connection to gracefully close
// Disabled to prevent close_notify from hanging BSSL_SSL_Client
// br_ssl_engine_close(_eng);
// if the engine isn't closed, and the socket is still open
auto state = br_ssl_engine_current_state(_eng);
if (state != BR_SSL_CLOSED && state != 0 && connected())
{
// Discard any incoming application data.
_recvapp_buf = br_ssl_engine_recvapp_buf(_eng, &_recvapp_len);
if (_recvapp_buf != nullptr)
br_ssl_engine_recvapp_ack(_eng, _recvapp_len);
// run SSL to finish any existing transactions
flush();
}
// tell the SSL connection to gracefully close
// Disabled to prevent close_notify from hanging BSSL_SSL_Client
// br_ssl_engine_close(_eng);
// if the engine isn't closed, and the socket is still open
auto state = br_ssl_engine_current_state(_eng);
if (state != BR_SSL_CLOSED && state != 0 && connected())
{
// Discard any incoming application data.
_recvapp_buf = br_ssl_engine_recvapp_buf(_eng, &_recvapp_len);
if (_recvapp_buf != nullptr)
br_ssl_engine_recvapp_ack(_eng, _recvapp_len);
// run SSL to finish any existing transactions
flush();
}

// close the socket
if (_basic_client && _basic_client->connected())
if (_basic_client)
{
_basic_client->flush();
_basic_client->stop();
Expand Down
4 changes: 2 additions & 2 deletions src/client/BSSL_SSL_Client.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* BSSL_SSL_Client library v1.0.8 for Arduino devices.
* BSSL_SSL_Client library v1.0.9 for Arduino devices.
*
* Created August 11, 2003
* Created August 13, 2003
*
* This work contains codes based on WiFiClientSecure from Earle F. Philhower and SSLClient from OSU OPEnS Lab.
*
Expand Down
10 changes: 7 additions & 3 deletions src/client/BSSL_TCP_Client.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* BSSL_TCP_Client v2.0.9 for Arduino devices.
* BSSL_TCP_Client v2.0.10 for Arduino devices.
*
* Created August 11, 2023
* Created August 13, 2023
*
* The MIT License (MIT)
* Copyright (c) 2023 K. Suwatchai (Mobizt)
Expand Down Expand Up @@ -272,7 +272,11 @@ void BSSL_TCP_Client::setHandshakeTimeout(unsigned long handshake_timeout)

void BSSL_TCP_Client::flush()
{
_ssl_client.flush();
if (!_basic_client)
return;

while (available() > 0)
read();
}

void BSSL_TCP_Client::setBufferSizes(int recv, int xmit)
Expand Down
4 changes: 2 additions & 2 deletions src/client/BSSL_TCP_Client.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* BSSL_TCP_Client v2.0.9 for Arduino devices.
* BSSL_TCP_Client v2.0.10 for Arduino devices.
*
* Created August 11, 2023
* Created August 13, 2023
*
* The MIT License (MIT)
* Copyright (c) 2023 K. Suwatchai (Mobizt)
Expand Down

0 comments on commit ce6df21

Please sign in to comment.