diff --git a/GNUmakefile b/GNUmakefile index f713ce2..317fb14 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -9,10 +9,10 @@ MV := mv RANLIB := ranlib CFLAGS += -pipe -Wall USE_SSL ?= NO +USE_LIBEVENT ?= YES USE_BIGENDIAN ?= AUTO BITS ?= AUTO SILENT ?= YES -LDLIBS += -levent TERSE ?= NO STACK_PROTECT ?= NO @@ -116,10 +116,14 @@ CFLAGS += -DSSL_SUPPORT LDLIBS += -lssl endif +ifeq ($(USE_LIBEVENT),YES) +CFLAGS += -DUSE_LIBEVENT +LDLIBS += -levent ifneq ($(LIBEVENT_PATH),) CFLAGS += -I$(LIBEVENT_PATH) LDFLAGS += -L$(LIBEVENT_PATH) endif +endif ifeq ($(GIT_REVISION),YES) CFLAGS += -DGIT_REVISION=\"$(shell git show --abbrev-commit | head -n 1 | cut -f 2 -d " ")\" diff --git a/src/network/connection.c b/src/network/connection.c index 3c6f4f8..32f267d 100644 --- a/src/network/connection.c +++ b/src/network/connection.c @@ -53,6 +53,7 @@ static inline void net_con_flag_unset(struct net_connection* con, unsigned int f con->flags &= ~flag; } +#ifdef USE_LIBEVENT static inline int net_con_convert_to_libevent_mask(int ev) { int events = 0; @@ -69,6 +70,7 @@ static inline int net_con_convert_from_libevent_mask(int ev) if (ev & EV_WRITE) events |= NET_EVENT_WRITE; return events; } +#endif static void net_con_event(int fd, short ev, void *arg); @@ -92,10 +94,6 @@ void net_con_set(struct net_connection* con) net_con_flag_set(con, NET_INITIALIZED); } -#define CALLBACK(CON, EVENTS) \ - if (CON->callback) \ - CON->callback(con, EVENTS, CON->ptr); - static void net_con_after_close(struct net_connection* con) { if (net_con_flag_get(con, NET_INITIALIZED)) @@ -114,6 +112,10 @@ static void net_con_after_close(struct net_connection* con) hub_free(con); } +#define CALLBACK(CON, EVENTS) \ + if (CON->callback) \ + CON->callback(con, EVENTS, CON->ptr); + static void net_con_event(int fd, short ev, void *arg) { struct net_connection* con = (struct net_connection*) arg; @@ -192,6 +194,7 @@ static void net_con_event(int fd, short ev, void *arg) } } + void net_con_initialize(struct net_connection* con, int sd, net_connection_cb callback, const void* ptr, int ev) { uhub_assert(con); diff --git a/src/network/connection.h b/src/network/connection.h index bf02a69..5ef5ca5 100644 --- a/src/network/connection.h +++ b/src/network/connection.h @@ -52,8 +52,12 @@ struct net_connection unsigned int flags; /** Connection flags */ void* ptr; /** data pointer */ net_connection_cb callback; /** Callback function */ +#ifdef USE_LIBEVENT struct event event; /** libevent struct for read/write events */ struct event timeout; /** Used for internal timeout handling */ +#else +#warning not implemented +#endif time_t last_recv; /** Timestamp for last recv() */ time_t last_send; /** Timestamp for last send() */ #ifdef SSL_SUPPORT diff --git a/src/system.h b/src/system.h index 93c155c..44e89dc 100644 --- a/src/system.h +++ b/src/system.h @@ -102,7 +102,9 @@ #define uhub_assert assert +#ifdef USE_LIBEVENT #include +#endif #if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__sun__) #undef HAVE_STRNDUP