+2004-02-25 David Fritz <zeroxdf@att.net>
+
+ * mswindows.c (set_sleep_mode): Remove argument and return value.
+ Call GetModuleHandle() instead of LoadLibrary()/FreeLibrary() for
+ kernel32.dll. Use typedef for function-pointer. Don't cast
+ l-value. Don't use dereference operator when calling through
+ function-pointer.
+ (ws_startup): Update call to set_sleep_mode().
+ (ws_cleanup): Remove call to set_sleep_mode().
+
2004-02-23 David Fritz <zeroxdf@att.net>
* http.c (http_loop): Ditto.
/* Defined in log.c. */
void log_request_redirect_output PARAMS ((const char *));
-static DWORD set_sleep_mode (DWORD mode);
-
-static DWORD pwr_mode = 0;
static int windows_nt_p;
/* Windows version of xsleep in utils.c. */
ws_cleanup (void)
{
WSACleanup ();
- if (pwr_mode)
- set_sleep_mode (pwr_mode);
- pwr_mode = 0;
}
static void
return wspathsave;
}
+/* Prevent Windows entering sleep/hibernation-mode while Wget is doing
+ a lengthy transfer. Windows does not, by default, consider network
+ activity in console-programs as activity! Works on Win-98/ME/2K
+ and up. */
+static void
+set_sleep_mode (void)
+{
+ typedef DWORD (WINAPI *func_t) (DWORD);
+ func_t set_exec_state;
+
+ set_exec_state =
+ (func_t) GetProcAddress (GetModuleHandle ("KERNEL32.DLL"),
+ "SetThreadExecutionState");
+
+ if (set_exec_state)
+ set_exec_state (ES_SYSTEM_REQUIRED | ES_CONTINUOUS);
+}
+
/* Perform Windows specific initialization. */
void
ws_startup (void)
}
atexit (ws_cleanup);
- pwr_mode = set_sleep_mode (0);
+ set_sleep_mode ();
SetConsoleCtrlHandler (ws_handler, TRUE);
}
return res;
}
#endif
-
-/* Prevent Windows entering sleep/hibernation-mode while Wget is doing
- a lengthy transfer. Windows does not, by default, consider network
- activity in console-programs as activity! Works on Win-98/ME/2K
- and up. */
-static DWORD
-set_sleep_mode (DWORD mode)
-{
- HMODULE mod = LoadLibrary ("kernel32.dll");
- DWORD (WINAPI *_SetThreadExecutionState) (DWORD) = NULL;
- DWORD rc = (DWORD)-1;
-
- if (mod)
- (void *)_SetThreadExecutionState
- = GetProcAddress ((HINSTANCE)mod, "SetThreadExecutionState");
-
- if (_SetThreadExecutionState)
- {
- if (mode == 0) /* first time */
- mode = (ES_SYSTEM_REQUIRED | ES_CONTINUOUS);
- rc = (*_SetThreadExecutionState) (mode);
- }
- if (mod)
- FreeLibrary (mod);
- DEBUGP (("set_sleep_mode(): mode 0x%08lX, rc 0x%08lX\n", mode, rc));
- return rc;
-}
\f
/* run_with_timeout Windows implementation. */