add enable-iopool , simple I/O pool example using memory overrides
This commit is contained in:
parent
cd8e80e391
commit
b56ecd1842
26
configure.ac
26
configure.ac
@ -101,8 +101,13 @@ OPTIMIZE_FAST_CFLAGS="-O2 -fomit-frame-pointer"
|
||||
OPTIMIZE_HUGE_CFLAGS="-funroll-loops -DTFM_SMALL_SET -DTFM_HUGE_SET"
|
||||
DEBUG_CFLAGS="-g -DDEBUG -DDEBUG_CYASSL"
|
||||
|
||||
thread_ls_on=no
|
||||
# Thread local storage
|
||||
AX_TLS([AM_CFLAGS="$AM_CFLAGS -DHAVE_THREAD_LS"], [:])
|
||||
AX_TLS([
|
||||
[AM_CFLAGS="$AM_CFLAGS -DHAVE_THREAD_LS"]
|
||||
[thread_ls_on=yes]
|
||||
] , [:])
|
||||
|
||||
|
||||
# DEBUG
|
||||
AX_DEBUG
|
||||
@ -1338,6 +1343,24 @@ then
|
||||
fi
|
||||
|
||||
|
||||
# I/O Pool, an example to show user how to override memory handler and use
|
||||
# a pool for the input/output buffer requests
|
||||
AC_ARG_ENABLE([iopool],
|
||||
[ --enable-iopool Enable I/O Pool example (default: disabled)],
|
||||
[ ENABLED_IOPOOL=$enableval ],
|
||||
[ ENABLED_IOPOOL=no ]
|
||||
)
|
||||
|
||||
if test "$ENABLED_IOPOOL" = "yes"
|
||||
then
|
||||
if test "$thread_ls_on" = "no"
|
||||
then
|
||||
AC_MSG_ERROR([I/O Pool example requires Thread Local Storage])
|
||||
fi
|
||||
AM_CFLAGS="$AM_CFLAGS -DHAVE_IO_POOL -DXMALLOC_USER"
|
||||
fi
|
||||
|
||||
|
||||
# Certificate Service Support
|
||||
AC_ARG_ENABLE([certservice],
|
||||
[ --enable-certservice Enable cert service (default: disabled)],
|
||||
@ -1690,6 +1713,7 @@ echo " * ECC_ENCRYPT: $ENABLED_ECC_ENCRYPT"
|
||||
echo " * ASN: $ENABLED_ASN"
|
||||
echo " * CODING: $ENABLED_CODING"
|
||||
echo " * MEMORY: $ENABLED_MEMORY"
|
||||
echo " * I/O POOL: $ENABLED_IOPOOL"
|
||||
echo " * ERROR_STRINGS: $ENABLED_ERROR_STRINGS"
|
||||
echo " * DTLS: $ENABLED_DTLS"
|
||||
echo " * Old TLS Versions: $ENABLED_OLD_TLS"
|
||||
|
@ -102,3 +102,82 @@ void* CyaSSL_Realloc(void *ptr, size_t size)
|
||||
}
|
||||
|
||||
#endif /* USE_CYASSL_MEMORY */
|
||||
|
||||
|
||||
#ifdef HAVE_IO_POOL
|
||||
|
||||
/* Example for user io pool, shared build may need definitions in lib proper */
|
||||
|
||||
#include <cyassl/ctaocrypt/types.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
#error "Oops, simple I/O pool example needs thread local storage"
|
||||
#endif
|
||||
|
||||
|
||||
/* allow simple per thread in and out pools */
|
||||
/* use 17k size sense max record size is 16k plus overhead */
|
||||
static THREAD_LS_T byte pool_in[17*1024];
|
||||
static THREAD_LS_T byte pool_out[17*1024];
|
||||
|
||||
|
||||
void* XMALLOC(size_t n, void* heap, int type)
|
||||
{
|
||||
(void)heap;
|
||||
|
||||
if (type == DYNAMIC_TYPE_IN_BUFFER) {
|
||||
if (n < sizeof(pool_in))
|
||||
return pool_in;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (type == DYNAMIC_TYPE_OUT_BUFFER) {
|
||||
if (n < sizeof(pool_out))
|
||||
return pool_out;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return malloc(n);
|
||||
}
|
||||
|
||||
void* XREALLOC(void *p, size_t n, void* heap, int type)
|
||||
{
|
||||
(void)heap;
|
||||
|
||||
if (type == DYNAMIC_TYPE_IN_BUFFER) {
|
||||
if (n < sizeof(pool_in))
|
||||
return pool_in;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (type == DYNAMIC_TYPE_OUT_BUFFER) {
|
||||
if (n < sizeof(pool_out))
|
||||
return pool_out;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return realloc(p, n);
|
||||
}
|
||||
|
||||
|
||||
/* unit api calls, let's make sure visisble with CYASSL_API */
|
||||
CYASSL_API void XFREE(void *p, void* heap, int type)
|
||||
{
|
||||
(void)heap;
|
||||
|
||||
if (type == DYNAMIC_TYPE_IN_BUFFER)
|
||||
return; /* do nothing, static pool */
|
||||
|
||||
if (type == DYNAMIC_TYPE_OUT_BUFFER)
|
||||
return; /* do nothing, static pool */
|
||||
|
||||
free(p);
|
||||
}
|
||||
|
||||
#endif /* HAVE_IO_POOL */
|
||||
|
||||
|
@ -25,6 +25,10 @@
|
||||
|
||||
#include <cyassl/ctaocrypt/settings.h>
|
||||
|
||||
#ifdef XMALLOC_USER
|
||||
#include <stdlib.h> /* we're using malloc / free direct here */
|
||||
#endif
|
||||
|
||||
#ifndef NO_CRYPT_TEST
|
||||
|
||||
#ifdef CYASSL_TEST_CERT
|
||||
|
@ -894,7 +894,7 @@ enum {
|
||||
MTU_EXTRA + MAX_MSG_EXTRA
|
||||
#else
|
||||
/* don't fragment memory from the record header */
|
||||
#define STATIC_BUFFER_LEN RECORD_HEADER_SZ
|
||||
#define STATIC_BUFFER_LEN RECORD_HEADER_SZ
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
|
@ -1674,6 +1674,9 @@ static INLINE void SetupPkCallbacks(CYASSL_CTX* ctx, CYASSL* ssl)
|
||||
#endif /* HAVE_PK_CALLBACKS */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#if defined(__hpux__) || defined(__MINGW32__)
|
||||
|
||||
/* HP/UX doesn't have strsep, needed by test/suites.c */
|
||||
|
Loading…
Reference in New Issue
Block a user