diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2014-08-29 18:17:27 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2014-08-29 18:17:27 +0200 |
commit | 7b546bea2e374a20c52ffd71de51f91eba07256d (patch) | |
tree | e743d06f609ab755d688d5b0cef80be14ac66b67 /src | |
parent | ddd829a1c707deb2ff1d4dfe2a5bd4ab09d048ba (diff) | |
download | weechat-7b546bea2e374a20c52ffd71de51f91eba07256d.zip |
api: use microseconds instead of milliseconds in functions util_timeval_diff and util_timeval_add
Diffstat (limited to 'src')
-rw-r--r-- | src/core/wee-hook.c | 8 | ||||
-rw-r--r-- | src/core/wee-upgrade.c | 4 | ||||
-rw-r--r-- | src/core/wee-util.c | 19 | ||||
-rw-r--r-- | src/core/wee-util.h | 4 | ||||
-rw-r--r-- | src/plugins/irc/irc-protocol.c | 4 | ||||
-rw-r--r-- | src/plugins/irc/irc-server.c | 4 | ||||
-rw-r--r-- | src/plugins/relay/weechat/relay-weechat-msg.c | 6 | ||||
-rw-r--r-- | src/plugins/weechat-plugin.h | 6 |
8 files changed, 29 insertions, 26 deletions
diff --git a/src/core/wee-hook.c b/src/core/wee-hook.c index 015056ef8..5e0f0e77a 100644 --- a/src/core/wee-hook.c +++ b/src/core/wee-hook.c @@ -984,7 +984,8 @@ hook_timer_init (struct t_hook *hook) HOOK_TIMER(hook, next_exec).tv_usec = HOOK_TIMER(hook, last_exec).tv_usec; /* add interval to next call date */ - util_timeval_add (&HOOK_TIMER(hook, next_exec), HOOK_TIMER(hook, interval)); + util_timeval_add (&HOOK_TIMER(hook, next_exec), + ((long long)HOOK_TIMER(hook, interval)) * 1000); } /* @@ -1179,8 +1180,9 @@ hook_timer_exec () HOOK_TIMER(ptr_hook, last_exec).tv_sec = tv_time.tv_sec; HOOK_TIMER(ptr_hook, last_exec).tv_usec = tv_time.tv_usec; - util_timeval_add (&HOOK_TIMER(ptr_hook, next_exec), - HOOK_TIMER(ptr_hook, interval)); + util_timeval_add ( + &HOOK_TIMER(ptr_hook, next_exec), + ((long long)HOOK_TIMER(ptr_hook, interval)) * 1000); if (HOOK_TIMER(ptr_hook, remaining_calls) > 0) { diff --git a/src/core/wee-upgrade.c b/src/core/wee-upgrade.c index 5826399a5..6e07b6c65 100644 --- a/src/core/wee-upgrade.c +++ b/src/core/wee-upgrade.c @@ -898,7 +898,7 @@ void upgrade_weechat_end () { struct timeval tv_now; - long time_diff; + long long time_diff; /* remove .upgrade files */ util_exec_on_files (weechat_home, @@ -912,7 +912,7 @@ upgrade_weechat_end () gui_chat_printf (NULL, /* TRANSLATORS: %.02fs is a float number + "s" ("seconds") */ _("Upgrade done (%.02fs)"), - ((float)time_diff) / 1000); + ((float)time_diff) / 1000000); /* upgrading ended */ weechat_upgrading = 0; diff --git a/src/core/wee-util.c b/src/core/wee-util.c index 1223b0488..c709d4b25 100644 --- a/src/core/wee-util.c +++ b/src/core/wee-util.c @@ -254,13 +254,13 @@ util_timeval_cmp (struct timeval *tv1, struct timeval *tv2) /* * Calculates difference between two timeval structures. * - * Returns difference in milliseconds. + * Returns difference in microseconds. */ -long +long long util_timeval_diff (struct timeval *tv1, struct timeval *tv2) { - long diff_sec, diff_usec; + long long diff_sec, diff_usec; if (!tv1 || !tv2) return 0; @@ -273,23 +273,24 @@ util_timeval_diff (struct timeval *tv1, struct timeval *tv2) diff_usec += 1000000; diff_sec--; } - return ((diff_usec / 1000) + (diff_sec * 1000)); + + return (diff_sec * 1000000) + diff_usec; } /* - * Adds interval (in milliseconds) to a timeval structure. + * Adds interval (in microseconds) to a timeval structure. */ void -util_timeval_add (struct timeval *tv, long interval) +util_timeval_add (struct timeval *tv, long long interval) { - long usec; + long long usec; if (!tv) return; - tv->tv_sec += (interval / 1000); - usec = tv->tv_usec + ((interval % 1000) * 1000); + tv->tv_sec += (interval / 1000000); + usec = tv->tv_usec + (interval % 1000000); if (usec > 1000000) { tv->tv_usec = usec % 1000000; diff --git a/src/core/wee-util.h b/src/core/wee-util.h index 2471868a6..e0fb631eb 100644 --- a/src/core/wee-util.h +++ b/src/core/wee-util.h @@ -36,8 +36,8 @@ struct t_util_signal extern void util_setrlimit (); extern int util_timeval_cmp (struct timeval *tv1, struct timeval *tv2); -extern long util_timeval_diff (struct timeval *tv1, struct timeval *tv2); -extern void util_timeval_add (struct timeval *tv, long interval); +extern long long util_timeval_diff (struct timeval *tv1, struct timeval *tv2); +extern void util_timeval_add (struct timeval *tv, long long interval); extern char *util_get_time_string (const time_t *date); extern int util_signal_search (const char *name); extern void util_catch_signal (int signum, void (*handler)(int)); diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c index fcf25d05b..3c15d614d 100644 --- a/src/plugins/irc/irc-protocol.c +++ b/src/plugins/irc/irc-protocol.c @@ -1633,8 +1633,8 @@ IRC_PROTOCOL_CALLBACK(pong) /* calculate lag (time diff with lag check) */ old_lag = server->lag; gettimeofday (&tv, NULL); - server->lag = (int) weechat_util_timeval_diff (&(server->lag_check_time), - &tv); + server->lag = (int)(weechat_util_timeval_diff (&(server->lag_check_time), + &tv) / 1000); if (old_lag != server->lag) weechat_bar_item_update ("lag"); diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c index 5f8418b61..d954b79e3 100644 --- a/src/plugins/irc/irc-server.c +++ b/src/plugins/irc/irc-server.c @@ -2898,8 +2898,8 @@ irc_server_timer_cb (void *data, int remaining_calls) if (ptr_server->lag_check_time.tv_sec != 0) { gettimeofday (&tv, NULL); - ptr_server->lag = (int) weechat_util_timeval_diff (&(ptr_server->lag_check_time), - &tv); + ptr_server->lag = (int)(weechat_util_timeval_diff (&(ptr_server->lag_check_time), + &tv) / 1000); /* refresh lag item if needed */ if (((ptr_server->lag_last_refresh == 0) || (current_time >= ptr_server->lag_last_refresh + weechat_config_integer (irc_config_network_lag_refresh_interval))) diff --git a/src/plugins/relay/weechat/relay-weechat-msg.c b/src/plugins/relay/weechat/relay-weechat-msg.c index a7be45f2c..4fc601440 100644 --- a/src/plugins/relay/weechat/relay-weechat-msg.c +++ b/src/plugins/relay/weechat/relay-weechat-msg.c @@ -1023,7 +1023,7 @@ relay_weechat_msg_send (struct t_relay_client *client, Bytef *dest; uLongf dest_size; struct timeval tv1, tv2; - long time_diff; + long long time_diff; if (weechat_config_integer (relay_config_network_compression_level) > 0) { @@ -1049,11 +1049,11 @@ relay_weechat_msg_send (struct t_relay_client *client, /* display message in raw buffer */ snprintf (raw_message, sizeof (raw_message), - "obj: %d/%d bytes (%d%%, %ldms), id: %s", + "obj: %d/%d bytes (%d%%, %.2fms), id: %s", (int)dest_size + 5, msg->data_size, 100 - ((((int)dest_size + 5) * 100) / msg->data_size), - time_diff, + ((float)time_diff) / 1000, msg->id); /* send compressed data */ diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index ad619e9c2..f53283365 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -57,7 +57,7 @@ struct timeval; * please change the date with current one; for a second change at same * date, increment the 01, otherwise please keep 01. */ -#define WEECHAT_PLUGIN_API_VERSION "20140802-01" +#define WEECHAT_PLUGIN_API_VERSION "20140829-01" /* macros for defining plugin infos */ #define WEECHAT_PLUGIN_NAME(__name) \ @@ -304,8 +304,8 @@ struct t_weechat_plugin /* util */ int (*util_timeval_cmp) (struct timeval *tv1, struct timeval *tv2); - long (*util_timeval_diff) (struct timeval *tv1, struct timeval *tv2); - void (*util_timeval_add) (struct timeval *tv, long interval); + long long (*util_timeval_diff) (struct timeval *tv1, struct timeval *tv2); + void (*util_timeval_add) (struct timeval *tv, long long interval); char *(*util_get_time_string) (const time_t *date); int (*util_version_number) (const char *version); |