@@ -40,6 +40,8 @@ extern "C"
40
40
#include " include/ClientContext.h"
41
41
#include " c_types.h"
42
42
43
+ #include < map> // is it too much?
44
+
43
45
#ifdef DEBUG_ESP_SSL
44
46
#define DEBUG_SSL
45
47
#endif
@@ -59,6 +61,7 @@ class SSLContext
59
61
_ssl_ctx = ssl_ctx_new (SSL_SERVER_VERIFY_LATER | SSL_DEBUG_OPTS | SSL_CONNECT_IN_PARTS | SSL_READ_BLOCKING | SSL_NO_DEFAULT_KEY, 0 );
60
62
}
61
63
++_ssl_ctx_refcnt;
64
+ _fd = ++_fdcounter;
62
65
}
63
66
64
67
~SSLContext ()
@@ -72,8 +75,6 @@ class SSLContext
72
75
if (_ssl_ctx_refcnt == 0 ) {
73
76
ssl_ctx_free (_ssl_ctx);
74
77
}
75
-
76
- s_io_ctx = nullptr ;
77
78
}
78
79
79
80
void ref ()
@@ -93,11 +94,11 @@ class SSLContext
93
94
SSL_EXTENSIONS* ext = ssl_ext_new ();
94
95
ssl_ext_set_host_name (ext, hostName);
95
96
ssl_ext_set_max_fragment_size (ext, 4096 );
96
- s_io_ctx = ctx;
97
+ s_io_ctx[_fd] = ctx;
97
98
if (_ssl) {
98
99
ssl_free (_ssl);
99
100
}
100
- _ssl = ssl_client_new (_ssl_ctx, 0 , nullptr , 0 , ext);
101
+ _ssl = ssl_client_new (_ssl_ctx, _fd , nullptr , 0 , ext);
101
102
uint32_t t = millis ();
102
103
103
104
while (millis () - t < timeout_ms && ssl_handshake_status (_ssl) != SSL_OK) {
@@ -110,8 +111,8 @@ class SSLContext
110
111
}
111
112
112
113
void connectServer (ClientContext *ctx) {
113
- s_io_ctx = ctx;
114
- _ssl = ssl_server_new (_ssl_ctx, 0 );
114
+ s_io_ctx[_fd] = ctx;
115
+ _ssl = ssl_server_new (_ssl_ctx, _fd );
115
116
_isServer = true ;
116
117
117
118
int timeout_ms = 5000 ;
@@ -128,7 +129,6 @@ class SSLContext
128
129
129
130
void stop ()
130
131
{
131
- s_io_ctx = nullptr ;
132
132
}
133
133
134
134
bool connected ()
@@ -238,8 +238,7 @@ class SSLContext
238
238
239
239
static ClientContext* getIOContext (int fd)
240
240
{
241
- (void ) fd;
242
- return s_io_ctx;
241
+ return s_io_ctx[fd];
243
242
}
244
243
245
244
int loadServerX509Cert (const uint8_t *cert, int len) {
@@ -277,16 +276,19 @@ class SSLContext
277
276
bool _isServer = false ;
278
277
static SSL_CTX* _ssl_ctx;
279
278
static int _ssl_ctx_refcnt;
279
+ static int _fdcounter; // increased in constructor
280
+ int _fd; // axtls file descriptor
280
281
SSL* _ssl = nullptr ;
281
282
int _refcnt = 0 ;
282
283
const uint8_t * _read_ptr = nullptr ;
283
284
size_t _available = 0 ;
284
- static ClientContext* s_io_ctx;
285
+ static std::map< int , ClientContext*> s_io_ctx;
285
286
};
286
287
287
288
SSL_CTX* SSLContext::_ssl_ctx = nullptr ;
288
289
int SSLContext::_ssl_ctx_refcnt = 0 ;
289
- ClientContext* SSLContext::s_io_ctx = nullptr ;
290
+ int SSLContext::_fdcounter = 0 ;
291
+ std::map<int , ClientContext*> SSLContext::s_io_ctx;
290
292
291
293
WiFiClientSecure::WiFiClientSecure ()
292
294
{
0 commit comments