# USE_NETFILTER : enable netfilter on Linux. Automatic.
# USE_PCRE : enable use of libpcre for regex. Recommended.
# USE_POLL : enable poll(). Automatic.
+# USE_PRIVATE_CACHE : disable shared memory cache of ssl sessions.
# USE_REGPARM : enable regparm optimization. Recommended on x86.
# USE_SEPOLL : enable speculative epoll(). Automatic.
# USE_STATIC_PCRE : enable static libpcre. Recommended.
OPTIONS_CFLAGS += -DUSE_OPENSSL
OPTIONS_LDFLAGS += -lssl -lcrypto
OPTIONS_OBJS += src/ssl_sock.o src/shctx.o
+ifneq ($(USE_PRIVATE_CACHE),)
+OPTIONS_CFLAGS += -DUSE_PRIVATE_CACHE
+else
ifneq ($(USE_FUTEX),)
OPTIONS_CFLAGS += -DUSE_SYSCALL_FUTEX
else
OPTIONS_LDFLAGS += -lpthread
endif
endif
+endif
ifneq ($(USE_PCRE),)
# PCREDIR is the directory hosting include/pcre.h and lib/libpcre.*. It is
/* Allocate shared memory context.
* size is maximum cached sessions.
* if set less or equal to 0, SHCTX_DEFAULT_SIZE is used.
- * use_shared_memory is set to 1 to use a mapped share memory
+ * set use_shared_memory to 1 to use a mapped shared memory insteed
+ * of private. (ignored if compiled whith USE_PRIVATE_CACHE=1)
* Returns: -1 on alloc failure, size if it performs context alloc,
* and 0 if cache is already allocated */
int shared_context_init(int size, int use_shared_memory);
*/
#include <sys/mman.h>
+#ifndef USE_PRIVATE_CACHE
#ifdef USE_SYSCALL_FUTEX
#include <unistd.h>
#ifndef u32
#else /* USE_SYSCALL_FUTEX */
#include <pthread.h>
#endif /* USE_SYSCALL_FUTEX */
+#endif
#include "ebmbtree.h"
#include "proto/shctx.h"
struct shared_context {
+#ifndef USE_PRIVATE_CACHE
#ifdef USE_SYSCALL_FUTEX
unsigned int waiters;
#else /* USE_SYSCALL_FUTEX */
pthread_mutex_t mutex;
+#endif
#endif
struct shared_session active;
struct shared_session free;
/* Static shared context */
static struct shared_context *shctx = NULL;
+#ifndef USE_PRIVATE_CACHE
static int use_shared_mem = 0;
+#endif
/* Callbacks */
static void (*shared_session_new_cbk)(unsigned char *session, unsigned int session_len, long cdate);
/* Lock functions */
+#ifdef USE_PRIVATE_CACHE
+#define shared_context_lock(v)
+#define shared_context_unlock(v)
+
+#else
#ifdef USE_SYSCALL_FUTEX
#if defined (__i586__) || defined (__x86_64__)
static inline unsigned int xchg(unsigned int *ptr, unsigned int x)
#define shared_context_unlock(v) if (use_shared_mem) pthread_mutex_unlock(&shctx->mutex)
+#endif
#endif
/* List Macros */
int shared_context_init(int size, int shared)
{
int i;
+#ifndef USE_PRIVATE_CACHE
#ifndef USE_SYSCALL_FUTEX
pthread_mutexattr_t attr;
#endif /* USE_SYSCALL_FUTEX */
+#endif
struct shared_session *prev,*cur;
int maptype = MAP_PRIVATE;
if (size<=0)
size = SHCTX_DEFAULT_SIZE;
+#ifndef USE_PRIVATE_CACHE
if (shared)
maptype = MAP_SHARED;
+#endif
shctx = (struct shared_context *)mmap(NULL, sizeof(struct shared_context)+(size*sizeof(struct shared_session)),
PROT_READ | PROT_WRITE, maptype | MAP_ANON, -1, 0);
return -1;
}
+#ifndef USE_PRIVATE_CACHE
#ifdef USE_SYSCALL_FUTEX
shctx->waiters = 0;
#else
#endif
if (maptype == MAP_SHARED)
use_shared_mem = 1;
+#endif
memset(&shctx->active.key, 0, sizeof(struct ebmb_node));
memset(&shctx->free.key, 0, sizeof(struct ebmb_node));