From 304ecda16ae402758d8d1568cc9d6a79cc043747 Mon Sep 17 00:00:00 2001 From: Jan Vidar Krey Date: Sat, 23 Jan 2010 00:43:38 +0100 Subject: [PATCH] Enable the statistics timer again, so that !stats provide up to date network statistics. --- src/core/usermanager.c | 20 ++++++++++++++++---- src/core/usermanager.h | 1 + src/network/epoll.c | 7 ++++--- src/network/select.c | 6 +++--- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/core/usermanager.c b/src/core/usermanager.c index 3c0eb36..4daf4ab 100644 --- a/src/core/usermanager.c +++ b/src/core/usermanager.c @@ -19,8 +19,6 @@ #include "uhub.h" -#define USERMANAGER_TIMER - /* * This callback function is used to clear user objects from the userlist. * Should only be used in uman_shutdown(). @@ -40,7 +38,6 @@ static void clear_user_list_callback(void* ptr) } } - void uman_update_stats(struct hub_info* hub) { const int factor = TIMEOUT_STATS; @@ -58,7 +55,6 @@ void uman_update_stats(struct hub_info* hub) net_stats_reset(); } - void uman_print_stats(struct hub_info* hub) { LOG_INFO("Statistics users=" PRINTF_SIZE_T " (peak_users=" PRINTF_SIZE_T "), net_tx=%d KB/s, net_rx=%d KB/s (peak_tx=%d KB/s, peak_rx=%d KB/s)", @@ -70,6 +66,13 @@ void uman_print_stats(struct hub_info* hub) (int) hub->stats.net_rx_peak / 1024); } +static void timer_statistics(struct timeout_evt* t) +{ + struct hub_info* hub = (struct hub_info*) t->ptr; + uman_update_stats(hub); + timeout_queue_reschedule(net_backend_get_timeout_queue(), hub->users->timeout, TIMEOUT_STATS); +} + int uman_init(struct hub_info* hub) { struct hub_user_manager* users = NULL; @@ -90,6 +93,10 @@ int uman_init(struct hub_info* hub) return -1; } + users->timeout = hub_malloc_zero(sizeof(struct timeout_evt)); + timeout_evt_initialize(users->timeout, timer_statistics, hub); + timeout_queue_insert(net_backend_get_timeout_queue(), users->timeout, TIMEOUT_STATS); + hub->users = users; return 0; } @@ -100,6 +107,9 @@ int uman_shutdown(struct hub_info* hub) if (!hub || !hub->users) return -1; + timeout_queue_remove(net_backend_get_timeout_queue(), hub->users->timeout); + hub_free(hub->users->timeout); + if (hub->users->list) { list_clear(hub->users->list, &clear_user_list_callback); @@ -108,6 +118,8 @@ int uman_shutdown(struct hub_info* hub) sid_pool_destroy(hub->users->sids); hub_free(hub->users); hub->users = 0; + + return 0; } diff --git a/src/core/usermanager.h b/src/core/usermanager.h index af59460..7cc5190 100644 --- a/src/core/usermanager.h +++ b/src/core/usermanager.h @@ -28,6 +28,7 @@ struct hub_user_manager uint64_t shared_size; /**<< "The total number of shared bytes among fully connected users." */ uint64_t shared_files; /**<< "The total number of shared files among fully connected users." */ struct linked_list* list; /**<< "Contains all logged in users" */ + struct timeout_evt* timeout; /**<< "Timeout handler for statistics" */ }; /** diff --git a/src/network/epoll.c b/src/network/epoll.c index 0726b77..cfaf5e1 100644 --- a/src/network/epoll.c +++ b/src/network/epoll.c @@ -110,15 +110,16 @@ int net_backend_process() size_t secs = timeout_queue_get_next_timeout(&g_backend->timeout_queue, g_backend->now); LOG_TRACE("epoll_wait: fd=%d, events=%x, max=%zu, seconds=%d", g_backend->epfd, g_backend->events, MIN(g_backend->num, EPOLL_EVBUFFER), (int) secs); int res = epoll_wait(g_backend->epfd, g_backend->events, MIN(g_backend->num, EPOLL_EVBUFFER), secs * 1000); + + g_backend->now = time(0); + timeout_queue_process(&g_backend->timeout_queue, g_backend->now); + if (res == -1) { LOG_WARN("epoll_wait returned -1"); return 0; } - g_backend->now = time(0); - timeout_queue_process(&g_backend->timeout_queue, g_backend->now); - for (n = 0; n < res; n++) { struct net_connection_epoll* con = (struct net_connection_epoll*) g_backend->events[n].data.ptr; diff --git a/src/network/select.c b/src/network/select.c index 872ad24..9f217b9 100644 --- a/src/network/select.c +++ b/src/network/select.c @@ -117,15 +117,15 @@ int net_backend_process() } int res = select(maxfd+1, &g_backend->rfds, &g_backend->wfds, 0, &tval); + g_backend->now = time(0); + timeout_queue_process(&g_backend->timeout_queue, g_backend->now); + if (res == -1) { LOG_WARN("select returned -1"); return 0; } - g_backend->now = time(0); - timeout_queue_process(&g_backend->timeout_queue, g_backend->now); - for (n = 0, found = 0; found < res && n < (maxfd+1); n++) { struct net_connection_select* con = g_backend->conns[n];