From 4f8edfe9c88ae3add79b5fdfdfda76a62a290337 Mon Sep 17 00:00:00 2001 From: Jan Vidar Krey Date: Wed, 18 Mar 2009 02:32:00 +0100 Subject: [PATCH] Started working on an updated libevent and event queue implementation that would not require timers. Signed-off-by: Jan Vidar Krey --- ChangeLog | 3 +++ src/hub.c | 31 +++++++++++++++++++++++++++++++ src/hub.h | 5 +++++ src/main.c | 2 +- src/network.c | 16 ---------------- version.h | 2 +- 6 files changed, 41 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5825dff..e77c261 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +0.2.7: + + 0.2.6: - Better "!uptime" command formatting. - Better "!stats"; can display peak and current bandwidth usage. diff --git a/src/hub.c b/src/hub.c index 18e1ce0..358b6ea 100644 --- a/src/hub.c +++ b/src/hub.c @@ -479,11 +479,20 @@ struct hub_info* hub_start_service(struct hub_config* config) net_address_to_string(AF_INET6, &((struct sockaddr_in6*) &addr)->sin6_addr, address_buf, INET6_ADDRSTRLEN); } + hub->evbase = event_init(); + if (!hub->evbase) + { + hub_log(log_error, "Unable to initialize libevent."); + hub_free(hub); + return 0; + } + hub_log(log_info, "Starting server, listening on %s:%d...", address_buf, config->server_port); server_tcp = net_socket_create(af, SOCK_STREAM, IPPROTO_TCP); if (server_tcp == -1) { + event_base_free(hub->evbase); hub_free(hub); return 0; } @@ -492,6 +501,7 @@ struct hub_info* hub_start_service(struct hub_config* config) server_udp = net_socket_create(af, SOCK_DGRAM, IPPROTO_UDP); if (server_udp == -1) { + event_base_free(hub->evbase); hub_free(hub); return 0; } @@ -500,6 +510,7 @@ struct hub_info* hub_start_service(struct hub_config* config) ret = net_set_reuseaddress(server_tcp, 1); if (ret == -1) { + event_base_free(hub->evbase); hub_free(hub); net_close(server_tcp); #ifdef ADC_UDP_OPERATION @@ -512,6 +523,7 @@ struct hub_info* hub_start_service(struct hub_config* config) ret = net_set_reuseaddress(server_udp, 1); if (ret == -1) { + event_base_free(hub->evbase); hub_free(hub); net_close(server_tcp); net_close(server_udp); @@ -523,6 +535,7 @@ struct hub_info* hub_start_service(struct hub_config* config) ret = net_set_nonblocking(server_tcp, 1); if (ret == -1) { + event_base_free(hub->evbase); hub_free(hub); net_close(server_tcp); #ifdef ADC_UDP_OPERATION @@ -535,6 +548,7 @@ struct hub_info* hub_start_service(struct hub_config* config) ret = net_set_nonblocking(server_udp, 1); if (ret == -1) { + event_base_free(hub->evbase); hub_free(hub); net_close(server_tcp); net_close(server_udp); @@ -547,6 +561,7 @@ struct hub_info* hub_start_service(struct hub_config* config) if (ret == -1) { hub_log(log_fatal, "hub_start_service(): Unable to bind to TCP local address. errno=%d, str=%s", net_error(), net_error_string(net_error())); + event_base_free(hub->evbase); hub_free(hub); net_close(server_tcp); #ifdef ADC_UDP_OPERATION @@ -560,6 +575,7 @@ struct hub_info* hub_start_service(struct hub_config* config) if (ret == -1) { hub_log(log_fatal, "hub_start_service(): Unable to bind to UDP local address. errno=%d, str=%s", net_error(), net_error_string(net_error())); + event_base_free(hub->evbase); hub_free(hub); net_close(server_tcp); net_close(server_udp); @@ -571,6 +587,7 @@ struct hub_info* hub_start_service(struct hub_config* config) if (ret == -1) { hub_log(log_fatal, "hub_start_service(): Unable to listen to socket"); + event_base_free(hub->evbase); hub_free(hub); net_close(server_tcp); #ifdef ADC_UDP_OPERATION @@ -650,6 +667,7 @@ void hub_shutdown_service(struct hub_info* hub) net_close(hub->fd_tcp); user_manager_shutdown(hub); hub->status = hub_status_stopped; + event_base_free(hub->evbase); hub_free(hub); hub = 0; } @@ -950,3 +968,16 @@ size_t hub_get_min_hubs_op(struct hub_info* hub) } +void hub_event_loop(struct hub_info* hub) +{ +#if 0 + event_dispatch(); +#endif + int ret; + do + { + ret = event_base_loop(hub->evbase, EVLOOP_ONCE); + + } + while (ret == hub_status_running); +} diff --git a/src/hub.h b/src/hub.h index 5ef99f8..686ce99 100644 --- a/src/hub.h +++ b/src/hub.h @@ -92,6 +92,7 @@ struct hub_info #endif struct hub_stats stats; struct event_queue* queue; + struct event_base* evbase; struct hub_config* config; struct user_manager* users; struct acl_handle* acl; @@ -334,6 +335,10 @@ extern size_t hub_get_max_hubs_total(struct hub_info* hub); */ extern void hub_schedule_runslice(struct hub_info* hub); +/** + * Run event loop. + */ +extern void hub_event_loop(struct hub_info* hub); #endif /* HAVE_UHUB_HUB_H */ diff --git a/src/main.c b/src/main.c index 1745efc..e27550c 100644 --- a/src/main.c +++ b/src/main.c @@ -153,7 +153,7 @@ int main_loop() hub_set_variables(hub, &acl); - event_dispatch(); + hub_event_loop(hub); hub_free_variables(hub); acl_shutdown(&acl); diff --git a/src/network.c b/src/network.c index 469e773..435c00a 100644 --- a/src/network.c +++ b/src/network.c @@ -23,7 +23,6 @@ static int is_ipv6_supported = -1; /* -1 = CHECK, 0 = NO, 1 = YES */ static int net_initialized = 0; static struct net_statistics stats; static struct net_statistics stats_total; -static struct event_base* evbase; #if defined(IPV6_BINDV6ONLY) #define SOCK_DUAL_STACK_OPT IPV6_BINDV6ONLY @@ -53,16 +52,6 @@ int net_initialize() /* FIXME: Initialize OpenSSL here. */ #endif /* SSL_SUPPORT */ -#ifdef OLD_LIBEVENT - event_init(); -#else - evbase = event_init(); - if (!evbase) - { - hub_log(log_error, "Unable to initialize libevent."); - return -1; - } -#endif net_initialized = 1; return 0; } @@ -80,11 +69,6 @@ int net_shutdown() /* FIXME: Shutdown OpenSSL here. */ #endif -#ifndef OLD_LIBEVENT - event_base_free(evbase); -#endif - evbase = 0; - #ifdef WINSOCK WSACleanup(); #endif diff --git a/version.h b/version.h index c69ee6e..6858918 100644 --- a/version.h +++ b/version.h @@ -7,7 +7,7 @@ #endif #ifndef VERSION -#define VERSION "0.2.6" +#define VERSION "0.2.7-alpha" #endif #ifndef COPYRIGHT