Reverted, bad commit
authorPekka Riikonen <priikone@silcnet.org>
Tue, 14 Jan 2003 11:47:24 +0000 (11:47 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Tue, 14 Jan 2003 11:47:24 +0000 (11:47 +0000)
lib/silcutil/win32/silcwin32schedule.c

index 671b126849d25c51f65c37295833b1ca37bfd490..22445aef9bb1cbe5b869c0e1d58c1a49571627a4 100644 (file)
@@ -52,7 +52,7 @@
 
 int silc_select(SilcScheduleFd fds, SilcUInt32 fds_count, struct timeval *timeout)
 {
-  static HANDLE handles[MAXIMUM_WAIT_OBJECTS];
+  HANDLE handles[MAXIMUM_WAIT_OBJECTS];
   DWORD ready, curtime, timeo;
   int nhandles = 0, i;
   MSG msg;
@@ -83,17 +83,27 @@ int silc_select(SilcScheduleFd fds, SilcUInt32 fds_count, struct timeval *timeou
      and wait just for windows messages. */
   if (nhandles == 0 && timeout) {
     UINT timer = SetTimer(NULL, 0, timeo, NULL);
+    curtime = GetTickCount();
+    while (timer) {
+      WaitMessage();
+
+      while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
+       if (msg.message == WM_TIMER) {
+         KillTimer(NULL, timer);
+         return 0;
+       }
+       TranslateMessage(&msg); 
+       DispatchMessage(&msg); 
+      }
 
-    GetMessage(&msg, NULL, 0, 0);
-    if (msg.message == WM_TIMER) {
       KillTimer(NULL, timer);
-      return 0;
+      if (timeo != INFINITE) {
+       timeo -= GetTickCount() - curtime;
+       if (timeo < 0)
+         timeo = 0;
+      }
+      timer = SetTimer(NULL, 0, timeo, NULL);
     }
-    TranslateMessage(&msg); 
-    DispatchMessage(&msg); 
-
-    KillTimer(NULL, timer);
-    timeo = 0;
   }
 
  retry: