api: use microseconds instead of milliseconds in functions util_timeval_diff and util_timeval_add
This commit is contained in:
parent
ddd829a1c7
commit
7b546bea2e
@ -19,6 +19,8 @@ http://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes]
|
||||
|
||||
* core: allow incomplete commands if unambiguous, new option
|
||||
weechat.look.command_incomplete (task #5419)
|
||||
* api: use microseconds instead of milliseconds in functions util_timeval_diff
|
||||
and util_timeval_add
|
||||
* trigger: add option "restore" in command /trigger
|
||||
|
||||
=== Bugs fixed
|
||||
|
@ -17,6 +17,15 @@ http://weechat.org/files/changelog/ChangeLog-devel.html[ChangeLog]
|
||||
|
||||
== Version 1.1 (under dev)
|
||||
|
||||
=== Microseconds in API timeval functions
|
||||
|
||||
The API functions using timeval are now using or returning microseconds,
|
||||
instead of milliseconds:
|
||||
|
||||
* function 'util_timeval_diff': returns microseconds
|
||||
* function 'util_timeval_add': the argument 'interval' is now expressed in
|
||||
microseconds.
|
||||
|
||||
=== Default triggers for hiding passwords
|
||||
|
||||
Triggers used to hide passwords have been fixed for *BSD operating systems.
|
||||
|
@ -2668,13 +2668,15 @@ This function is not available in scripting API.
|
||||
|
||||
==== weechat_util_timeval_diff
|
||||
|
||||
Return difference (in milliseconds) between two "timeval" structures.
|
||||
_Updated in 1.1._
|
||||
|
||||
Return difference (in microseconds) between two "timeval" structures.
|
||||
|
||||
Prototype:
|
||||
|
||||
[source,C]
|
||||
----
|
||||
long weechat_util_timeval_diff (struct timeval *tv1, struct timeval *tv2);
|
||||
long long weechat_util_timeval_diff (struct timeval *tv1, struct timeval *tv2);
|
||||
----
|
||||
|
||||
Arguments:
|
||||
@ -2684,13 +2686,16 @@ Arguments:
|
||||
|
||||
Return value:
|
||||
|
||||
* difference in milliseconds
|
||||
* difference in microseconds
|
||||
|
||||
[NOTE]
|
||||
With WeeChat ≤ 1.0, the returned value was in milliseconds.
|
||||
|
||||
C example:
|
||||
|
||||
[source,C]
|
||||
----
|
||||
long diff = weechat_util_timeval_diff (&tv1, &tv2);
|
||||
long long diff = weechat_util_timeval_diff (&tv1, &tv2);
|
||||
----
|
||||
|
||||
[NOTE]
|
||||
@ -2698,25 +2703,30 @@ This function is not available in scripting API.
|
||||
|
||||
==== weechat_util_timeval_add
|
||||
|
||||
Add interval (in milliseconds) to a timeval structure.
|
||||
_Updated in 1.1._
|
||||
|
||||
Add interval (in microseconds) to a timeval structure.
|
||||
|
||||
Prototype:
|
||||
|
||||
[source,C]
|
||||
----
|
||||
void weechat_util_timeval_add (struct timeval *tv, long interval);
|
||||
void weechat_util_timeval_add (struct timeval *tv, long long interval);
|
||||
----
|
||||
|
||||
Arguments:
|
||||
|
||||
* 'tv': timeval structure
|
||||
* 'interval': interval (in milliseconds)
|
||||
* 'interval': interval (in microseconds)
|
||||
|
||||
[NOTE]
|
||||
With WeeChat ≤ 1.0, the interval was expressed in milliseconds.
|
||||
|
||||
C example:
|
||||
|
||||
[source,C]
|
||||
----
|
||||
weechat_util_timeval_add (&tv, 2000); /* add 2 seconds */
|
||||
weechat_util_timeval_add (&tv, 2000000); /* add 2 seconds */
|
||||
----
|
||||
|
||||
[NOTE]
|
||||
|
@ -2713,13 +2713,15 @@ Cette fonction n'est pas disponible dans l'API script.
|
||||
|
||||
==== weechat_util_timeval_diff
|
||||
|
||||
Retourner la différence (en millisecondes) entre deux structures "timeval".
|
||||
_Mis à jour dans la 1.1._
|
||||
|
||||
Retourner la différence (en microsecondes) entre deux structures "timeval".
|
||||
|
||||
Prototype :
|
||||
|
||||
[source,C]
|
||||
----
|
||||
long weechat_util_timeval_diff (struct timeval *tv1, struct timeval *tv2);
|
||||
long long weechat_util_timeval_diff (struct timeval *tv1, struct timeval *tv2);
|
||||
----
|
||||
|
||||
Paramètres :
|
||||
@ -2729,13 +2731,16 @@ Paramètres :
|
||||
|
||||
Valeur de retour :
|
||||
|
||||
* différence en millisecondes
|
||||
* différence en microsecondes
|
||||
|
||||
[NOTE]
|
||||
Avec WeeChat ≤ 1.0, la valeur retournée était en millisecondes.
|
||||
|
||||
Exemple en C :
|
||||
|
||||
[source,C]
|
||||
----
|
||||
long diff = weechat_util_timeval_diff (&tv1, &tv2);
|
||||
long long diff = weechat_util_timeval_diff (&tv1, &tv2);
|
||||
----
|
||||
|
||||
[NOTE]
|
||||
@ -2743,25 +2748,30 @@ Cette fonction n'est pas disponible dans l'API script.
|
||||
|
||||
==== weechat_util_timeval_add
|
||||
|
||||
Ajouter un intervalle (en millisecondes) à une structure "timeval".
|
||||
_Mis à jour dans la 1.1._
|
||||
|
||||
Ajouter un intervalle (en microsecondes) à une structure "timeval".
|
||||
|
||||
Prototype :
|
||||
|
||||
[source,C]
|
||||
----
|
||||
void weechat_util_timeval_add (struct timeval *tv, long interval);
|
||||
void weechat_util_timeval_add (struct timeval *tv, long long interval);
|
||||
----
|
||||
|
||||
Paramètres :
|
||||
|
||||
* 'tv' : structure "timeval"
|
||||
* 'interval' : intervalle (en millisecondes)
|
||||
* 'interval' : intervalle (en microsecondes)
|
||||
|
||||
[NOTE]
|
||||
Avec WeeChat ≤ 1.0, l'intervalle était exprimé en millisecondes.
|
||||
|
||||
Exemple en C :
|
||||
|
||||
[source,C]
|
||||
----
|
||||
weechat_util_timeval_add (&tv, 2000); /* ajoute 2 secondes */
|
||||
weechat_util_timeval_add (&tv, 2000000); /* ajouter 2 secondes */
|
||||
----
|
||||
|
||||
[NOTE]
|
||||
|
@ -2736,13 +2736,17 @@ Questa funzione non è disponibile nelle API per lo scripting.
|
||||
|
||||
==== weechat_util_timeval_diff
|
||||
|
||||
Restituisce la differenza (in millisecondi) tra due strutture "timeval".
|
||||
// TRANSLATION MISSING
|
||||
_Updated in 1.1._
|
||||
|
||||
// TRANSLATION MISSING
|
||||
Return difference (in microseconds) between two "timeval" structures.
|
||||
|
||||
Prototipo:
|
||||
|
||||
[source,C]
|
||||
----
|
||||
long weechat_util_timeval_diff (struct timeval *tv1, struct timeval *tv2);
|
||||
long long weechat_util_timeval_diff (struct timeval *tv1, struct timeval *tv2);
|
||||
----
|
||||
|
||||
Argomenti:
|
||||
@ -2752,13 +2756,18 @@ Argomenti:
|
||||
|
||||
Valore restituito:
|
||||
|
||||
* differenza in millisecondi
|
||||
// TRANSLATION MISSING
|
||||
* difference in microseconds
|
||||
|
||||
// TRANSLATION MISSING
|
||||
[NOTE]
|
||||
With WeeChat ≤ 1.0, the returned value was in milliseconds.
|
||||
|
||||
Esempio in C:
|
||||
|
||||
[source,C]
|
||||
----
|
||||
long diff = weechat_util_timeval_diff (&tv1, &tv2);
|
||||
long long diff = weechat_util_timeval_diff (&tv1, &tv2);
|
||||
----
|
||||
|
||||
[NOTE]
|
||||
@ -2766,25 +2775,34 @@ Questa funzione non è disponibile nelle API per lo scripting.
|
||||
|
||||
==== weechat_util_timeval_add
|
||||
|
||||
Aggiungi intervallo (in millisecondi) ad una struttura timeval.
|
||||
// TRANSLATION MISSING
|
||||
_Updated in 1.1._
|
||||
|
||||
// TRANSLATION MISSING
|
||||
Add interval (in microseconds) to a timeval structure.
|
||||
|
||||
Prototipo:
|
||||
|
||||
[source,C]
|
||||
----
|
||||
void weechat_util_timeval_add (struct timeval *tv, long interval);
|
||||
void weechat_util_timeval_add (struct timeval *tv, long long interval);
|
||||
----
|
||||
|
||||
Argomenti:
|
||||
|
||||
* 'tv': struttura timeval
|
||||
* 'interval': intervallo (in millisecondi)
|
||||
// TRANSLATION MISSING
|
||||
* 'interval': interval (in microseconds)
|
||||
|
||||
// TRANSLATION MISSING
|
||||
[NOTE]
|
||||
With WeeChat ≤ 1.0, the interval was expressed in milliseconds.
|
||||
|
||||
Esempio in C:
|
||||
|
||||
[source,C]
|
||||
----
|
||||
weechat_util_timeval_add (&tv, 2000); /* aggiunge 2 secondi */
|
||||
weechat_util_timeval_add (&tv, 2000000); /* aggiunge 2 secondi */
|
||||
----
|
||||
|
||||
[NOTE]
|
||||
|
@ -2664,13 +2664,16 @@ if (weechat_util_timeval_cmp (&tv1, &tv2) > 0)
|
||||
|
||||
==== weechat_util_timeval_diff
|
||||
|
||||
2 つの "timeval" 構造体の差を (ミリ秒単位で) 返す。
|
||||
_バージョン 1.1 で更新。_
|
||||
|
||||
// TRANSLATION MISSING
|
||||
Return difference (in microseconds) between two "timeval" structures.
|
||||
|
||||
プロトタイプ:
|
||||
|
||||
[source,C]
|
||||
----
|
||||
long weechat_util_timeval_diff (struct timeval *tv1, struct timeval *tv2);
|
||||
long long weechat_util_timeval_diff (struct timeval *tv1, struct timeval *tv2);
|
||||
----
|
||||
|
||||
引数:
|
||||
@ -2680,13 +2683,18 @@ long weechat_util_timeval_diff (struct timeval *tv1, struct timeval *tv2);
|
||||
|
||||
戻り値:
|
||||
|
||||
* ミリ秒単位の差
|
||||
// TRANSLATION MISSING
|
||||
* difference in microseconds
|
||||
|
||||
// TRANSLATION MISSING
|
||||
[NOTE]
|
||||
With WeeChat ≤ 1.0, the returned value was in milliseconds.
|
||||
|
||||
C 言語での使用例:
|
||||
|
||||
[source,C]
|
||||
----
|
||||
long diff = weechat_util_timeval_diff (&tv1, &tv2);
|
||||
long long diff = weechat_util_timeval_diff (&tv1, &tv2);
|
||||
----
|
||||
|
||||
[NOTE]
|
||||
@ -2694,25 +2702,33 @@ long diff = weechat_util_timeval_diff (&tv1, &tv2);
|
||||
|
||||
==== weechat_util_timeval_add
|
||||
|
||||
timeval 構造体に時間間隔 (ミリ秒単位) を追加
|
||||
_バージョン 1.1 で更新。_
|
||||
|
||||
// TRANSLATION MISSING
|
||||
Add interval (in microseconds) to a timeval structure.
|
||||
|
||||
プロトタイプ:
|
||||
|
||||
[source,C]
|
||||
----
|
||||
void weechat_util_timeval_add (struct timeval *tv, long interval);
|
||||
void weechat_util_timeval_add (struct timeval *tv, long long interval);
|
||||
----
|
||||
|
||||
引数:
|
||||
|
||||
* 'tv': timeval 構造体
|
||||
* 'interval': 時間間隔 (ミリ秒単位)
|
||||
// TRANSLATION MISSING
|
||||
* 'interval': interval (in microseconds)
|
||||
|
||||
// TRANSLATION MISSING
|
||||
[NOTE]
|
||||
With WeeChat ≤ 1.0, the interval was expressed in milliseconds.
|
||||
|
||||
C 言語での使用例:
|
||||
|
||||
[source,C]
|
||||
----
|
||||
weechat_util_timeval_add (&tv, 2000); /* add 2 seconds */
|
||||
weechat_util_timeval_add (&tv, 2000000); /* add 2 seconds */
|
||||
----
|
||||
|
||||
[NOTE]
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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));
|
||||
|
@ -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");
|
||||
|
||||
|
@ -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)))
|
||||
|
@ -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 */
|
||||
|
@ -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);
|
||||
|
||||
|
@ -43,9 +43,11 @@ TEST_GROUP(Util)
|
||||
|
||||
TEST(Util, Timeval)
|
||||
{
|
||||
struct timeval tv_zero = { 0, 0 };
|
||||
struct timeval tv1 = { 123456, 12000 };
|
||||
struct timeval tv2 = { 123456, 15000 };
|
||||
struct timeval tv3 = { 123457, 15000 };
|
||||
struct timeval tv4 = { 1409288400, 0 }; /* 2014-08-29 05:00:00 GMT */
|
||||
struct timeval tv;
|
||||
|
||||
/* comparison */
|
||||
@ -60,17 +62,18 @@ TEST(Util, Timeval)
|
||||
LONGS_EQUAL(0, util_timeval_diff (NULL, NULL));
|
||||
LONGS_EQUAL(0, util_timeval_diff (NULL, &tv1));
|
||||
LONGS_EQUAL(0, util_timeval_diff (&tv1, NULL));
|
||||
LONGS_EQUAL(3, util_timeval_diff (&tv1, &tv2));
|
||||
LONGS_EQUAL(1003, util_timeval_diff (&tv1, &tv3));
|
||||
LONGS_EQUAL(3000, util_timeval_diff (&tv1, &tv2));
|
||||
LONGS_EQUAL(1003000, util_timeval_diff (&tv1, &tv3));
|
||||
CHECK(1409288400 * 1000000LL == util_timeval_diff (&tv_zero, &tv4));
|
||||
|
||||
/* add interval */
|
||||
util_timeval_add (NULL, 0);
|
||||
tv.tv_sec = 123456;
|
||||
tv.tv_usec = 12000;
|
||||
util_timeval_add (&tv, 10);
|
||||
util_timeval_add (&tv, 10000);
|
||||
LONGS_EQUAL(123456, tv.tv_sec);
|
||||
LONGS_EQUAL(22000, tv.tv_usec);
|
||||
util_timeval_add (&tv, 4000);
|
||||
util_timeval_add (&tv, 4000000);
|
||||
LONGS_EQUAL(123460, tv.tv_sec);
|
||||
LONGS_EQUAL(22000, tv.tv_usec);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user