silc_compare_timeval returns < 0, 0, > 0 instead of TRUE/FALSE.
authorPekka Riikonen <priikone@silcnet.org>
Tue, 8 May 2007 20:21:16 +0000 (20:21 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Tue, 8 May 2007 20:21:16 +0000 (20:21 +0000)
Fixed timeout task dispatching to check for equal or bigger
timeout instead just bigger.  This fixes WIN32 0 timeout task
dispatching.

CHANGES
lib/silcutil/silcfsm.h
lib/silcutil/silcschedule.c
lib/silcutil/silctime.c
lib/silcutil/silctime.h
lib/silcutil/unix/silcunixsocketstream.c

diff --git a/CHANGES b/CHANGES
index 0aa26c85315d1de32a62a313ca091983e27a6ce1..cf4cce4822a45c0ab7cdf0e899ad03781e9db6dd 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -18,6 +18,11 @@ Tue May  8 18:13:38 EEST 2007  Pekka Riikonen <priikone@silcnet.org>
        * 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 <priikone@silcnet.org>
 
        * Fixed CMODE channel auth public key retrieval.  Affected
index 6d6b8c9d030a74a0dd138102c75606993dffa825..24daa6fa5ec165627d59faf69e095f1ebea3e4f1 100644 (file)
@@ -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;                  \
index 7ffcc51088be6edb0b1f22cd0d60a4b9d13f10d0..ae8560aa6f7bbf75fa4251fe955e939abc51fdfa 100644 (file)
@@ -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;
       }
index 350caf0372a15b79cd99f4629b6c502d5180d002..6dc321d690b56e4875afdcc6f93eec07ab1fa337 100644 (file)
@@ -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;
 }
index cd9499c1d247264ce3877a999ce321c85e79ff4b..03cdb5566cdf3ab050f87722afc4694fa041edd2 100644 (file)
@@ -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
  *
index 65047081c1055deb4ba2c8d375693c93383d028c..f3107f39c36a1044401de229ea04a69de7fe01c7 100644 (file)
@@ -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;