cURL CONNECTTIMEOUT alert
i am doing this project in开发者_StackOverflow which a small part is to connect to a server and do some things and if it fails to connect to the server within a time, then give an error message.. i know the curl code looks something like this curl_easy_setopt(c,CURLOPT_CONNECTTIMEOUT,1L); and also that it has a MilliSecond option. What i want is for the program to alert me if curl fails to connect to the server within the given time(in this case 1 second.)
Have you tried this?
char* pErrorBuffer = NULL;
pErrorBuffer = (char*)malloc( 512 );
memset( pErrorBuffer, 0, 512 );
curl_easy_setopt( curlHandle, CURLOPT_ERRORBUFFER, pErrorBuffer );
curl_easy_setopt( curlHandle, CURLOPT_CONNECTTIMEOUT, 1 ); // 1 s connect timeout
if( CURLE_OK != curl_easy_perform( curlHandle ) )
{
// pErrorBuffer contains error string returned by cURL
pErrorBuffer[511] = '\0';
printf( "cURL returned: %s", pErrorBuffer );
}
// Free when you're done.
free( pErrorBuffer );
精彩评论