Game Development Reference
In-Depth Information
How to do it…
1.
We derive the DownloadTask class, which performs an HTTP request using the
libcurl library, from iTask . Here, we implement its method Run() , which sets up
the libcurl library and performs a network operation:
void DownloadTask::Run()
{
clPtr<DownloadTask> Guard( this );
CURL* C = curl_easy_init();
2.
Setup parameters for libcurl:
curl_easy_setopt( C, CURLOPT_URL, FURL.c_str() );
curl_easy_setopt( C, CURLOPT_FOLLOWLOCATION, 1 );
curl_easy_setopt( C, CURLOPT_NOPROGRESS, false );
curl_easy_setopt( C, CURLOPT_FAILONERROR, true );
curl_easy_setopt( C, CURLOPT_MAXCONNECTS, 10 );
curl_easy_setopt( C, CURLOPT_MAXFILESIZE,
DownloadSizeLimit );
curl_easy_setopt( C, CURLOPT_WRITEFUNCTION,
&MemoryCallback );
curl_easy_setopt( C, CURLOPT_WRITEDATA, this );
curl_easy_setopt( C, CURLOPT_PROGRESSFUNCTION,
&ProgressCallback );
curl_easy_setopt( C, CURLOPT_PROGRESSDATA, this );
curl_easy_setopt( C, CURLOPT_CONNECTTIMEOUT, 30 );
curl_easy_setopt( C, CURLOPT_TIMEOUT, 60 );
3. Disable SSL keys veriication:
curl_easy_setopt( C, CURLOPT_SSL_VERIFYPEER, 0 );
curl_easy_setopt( C, CURLOPT_SSL_VERIFYHOST, 0 );
4.
Perform a network operation synchronously. The call curl_easy_perform() blocks
the current thread until the result is obtained from the network, or an error occurs:
FCurlCode = curl_easy_perform( Curl );
5.
Read the result and clean up for the library:
curl_easy_getinfo( Curl, CURLINFO_RESPONSE_CODE,
&FRespCode );
curl_easy_cleanup( Curl );
6.
Tell the downloader to invoke completion callback for this task:
if ( FDownloader ) { FDownloader->CompleteTask( this ); }
}
 
Search WWH ::




Custom Search