@@ -1083,6 +1083,17 @@ bool WiFiClientSecureCtx::_installClientX509Validator() {
1083
1083
return true ;
1084
1084
}
1085
1085
1086
+ std::shared_ptr<unsigned char > WiFiClientSecureCtx::_alloc_iobuf (size_t sz)
1087
+ { // Allocate buffer with preference to IRAM
1088
+ HeapSelectIram primary;
1089
+ auto sptr = std::shared_ptr<unsigned char >(new (std::nothrow) unsigned char [sz], std::default_delete<unsigned char []>());
1090
+ if (!sptr) {
1091
+ HeapSelectDram alternate;
1092
+ sptr = std::shared_ptr<unsigned char >(new (std::nothrow) unsigned char [sz], std::default_delete<unsigned char []>());
1093
+ }
1094
+ return sptr;
1095
+ }
1096
+
1086
1097
// Called by connect() to do the actual SSL setup and handshake.
1087
1098
// Returns if the SSL handshake succeeded.
1088
1099
bool WiFiClientSecureCtx::_connectSSL (const char * hostName) {
@@ -1099,17 +1110,12 @@ bool WiFiClientSecureCtx::_connectSSL(const char* hostName) {
1099
1110
1100
1111
_sc = std::make_shared<br_ssl_client_context>();
1101
1112
_eng = &_sc->eng ; // Allocation/deallocation taken care of by the _sc shared_ptr
1102
- // C This was borrowed from @earlephilhower PoC, to exemplify the use of IRAM.
1103
- // C Is this something we want to keep in the final release?
1104
- { // ESP.setIramHeap(); would be an alternative to using a class to set a scope for IRAM usage.
1105
- HeapSelectIram ephemeral;
1106
- _iobuf_in = std::shared_ptr<unsigned char >(new (std::nothrow) unsigned char [_iobuf_in_size], std::default_delete<unsigned char []>());
1107
- _iobuf_out = std::shared_ptr<unsigned char >(new (std::nothrow) unsigned char [_iobuf_out_size], std::default_delete<unsigned char []>());
1108
- DBG_MMU_PRINTF (" \n _iobuf_in: %p\n " , _iobuf_in.get ());
1109
- DBG_MMU_PRINTF ( " _iobuf_out: %p\n " , _iobuf_out.get ());
1110
- DBG_MMU_PRINTF ( " _iobuf_in_size: %u\n " , _iobuf_in_size);
1111
- DBG_MMU_PRINTF ( " _iobuf_out_size: %u\n " , _iobuf_out_size);
1112
- } // ESP.resetHeap();
1113
+ _iobuf_in = _alloc_iobuf (_iobuf_in_size);
1114
+ _iobuf_out = _alloc_iobuf (_iobuf_out_size);
1115
+ DBG_MMU_PRINTF (" \n _iobuf_in: %p\n " , _iobuf_in.get ());
1116
+ DBG_MMU_PRINTF ( " _iobuf_out: %p\n " , _iobuf_out.get ());
1117
+ DBG_MMU_PRINTF ( " _iobuf_in_size: %u\n " , _iobuf_in_size);
1118
+ DBG_MMU_PRINTF ( " _iobuf_out_size: %u\n " , _iobuf_out_size);
1113
1119
1114
1120
if (!_sc || !_iobuf_in || !_iobuf_out) {
1115
1121
_freeSSL (); // Frees _sc, _iobuf*
@@ -1225,15 +1231,12 @@ bool WiFiClientSecureCtx::_connectSSLServerRSA(const X509List *chain,
1225
1231
_oom_err = false ;
1226
1232
_sc_svr = std::make_shared<br_ssl_server_context>();
1227
1233
_eng = &_sc_svr->eng ; // Allocation/deallocation taken care of by the _sc shared_ptr
1228
- { // ESP.setIramHeap();
1229
- HeapSelectIram ephemeral;
1230
- _iobuf_in = std::shared_ptr<unsigned char >(new (std::nothrow) unsigned char [_iobuf_in_size], std::default_delete<unsigned char []>());
1231
- _iobuf_out = std::shared_ptr<unsigned char >(new (std::nothrow) unsigned char [_iobuf_out_size], std::default_delete<unsigned char []>());
1232
- DBG_MMU_PRINTF (" \n _iobuf_in: %p\n " , _iobuf_in.get ());
1233
- DBG_MMU_PRINTF ( " _iobuf_out: %p\n " , _iobuf_out.get ());
1234
- DBG_MMU_PRINTF ( " _iobuf_in_size: %u\n " , _iobuf_in_size);
1235
- DBG_MMU_PRINTF ( " _iobuf_out_size: %u\n " , _iobuf_out_size);
1236
- } // ESP.resetHeap();
1234
+ _iobuf_in = _alloc_iobuf (_iobuf_in_size);
1235
+ _iobuf_out = _alloc_iobuf (_iobuf_out_size);
1236
+ DBG_MMU_PRINTF (" \n _iobuf_in: %p\n " , _iobuf_in.get ());
1237
+ DBG_MMU_PRINTF ( " _iobuf_out: %p\n " , _iobuf_out.get ());
1238
+ DBG_MMU_PRINTF ( " _iobuf_in_size: %u\n " , _iobuf_in_size);
1239
+ DBG_MMU_PRINTF ( " _iobuf_out_size: %u\n " , _iobuf_out_size);
1237
1240
1238
1241
if (!_sc_svr || !_iobuf_in || !_iobuf_out) {
1239
1242
_freeSSL ();
@@ -1272,15 +1275,12 @@ bool WiFiClientSecureCtx::_connectSSLServerEC(const X509List *chain,
1272
1275
_oom_err = false ;
1273
1276
_sc_svr = std::make_shared<br_ssl_server_context>();
1274
1277
_eng = &_sc_svr->eng ; // Allocation/deallocation taken care of by the _sc shared_ptr
1275
- { // ESP.setIramHeap();
1276
- HeapSelectIram ephemeral;
1277
- _iobuf_in = std::shared_ptr<unsigned char >(new (std::nothrow) unsigned char [_iobuf_in_size], std::default_delete<unsigned char []>());
1278
- _iobuf_out = std::shared_ptr<unsigned char >(new (std::nothrow) unsigned char [_iobuf_out_size], std::default_delete<unsigned char []>());
1279
- DBG_MMU_PRINTF (" \n _iobuf_in: %p\n " , _iobuf_in.get ());
1280
- DBG_MMU_PRINTF ( " _iobuf_out: %p\n " , _iobuf_out.get ());
1281
- DBG_MMU_PRINTF ( " _iobuf_in_size: %u\n " , _iobuf_in_size);
1282
- DBG_MMU_PRINTF ( " _iobuf_out_size: %u\n " , _iobuf_out_size);
1283
- } // ESP.resetHeap();
1278
+ _iobuf_in = _alloc_iobuf (_iobuf_in_size);
1279
+ _iobuf_out = _alloc_iobuf (_iobuf_out_size);
1280
+ DBG_MMU_PRINTF (" \n _iobuf_in: %p\n " , _iobuf_in.get ());
1281
+ DBG_MMU_PRINTF ( " _iobuf_out: %p\n " , _iobuf_out.get ());
1282
+ DBG_MMU_PRINTF ( " _iobuf_in_size: %u\n " , _iobuf_in_size);
1283
+ DBG_MMU_PRINTF ( " _iobuf_out_size: %u\n " , _iobuf_out_size);
1284
1284
1285
1285
if (!_sc_svr || !_iobuf_in || !_iobuf_out) {
1286
1286
_freeSSL ();
0 commit comments