Integer type name change.
[silc.git] / lib / silcutil / win32 / silcwin32schedule.c
index 433b5ec2ddf4ca339b137e870840c76229ddf6c0..f3bf02cc0f894d5ef98083bcd8baf7e8483917b2 100644 (file)
@@ -20,7 +20,7 @@
 /* $Id$ */
 
 #include "silcincludes.h"
-#includd "silcschedule_i.h"
+#include "silcschedule_i.h"
 
 /* Our "select()" for WIN32. This mimics the behaviour of select() system
    call. It does not call the Winsock's select() though. Its functions
 
 */
 
-int silc_select(SilcScheduleFd fds, uint32 fds_count, struct timeval *timeout)
+int silc_select(SilcScheduleFd fds, SilcUInt32 fds_count, struct timeval *timeout)
 {
   HANDLE handles[MAXIMUM_WAIT_OBJECTS];
   DWORD ready, curtime, timeo;
   int nhandles = 0, i;
   MSG msg;
 
+  if (fds_count > MAXIMUM_WAIT_OBJECTS)
+    fds_count = MAXIMUM_WAIT_OBJECTS;
+
   for (i = 0; i < fds_count; i++) {
     if (!fds[i].events)
       continue;
 
     if (fds[i].events & SILC_TASK_READ)
-      handles[nhandles++] = (HANDLE)i;
+      handles[nhandles++] = (HANDLE)fds[i].fd;
 
-    if (fds[i].events & SILC_TASK_WRITE)
+    /* If writing then just set the bit and return */
+    if (fds[i].events & SILC_TASK_WRITE) {
+      fds[i].revents = SILC_TASK_WRITE;
       return 1;
+    }
 
     fds[i].revents = 0;
   }
@@ -137,8 +143,7 @@ int silc_select(SilcScheduleFd fds, uint32 fds_count, struct timeval *timeout)
 
     /* Give the wait another try */
    goto retry;
-  } else if (ready >= WAIT_OBJECT_0 && ready < WAIT_OBJECT_0 + nhandles &&
-            readfds) {
+  } else if (ready >= WAIT_OBJECT_0 && ready < WAIT_OBJECT_0 + nhandles) {
     /* Some other event, like SOCKET or something. */
 
     /* Go through all fds even though only one was set. This is to avoid