]> sjero.net Git - wget/commitdiff
[svn] Improved Windows power management logic. Submitted by David Fritz.
authorhniksic <devnull@localhost>
Thu, 26 Feb 2004 14:34:17 +0000 (06:34 -0800)
committerhniksic <devnull@localhost>
Thu, 26 Feb 2004 14:34:17 +0000 (06:34 -0800)
src/ChangeLog
src/mswindows.c

index 17c101ab05af9cf5e0e9314797d29d4b41377a4a..26578729c7d7c4a768428bfcb2e633b1f77bf50e 100644 (file)
@@ -1,3 +1,13 @@
+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.
index 0406bb355f786ddf1e4d15bfbb7816deca41964c..a2094900e1963eb43551dcc18c5e2dd670b3ba37 100644 (file)
@@ -70,9 +70,6 @@ extern int errno;
 /* 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.  */
@@ -109,9 +106,6 @@ static void
 ws_cleanup (void)
 {
   WSACleanup ();
-  if (pwr_mode)
-     set_sleep_mode (pwr_mode);
-  pwr_mode = 0;
 }
 
 static void
@@ -233,6 +227,24 @@ ws_mypath (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)
@@ -264,7 +276,7 @@ ws_startup (void)
     }
 
   atexit (ws_cleanup);
-  pwr_mode = set_sleep_mode (0);
+  set_sleep_mode ();
   SetConsoleCtrlHandler (ws_handler, TRUE);
 }
 
@@ -295,33 +307,6 @@ borland_utime (const char *path, const struct utimbuf *times)
   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.  */