updates.
authorPekka Riikonen <priikone@silcnet.org>
Wed, 18 Jul 2001 06:57:44 +0000 (06:57 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Wed, 18 Jul 2001 06:57:44 +0000 (06:57 +0000)
CHANGES
lib/silcutil/silcschedule_i.h [new file with mode: 0644]
lib/silcutil/win32/silcwin32schedule.c

diff --git a/CHANGES b/CHANGES
index db43190d0bf14138df3472b5add391b0487ebcff..e37f1216f435c82dc585c2c3a55d7d7511afd130 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,8 @@
+Wed Jul 18 09:40:04 EEST 2001  Pekka Riikonen <priikone@silcnet.org>
+
+       * Added for WIN32 support for the new scheduler as well.
+         Affected file lib/silcutil/win32/silcwin32schedule.c.
+
 Tue Jul 17 23:04:10 EEST 2001  Pekka Riikonen <priikone@silcnet.org>
 
        * Rewrote the SILC Scheduler entirely.  Removed the old SILC Task
diff --git a/lib/silcutil/silcschedule_i.h b/lib/silcutil/silcschedule_i.h
new file mode 100644 (file)
index 0000000..b3a2c92
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+
+  silcschedule_i.h.
+
+  Author: Pekka Riikonen <priikone@silcnet.org>
+
+  Copyright (C) 2001 Pekka Riikonen
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+  
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+*/
+
+#ifndef SILCSCHEDULE_I_H
+#define SILCSCHEDULE_I_H
+
+#include "silcincludes.h"
+
+/* Schedule FD structure. Includes the file descriptors that the scheduler
+   will listen. This is given as argument to the silc_select function. */
+typedef struct {
+  uint32 fd;                   /* The file descriptor (or handle on WIN32) */
+  uint16 events;               /* Mask of task events, if events is 0 then
+                                  the fd must be omitted. */
+  uint16 revents;              /* Returned events mask */
+} *SilcScheduleFd;
+
+#endif
index 693cbfc8d6ab3e607615f16e62dad94f3a8c178d..433b5ec2ddf4ca339b137e870840c76229ddf6c0 100644 (file)
@@ -20,6 +20,7 @@
 /* $Id$ */
 
 #include "silcincludes.h"
+#includd "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
@@ -28,8 +29,7 @@
    This makes following assumptions, which I don't know whether they
    are correct or not:
 
-   o writefds are ignored, if set this will return immediately.
-   o exceptfds are ignored totally
+   o SILC_TASK_WRITE is ignored, if set this will return immediately.
    o If all arguments except timeout are NULL then this will register
      a timeout with SetTimer and will wait just for Windows messages
      with WaitMessage.
 
 */
 
-int silc_select(int n, fd_set *readfds, fd_set *writefds,
-               fd_set *exceptfds, struct timeval *timeout)
+int silc_select(SilcScheduleFd fds, uint32 fds_count, struct timeval *timeout)
 {
   HANDLE handles[MAXIMUM_WAIT_OBJECTS];
   DWORD ready, curtime, timeo;
   int nhandles = 0, i;
   MSG msg;
 
-  /* Check fd sets (ignoring the exceptfds) */
-  if (readfds) {
-    for (i = 0; i < n; i++)
-      if (FD_ISSET(i, readfds))
-       handles[nhandles++] = (HANDLE)i;
+  for (i = 0; i < fds_count; i++) {
+    if (!fds[i].events)
+      continue;
 
-    FD_ZERO(readfds);
-  }
+    if (fds[i].events & SILC_TASK_READ)
+      handles[nhandles++] = (HANDLE)i;
+
+    if (fds[i].events & SILC_TASK_WRITE)
+      return 1;
 
-  /* If writefds is set then return immediately */
-  if (writefds) {
-    for (i = 0; i < n; i++)
-      if (FD_ISSET(i, writefds))
-       return 1;
+    fds[i].revents = 0;
   }
 
   timeo = (timeout ? (timeout->tv_sec * 1000) + (timeout->tv_usec / 1000) :
@@ -113,7 +109,6 @@ int silc_select(int n, fd_set *readfds, fd_set *writefds,
     /* Wait failed with error */
     SILC_LOG_WARNING(("WaitForMultipleObjects() failed"));
     return -1;
-
   } else if (ready >= WAIT_ABANDONED_0 &&
             ready < WAIT_ABANDONED_0 + nhandles) {
     /* Signal abandoned */
@@ -149,20 +144,25 @@ int silc_select(int n, fd_set *readfds, fd_set *writefds,
     /* Go through all fds even though only one was set. This is to avoid
        starvation of high numbered fds. */
     ready -= WAIT_OBJECT_0;
-    i = 0;
     do {
-      /* Set the handle to fd set */
-      FD_SET((int)handles[ready], readfds);
-      i++;
+      for (i = 0; i < fds_count; i++) {
+       if (!fds[i].events)
+         continue;
+       
+       if (fds[i].fd == (int)handles[ready]) {
+         fds[i].revents |= SILC_TASK_READ;
+         break;
+       }
+      }
 
-      /* Check the status of the next handle and set it's fd to the fd
+      /* Check the status of the next handle and set its fd to the fd
         set if data is available. */
-      while (++ready < n)
+      while (++ready < fds_count)
        if (WaitForSingleObject(handles[ready], 0) == WAIT_OBJECT_0)
          break;
-    } while (ready < n);
+    } while (ready < fds_count);
 
-    return i;
+    return i + 1;
   }
 
   return -1;