Skip to content

Commit 9731f86

Browse files
andreagilardonipennam
authored andcommitted
BearSSLClient: allow clients to stop independently
making _sslio_closing not static anymore, so that we are able to stop bearsslclients independently from one another
1 parent bbbbd60 commit 9731f86

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

src/tls/BearSSLClient.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,12 @@
3434

3535
#include "BearSSLClient.h"
3636

37-
bool BearSSLClient::_sslio_closing = false;
38-
3937
extern "C" void aiotc_client_profile_init(br_ssl_client_context *cc, br_x509_minimal_context *xc, const br_x509_trust_anchor *trust_anchors, size_t trust_anchors_num);
4038

4139
BearSSLClient::BearSSLClient() :
4240
_noSNI(false),
43-
_get_time_func(nullptr)
41+
_get_time_func(nullptr),
42+
_sslio_closing(false)
4443
{
4544
_ecKey.curve = 0;
4645
_ecKey.x = NULL;
@@ -172,7 +171,7 @@ void BearSSLClient::stop()
172171
{
173172
if (_client->connected()) {
174173
if ((br_ssl_engine_current_state(&_sc.eng) & BR_SSL_CLOSED) == 0) {
175-
BearSSLClient::_sslio_closing = true;
174+
_sslio_closing = true;
176175
br_sslio_close(&_ioc);
177176
}
178177

@@ -314,7 +313,7 @@ int BearSSLClient::connectSSL(const char* host)
314313
br_x509_minimal_set_time(&_xc, days, sec);
315314

316315
// use our own socket I/O operations
317-
br_sslio_init(&_ioc, &_sc.eng, BearSSLClient::clientRead, _client, BearSSLClient::clientWrite, _client);
316+
br_sslio_init(&_ioc, &_sc.eng, BearSSLClient::clientRead, this, BearSSLClient::clientWrite, this);
318317

319318
br_sslio_flush(&_ioc);
320319

@@ -335,12 +334,13 @@ int BearSSLClient::connectSSL(const char* host)
335334

336335
int BearSSLClient::clientRead(void *ctx, unsigned char *buf, size_t len)
337336
{
338-
if (BearSSLClient::_sslio_closing) {
337+
BearSSLClient* bc = (BearSSLClient*)ctx;
338+
Client* c = bc->_client;
339+
340+
if(bc->_sslio_closing) {
339341
return -1;
340342
}
341343

342-
Client* c = (Client*)ctx;
343-
344344
if (!c->connected()) {
345345
return -1;
346346
}
@@ -370,12 +370,13 @@ int BearSSLClient::clientRead(void *ctx, unsigned char *buf, size_t len)
370370

371371
int BearSSLClient::clientWrite(void *ctx, const unsigned char *buf, size_t len)
372372
{
373-
if (BearSSLClient::_sslio_closing) {
373+
BearSSLClient* bc = (BearSSLClient*)ctx;
374+
Client* c = bc->_client;
375+
376+
if(bc->_sslio_closing) {
374377
return -1;
375378
}
376379

377-
Client* c = (Client*)ctx;
378-
379380
#ifdef DEBUGSERIAL
380381
DEBUGSERIAL.print("BearSSLClient::clientWrite - ");
381382
DEBUGSERIAL.print(len);

src/tls/BearSSLClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class BearSSLClient : public Client {
100100
br_x509_certificate _ecCert;
101101
bool _ecCertDynamic;
102102

103-
static bool _sslio_closing;
103+
bool _sslio_closing;
104104
br_ssl_client_context _sc;
105105
br_x509_minimal_context _xc;
106106
unsigned char _ibuf[BEAR_SSL_CLIENT_IBUF_SIZE];

0 commit comments

Comments
 (0)