mirror of
https://github.com/shadowsocks/shadowsocks-libev.git
synced 2026-10-23 08:03:54 +00:00
Revert "Triger timer only if there are packets received"
This reverts commit 4bdfc9f3b1.
This commit is contained in:
+12
-10
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user