summaryrefslogtreecommitdiff
path: root/accel-pptpd/triton
diff options
context:
space:
mode:
authorKozlov Dmitry <dima@server>2010-09-02 19:01:47 +0400
committerKozlov Dmitry <dima@server>2010-09-02 19:01:47 +0400
commitb43d224c8a306ff54bbb913c5aab891f82541f6e (patch)
treec3b6c135030fcd4bba4a2ea44d21745fba254a6c /accel-pptpd/triton
parent81515c09f55f152e8330c3b43ad159be64f494e8 (diff)
downloadaccel-ppp-xebd-b43d224c8a306ff54bbb913c5aab891f82541f6e.tar.gz
accel-ppp-xebd-b43d224c8a306ff54bbb913c5aab891f82541f6e.zip
rewriting triton library ...
Diffstat (limited to 'accel-pptpd/triton')
-rw-r--r--accel-pptpd/triton/CMakeLists.txt3
-rw-r--r--accel-pptpd/triton/conf_file.c17
-rw-r--r--accel-pptpd/triton/log.c8
-rw-r--r--accel-pptpd/triton/md.c19
-rw-r--r--accel-pptpd/triton/timer.c6
-rw-r--r--accel-pptpd/triton/triton.c15
-rw-r--r--accel-pptpd/triton/triton.h16
7 files changed, 62 insertions, 22 deletions
diff --git a/accel-pptpd/triton/CMakeLists.txt b/accel-pptpd/triton/CMakeLists.txt
index c78703d..b11025d 100644
--- a/accel-pptpd/triton/CMakeLists.txt
+++ b/accel-pptpd/triton/CMakeLists.txt
@@ -10,4 +10,5 @@ SET(sources_c
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
ADD_DEFINITIONS("-DUSE_SPINLOCK")
-ADD_LIBRARY(${target} STATIC ${sources_c})
+ADD_LIBRARY(${target} SHARED ${sources_c})
+
diff --git a/accel-pptpd/triton/conf_file.c b/accel-pptpd/triton/conf_file.c
index b0bc58b..e99afaa 100644
--- a/accel-pptpd/triton/conf_file.c
+++ b/accel-pptpd/triton/conf_file.c
@@ -164,8 +164,23 @@ static struct conf_option_t *find_item(struct conf_sect_t *sect, const char *nam
return NULL;
}
-struct conf_sect_t *conf_file_get_section(const char *name)
+struct conf_sect_t * conf_get_section(const char *name)
{
return find_sect(name);
}
+char * conf_get_opt(const char *sect, const char *name)
+{
+ struct conf_option_t *opt;
+ struct conf_sect_t *s = conf_get_section(sect);
+
+ if (!s)
+ return NULL;
+
+ opt = find_item(s, name);
+ if (!opt)
+ return NULL;
+
+ return opt->val;
+}
+
diff --git a/accel-pptpd/triton/log.c b/accel-pptpd/triton/log.c
index 7ff90f8..4504db4 100644
--- a/accel-pptpd/triton/log.c
+++ b/accel-pptpd/triton/log.c
@@ -9,8 +9,8 @@ static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
int log_init(void)
{
- char *log_error = conf_get_opt("core","log_error");
- char *log_debug = conf_get_opt("core","log_debug");
+ char *log_error = conf_get_opt("core","log-error");
+ char *log_debug = conf_get_opt("core","log-debug");
if (log_error) {
f_error = fopen(log_error, "a");
@@ -48,8 +48,10 @@ static void do_log(FILE *f, const char *fmt, va_list ap)
void triton_log_error(const char *fmt,...)
{
va_list ap;
+
if (!f_error)
return;
+
va_start(ap, fmt);
do_log(f_error, fmt, ap);
}
@@ -57,8 +59,10 @@ void triton_log_error(const char *fmt,...)
void triton_log_debug(const char *fmt,...)
{
va_list ap;
+
if (!f_debug)
return;
+
va_start(ap, fmt);
do_log(f_debug, fmt, ap);
}
diff --git a/accel-pptpd/triton/md.c b/accel-pptpd/triton/md.c
index 874e494..c1aefcf 100644
--- a/accel-pptpd/triton/md.c
+++ b/accel-pptpd/triton/md.c
@@ -63,10 +63,13 @@ static void *md_thread(void *arg)
for(i = 0; i < n; i++) {
h = (struct triton_md_handler_t *)epoll_events[i].data.ptr;
spin_lock(&h->ctx->lock);
- h->trig_epoll_events = epoll_events[i].events;
- list_add_tail(&h->entry2, &h->ctx->pending_handlers);
- h->pending = 1;
- r=triton_queue_ctx(h->ctx);
+ h->trig_epoll_events |= epoll_events[i].events;
+ if (!h->pending) {
+ list_add_tail(&h->entry2, &h->ctx->pending_handlers);
+ h->pending = 1;
+ r = triton_queue_ctx(h->ctx);
+ } else
+ r = 0;
spin_unlock(&h->ctx->lock);
if (r)
triton_thread_wakeup(h->ctx->thread);
@@ -76,7 +79,7 @@ static void *md_thread(void *arg)
return NULL;
}
-void triton_md_register_handler(struct triton_md_handler_t *h)
+void __export triton_md_register_handler(struct triton_md_handler_t *h)
{
h->epoll_event.data.ptr = h;
if (!h->ctx)
@@ -85,7 +88,7 @@ void triton_md_register_handler(struct triton_md_handler_t *h)
list_add_tail(&h->entry, &h->ctx->handlers);
spin_unlock(&h->ctx->lock);
}
-void triton_md_unregister_handler(struct triton_md_handler_t *h)
+void __export triton_md_unregister_handler(struct triton_md_handler_t *h)
{
spin_lock(&h->ctx->lock);
list_del(&h->entry);
@@ -93,7 +96,7 @@ void triton_md_unregister_handler(struct triton_md_handler_t *h)
list_del(&h->entry2);
spin_unlock(&h->ctx->lock);
}
-int triton_md_enable_handler(struct triton_md_handler_t *h, int mode)
+int __export triton_md_enable_handler(struct triton_md_handler_t *h, int mode)
{
int r;
int events = h->epoll_event.events;
@@ -115,7 +118,7 @@ int triton_md_enable_handler(struct triton_md_handler_t *h, int mode)
return r;
}
-int triton_md_disable_handler(struct triton_md_handler_t *h,int mode)
+int __export triton_md_disable_handler(struct triton_md_handler_t *h,int mode)
{
int r=0;
diff --git a/accel-pptpd/triton/timer.c b/accel-pptpd/triton/timer.c
index 92187be..5f7de93 100644
--- a/accel-pptpd/triton/timer.c
+++ b/accel-pptpd/triton/timer.c
@@ -76,7 +76,7 @@ void *timer_thread(void *arg)
return NULL;
}
-int triton_timer_add(struct triton_timer_t *t, int abs_time)
+int __export triton_timer_add(struct triton_timer_t *t, int abs_time)
{
t->epoll_event.data.ptr = t;
t->epoll_event.events = EPOLLIN | EPOLLET;
@@ -108,7 +108,7 @@ int triton_timer_add(struct triton_timer_t *t, int abs_time)
return 0;
}
-int triton_timer_mod(struct triton_timer_t *t,int abs_time)
+int __export triton_timer_mod(struct triton_timer_t *t,int abs_time)
{
struct itimerspec ts = {
.it_value.tv_sec = t->expire_tv.tv_sec,
@@ -127,7 +127,7 @@ int triton_timer_mod(struct triton_timer_t *t,int abs_time)
return 0;
}
-void triton_timer_del(struct triton_timer_t *t)
+void __export triton_timer_del(struct triton_timer_t *t)
{
epoll_ctl(epoll_fd, EPOLL_CTL_DEL, t->fd, &t->epoll_event);
close(t->fd);
diff --git a/accel-pptpd/triton/triton.c b/accel-pptpd/triton/triton.c
index 2b160a9..121e695 100644
--- a/accel-pptpd/triton/triton.c
+++ b/accel-pptpd/triton/triton.c
@@ -7,7 +7,7 @@
#include "triton_p.h"
-int thread_count = 64;
+int thread_count = 4;
int max_events = 64;
static spinlock_t threads_lock = SPINLOCK_INITIALIZER;
@@ -66,7 +66,7 @@ cont:
if (h->read)
if (h->read(h))
continue;
- if (h->trig_epoll_events & EPOLLOUT)
+ if (h->trig_epoll_events & (EPOLLOUT | EPOLLERR | EPOLLHUP))
if (h->write)
if (h->write(h))
continue;
@@ -130,13 +130,14 @@ int triton_queue_ctx(struct triton_ctx_t *ctx)
}
ctx->thread = list_entry(sleep_threads.next, typeof(*ctx->thread), entry2);
+ ctx->thread->ctx = ctx;
list_del(&ctx->thread->entry2);
spin_unlock(&threads_lock);
return 1;
}
-void triton_register_ctx(struct triton_ctx_t *ctx)
+void __export triton_register_ctx(struct triton_ctx_t *ctx)
{
spinlock_init(&ctx->lock);
INIT_LIST_HEAD(&ctx->handlers);
@@ -149,7 +150,7 @@ void triton_register_ctx(struct triton_ctx_t *ctx)
spin_unlock(&ctx_list_lock);
}
-void triton_unregister_ctx(struct triton_ctx_t *ctx)
+void __export triton_unregister_ctx(struct triton_ctx_t *ctx)
{
ctx->need_free = 1;
spin_lock(&ctx_list_lock);
@@ -157,7 +158,7 @@ void triton_unregister_ctx(struct triton_ctx_t *ctx)
spin_unlock(&ctx_list_lock);
}
-int triton_init(const char *conf_file)
+int __export triton_init(const char *conf_file)
{
default_ctx=malloc(sizeof(*default_ctx));
if (!default_ctx) {
@@ -181,7 +182,7 @@ int triton_init(const char *conf_file)
return 0;
}
-void triton_run()
+void __export triton_run()
{
struct triton_thread_t *t;
int i;
@@ -199,7 +200,7 @@ void triton_run()
timer_run();
}
-void triton_terminate()
+void __export triton_terminate()
{
struct triton_ctx_t *ctx;
struct triton_thread_t *t;
diff --git a/accel-pptpd/triton/triton.h b/accel-pptpd/triton/triton.h
index 7364021..2cc4edb 100644
--- a/accel-pptpd/triton/triton.h
+++ b/accel-pptpd/triton/triton.h
@@ -115,4 +115,20 @@ int triton_init(const char *conf_file);
void triton_run(void);
void triton_terminate(void);
+
+#define __init __attribute__((constructor))
+
+#undef offsetof
+#ifdef __compiler_offsetof
+#define offsetof(TYPE,MEMBER) __compiler_offsetof(TYPE,MEMBER)
+#else
+#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
+#endif
+
+#define container_of(ptr, type, member) ({ \
+ const typeof( ((type *)0)->member ) *__mptr = (ptr); \
+ (type *)( (char *)__mptr - offsetof(type,member) );})
+
+#define __export __attribute__((visibility("default")))
+
#endif