Added silc_buffer_steal. Optimized some encoding and decoding
[silc.git] / lib / silcutil / win32 / silcwin32schedule.c
index 22445aef9bb1cbe5b869c0e1d58c1a49571627a4..671b126849d25c51f65c37295833b1ca37bfd490 100644 (file)
@@ -52,7 +52,7 @@
 
 int silc_select(SilcScheduleFd fds, SilcUInt32 fds_count, struct timeval *timeout)
 {
-  HANDLE handles[MAXIMUM_WAIT_OBJECTS];
+  static HANDLE handles[MAXIMUM_WAIT_OBJECTS];
   DWORD ready, curtime, timeo;
   int nhandles = 0, i;
   MSG msg;
@@ -83,27 +83,17 @@ 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);
-      if (timeo != INFINITE) {
-       timeo -= GetTickCount() - curtime;
-       if (timeo < 0)
-         timeo = 0;
-      }
-      timer = SetTimer(NULL, 0, timeo, NULL);
+      return 0;
     }
+    TranslateMessage(&msg); 
+    DispatchMessage(&msg); 
+
+    KillTimer(NULL, timer);
+    timeo = 0;
   }
 
  retry: