mirror of
https://github.com/moparisthebest/wget
synced 2024-07-03 16:38:41 -04:00
[svn] Improved Windows power management logic. Submitted by David Fritz.
This commit is contained in:
parent
a0642cc62e
commit
a865004aba
@ -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>
|
2004-02-23 David Fritz <zeroxdf@att.net>
|
||||||
|
|
||||||
* http.c (http_loop): Ditto.
|
* http.c (http_loop): Ditto.
|
||||||
|
@ -70,9 +70,6 @@ extern int errno;
|
|||||||
/* Defined in log.c. */
|
/* Defined in log.c. */
|
||||||
void log_request_redirect_output PARAMS ((const char *));
|
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;
|
static int windows_nt_p;
|
||||||
|
|
||||||
/* Windows version of xsleep in utils.c. */
|
/* Windows version of xsleep in utils.c. */
|
||||||
@ -109,9 +106,6 @@ static void
|
|||||||
ws_cleanup (void)
|
ws_cleanup (void)
|
||||||
{
|
{
|
||||||
WSACleanup ();
|
WSACleanup ();
|
||||||
if (pwr_mode)
|
|
||||||
set_sleep_mode (pwr_mode);
|
|
||||||
pwr_mode = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -233,6 +227,24 @@ ws_mypath (void)
|
|||||||
return wspathsave;
|
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. */
|
/* Perform Windows specific initialization. */
|
||||||
void
|
void
|
||||||
ws_startup (void)
|
ws_startup (void)
|
||||||
@ -264,7 +276,7 @@ ws_startup (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
atexit (ws_cleanup);
|
atexit (ws_cleanup);
|
||||||
pwr_mode = set_sleep_mode (0);
|
set_sleep_mode ();
|
||||||
SetConsoleCtrlHandler (ws_handler, TRUE);
|
SetConsoleCtrlHandler (ws_handler, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -295,33 +307,6 @@ borland_utime (const char *path, const struct utimbuf *times)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
#endif
|
#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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* run_with_timeout Windows implementation. */
|
/* run_with_timeout Windows implementation. */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user