diff --git a/src/d_netfil.c b/src/d_netfil.c index 9b2e55f86..0137d38c5 100644 --- a/src/d_netfil.c +++ b/src/d_netfil.c @@ -111,6 +111,7 @@ static fileused_t transferFiles[UINT8_MAX + 1]; // Receiver structure INT32 fileneedednum; // Number of files needed to join the server fileneeded_t fileneeded[MAX_WADFILES]; // List of needed files +static I_mutex downloadmutex; char downloaddir[512] = "DOWNLOAD"; #ifdef CLIENT_LOADINGSCREEN @@ -1337,6 +1338,7 @@ void CURLPrepareFile(const char* url, int dfilenum) curl_starttime = time(NULL); curl_running = true; + #ifdef HAVE_THREADS I_spawn_thread("http-download", (I_thread_fn)CURLGetFile, NULL); #endif @@ -1346,10 +1348,15 @@ void CURLPrepareFile(const char* url, int dfilenum) void CURLAbortFile(void) { curl_running = false; + + // lock and unlock to wait for the download thread to exit + I_lock_mutex(&downloadmutex); + I_unlock_mutex(downloadmutex); } void CURLGetFile(void) { + I_lock_mutex(&downloadmutex); CURLMcode mc; /* return code used by curl_multi_wait() */ CURLcode easyres; /* Return from easy interface */ CURLMsg *m; /* for picking up messages with the transfer status */ @@ -1442,6 +1449,7 @@ void CURLGetFile(void) multi_handle = NULL; } curl_running = false; + I_unlock_mutex(downloadmutex); } HTTP_login *