From 778ccb27872ad1cb5e42e28e74de5183044df08f Mon Sep 17 00:00:00 2001 From: Max Lv Date: Sat, 21 Nov 2015 16:58:28 +0800 Subject: [PATCH] Revert "Triger timer only if there are packets received" This reverts commit 4bdfc9f3b10b4466610a841ab6b388da24ff54c9. --- src/local.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/local.c b/src/local.c index 5ec57450..024a97c0 100644 --- a/src/local.c +++ b/src/local.c @@ -84,6 +84,7 @@ int verbose = 0; int vpn = 0; uint64_t tx = 0; uint64_t rx = 0; +ev_timer stat_timer; #endif static int acl = 0; @@ -583,13 +584,9 @@ static void server_send_cb(EV_P_ ev_io *w, int revents) } #ifdef ANDROID -static void stat_update_cb(struct ev_loop *loop) +static void stat_update_cb(EV_P_ ev_timer *watcher, int revents) { - static ev_tstamp last = ev_now(loop); - if (ev_now(EV_A_) - last > 1.0) { - send_traffic_stat(tx, rx); - last = ev_now(loop); - } + send_traffic_stat(tx, rx); } #endif @@ -616,10 +613,6 @@ static void remote_recv_cb(EV_P_ ev_io *w, int revents) ev_timer_again(EV_A_ & remote->recv_ctx->watcher); -#ifdef ANDROID - stat_update_cb(loop); -#endif - ssize_t r = recv(remote->fd, server->buf, BUF_SIZE, 0); if (r == 0) { @@ -1161,6 +1154,11 @@ int main(int argc, char **argv) struct ev_loop *loop = EV_DEFAULT; +#ifdef ANDROID + ev_timer_init(&stat_timer, stat_update_cb, 1, 1); + ev_timer_start(loop, &stat_timer); +#endif + // Setup socket int listenfd; listenfd = create_and_bind(local_addr, local_port); @@ -1203,6 +1201,10 @@ int main(int argc, char **argv) // Clean up +#ifdef ANDROID + ev_timer_stop(loop, &stat_timer); +#endif + ev_io_stop(loop, &listen_ctx.io); free_connections(loop);