Started working on an updated libevent and event queue implementation that would not require timers.

Signed-off-by: Jan Vidar Krey <janvidar@extatic.org>
This commit is contained in:
Jan Vidar Krey 2009-03-18 02:32:00 +01:00
parent 4d0ed61a05
commit 4f8edfe9c8
6 changed files with 41 additions and 18 deletions

View File

@ -1,3 +1,6 @@
0.2.7:
0.2.6:
- Better "!uptime" command formatting.
- Better "!stats"; can display peak and current bandwidth usage.

View File

@ -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);
}

View File

@ -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 */

View File

@ -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);

View File

@ -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

View File

@ -7,7 +7,7 @@
#endif
#ifndef VERSION
#define VERSION "0.2.6"
#define VERSION "0.2.7-alpha"
#endif
#ifndef COPYRIGHT