From a701291da97f797e954bdb6579d3f187f17fb8d2 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Tue, 8 May 2007 20:21:16 +0000 Subject: [PATCH] silc_compare_timeval returns < 0, 0, > 0 instead of TRUE/FALSE. Fixed timeout task dispatching to check for equal or bigger timeout instead just bigger. This fixes WIN32 0 timeout task dispatching. --- CHANGES | 5 +++++ lib/silcutil/silcfsm.h | 2 +- lib/silcutil/silcschedule.c | 6 +++--- lib/silcutil/silctime.c | 13 +++++-------- lib/silcutil/silctime.h | 11 +++++------ lib/silcutil/unix/silcunixsocketstream.c | 2 +- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/CHANGES b/CHANGES index 0aa26c85..cf4cce48 100644 --- a/CHANGES +++ b/CHANGES @@ -18,6 +18,11 @@ Tue May 8 18:13:38 EEST 2007 Pekka Riikonen * Make Toolkit compile on WIN32. Affected files in win32/ and in lib/silcutil/win32/. + * Changed silc_compare_timeval to return negative, zero or + positive instead of just TRUE or FALSE. This fixes 0 timeout + task dispatching on Windows. Affected files are + lib/silcutil/silctime.[ch] and silcschedule.c. + Mon May 7 18:18:48 EEST 2007 Pekka Riikonen * Fixed CMODE channel auth public key retrieval. Affected diff --git a/lib/silcutil/silcfsm.h b/lib/silcutil/silcfsm.h index 6d6b8c9d..24daa6fa 100644 --- a/lib/silcutil/silcfsm.h +++ b/lib/silcutil/silcfsm.h @@ -291,7 +291,7 @@ typedef int (*SilcFSMStateCallback)(struct SilcFSMObject *fsm, ***/ #define SILC_FSM_CALL(function) \ do { \ - assert(!silc_fsm_set_call(fsm, TRUE)); \ + SILC_ASSERT(!silc_fsm_set_call(fsm, TRUE)); \ function; \ if (!silc_fsm_set_call(fsm, FALSE)) \ return SILC_FSM_CONTINUE; \ diff --git a/lib/silcutil/silcschedule.c b/lib/silcutil/silcschedule.c index 7ffcc510..ae8560aa 100644 --- a/lib/silcutil/silcschedule.c +++ b/lib/silcutil/silcschedule.c @@ -106,7 +106,7 @@ static void silc_schedule_dispatch_timeout(SilcSchedule schedule, } /* Execute the task if the timeout has expired */ - if (!silc_compare_timeval(&task->timeout, &curtime) && !dispatch_all) + if (silc_compare_timeval(&task->timeout, &curtime) > 0 && !dispatch_all) break; t->valid = FALSE; @@ -155,7 +155,7 @@ static void silc_schedule_select_timeout(SilcSchedule schedule) /* If the timeout is in past, we will run the task and all other timeout tasks from the past. */ - if (silc_compare_timeval(&task->timeout, &curtime) && dispatch) { + if (silc_compare_timeval(&task->timeout, &curtime) <= 0 && dispatch) { silc_schedule_dispatch_timeout(schedule, FALSE); if (silc_unlikely(!schedule->valid)) return; @@ -591,7 +591,7 @@ SilcTask silc_schedule_task_add(SilcSchedule schedule, SilcUInt32 fd, prev = NULL; while ((tmp = silc_list_get(list)) != SILC_LIST_END) { /* If we have shorter timeout, we have found our spot */ - if (silc_compare_timeval(&ttask->timeout, &tmp->timeout)) { + if (silc_compare_timeval(&ttask->timeout, &tmp->timeout) < 0) { silc_list_insert(schedule->timeout_queue, prev, ttask); break; } diff --git a/lib/silcutil/silctime.c b/lib/silcutil/silctime.c index 350caf03..6dc321d6 100644 --- a/lib/silcutil/silctime.c +++ b/lib/silcutil/silctime.c @@ -380,13 +380,10 @@ SilcBool silc_time_generalized_string(SilcTime time_val, char *ret_string, /* Return TRUE if `smaller' is smaller than `bigger'. */ -SilcBool silc_compare_timeval(struct timeval *smaller, - struct timeval *bigger) +int silc_compare_timeval(struct timeval *t1, struct timeval *t2) { - if ((smaller->tv_sec < bigger->tv_sec) || - ((smaller->tv_sec == bigger->tv_sec) && - (smaller->tv_usec < bigger->tv_usec))) - return TRUE; - - return FALSE; + SilcInt32 s = t1->tv_sec - t2->tv_sec; + if (!s) + return t1->tv_usec - t2->tv_usec; + return s; } diff --git a/lib/silcutil/silctime.h b/lib/silcutil/silctime.h index cd9499c1..03cdb556 100644 --- a/lib/silcutil/silctime.h +++ b/lib/silcutil/silctime.h @@ -247,17 +247,16 @@ SilcBool silc_time_generalized_string(SilcTime time_val, char *ret_string, * * SYNOPSIS * - * SilcBool silc_compare_timeval(struct time_val *smaller, - * struct time_val *bigger) + * int silc_compare_timeval(struct time_val *t1, struct time_val *t2); * * DESCRIPTION * - * Compare two timeval structures and return TRUE if the first - * time value is smaller than the second time value. + * Compares `t1' and `t2' time structures and returns less than zero, + * zero or more than zero when `t1' is smaller, equal or bigger than + * `t2', respectively. * ***/ -SilcBool silc_compare_timeval(struct timeval *smaller, - struct timeval *bigger); +int silc_compare_timeval(struct timeval *t1, struct timeval *t2); /****f* silcutil/SilcTimeAPI/silc_gettimeofday * diff --git a/lib/silcutil/unix/silcunixsocketstream.c b/lib/silcutil/unix/silcunixsocketstream.c index 65047081..f3107f39 100644 --- a/lib/silcutil/unix/silcunixsocketstream.c +++ b/lib/silcutil/unix/silcunixsocketstream.c @@ -150,7 +150,7 @@ int silc_socket_stream_read(SilcStream stream, unsigned char *buf, /* If we have passed the rate time limit, set our new time limit, and zero the rate limit. This limits reads per second. */ silc_gettimeofday(&curtime); - if (!silc_compare_timeval(&curtime, &sock->qos->next_limit)) { + if (silc_compare_timeval(&curtime, &sock->qos->next_limit) > 0) { curtime.tv_sec++; sock->qos->next_limit = curtime; sock->qos->cur_rate = 0; -- 2.24.0