CURL CONNECTTIMEOUT Warning

I am doing this project in which a small part is designed to connect to the server and do something, and if it fails to connect to the server for some time, then give an error message. I know that curl code looks something like curl_easy_setopt (with, CURLOPT_CONNECTTIMEOUT, 1L); and also that it has the MilliSecond option. I want the program to warn me if curl was unable to connect to the server for a given time (in this case, 1 second.)

+3
source share
1 answer

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 );
+2
source

Source: https://habr.com/ru/post/1773850/


All Articles