SILC Runtime Toolkit 1.2 Beta 1
[runtime.git] / lib / silcutil / win32 / silcwin32schedule.c
index 4c31c0d980b804d518e520da9bc31710413642d2..93b7fc64fb38caa248db1c765cd939acc5b5d50c 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2001 - 2007 Pekka Riikonen
+  Copyright (C) 2001 - 2008 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
@@ -16,9 +16,8 @@
   GNU General Public License for more details.
 
 */
-/* $Id$ */
 
-#include "silc.h"
+#include "silcruntime.h"
 
 const SilcScheduleOps schedule_ops;
 
@@ -40,7 +39,6 @@ typedef struct {
 int silc_select(SilcSchedule schedule, void *context)
 {
   SilcWin32Scheduler internal = (SilcWin32Scheduler)context;
-  SilcHashTableList htl;
   HANDLE handles[MAXIMUM_WAIT_OBJECTS];
   DWORD ready, curtime;
   LONG timeo = INFINITE;
@@ -54,7 +52,7 @@ int silc_select(SilcSchedule schedule, void *context)
   }
 
   /* Add wakeup semaphore to events */
-  handles[nhandles++] = (HANDLE)internal->wakeup_sema;
+  handles[nhandles++] = internal->wakeup_sema;
 
   /* Get timeout */
   if (schedule->has_timeout)
@@ -126,12 +124,12 @@ int silc_select(SilcSchedule schedule, void *context)
 
 /* Window callback.  We get here when some event occurs on file descriptor
    or socket that has been scheduled.  We add them to dispatch queue and
-   notify the scheduler handle them. */
+   notify the scheduler to handle them. */
 
 static LRESULT CALLBACK
 silc_schedule_wnd_proc(HWND hwnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
 {
-  SilcSchedule schedule = (SilcSchedule)GetWindowLong(hwnd, GWL_USERDATA);
+  SilcSchedule schedule = (SilcSchedule)GetWindowLongPtr(hwnd, GWL_USERDATA);
   SilcWin32Scheduler internal;
   SilcUInt32 fd;
   SilcTaskFd task;
@@ -157,11 +155,12 @@ silc_schedule_wnd_proc(HWND hwnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
       break;
     }
 
-    /* Ignore the event if the task not valid anymore */
+    /* Ignore the event if the task is not valid anymore */
     if (!task->header.valid || !task->events) {
       SILC_SCHEDULE_UNLOCK(schedule);
       break;
     }
+    task->revents = 0;
 
     /* Handle event */
     switch (WSAGETSELECTEVENT(lParam)) {
@@ -268,7 +267,7 @@ void *silc_schedule_internal_init(SilcSchedule schedule, void *app_context)
   }
 
   /* Set the scheduler as the window's context */
-  SetWindowLong(internal->window, GWL_USERDATA, (void *)schedule);
+  SetWindowLongPtr(internal->window, GWL_USERDATA, (void *)schedule);
   SetWindowPos(internal->window, HWND_BOTTOM, 0, 0, 0, 0, SWP_FRAMECHANGED);
 
   internal->wakeup_sema = CreateSemaphore(NULL, 0, 100, NULL);
@@ -324,6 +323,7 @@ SilcBool silc_schedule_internal_schedule_fd(SilcSchedule schedule,
   /* Schedule for events.  The silc_schedule_wnd_proc will be called to
      deliver the events for this fd. */
   WSAAsyncSelect(task->fd, internal->window, SILC_WM_EVENT, events);
+  task->revents = 0;
 
   return TRUE;
 }