From 61554483a612f93f917e64d1c3f7f25bc96dff85 Mon Sep 17 00:00:00 2001 From: "James Kolb (Ardagnir)" Date: Sun, 25 Sep 2016 12:57:19 -0400 Subject: [PATCH] Fix time bugs. In practice, the recent time code I've added seems to work very well, but this is probably just luck because it should be really broken. Let's fix it. --- athame.c | 2 +- athame_util.h | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/athame.c b/athame.c index 3d74190..66575e0 100644 --- a/athame.c +++ b/athame.c @@ -223,7 +223,7 @@ char athame_loop(int instream) else { while(selected == 0 && !athame_failure) { - int timeout_msec = get_timeout_msec(); + long timeout_msec = get_timeout_msec(); selected = athame_select(instream, vim_term, 0, timeout_msec, 0); if (waitpid(vim_pid, NULL, WNOHANG) == 0) // Is vim still running? { diff --git a/athame_util.h b/athame_util.h index 888263e..15216f5 100644 --- a/athame_util.h +++ b/athame_util.h @@ -50,7 +50,7 @@ static char* servername; static int vim_stage = VIM_NOT_STARTED; static int sent_to_vim = 0; // Measured in ms since epoch -static int time_to_poll = -1; +static long time_to_poll = -1; // Number of stale polls since last keypress or change static int stale_polls = 0; static int change_since_key=0; @@ -436,11 +436,11 @@ static void athame_update_vimline(int row, int col) updated = 1; } -static int get_timeout_msec() { +static long get_timeout_msec() { if (time_to_poll == -1) { return -1; } - return MAX(30, time_to_poll - time(NULL) + 5); + return MAX(30, time_to_poll - get_time() + 5); } @@ -448,7 +448,7 @@ static void request_poll() { if (stale_polls > 2) { return; } - int request_time = get_time() + (change_since_key || stale_polls > 0 ? 500 : 100); + long request_time = get_time() + (change_since_key || stale_polls > 0 ? 500 : 100); time_to_poll = time_to_poll < 0 ? request_time : MIN(time_to_poll, request_time); }