wininet: Call FreeUrlCacheSpaceW when cache is full.

This commit is contained in:
Piotr Caban 2012-09-21 14:53:33 +02:00 committed by Alexandre Julliard
parent b037bd7bff
commit ed71ed596f
3 changed files with 44 additions and 6 deletions

View File

@ -292,7 +292,11 @@ BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
if (g_dwTlsErrIndex == TLS_OUT_OF_INDEXES)
return FALSE;
URLCacheContainers_CreateDefaults();
if(!init_urlcache())
{
TlsFree(g_dwTlsErrIndex);
return FALSE;
}
WININET_hModule = hinstDLL;
break;
@ -310,7 +314,7 @@ BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
case DLL_PROCESS_DETACH:
collect_connections(COLLECT_CLEANUP);
NETCON_unload();
URLCacheContainers_DeleteAll();
free_urlcache();
if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
{

View File

@ -551,8 +551,8 @@ int sock_get_error(int) DECLSPEC_HIDDEN;
server_t *get_server(const WCHAR*,INTERNET_PORT,BOOL);
extern void URLCacheContainers_CreateDefaults(void) DECLSPEC_HIDDEN;
extern void URLCacheContainers_DeleteAll(void) DECLSPEC_HIDDEN;
BOOL init_urlcache(void) DECLSPEC_HIDDEN;
void free_urlcache(void) DECLSPEC_HIDDEN;
#define MAX_REPLY_LEN 0x5B4

View File

@ -2326,6 +2326,22 @@ static BOOL DeleteUrlCacheEntryInternal(const URLCACHECONTAINER * pContainer,
return TRUE;
}
static HANDLE free_cache_running;
static DWORD WINAPI handle_full_cache_worker(void *param)
{
FreeUrlCacheSpaceW(NULL, 20, 0);
ReleaseSemaphore(free_cache_running, 1, NULL);
return 0;
}
static void handle_full_cache(void)
{
if(WaitForSingleObject(free_cache_running, 0) == WAIT_OBJECT_0) {
if(!QueueUserWorkItem(handle_full_cache_worker, NULL, 0))
ReleaseSemaphore(free_cache_running, 1, NULL);
}
}
/***********************************************************************
* UnlockUrlCacheEntryFileA (WININET.@)
*
@ -2712,7 +2728,6 @@ BOOL WINAPI CreateUrlCacheEntryW(
return FALSE;
}
/***********************************************************************
* CommitUrlCacheEntryInternal (Compensates for an MS bug)
*
@ -2969,7 +2984,7 @@ static BOOL CommitUrlCacheEntryInternal(
pHeader->CacheUsage.QuadPart += file_size.QuadPart;
if (pHeader->CacheUsage.QuadPart + pHeader->ExemptUsage.QuadPart >
pHeader->CacheLimit.QuadPart)
FIXME("file of size %s bytes fills cache\n", wine_dbgstr_longlong(file_size.QuadPart));
handle_full_cache();
}
cleanup:
@ -4114,3 +4129,22 @@ DWORD WINAPI RunOnceUrlCache(HWND hwnd, HINSTANCE hinst, LPSTR cmd, int cmdshow)
FIXME("(%p, %p, %s, %d): stub\n", hwnd, hinst, debugstr_a(cmd), cmdshow);
return 0;
}
BOOL init_urlcache(void)
{
free_cache_running = CreateSemaphoreW(NULL, 1, 1, NULL);
if(!free_cache_running)
return FALSE;
URLCacheContainers_CreateDefaults();
return TRUE;
}
void free_urlcache(void)
{
WaitForSingleObject(free_cache_running, INFINITE);
ReleaseSemaphore(free_cache_running, 1, NULL);
CloseHandle(free_cache_running);
URLCacheContainers_DeleteAll();
}