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;
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: