@@ -191,6 +191,13 @@ int server_async_test(int argc, char** argv)
191191 int wouldblock_count = 0 ;
192192 int pending_count = 0 ;
193193#endif
194+ #ifdef WOLFSSL_STATIC_MEMORY
195+ static byte memory [300000 ];
196+ static byte memoryIO [34500 ];
197+ #if !defined(WOLFSSL_STATIC_MEMORY_LEAN )
198+ WOLFSSL_MEM_CONN_STATS ssl_stats ;
199+ #endif
200+ #endif
194201
195202 /* declare wolfSSL objects */
196203 WOLFSSL_CTX * ctx = NULL ;
@@ -279,12 +286,36 @@ int server_async_test(int argc, char** argv)
279286#endif
280287
281288 /* Create and initialize WOLFSSL_CTX */
282- #ifndef WOLFSSL_NO_TLS12
289+ #ifdef WOLFSSL_STATIC_MEMORY
290+ {
291+ wolfSSL_method_func method ;
292+ #ifndef WOLFSSL_NO_TLS12
293+ if (tls12 )
294+ method = wolfTLSv1_2_server_method_ex ;
295+ else
296+ #endif
297+ method = wolfSSLv23_server_method_ex ;
298+ if (wolfSSL_CTX_load_static_memory (& ctx , method , memory ,
299+ sizeof (memory ), 0 , 1 ) != WOLFSSL_SUCCESS ) {
300+ fprintf (stderr , "ERROR: unable to load static memory\n" );
301+ goto exit ;
302+ }
303+ if (wolfSSL_CTX_load_static_memory (& ctx , NULL , memoryIO ,
304+ sizeof (memoryIO ),
305+ WOLFMEM_IO_POOL_FIXED | WOLFMEM_TRACK_STATS , 1 )
306+ != WOLFSSL_SUCCESS ) {
307+ fprintf (stderr , "ERROR: unable to load static IO memory\n" );
308+ goto exit ;
309+ }
310+ }
311+ #else
312+ #ifndef WOLFSSL_NO_TLS12
283313 if (tls12 )
284314 ctx = wolfSSL_CTX_new (wolfTLSv1_2_server_method ());
285315 else
286- #endif
316+ #endif
287317 ctx = wolfSSL_CTX_new (wolfSSLv23_server_method ());
318+ #endif /* WOLFSSL_STATIC_MEMORY */
288319 if (ctx == NULL ) {
289320 fprintf (stderr , "ERROR: failed to create WOLFSSL_CTX\n" );
290321 ret = -1 ;
@@ -535,6 +566,21 @@ int server_async_test(int argc, char** argv)
535566#endif
536567
537568 /* Cleanup after this connection */
569+ #if defined(WOLFSSL_STATIC_MEMORY ) && !defined(WOLFSSL_STATIC_MEMORY_LEAN )
570+ if (ssl != NULL &&
571+ wolfSSL_is_static_memory (ssl , & ssl_stats ) == 1 ) {
572+ fprintf (stderr , "peak connection memory = %d\n" ,
573+ ssl_stats .peakMem );
574+ fprintf (stderr , "current memory in use = %d\n" ,
575+ ssl_stats .curMem );
576+ fprintf (stderr , "peak connection allocs = %d\n" ,
577+ ssl_stats .peakAlloc );
578+ fprintf (stderr , "total connection allocs = %d\n" ,
579+ ssl_stats .totalAlloc );
580+ fprintf (stderr , "total connection frees = %d\n" ,
581+ ssl_stats .totalFr );
582+ }
583+ #endif
538584 wolfSSL_shutdown (ssl );
539585 if (ssl ) {
540586 wolfSSL_free (ssl );
0 commit comments