Beispiel #1
0
void* get_http_page_threaded( ALLEGRO_THREAD* thread, void* ThreadData )
{
  DOWNLOAD_THREAD_DATA* threadData = (DOWNLOAD_THREAD_DATA*)ThreadData;
	CURL* curl_handle;
	Memory* buffer = new Memory( 0 );
	int cTO = 60;

	curl_handle = curl_easy_init();
	curl_easy_setopt( curl_handle, CURLOPT_URL, threadData->URL->c_str() );
	curl_easy_setopt( curl_handle, CURLOPT_FOLLOWLOCATION, 1L );
  curl_easy_setopt( curl_handle, CURLOPT_NOPROGRESS, 0L );
  curl_easy_setopt( curl_handle, CURLOPT_WRITEFUNCTION, write_data );
	curl_easy_setopt( curl_handle, CURLOPT_WRITEDATA, (void*)buffer );
  curl_easy_setopt( curl_handle, CURLOPT_PROGRESSFUNCTION, download_progress );
	curl_easy_setopt( curl_handle, CURLOPT_PROGRESSDATA, threadData->Information );

	cTO = FRAMEWORK->Settings->GetQuickIntegerValue( "Downloads.TimeOut", 60 ); // Default timeout is 60, but get settings
  curl_easy_setopt( curl_handle, CURLOPT_TIMEOUT, (long)cTO );
	curl_easy_setopt( curl_handle, CURLOPT_NOSIGNAL, 1L );

	if( FRAMEWORK->Settings->GetQuickBooleanValue( "Downloads.ProxyRequired", false ) )
	{
		curl_easy_setopt( curl_handle, CURLOPT_PROXY, FRAMEWORK->Settings->GetQuickStringValue( "Downloads.ProxyServer", "" )->c_str() );
		curl_easy_setopt( curl_handle, CURLOPT_PROXYPORT, FRAMEWORK->Settings->GetQuickInteger64Value( "Downloads.ProxyPort", 8080 ) );
	}

	if( curl_easy_perform( curl_handle ) != 0 )
	{
		buffer->Clear();
	}
	curl_easy_cleanup( curl_handle );

	if( !DownloadManager::AbortDownloads )
  {
    Event* fwEvent = new Event();
    fwEvent->Type = EVENT_DOWNLOAD_COMPLETE;
    fwEvent->Data.Download.URL = new std::string( threadData->URL->c_str() );
    fwEvent->Data.Download.Contents = buffer;
    FRAMEWORK->PushEvent( fwEvent );
  }

	if( thread != 0 )
	{
		al_destroy_thread( thread );
	}

	return 0;
}