]> sjero.net Git - wget/commitdiff
[svn] Windows fixes by Gisle Vanem.
authorhniksic <devnull@localhost>
Sat, 27 Sep 2003 00:35:31 +0000 (17:35 -0700)
committerhniksic <devnull@localhost>
Sat, 27 Sep 2003 00:35:31 +0000 (17:35 -0700)
src/ChangeLog
src/mswindows.c
src/mswindows.h
windows/config.h.ms

index ed573983dd1ca88a5271407d4a448677d38814ef..75f7ecf0c88cb0f276e5d537b3076af3030c6a6f 100644 (file)
@@ -1,3 +1,9 @@
+2003-09-26  Gisle Vanem  <giva@bgnett.no>
+
+       * mswindows.c (read_registry): Removed.
+       (set_sleep_mode): New function.
+       (windows_main_junk): Call it.
+
 2003-09-26  Gisle Vanem  <giva@bgnett.no>
 
        * mswindows.c (read_registry): Fix invocation of registry
index 0b5242f15390760a8a777c4a6433c27fb37f2e4d..a3a186a8e97fd0bf97cce5d23d8fb1d65428f4ed 100644 (file)
@@ -57,13 +57,25 @@ so, delete this exception statement from your version.  */
 extern int errno;
 #endif
 
+#ifndef ES_SYSTEM_REQUIRED
+#define ES_SYSTEM_REQUIRED  0x00000001
+#endif
+
+#ifndef ES_CONTINUOUS
+#define ES_CONTINUOUS       0x80000000
+#endif
+
+
 /* Defined in log.c.  */
 void log_request_redirect_output PARAMS ((const char *));
 
-static int windows_nt_p;
+static DWORD set_sleep_mode (DWORD mode);
 
+static DWORD pwr_mode = 0;
+static int windows_nt_p;
 
 #ifndef HAVE_SLEEP
+
 /* Emulation of Unix sleep.  */
 
 unsigned int
@@ -92,21 +104,6 @@ usleep (unsigned long usec)
 }
 #endif  /* HAVE_USLEEP */
 
-static char *
-read_registry (HKEY hkey, char *subkey, char *valuename, char *buf, int *len)
-{
-  HKEY result;
-  DWORD size = *len;
-  DWORD type = REG_SZ;
-  if (RegOpenKeyEx (hkey, subkey, 0, KEY_READ, &result) != ERROR_SUCCESS)
-    return NULL;
-  if (RegQueryValueEx (result, valuename, NULL, &type, (LPBYTE)buf, &size) != ERROR_SUCCESS)
-    buf = NULL;
-  *len = size;
-  RegCloseKey (result);
-  return buf;
-}
-
 void
 windows_main_junk (int *argc, char **argv, char **exec_name)
 {
@@ -125,6 +122,9 @@ static void
 ws_cleanup (void)
 {
   WSACleanup ();
+  if (pwr_mode)
+     set_sleep_mode (pwr_mode);
+  pwr_mode = 0;
 }
 
 static void
@@ -170,7 +170,7 @@ ws_handler (DWORD dwEvent)
     case CTRL_CLOSE_EVENT:
     case CTRL_LOGOFF_EVENT:
     default:
-      WSACleanup ();
+      ws_cleanup ();
       return FALSE;
     }
   return TRUE;
@@ -266,6 +266,7 @@ ws_startup (void)
       exit (1);
     }
   atexit (ws_cleanup);
+  pwr_mode = set_sleep_mode (0);
   SetConsoleCtrlHandler (ws_handler, TRUE);
 }
 
@@ -295,3 +296,31 @@ int 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 by default not 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 (*_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);
+}
+
index 4f505d8002f5ea3700e6b2ea7e9ef416755f4e40..b7d9c9492d5ca7998f3811e041466e8df540efb1 100644 (file)
@@ -125,11 +125,6 @@ so, delete this exception statement from your version.  */
 #define ESTALE                  WSAESTALE
 #define EREMOTE                 WSAEREMOTE
 
-#ifdef __DMC__
-# define HAVE_SLEEP 1
-# define HAVE_USLEEP 1
-#endif
-
 /* Public functions.  */
 
 #ifndef HAVE_SLEEP
index 8db2a46e5bc3be91dcd9a75d92ca71d944fb6042..715377b62a889e593242d06110ecdf6ff77e9f33 100644 (file)
@@ -139,9 +139,10 @@ char *alloca ();
 #undef HAVE_UNISTD_H
 #endif
 
-/* None except Digital Mars have usleep function */
+/* None except Digital Mars have sleep/usleep functions */
 #if defined(__DMC__)
 #define HAVE_USLEEP
+#define HAVE_SLEEP
 #endif
 
 /* Define if you have the <utime.h> header file.  */